In
computer science
Computer science is the study of computation, information, and automation. Computer science spans Theoretical computer science, theoretical disciplines (such as algorithms, theory of computation, and information theory) to Applied science, ...
, a Boolean expression (also known as logical expression) is an
expression used in
programming language
A programming language is a system of notation for writing computer programs.
Programming languages are described in terms of their Syntax (programming languages), syntax (form) and semantics (computer science), semantics (meaning), usually def ...
s that produces a
Boolean value when evaluated. A Boolean value is either true or false. A Boolean expression may be composed of a combination of the Boolean constants True/False or Yes/No,
Boolean-typed variables, Boolean-valued operators, and
Boolean-valued functions.
Boolean expressions correspond to
propositional formulas in logic and are associated to
Boolean circuit
In computational complexity theory and circuit complexity, a Boolean circuit is a mathematical model for combinational digital logic circuits. A formal language can be decided by a family of Boolean circuits, one circuit for each possible inpu ...
s.
Boolean operators
Most
programming language
A programming language is a system of notation for writing computer programs.
Programming languages are described in terms of their Syntax (programming languages), syntax (form) and semantics (computer science), semantics (meaning), usually def ...
s have the Boolean operators
OR,
AND and
NOT; in
C and some
languages inspired by it, these are represented by ", , " (double pipe character), "&&" (double
ampersand
The ampersand, also known as the and sign, is the logogram , representing the grammatical conjunction, conjunction "and". It originated as a typographic ligature, ligature of the letters of the word (Latin for "and").
Etymology
Tradi ...
) and "!" (
exclamation point) respectively, while the corresponding
bitwise operation
In computer programming, a bitwise operation operates on a bit string, a bit array or a binary numeral (considered as a bit string) at the level of its individual bits. It is a fast and simple action, basic to the higher-level arithmetic operatio ...
s are represented by ", ", "&" and "~" (tilde).
[E.g. for ]Java
Java is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea (a part of Pacific Ocean) to the north. With a population of 156.9 million people (including Madura) in mid 2024, proje ...
see . In the mathematical literature the symbols used are often "+" (
plus), "·" (
dot) and
overbar, or "∨" (
vel), "∧" (
et) and "¬" (
not) or "′" (prime).
Some languages, e.g.,
Perl
Perl is a high-level, general-purpose, interpreted, dynamic programming language. Though Perl is not officially an acronym, there are various backronyms in use, including "Practical Extraction and Reporting Language".
Perl was developed ...
and
Ruby
Ruby is a pinkish-red-to-blood-red-colored gemstone, a variety of the mineral corundum ( aluminium oxide). Ruby is one of the most popular traditional jewelry gems and is very durable. Other varieties of gem-quality corundum are called sapph ...
, have two sets of Boolean operators, with identical functions but different precedence. Typically these languages use and, or and not for the lower precedence operators.
Some programming languages derived from
PL/I
PL/I (Programming Language One, pronounced and sometimes written PL/1) is a procedural, imperative computer programming language initially developed by IBM. It is designed for scientific, engineering, business and system programming. It has b ...
have a bit string type and use BIT(1) rather than a separate Boolean type. In those languages the same operators serve for Boolean operations and bitwise operations. The languages represent OR, AND, NOT and EXCLUSIVE OR by ", ", "&", "¬" (infix) and "¬" (prefix).
Short-circuit operators
Some programming languages, e.g.,
Ada, have
short-circuit Boolean operators. These operators use a
lazy evaluation
In programming language theory, lazy evaluation, or call-by-need, is an evaluation strategy which delays the evaluation of an Expression (computer science), expression until its value is needed (non-strict evaluation) and which avoids repeated eva ...
, that is, if the value of the expression can be determined from the left hand Boolean expression then they do not evaluate the right hand Boolean expression. As a result, there may be
side effects
In medicine, a side effect is an effect of the use of a medicinal drug or other treatment, usually adverse but sometimes beneficial, that is unintended. Herbal and traditional medicines also have side effects.
A drug or procedure usually used ...
that only occur for one value of the left hand operand.
Examples
*The expression is evaluated as .
*The expression is evaluated as .
* and are equivalent Boolean expressions, both of which are evaluated as .
*Of course, most Boolean expressions will contain at least one variable (), and often more ().
See also
*
Expression (computer science)
In computer science, an expression is a Syntax (programming languages), syntactic entity in a programming language that may be evaluated to determine its value (computer science), value. It is a combination of one or more Constant (programming), co ...
*
Expression (mathematics)
In mathematics, an expression is a written arrangement of symbol (mathematics), symbols following the context-dependent, syntax (logic), syntactic conventions of mathematical notation. Symbols can denote numbers, variable (mathematics), variabl ...
*
Boolean function
References
External links
The Calculus of Logic by George Boole, Cambridge and Dublin Mathematical Journal Vol. III (1848), pp. 183–98.
{{DEFAULTSORT:Boolean Expression
Boolean algebra
Operators (programming)