HOME

TheInfoList



OR:

In computer science, a Boolean expression is an expression used in
programming language A programming language is a system of notation for writing computer programs. Most programming languages are text-based formal languages, but they may also be graphical. They are a kind of computer language. The description of a programming ...
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 or false, Boolean-typed variables, Boolean-valued operators, and Boolean-valued functions. Boolean expressions correspond to
propositional formula In propositional logic, a propositional formula is a type of syntactic formula which is well formed and has a truth value. If the values of all variables in a propositional formula are given, it determines a unique truth value. A propositional fo ...
s in logic and are a
special case In logic, especially as applied in mathematics, concept is a special case or specialization of concept precisely if every instance of is also an instance of but not vice versa, or equivalently, if is a generalization of . A limiting case i ...
of Boolean circuits.


Boolean operators

Most
programming language A programming language is a system of notation for writing computer programs. Most programming languages are text-based formal languages, but they may also be graphical. They are a kind of computer language. The description of a programming ...
s have the Boolean operators OR,
AND or AND may refer to: Logic, grammar, and computing * Conjunction (grammar), connecting two words, phrases, or clauses * Logical conjunction in mathematical logic, notated as "∧", "⋅", "&", or simple juxtaposition * Bitwise AND, a boolea ...
and NOT; in C and some languages inspired by it, these are represented by ", , " (double pipe character), "&&" (double ampersand) and "!" (
exclamation point The exclamation mark, , or exclamation point (American English), is a punctuation mark usually used after an interjection or exclamation to indicate strong feelings or to show emphasis. The exclamation mark often marks the end of a sentence, f ...
) 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 oper ...
s are represented by ", ", "&" and "~" (tilde).E.g. for
Java Java (; id, Jawa, ; jv, ꦗꦮ; su, ) is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea to the north. With a population of 151.6 million people, Java is the world's most ...
see .
In the mathematical literature the symbols used are often "+" ( plus), "·" ( dot) and
overbar An overline, overscore, or overbar, is a typographical feature of a horizontal line drawn immediately above the text. In old mathematical notation, an overline was called a '' vinculum'', a notation for grouping symbols which is expressed in m ...
, or "∨" (
vel Vel ( ta, வேல், lit=Vēl) is a divine javelin or spear associated with Murugan, the Hindu god of war. Significance According to Shaiva tradition, the goddess Parvati presented the Vel to her son Murugan, as an embodiment of her shakti ...
), "∧" ( et) and "¬" ( not) or "′" (prime). Some languages, e.g.,
Perl Perl is a family of two high-level, general-purpose, interpreted, dynamic programming languages. "Perl" refers to Perl 5, but from 2000 to 2019 it also referred to its redesigned "sister language", Perl 6, before the latter's name was offic ...
and
Ruby A 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 sap ...
, 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 developed and published by IBM. It is designed for scientific, engineering, business and system programming. I ...
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 A short circuit (sometimes abbreviated to short or s/c) is an electrical circuit that allows a current to travel along an unintended path with no or very low electrical impedance. This results in an excessive current flowing through the 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 until its value is needed ( non-strict evaluation) and which also avoids repeated evaluations ( sharing). Th ...
, 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, whether therapeutic or adverse, that is secondary to the one intended; although the term is predominantly employed to describe adverse effects, it can also apply to beneficial, but unintended, consequence ...
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 . *
typeof typeof, alternately also typeOf, and TypeOf, is an operator provided by several programming languages to determine the data type of a variable. This is useful when constructing programs that must accept multiple types of data without explicitly s ...
true
and typeof false return *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 syntactic entity in a programming language that may be evaluated to determine its value. It is a combination of one or more constants, variables, functions, and operators that the programming language i ...
*
Expression (mathematics) In mathematics, an expression or mathematical expression is a finite combination of symbols that is well-formed according to rules that depend on the context. Mathematical symbols can designate numbers ( constants), variables, operations, ...
* 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)