6.1.4 Boolean operators: or xor and not
Booleans can be combined to form new booleans. For example, with
and: the statement “boolean 1 and
boolean 2” is true if both boolean 1 and
boolean 2 are true, otherwise the statement is false.
Xcas has the standard boolean operators, as follows (a and
b are two booleans):
-
or (or ||)
-
These are infixed operators.
(a or b) (or (a ||
b)) returns 0 (or false) if a
and b are both equal to 0 (or false) and returns
1 (or true) otherwise.
- xor
-
This is an infixed operator. It is the “exclusive or”
operator, meaning “one or the other but not both”.
(a xor b) returns 1 if a
is equal to 1 and b is equal to 0 or if a is equal
to 0 and b is equal to 1, and returns 0 if a and
b are both equal to 0 or if a and b are
both equal to 1.
- and (or &&)
-
These are infixed operators.
(a and b) (or (a &&
b)) returns 1 (or true) if a
and b are both equal to 1 (or true) and returns
0 (or false) otherwise.
- not
-
This is a prefixed operator.
not(a) returns 1 (or true) if a
is equal to 0 (or false), and 0 (or
false) if a is equal to 1 (or true).
Examples.
-
Input:
1>=0 or 1<0
Output:
- Input:
1>=0 xor 1>0
Output:
- Input:
1>=0 and 1>0
Output:
- Input:
not(0==0)
Output: