1459
|
1 |
(* Title: FOL/ex/nat2.ML
|
0
|
2 |
ID: $Id$
|
1459
|
3 |
Author: Tobias Nipkow
|
0
|
4 |
Copyright 1991 University of Cambridge
|
|
5 |
|
|
6 |
For ex/nat.thy.
|
|
7 |
Examples of simplification and induction on the natural numbers
|
|
8 |
*)
|
|
9 |
|
|
10 |
open Nat2;
|
|
11 |
|
2469
|
12 |
Addsimps [pred_0, pred_succ, plus_0, plus_succ,
|
|
13 |
nat_distinct1, nat_distinct2, succ_inject,
|
|
14 |
leq_0, leq_succ_succ, leq_succ_0,
|
|
15 |
lt_0_succ, lt_succ_succ, lt_0];
|
0
|
16 |
|
|
17 |
|
|
18 |
val prems = goal Nat2.thy
|
|
19 |
"[| P(0); !!x. P(succ(x)) |] ==> All(P)";
|
|
20 |
by (rtac nat_ind 1);
|
|
21 |
by (REPEAT (resolve_tac (prems@[allI,impI]) 1));
|
725
|
22 |
qed "nat_exh";
|
0
|
23 |
|
5050
|
24 |
Goal "~ n=succ(n)";
|
2469
|
25 |
by (IND_TAC nat_ind Simp_tac "n" 1);
|
0
|
26 |
result();
|
|
27 |
|
5050
|
28 |
Goal "~ succ(n)=n";
|
2469
|
29 |
by (IND_TAC nat_ind Simp_tac "n" 1);
|
0
|
30 |
result();
|
|
31 |
|
5050
|
32 |
Goal "~ succ(succ(n))=n";
|
2469
|
33 |
by (IND_TAC nat_ind Simp_tac "n" 1);
|
0
|
34 |
result();
|
|
35 |
|
5050
|
36 |
Goal "~ n=succ(succ(n))";
|
2469
|
37 |
by (IND_TAC nat_ind Simp_tac "n" 1);
|
0
|
38 |
result();
|
|
39 |
|
5050
|
40 |
Goal "m+0 = m";
|
2469
|
41 |
by (IND_TAC nat_ind Simp_tac "m" 1);
|
725
|
42 |
qed "plus_0_right";
|
0
|
43 |
|
5050
|
44 |
Goal "m+succ(n) = succ(m+n)";
|
2469
|
45 |
by (IND_TAC nat_ind Simp_tac "m" 1);
|
725
|
46 |
qed "plus_succ_right";
|
0
|
47 |
|
2469
|
48 |
Addsimps [plus_0_right, plus_succ_right];
|
|
49 |
|
5050
|
50 |
Goal "~n=0 --> m+pred(n) = pred(m+n)";
|
2469
|
51 |
by (IND_TAC nat_ind Simp_tac "n" 1);
|
0
|
52 |
result();
|
|
53 |
|
5050
|
54 |
Goal "~n=0 --> succ(pred(n))=n";
|
2469
|
55 |
by (IND_TAC nat_ind Simp_tac "n" 1);
|
0
|
56 |
result();
|
|
57 |
|
5050
|
58 |
Goal "m+n=0 <-> m=0 & n=0";
|
2469
|
59 |
by (IND_TAC nat_ind Simp_tac "m" 1);
|
0
|
60 |
result();
|
|
61 |
|
5050
|
62 |
Goal "m <= n --> m <= succ(n)";
|
2469
|
63 |
by (IND_TAC nat_ind Simp_tac "m" 1);
|
0
|
64 |
by (rtac (impI RS allI) 1);
|
2469
|
65 |
by (ALL_IND_TAC nat_ind Simp_tac 1);
|
|
66 |
by (Fast_tac 1);
|
|
67 |
bind_thm("le_imp_le_succ", result() RS mp);
|
0
|
68 |
|
5050
|
69 |
Goal "n<succ(n)";
|
2469
|
70 |
by (IND_TAC nat_ind Simp_tac "n" 1);
|
0
|
71 |
result();
|
|
72 |
|
5050
|
73 |
Goal "~ n<n";
|
2469
|
74 |
by (IND_TAC nat_ind Simp_tac "n" 1);
|
0
|
75 |
result();
|
|
76 |
|
5050
|
77 |
Goal "m < n --> m < succ(n)";
|
2469
|
78 |
by (IND_TAC nat_ind Simp_tac "m" 1);
|
0
|
79 |
by (rtac (impI RS allI) 1);
|
2469
|
80 |
by (ALL_IND_TAC nat_ind Simp_tac 1);
|
|
81 |
by (Fast_tac 1);
|
0
|
82 |
result();
|
|
83 |
|
5050
|
84 |
Goal "m <= n --> m <= n+k";
|
4091
|
85 |
by (IND_TAC nat_ind (simp_tac (simpset() addsimps [le_imp_le_succ]))
|
0
|
86 |
"k" 1);
|
755
|
87 |
qed "le_plus";
|
0
|
88 |
|
5050
|
89 |
Goal "succ(m) <= n --> m <= n";
|
0
|
90 |
by (res_inst_tac [("x","n")]spec 1);
|
4091
|
91 |
by (ALL_IND_TAC nat_exh (simp_tac (simpset() addsimps [le_imp_le_succ])) 1);
|
755
|
92 |
qed "succ_le";
|
0
|
93 |
|
5050
|
94 |
Goal "~m<n <-> n<=m";
|
2469
|
95 |
by (IND_TAC nat_ind Simp_tac "n" 1);
|
0
|
96 |
by (rtac (impI RS allI) 1);
|
2469
|
97 |
by (ALL_IND_TAC nat_ind Asm_simp_tac 1);
|
725
|
98 |
qed "not_less";
|
0
|
99 |
|
5050
|
100 |
Goal "n<=m --> ~m<n";
|
4091
|
101 |
by (simp_tac (simpset() addsimps [not_less]) 1);
|
755
|
102 |
qed "le_imp_not_less";
|
0
|
103 |
|
5050
|
104 |
Goal "m<n --> ~n<=m";
|
2469
|
105 |
by (cut_facts_tac [not_less] 1 THEN Fast_tac 1);
|
755
|
106 |
qed "not_le";
|
0
|
107 |
|
5050
|
108 |
Goal "m+k<=n --> m<=n";
|
0
|
109 |
by (IND_TAC nat_ind (K all_tac) "k" 1);
|
2469
|
110 |
by (Simp_tac 1);
|
0
|
111 |
by (rtac (impI RS allI) 1);
|
2469
|
112 |
by (Simp_tac 1);
|
0
|
113 |
by (REPEAT (resolve_tac [allI,impI] 1));
|
|
114 |
by (cut_facts_tac [succ_le] 1);
|
2469
|
115 |
by (Fast_tac 1);
|
755
|
116 |
qed "plus_le";
|
0
|
117 |
|
|
118 |
val prems = goal Nat2.thy "[| ~m=0; m <= n |] ==> ~n=0";
|
|
119 |
by (cut_facts_tac prems 1);
|
|
120 |
by (REPEAT (etac rev_mp 1));
|
2469
|
121 |
by (IND_TAC nat_exh Simp_tac "m" 1);
|
|
122 |
by (ALL_IND_TAC nat_exh Simp_tac 1);
|
755
|
123 |
qed "not0";
|
0
|
124 |
|
5050
|
125 |
Goal "a<=a' & b<=b' --> a+b<=a'+b'";
|
4091
|
126 |
by (IND_TAC nat_ind (simp_tac (simpset() addsimps [le_plus])) "b" 1);
|
0
|
127 |
by (resolve_tac [impI RS allI] 1);
|
|
128 |
by (resolve_tac [allI RS allI] 1);
|
2469
|
129 |
by (ALL_IND_TAC nat_exh Asm_simp_tac 1);
|
755
|
130 |
qed "plus_le_plus";
|
0
|
131 |
|
5050
|
132 |
Goal "i<=j --> j<=k --> i<=k";
|
0
|
133 |
by (IND_TAC nat_ind (K all_tac) "i" 1);
|
2469
|
134 |
by (Simp_tac 1);
|
0
|
135 |
by (resolve_tac [impI RS allI] 1);
|
2469
|
136 |
by (ALL_IND_TAC nat_exh Simp_tac 1);
|
4423
|
137 |
by (rtac impI 1);
|
2469
|
138 |
by (ALL_IND_TAC nat_exh Simp_tac 1);
|
|
139 |
by (Fast_tac 1);
|
755
|
140 |
qed "le_trans";
|
0
|
141 |
|
5050
|
142 |
Goal "i < j --> j <=k --> i < k";
|
0
|
143 |
by (IND_TAC nat_ind (K all_tac) "j" 1);
|
2469
|
144 |
by (Simp_tac 1);
|
0
|
145 |
by (resolve_tac [impI RS allI] 1);
|
2469
|
146 |
by (ALL_IND_TAC nat_exh Simp_tac 1);
|
|
147 |
by (ALL_IND_TAC nat_exh Simp_tac 1);
|
|
148 |
by (ALL_IND_TAC nat_exh Simp_tac 1);
|
|
149 |
by (Fast_tac 1);
|
755
|
150 |
qed "less_le_trans";
|
0
|
151 |
|
5050
|
152 |
Goal "succ(i) <= j <-> i < j";
|
2469
|
153 |
by (IND_TAC nat_ind Simp_tac "j" 1);
|
0
|
154 |
by (resolve_tac [impI RS allI] 1);
|
2469
|
155 |
by (ALL_IND_TAC nat_exh Asm_simp_tac 1);
|
755
|
156 |
qed "succ_le2";
|
0
|
157 |
|
5050
|
158 |
Goal "i<succ(j) <-> i=j | i<j";
|
2469
|
159 |
by (IND_TAC nat_ind Simp_tac "j" 1);
|
|
160 |
by (ALL_IND_TAC nat_exh Simp_tac 1);
|
0
|
161 |
by (resolve_tac [impI RS allI] 1);
|
2469
|
162 |
by (ALL_IND_TAC nat_exh Simp_tac 1);
|
|
163 |
by (Asm_simp_tac 1);
|
755
|
164 |
qed "less_succ";
|
0
|
165 |
|