Boolean expression

In computer science, a Boolean expression is an expression used in programming languages 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.[1]

Boolean expressions correspond to propositional formulas in logic and are a special case of Boolean circuits.[2]

Boolean operators

Most programming languages have the Boolean operators OR, AND and NOT; in C and some newer languages, these are represented by "||" (double pipe character), "&&" (double ampersand) and "!" (exclamation point) respectively, while the corresponding bitwise operations are represented by "|", "&" and "~" (tilde).[3] In the mathematical literature the symbols used are often "+" (plus), "·" (dot) and overbar, or "∨" (cup), "∧" (cap) and "¬" or "′" (prime).

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).
gollark: It seems like you're first suggesting that believing false things can be okay if it's emotionally good, but then contradicting that?
gollark: I don't understand what you're saying.
gollark: "A wizard did it" is a more plausible explanation for lightning than several hundred pages of theory on meteorology and electromagnetism.
gollark: Humans are generally wired to see agency in things which don't actually have it.
gollark: The problem is that "people using psychedelics feel god-related things" is entirely consistent with "god(s) exist" and "god(s) don't exist, but drugs can push god-related buttons in the brain".

See also

References

  1. Gries, David; Schneider, Fred B. (1993), "Chapter 2. Boolean Expressions", A Logical Approach to Discrete Math, Monographs in Computer Science, Springer, p. 25ff, ISBN 9780387941158.
  2. van Melkebeek, Dieter (2000), Randomness and Completeness in Computational Complexity, Lecture Notes in Computer Science, 1950, Springer, p. 22, ISBN 9783540414926.
  3. 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.
This article is issued from Wikipedia. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.