Boolean Operations

Logical Expressions

Mathematica allows to test various logical expressions:
"Equal", or "= ="
"Unequal", abbreviated "!=",
"<", "<=", ">" and ">=",
"Not", "And", "Or", exclusive or: "Xor",
and "Implies" for =>.

6 == 3 + 4

Equal[3 + 4, 7]

6 != 3 + 4

Unequal[3 + 4, 7]

7 < -1

4 <= Sqrt[16]

Not[3 == Sqrt[10]]

And[3 + 4 == 6, 4 == Sqrt[16]]

Or[3 + 4 == 6, 4 == Sqrt[16]]

Xor[3 + 4 == 7, 4 == 2^2]

Implies[False, True]

Implies[True, False]

Questions

Mathematica has various built-in questions; you will learn later to build your own questions.

PrimeQ[3]

IntegerQ[3/4]

IntegerQ[3/1]

EvenQ[4]

OddQ[4]

{NumberQ[3], NumberQ[3.1], NumberQ[π], NumberQ[3 - I]}

(Remember that  π is considered a symbol, not a number.)

{NumericQ[3], NumericQ[3.1], NumericQ[π], NumericQ[3 - I], 
      NumericQ[x]}

\(\(x = Sqrt[2]; 
    
{NumericQ[3], NumericQ[3.1], NumericQ[π], NumericQ[3 - I], 
      NumericQ[x]}
\)\)

VectorQ[1]

VectorQ[{1}]

Example: A Truth Table

\(express[{a_, b_}] := And[a, Not[b]]
\)\(vals = {{True, True}, {True, False}, {False, \ True}, {False, False}}; 
    
vals2 = Map[Function[x, express[x]], vals]; 

    TableForm[Partition[vals2, {2}], 
      TableHeadings
         -> {{StyleForm[\ True, FontWeight -> "Bold"], 
            StyleForm[False, FontWeight -> "Bold"]}, {
            StyleForm[True, FontWeight -> "Bold"], 
            StyleForm[False, FontWeight -> "Bold"]}}]\)

Etc.

Helmut Knaust, email: helmut@math.utep.edu. 
Created 2-22-1999. Last edit: 4-25-1999.