Movatterモバイル変換


[0]ホーム

URL:


Jump to content
WikipediaThe Free Encyclopedia
Search

Boolean expression

From Wikipedia, the free encyclopedia
Expression in a computer program

Incomputer science, aBoolean expression (also known aslogical expression) is anexpression used inprogramming languages that produces aBoolean value when evaluated. A Boolean value is eithertrue orfalse. A Boolean expression may be composed of a combination of the Boolean constantsTrue/False orYes/No,Boolean-typed variables, Boolean-valued operators, andBoolean-valued functions.[1]

Boolean expressions correspond topropositional formulas in logic and are associated toBoolean circuits.[2]

Boolean operators

[edit]

Mostprogramming languages have the Boolean operatorsOR,AND andNOT; inC and somelanguages inspired by it, these are represented by "||" (double pipe character), "&&" (doubleampersand) and "!" (exclamation point) respectively, while the correspondingbitwise operations are represented by "|", "&" and "~" (tilde).[3] In the mathematical literature the symbols used are often "+" (plus), "·" (dot) andoverbar, or "∨" (vel), "∧" (et) and "¬" (not) or "′" (prime).

Some languages, e.g.,Perl andRuby, have two sets of Boolean operators, with identical functions but different precedence. Typically these languages useand,or andnot for the lower precedence operators.

Some programming languages derived fromPL/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

[edit]
Main article:Short-circuit evaluation

Some programming languages, e.g.,Ada, haveshort-circuit Boolean operators. These operators use alazy 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 beside effects that only occur for one value of the left hand operand.

Examples

[edit]
  • The expression5 > 3 is evaluated astrue.
  • The expression3 > 5 is evaluated asfalse.
  • 5>=3 and3<=5 are equivalent Boolean expressions, both of which are evaluated astrue.
  • Of course, most Boolean expressions will contain at least one variable (X > 3), and often more (X > Y).

See also

[edit]

References

[edit]
  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, vol. 1950, Springer, p. 22,ISBN 9783540414926.
  3. ^E.g. forJava seeBrogden, William B.; Green, Marcus (2003),Java 2 Programmer, Que Publishing, p. 45,ISBN 9780789728616.

External links

[edit]
  • The Calculus of Logic, by George Boole, Cambridge and Dublin Mathematical Journal Vol. III (1848), pp. 183–98.
Retrieved from "https://en.wikipedia.org/w/index.php?title=Boolean_expression&oldid=1305785994"
Categories:
Hidden categories:

[8]ページ先頭

©2009-2026 Movatter.jp