Jump to content

Boolean expression

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by 2600:8801:3507:d700:641e:6700:fda:fac8 (talk) at 22:00, 25 April 2022 (I added some extra detail and also I added what a boolean search is too.). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

I said boolean search not boolean expression you moron.

Boolean operators

Most programming languages 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) and "!" (exclamation point) respectively, while the corresponding bitwise operations are represented by "|", "&" and "~" (tilde).[1] 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 and 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.

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).

Short-circuit operators

Some programming languages, e.g., Ada, have 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 effects that only occur for one value of the left hand operand.

Examples

  • The expression 5 > 3 is evaluated as true.
  • The expression 3 > 5 is evaluated as false.
  • 5>=3 and 3<=5 are equivalent Boolean expressions, both of which are evaluated as true.
  • typeof true and typeof false return boolean
  • Of course, most Boolean expressions will contain at least one variable (X > 3), and often more (X > Y).

See also

References

  1. ^ E.g. for Java see Brogden, William B.; Green, Marcus (2003), Java 2 Programmer, Que Publishing, p. 45, ISBN 9780789728616.
  • The Calculus of Logic, by George Boole, Cambridge and Dublin Mathematical Journal Vol. III (1848), pp. 183–98.