Boolean expression: Difference between revisions

Content deleted Content added
m Reverting possible vandalism by 62.49.24.124 to version by Solomon7968. Report False Positive? Thanks, ClueBot NG. (2344330) (Bot)
m Reverted edits by 60.48.39.68 (talk) (AV)
 
(48 intermediate revisions by 41 users not shown)
Line 1:
{{Short description|Expression in a computer program}}
In [[computer science]], a '''Boolean expression''' (also known as '''logical expression''') is an [[Expression (programming)|expression]] used in a [[programming language]]s that produces a [[Boolean value]] when evaluated, i.e. oneA ofBoolean value is either '''true''' or '''false'''. A Boolean expression may be composed of a combination of the Boolean constants '''trueTrue/False''' or '''falseYes/No''', [[Boolean data type|Boolean-typed]] variables, Boolean-valued operators, and [[Boolean-valued function]]s.<ref>{{citation
| last1 = Gries | first1 = David | author1-link = David Gries
| last2 = Schneider | first2 = Fred B. | author2-link = Fred B. Schneider
Line 8 ⟶ 9:
| series = Monographs in Computer Science
| title = A Logical Approach to Discrete Math
| url = httphttps://books.google.com/books?id=ZWTDQ6H6gsUC&pg=PA25
| year = 1993}}.</ref>
 
Boolean expressions correspond to [[propositional formula]]s in logic and are aassociated special case ofto [[Boolean circuit]]s.<ref>{{citation
| last = van Melkebeek | first = Dieter
| isbn = 9783540414926
Line 18 ⟶ 19:
| series = [[Lecture Notes in Computer Science]]
| title = Randomness and Completeness in Computational Complexity
| url = httphttps://books.google.com/books?id=-S0zCjOAIVwC&pg=PA22
| volume = 1950
| year = 2000}}.</ref>
 
==Boolean operators==
Most [[programming language]]s have the Boolean operators [[Logical disjunction|OR]], [[Logical conjunction|AND]] and [[Negation|''not''NOT]]; in [[C (programming language)|C]] and some newer[[List of C-family programming languages|languages inspired by it]], these are represented by "||" (double pipe character), "&&" (double [[ampersand]]) and "!" ([[Exclamation mark|exclamation point]]) respectively, while the corresponding [[bitwise operation]]s are represented by "|", "&" and "~" (tilde).<ref>E.g. for [[Java (programming language)|Java]] see {{citation
| last1 = Brogden | first1 = William B.
| last2 = Green | first2 = Marcus
Line 30 ⟶ 31:
| publisher = Que Publishing
| title = Java 2 Programmer
| url = httphttps://books.google.com/books?id=24nPZw9Wsf4C&pg=PA45
| year = 2003}}.</ref> In the mathematical literature the symbols used are often "+" ([[Plus sign|plus]]), "'''·'''" ([[Full stop|dot]]) and [[overbar]], or "∨" (cup[[Descending_wedge|vel]]), "∧" (cap[[Wedge_(symbol)|et]]) and "¬" ([[Negation|not]]) or "′" (prime).
 
Some languages, e.g., [[Perl]] and [[Ruby (programming language)|Ruby]], 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.
==Examples==
 
Some programming languages derived from [[PL/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).
*The expression "5 > 3" is evaluated as '''true'''.
 
===Short-circuit operators===
*"5>=3" and "3<=5" are equivalent Boolean expressions, both of which are evaluated as '''true'''.
{{Main|Short-circuit evaluation}}
Some programming languages, e.g., [[Ada (programming language)|Ada]], have [[Short-circuit evaluation|short-circuit]] Boolean operators. These operators use a [[lazy evaluation]], 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 effect (computer science)|side effects]] that only occur for one value of the left hand operand.
 
==Examples==
 
*The expression "{{code|5 > 3"}} is evaluated as '''{{samp|true'''}}.
*Of course, most Boolean expressions will contain at least one variable (X > 3), and often more (X > Y).
*The expression {{code|3 > 5}} is evaluated as {{samp|false}}.
*"{{code|1=5>=3"}} and "{{code|1=3<=5"}} are equivalent Boolean expressions, both of which are evaluated as '''{{samp|true'''}}.
*Of course, most Boolean expressions will contain at least one variable ({{code|X > 3}}), and often more ({{code|X > Y}}).
 
==See also==
*[[Expression (programmingcomputer science)]]
*[[Expression (mathematics)]]
*[[Boolean function]]
 
==References==
{{reflist}}
==External links==
*[http://www.maths.tcd.ie/pub/HistMath/People/Boole/CalcLogic/CalcLogic.html The Calculus of Logic], by George Boole, Cambridge and Dublin Mathematical Journal Vol. III (1848), pp.&nbsp;183–98.