Logical expressions
A logical expression is a combination of boolean values or expressions (relational or logical ones) and logical operators.The logical operators are: and, or, not.
and
or not |
intersection union negation |
Logical and
The "and" expression returns true if the two terms are true, false
otherwise.
Example of logical and: | boolean
x = true boolean y = false if x and y print "true" else print "false" /if |
Displays: | > true |
Logical or
An "or" expression returns true if one of the two terms is true, false
if the two ones are false.
Exemple de ou logique | boolean
x = true boolean y = false if x or y print "true" else print "false" /if |
Displays: | > false |
Logical not
If we add the "not" operator on the whole expression, it negates the
final result, thus: not(x or y) returns false.
Example of logical not | boolean
x = true boolean y = false if not (x or y) print "vrai" else print "false" /if |
Displays: | > false |
If we associate "not" to one of the terms, it negates this term: x and not y as x is true, and y is false, thus not y is true the whole return true.
Example or unary not | boolean
x = true boolean y = false if x and not y print "true" else print "false" /if |
Displays: | > false |
Implication
There is not keyword for the 'implication but it may be writtent with
other keywords:
a implicates b is written:
not (a and not b)
Exercises |
1) To compose assortments of 3 chalks, a producer follows there
rules. |