Debian Codegraph @

doc/citp-manual/peano.cafe

raw
1 **
2 ** Prove associativity and commutativity of addition
3 ** using CITP for CafeOBJ
4 **
5
6 mod! PNAT {
7 [ PZero PNzNat < PNat ]
8 op 0 : -> PZero {ctor} .
9 op s_ : PNat -> PNzNat {ctor} .
10 op _+_ : PNat PNat -> PNat .
11 eq 0 + N:PNat = N .
12 eq s M:PNat + N:PNat = s(M + N) .
13 }
14
15 select PNAT .
16 :goal { eq [lemma-1]: M:PNat + 0 = M:PNat .
17 eq [lemma-2]: M:PNat + s N:PNat = s(M:PNat + N:PNat). }
18
19 :ind on (M:PNat)
20
21 **> We want to see every goal generated in proof process.
22 :verbose on
23 **> We do the proof by 'auto'
24 :auto
25
26 **> :show proof shows the current proof tree .
27 **> at this time, all goals should have been proved.
28 :show proof
29
30 ** Proof of commuativity and associativity of _+_
31
32 mod! PNAT-L {
33 inc(PNAT)
34 -- we have already prooved these.
35 eq [lemma-1]: N:PNat + 0 = N .
36 eq [lemma-2]: M:PNat + s N:PNat = s(M + N).
37 }
38
39 open PNAT-L .
40 :goal { eq M:PNat + N:PNat = N:PNat + M:PNat . }
41 --> induction on variable M:PNat
42 :ind on (M:PNat)
43 --> :apply (si)
44 :apply (SI)
45 --> :show proof should shows base case and induction step
46 :show proof
47 --> :apply (tc)
48 :verbose off
49 :apply (TC)
50 --> :apply (rd)
51 :apply (RD)
52 --> :show proof
53 :show proof
54 --> rest :apply (tc rd)
55 :apply (TC RD)
56 --> done for all
57 :show proof
58 **> we redo the same proof by one :apply
59 :apply to root (SI TC RD)
60 **> the above is equvalent to the followings
61 --> select root
62 :select root
63 :apply (SI TC RD)
64
65 ** associativity
66 --> use :auto
67 :goal {eq (M:PNat + N:PNat) + P:PNat = N:PNat + (M:PNat + P:PNat) . }
68 :ind on (M:PNat)
69 :auto
70 :show proof
71 eof
72
73
74
75
76