14. Logical Connectives

Predicates can be combined into compound predicates using combining words called logical connectives. In this section, we consider “and”, “or” and “not”.

14.1 Definition: “and”

If $P$ and $Q$ are predicates, then $P \wedge Q$ (“$P$ and $Q$”) is also a predicate, and it is true precisely when both $P$ and $Q$ are true.

14.1.1 Worked Exercise Let $n$ be an integer variable and let $P (n)$ be the predicate ($n >3$ and $n$ is even). State whether $P(2)$, $P(6)$ and $P(7)$ are true.

Answer $P(2)$ is false, $P(6)$ is true and $P(7)$ is false.

14.1.2 Usage

a) A predicate of the form “$P \wedge Q$” is called a conjunction.

b) Another notation for $P \wedge Q$ is “$P Q$”. In Mathematica, “$P \wedge Q$” is written P && Q.

14.2 Definition: “or”

$P \vee Q$ (“$P$ or $Q$”) is a predicate which is true when at least one of $P$ and $Q$ is true.

14.2.1 Usage

a) A compound predicate of the form $P \vee Q$ is called a disjunction.

b) Often “$P +Q$” is used for “$P \vee Q$”. In Mathematica, it is written P || Q.

14.2.2 Example If $P$ is “$4\geq 2$” and $Q$ is “$25\leq -2$”, then “$P \wedge Q$” is false but “$P \vee Q$” is true.

14.2.3 Exercise For each predicate $P (n)$ given, state whether these propositions are true: $P(2)$, $P(6)$, $P(7)$.

a) ($n >3$ or $n$ is even)

b) ($n|6$ or $6|n$)

c) $n$ is prime or $(n|6)$

(Answer on page 243.)

14.2.4 Exercise For each predicate give (if possible) an integer $n$ for which the predicate is true and another integer for which it is false.

a) $(n + 1 =n )\vee (n= 5)$.

b) $(n > 7)\vee (n <4)$.

c) $(n > 7)\wedge (n <4)$.

d) $(n < 7)\vee (n >4)$.

(Answer on page 243.)

14.2.5 Exercise Which of the predicates in Problem 14.2.4 are universally true for integers? (Answer on page 243.)

14.3 Truth tables

The definitions of the symbols ‘$\wedge$’ and ‘$\vee$’ can be summarized in truth tables:

$$\begin{array}{ccc c ccc} P & Q & P\wedge Q & \quad & P & Q & P\vee Q \\ \cline{1-3}\cline{5-7} \text{T} & \text{T} & \text{T} & & \text{T} & \text{T} & \text{T} \\ \text{T} & \text{F} & \text{F} & & \text{T} & \text{F} & \text{T} \\ \text{F} & \text{T} & \text{F} & & \text{F} & \text{T} & \text{T} \\ \text{F} & \text{F} & \text{F} & & \text{F} & \text{F} & \text{F} \end{array}$$

14.3.1 Remark As the table shows, the definition of ‘$\vee$’ requires that $P \vee Q$ be true if either or both of $P$ and $Q$ are true; in other words, this is “or” in the sense of “and/or”. This meaning of “or” is called “inclusive or”.

14.3.2 Usage In computer science, “1” is often used for “true” and “0” for “false”.

14.4 Definition: “xor”

If $P$ and $Q$ are predicates, the compound predicate $P$ XOR $Q$ is true if exactly one of $P$ and $Q$ is true.

14.4.1 Fact The truth table of XOR is

$$\begin{array}{ccc} P & Q & P\ \text{XOR}\ Q \\ \hline \text{T} & \text{T} & \text{F} \\ \text{T} & \text{F} & \text{T} \\ \text{F} & \text{T} & \text{T} \\ \text{F} & \text{F} & \text{F} \end{array}$$

14.4.2 Usage

a) XOR in Mathematica is Xor. $P$ XOR $Q$ may be written either P ~Xor~ Q or Xor[P,Q].

b) In mathematical writing, “or” normally denotes the inclusive or, so that a statement like, “Either a number is bigger than 2 or it is smaller than 4” is considered correct. The writer might take pity on the reader and add the phrase, “or both”, but she is not obliged to.

14.4.3 Worked Exercise Which of the following sentences say the same thing? In each sentence, $n$ is an integer.

a) Either $n$ is even or it is positive.

b) $n$ is even or positive or both.

c) $n$ is both even and positive.

Answer (a) and (b) say the same thing. (c) is not true of 7, for example, but (a) and (b) are true of 7.

14.5 Definition: “not”

The symbol ‘$\neg P$’ denotes the negation of the predicate $P$.

14.5.1 Example For real numbers $x$ and $y, \neg (x < y)$ means the same thing as $x \geq y$.

14.5.2 Fact Negation has the very simple truth table

$$\begin{array}{cc} P & \neg P \\ \hline \text{T} & \text{F} \\ \text{F} & \text{T} \end{array}$$

14.5.3 Usage

a) Other notations for $\neg P$ are $\overline{P}$ and $\sim P$.

b) The symbol in Mathematica for “not” is !, the exclamation point. $\neg P$ is written !P.

c) The symbol ‘$\neg$’ always applies to the first predicate after it only. Thus in the expression $\neg P \vee Q$, only $P$ is negated. To negate the whole expression $P \vee Q$ you have to write “$\neg (P \vee Q)$”.

14.5.4 Warning Negating a predicate is not (usually) the same thing as stating its opposite. If $P$ is the statement “$3>2$”, then $\neg P$ is “3 is not greater than 2”, rather than “$3<2$”. Of course, $\neg P$ can be reworded as “$3\leq 2$”.

14.5.5 Example Writing the negation of a statement in English can be surprisingly subtle. For example, consider the (false) statement that 2 divides every integer. The negation of this statement is true; one way of wording it is that there is some integer which is not divisible by 2. In particular, the statement, “All integers are not divisible by 2” is not the negation of the statement that 2 divides every integer.

We will look at this sort of problem more closely in Section 77.

14.6 Truth Tables in Mathematica

The dmfuncs.m package has a command TruthTable that produces the truth table of a given Mathematica logical expression. For example, if you define the expression

e = a && (b || !c)

then TruthTable[e] produces

a b c  a && (b || !c)
T T T          T
T T F          T
T F T          F
T F F          T
F T T          F
F T F          F
F F T          F
F F F          F

Pages 21–23 of the book (PDF).