SE 500 (Math for SE)
Sample proof of 2-cent, 5-cent problem in Gries & Schneider (pp. 220-221)

Prove by induction that any amount greater than 3 cents can be obtained using 2-cent and 5-cent coins.

Solution: Let P.n : (x,y:ℕ |: 2x + 5y = n). We show (informally) that P.n holds for all n > 3, using induction on n.

Base Case: n=4. Taking x' = 2 and y' = 0, we have 2x' + 5y' = 4, which shows that P.4 holds. More formally, we have

      P.4

    =    < defn of P >

      (∃x,y |: 2x + 5y = 4)

   <==   < (9.28), ∃-Introduction, P:=2x+5y=4, x:=x,y, E:=2,0 >

      (2x + 5y = 4)[x,y := 2,0]

    =    < textual substitution >

      2×2 + 5×0  =  4

    =    < arithmetic >
 
      true

Thus, P.4 <== true, which by (3.58) and then (3.73) allows us to conclude P.4.

Here is an alternative proof that uses Range weakening/strengthening (9.25) instead of (9.28):

      P.4

    =    < defn of P >

      (∃x,y |: 2x + 5y = 4)

   <==   < (3.29), (9.25), P:=2x+5y=4, x:=x,y, E:=2,0, R:=true, Q:=x=2 ∧ y=0 >

      (∃x,y | x=2 ∧ y=0 : 2x + 5y = 4)

    =    < (8.20) Nesting >

      (∃x | x=2 : (∃y | y=0 : 2x + 5y = 4))

    =    < (8.14) One-point rule, arithmetic >

      (∃x | x=2 : 2x = 4))

    =    < (8.14) One-point rule, arithmetic >

      4 = 4

    =    < = is reflexive >

      true

Inductive Case: Let n≥4. As an IH (i.e., induction hypothesis), assume P.4 ∧ P.5 ∧ ... ∧ P.n. It turns out (as frequently happens) that we can prove P(n+1) using (only) P.n as an assumption. Let x' and y' be natural numbers such that 2x' + 5y' = n. (From the assumption P.n, we conclude that x' and y' exist.)

Case y' > 0: (i.e., at least one 5-cent coin is in the collection of coins that makes n cents). We take x = x' + 3 and y = y' - 1. (That is, we add three 2-cent coins and remove one 5-cent coin.) We have

        2x + 5y

      =    < x = x' + 3,  y = y' - 1 >

        2(x' + 3) + 5(y' - 1)

      =    < algebra >

        2x' + 6  +  5y' - 5

      =    < arithmetic >

        2x' + 5y' + 1

      =    < assumption 2x' + 5y' = n >

        n+1 

Thus, we have shown (assuming 2x' + 5y' = n, where x'≥0 ∧ y' > 0) that P(n+1) holds (i.e., that there exist x and y satisfying x≥0 ∧ y≥0 such that 2x + 5y = n+1).

Note that we would not have been justified in taking y = y' - 1 had we not been considering only the case in which y'>0. This explains the need for considering Case y'>0 (which we just did) and Case y'=0 (which we do below).

Case y' = 0: (i.e., no 5-cent coin is in the collection of coins that makes n cents). Substituting 0 for y' in 2x' + 5y' = n, we get 2x' = n. Since n≥4, it must be that x'≥2. We take x = x' - 2 and y = y' + 1. (That is, we remove two 2-cent coins and add one 5-cent coin.)

        2x + 5y

      =    < x = x' - 2,  y = y' + 1 >

        2(x' - 2) + 5(y' + 1)

      =    < algebra >

        2x' - 4  +  5y' +  5

      =    < arithmetic >

        2x' + 5y' + 1

      =    < assumption 2x' + 5y' = n >

        n+1

Let us repeat the inductive step with a little more formality. Recall that the goal of that step is to prove

(P.4 ∧ P.5 ∧ ... ∧ P.n) ==> P(n+1)

for an arbitrary n≥4. By (3.82a) (taking p:= P.4 ∧ P.5 ∧ ... ∧ P.n, q:= P.n, and r:= P(n+1)), it suffices to prove P.n ==> P(n+1), which is what we shall do.

Recall that P.n : (x,y:ℕ |: 2x + 5y = n). By Metatheorem Witness (9.30), then, to prove P.n ⇒ P(n+1) it suffices to prove

(2x' + 5y' = n)  ==>  P(n+1)

Appealing to Case analysis (4.6), we consider two cases: y'>0 and y'=0.

Case y'>0: Assuming the antecedant (2x' + 5y' = n), we prove the consequent:

        P(n+1)

      =    < defn of P >

        (∃x,y:ℕ |: 2x + 5y = n+1)

     <==   < (9.28), ∃-introduction, P:=2x+5y = n+1, x:=x,y, E:=x'+3,y'-1 >

        2(x'+3) + 5(y'-1)  =  n+1

      =    < algebra >

        2x' + 6 + 5y' - 5  =  n+1

      =    < arithmetic, assumption 2x' + 5y' = n >

        n+1 = n+1

      =    < = is reflexive >

        true

Note that, because y is of type ℕ (natural number), the instantiation y:=y'-1 in the application of (9.28) is justified only if y'>0, which is, indeed, the case we were considering.

Case y'=0: Assuming the antecedant (2x' + 5y' = n), we prove the consequent:

        P(n+1)

      =    < defn of P >

        (∃x,y:ℕ |: 2x + 5y = n+1)

     <==   < (9.28), ∃-introduction, P:=2x+5y = n+1, x:=x,y, E:=x'-2,y'+1 >

        2(x'-2) + 5(y'+1)  =  n+1

      =    < algebra >

        2x' - 4 + 5y' + 5  =  n+1

      =    < arithmetic, assumption 2x' + 5y' = n >

        n+1 = n+1

      =    < = is reflexive >

        true 

But wait! Is our instantiation x:=x'-2 in the application of (9.28) justified? To be so, we must have x'≥2, or else x would not be being instantiated to a natural number. Hence, to verify that our above proof is valid, we should show that the assumptions 2x' + 5y' = n (the assumed antecedant), n≥4 (we are proving P.n ==> P(n+1) for n≥4), and y'=0 (the case we are considering), implies x'≥2.

        2x' + 5y' = n  ∧  n ≥ 4  ∧ y'=0

     ==>   < 3.84a, 3.76b >

        2x' + 5*0 = n  ∧  n ≥ 4

      =    < arithmetic >

        2x' = n  ∧  n ≥ 4 

     ==>   < = and ≥ are transitive >

        2x' ≥ 4

      =    < algebra >

        x' ≥ 2