# CMPSCI 250 Discussion #3: Practicing Proofs

#### 26 September 2007

In this discussion we applied our proof methods, for both the propositional and predicate calculi, to prove some statements about numbers and strings.

First, recall the definitions of a string over a fixed alphabet, the concatenation of two strings, and the reversal wR of a string w (which is w written backwards). We will assume the following two facts, which we aren't prepared to prove yet:

• Fact I: ∀w: (wR)R = w
• Fact II: ∀u:∀v: (uv)R = vRuR

A palindrome is a string w such that wR = 2. Examples the empty string λ, "hannah", and a statement attributed to Napoleon, "Able was I ere I saw Elba", which is a palindrome as long as we ignore capitalization. We'll write Pal(w) to mean "w is a palindrome".

One string is a prefix of another if you can make the second by concatenating some string onto the first -- using quantifiers:

Pre(u,v) ↔ ∃w:(uw=v)

#### Writing Exercises:

1. We begin by using the quantifier rules to prove some statements about natural numbers as in Discussion #1. We define Even(x) to mean ∃y: x = 2y and Odd(x) to mean ∃y: x = 2y+1. Prove:

∀x:forall;y: [Odd(x) ∧ Odd(y)] → [Even(x+y) ∧ Odd(xy)]

Since we want to prove a universal statement, we start by letting a and b we arbitrary naturals. We assume Odd(a) and Odd(b) to start a direct proof of the implication [Odd(a) ∧ Odd(b)] → [Even(a+b) ∧ Odd(ab)].

By the definition of Odd, we have ∃c:a = 2c+1 and ∃d: b = 2d+1. By Instantiation, let c and d be naturals such that a = 2c+1 and b = 2d+1. By arithmetic, a+b = 2c + 2d + 2 = 2(c+d+1). By Existence, letting e = c+d+1, we get that ∃e: a+b = 2e which is the definition of Even(a+b). By more arithmetic, ab = (2c+1)(2d+1) = 4cd + 2c + 2d + 1 = 2(2cd+c+d) + 1. Using Existence with f = 2cd+c+d, we have ∃f: ab = 2f+1 which is the definition of Odd(ab).

Assuming Odd(a) ∧ Odd(b), we have proved Even(a+b) ∧ Odd(ab), so we have proved the desired implication by direct proof.

Since a and b were arbitrary, by Generalization we may conclude ∀x:∀y:[Odd(x) ∧ Odd(y)] → [Even(x+y) ∧ Odd(ab)].

2. Now using the Pal and Pre predicates defined above, prove

∀x:∃y: Pre(x,y) ∧ Pal(y)

1. Let a be an arbitrary string.
2. Let b be aaR. (Note: This is the creative step -- we have to convince ourselves that this is the string we want.)
3. Letting c be aR, note that ac = b and hence ∃c: ac = b by Existence.
4. By the definition of Pre, we have that Pre(a,b).
5. Since (aaR)R = (aR)RaR by Fact II which equals aaR by Fact I, we know that Pal(aaR) and hence Pal(b).
6. Using Existence on b, we have that ∃y:Pre(a,y) ∧ Pal(y).
7. Since a was arbitrary, by Generalization we have ∀x:∃y: Pre(x,y) ∧ Pal(y).
3. Prove ∃u:∀v:∃w: (v = (uw)R), where again all variables denote strings.

This one is tricky in that the first step of the formal proof requires us to decide what u is going to be. But note that u is going to have the property that for any v, we can find a w to make v = (uw)R true. If v happens to be empty, uw will have to be empty and thus u will have to be empty.

1. We need to prove ∀v:∃w: v = (λw)R.
2. Let v be arbitrary.
3. Let w be vR. Note that λw = w.
4. By Fact I, wR = (vR)R = v.
5. By Existence, we have that ∃w: v = (λw)R.
6. Since v was arbitrary, we have that ∀v:∃w: v = (λw)R.
7. By Existence, letting u be λ, we have ∃u:∀v:∃w: v = (uw)R, as desired.
4. Prove that Pre is a partial order on the set of all strings. To prove antisymmetry, use the fact that every string w has a length |w|, the fact that |uv| = |u| + |v|, and arithmetic on naturals.

• Pre is reflexive: We must prove ∀x: Pre(x,x). Because x = xλ, by Existence we have ∃w: xw = x, which is the definition of Pre(x,x).
• Pre is antisymmetric: We must prove ∀u:∀v:[Pre(u,v) ∧ Pre(v,u)] → (u=v). Let u and v be arbitrary strings and assume Pre(u,v) and Pre(v,u). By Instantiation on the definitions of Pre(u,v) and Pre(v,u), let w and x be strings such that uw = v and vx = w. By the given rules about lengths, |v| = |uw| = |u| + |w| and |u| = |vx| = |v| + |x|. Since |w| and |x| are naturals and cannot be negative, we must have |w| = |x| = 0 so that w = x = λ. But then u = uλ = v. We have proved that [Pre(u,v) ∧ Pre(v,u)] → (u=v), and since u and v were arbitrary we have proved antisymmetry.
• Pre is transitive: We must prove ∀u:∀v:∀w: [Pre(u,v) ∧ Pre(v,w)] → Pre(u,w). So let u, v, and w be arbitrary strings and assume Pre(u,v) and Pre(v,w). By Instantiation on the definition of Pre, let x and y be strings such that ux = v and vy = w. Then by substitution, w = vy = (ux)y. Letting z = xy, we have w = uz and hence ∃z: uz = w by Existence. This is the definition of Pre(u,w). We have proved the desired implication by direct proof, and since u, v, and w were arbitrary we can conclude the quantified statement by Generalization.