author | paulson |
Fri, 17 Jul 1998 11:23:17 +0200 | |
changeset 5158 | 48ca9ef35fb0 |
parent 5147 | 825877190618 |
child 5325 | f7a5e06adea1 |
permissions | -rw-r--r-- |
1461 | 1 |
(* Title: ZF/nat.ML |
0 | 2 |
ID: $Id$ |
1461 | 3 |
Author: Lawrence C Paulson, Cambridge University Computer Laboratory |
0 | 4 |
Copyright 1992 University of Cambridge |
5 |
||
6 |
For nat.thy. Natural numbers in Zermelo-Fraenkel Set Theory |
|
7 |
*) |
|
8 |
||
9 |
open Nat; |
|
10 |
||
5067 | 11 |
Goal "bnd_mono(Inf, %X. {0} Un {succ(i). i:X})"; |
0 | 12 |
by (rtac bnd_monoI 1); |
13 |
by (REPEAT (ares_tac [subset_refl, RepFun_mono, Un_mono] 2)); |
|
14 |
by (cut_facts_tac [infinity] 1); |
|
4243 | 15 |
by (Blast_tac 1); |
760 | 16 |
qed "nat_bnd_mono"; |
0 | 17 |
|
18 |
(* nat = {0} Un {succ(x). x:nat} *) |
|
19 |
val nat_unfold = nat_bnd_mono RS (nat_def RS def_lfp_Tarski); |
|
20 |
||
21 |
(** Type checking of 0 and successor **) |
|
22 |
||
5067 | 23 |
Goal "0 : nat"; |
2033 | 24 |
by (stac nat_unfold 1); |
0 | 25 |
by (rtac (singletonI RS UnI1) 1); |
760 | 26 |
qed "nat_0I"; |
0 | 27 |
|
5137 | 28 |
Goal "n : nat ==> succ(n) : nat"; |
2033 | 29 |
by (stac nat_unfold 1); |
5137 | 30 |
by (etac (RepFunI RS UnI2) 1); |
760 | 31 |
qed "nat_succI"; |
0 | 32 |
|
5067 | 33 |
Goal "1 : nat"; |
0 | 34 |
by (rtac (nat_0I RS nat_succI) 1); |
760 | 35 |
qed "nat_1I"; |
0 | 36 |
|
5067 | 37 |
Goal "2 : nat"; |
829 | 38 |
by (rtac (nat_1I RS nat_succI) 1); |
39 |
qed "nat_2I"; |
|
40 |
||
5137 | 41 |
Addsimps [nat_0I, nat_1I, nat_2I]; |
42 |
AddSIs [nat_0I, nat_1I, nat_2I, nat_succI]; |
|
2469 | 43 |
|
5067 | 44 |
Goal "bool <= nat"; |
120 | 45 |
by (REPEAT (ares_tac [subsetI,nat_0I,nat_1I] 1 |
1461 | 46 |
ORELSE eresolve_tac [boolE,ssubst] 1)); |
760 | 47 |
qed "bool_subset_nat"; |
0 | 48 |
|
49 |
val bool_into_nat = bool_subset_nat RS subsetD; |
|
50 |
||
51 |
||
52 |
(** Injectivity properties and induction **) |
|
53 |
||
54 |
(*Mathematical induction*) |
|
55 |
val major::prems = goal Nat.thy |
|
56 |
"[| n: nat; P(0); !!x. [| x: nat; P(x) |] ==> P(succ(x)) |] ==> P(n)"; |
|
57 |
by (rtac ([nat_def, nat_bnd_mono, major] MRS def_induct) 1); |
|
4243 | 58 |
by (blast_tac (claset() addIs prems) 1); |
760 | 59 |
qed "nat_induct"; |
0 | 60 |
|
61 |
(*Perform induction on n, then prove the n:nat subgoal using prems. *) |
|
62 |
fun nat_ind_tac a prems i = |
|
63 |
EVERY [res_inst_tac [("n",a)] nat_induct i, |
|
1461 | 64 |
rename_last_tac a ["1"] (i+2), |
65 |
ares_tac prems i]; |
|
0 | 66 |
|
67 |
val major::prems = goal Nat.thy |
|
68 |
"[| n: nat; n=0 ==> P; !!x. [| x: nat; n=succ(x) |] ==> P |] ==> P"; |
|
15
6c6d2f6e3185
ex/{bin.ML,comb.ML,prop.ML}: replaced NewSext by Syntax.simple_sext
lcp
parents:
6
diff
changeset
|
69 |
by (rtac (major RS (nat_unfold RS equalityD1 RS subsetD) RS UnE) 1); |
0 | 70 |
by (DEPTH_SOLVE (eresolve_tac [singletonE,RepFunE] 1 |
71 |
ORELSE ares_tac prems 1)); |
|
760 | 72 |
qed "natE"; |
0 | 73 |
|
74 |
val prems = goal Nat.thy "n: nat ==> Ord(n)"; |
|
75 |
by (nat_ind_tac "n" prems 1); |
|
76 |
by (REPEAT (ares_tac [Ord_0, Ord_succ] 1)); |
|
760 | 77 |
qed "nat_into_Ord"; |
0 | 78 |
|
1610 | 79 |
(* i: nat ==> 0 le i; same thing as 0<succ(i) *) |
80 |
bind_thm ("nat_0_le", nat_into_Ord RS Ord_0_le); |
|
435 | 81 |
|
1610 | 82 |
(* i: nat ==> i le i; same thing as i<succ(i) *) |
83 |
bind_thm ("nat_le_refl", nat_into_Ord RS le_refl); |
|
15
6c6d2f6e3185
ex/{bin.ML,comb.ML,prop.ML}: replaced NewSext by Syntax.simple_sext
lcp
parents:
6
diff
changeset
|
84 |
|
5067 | 85 |
Goal "Ord(nat)"; |
0 | 86 |
by (rtac OrdI 1); |
435 | 87 |
by (etac (nat_into_Ord RS Ord_is_Transset) 2); |
0 | 88 |
by (rewtac Transset_def); |
89 |
by (rtac ballI 1); |
|
90 |
by (etac nat_induct 1); |
|
91 |
by (REPEAT (ares_tac [empty_subsetI,succ_subsetI] 1)); |
|
760 | 92 |
qed "Ord_nat"; |
0 | 93 |
|
5067 | 94 |
Goalw [Limit_def] "Limit(nat)"; |
5137 | 95 |
by (safe_tac (claset() addSIs [ltI, Ord_nat])); |
435 | 96 |
by (etac ltD 1); |
760 | 97 |
qed "Limit_nat"; |
435 | 98 |
|
5137 | 99 |
(* succ(i): nat ==> i: nat *) |
100 |
val succ_natD = [succI1, asm_rl, Ord_nat] MRS Ord_trans; |
|
101 |
AddSDs [succ_natD]; |
|
102 |
||
103 |
Goal "succ(n): nat <-> n: nat"; |
|
104 |
by (Blast_tac 1); |
|
105 |
qed "nat_succ_iff"; |
|
106 |
||
107 |
Addsimps [Ord_nat, Limit_nat, nat_succ_iff]; |
|
2469 | 108 |
AddSIs [Ord_nat, Limit_nat]; |
109 |
||
5137 | 110 |
Goal "Limit(i) ==> nat le i"; |
1461 | 111 |
by (rtac subset_imp_le 1); |
484 | 112 |
by (rtac subsetI 1); |
1461 | 113 |
by (etac nat_induct 1); |
4091 | 114 |
by (blast_tac (claset() addIs [Limit_has_succ RS ltD, ltI, Limit_is_Ord]) 2); |
484 | 115 |
by (REPEAT (ares_tac [Limit_has_0 RS ltD, |
1461 | 116 |
Ord_nat, Limit_is_Ord] 1)); |
760 | 117 |
qed "nat_le_Limit"; |
484 | 118 |
|
15
6c6d2f6e3185
ex/{bin.ML,comb.ML,prop.ML}: replaced NewSext by Syntax.simple_sext
lcp
parents:
6
diff
changeset
|
119 |
(* [| succ(i): k; k: nat |] ==> i: k *) |
435 | 120 |
val succ_in_naturalD = [succI1, asm_rl, nat_into_Ord] MRS Ord_trans; |
15
6c6d2f6e3185
ex/{bin.ML,comb.ML,prop.ML}: replaced NewSext by Syntax.simple_sext
lcp
parents:
6
diff
changeset
|
121 |
|
5137 | 122 |
Goal "[| m<n; n: nat |] ==> m: nat"; |
30 | 123 |
by (etac ltE 1); |
124 |
by (etac (Ord_nat RSN (3,Ord_trans)) 1); |
|
125 |
by (assume_tac 1); |
|
760 | 126 |
qed "lt_nat_in_nat"; |
30 | 127 |
|
128 |
||
0 | 129 |
(** Variations on mathematical induction **) |
130 |
||
131 |
(*complete induction*) |
|
132 |
val complete_induct = Ord_nat RSN (2, Ord_induct); |
|
133 |
||
134 |
val prems = goal Nat.thy |
|
135 |
"[| m: nat; n: nat; \ |
|
30 | 136 |
\ !!x. [| x: nat; m le x; P(x) |] ==> P(succ(x)) \ |
137 |
\ |] ==> m le n --> P(m) --> P(n)"; |
|
0 | 138 |
by (nat_ind_tac "n" prems 1); |
139 |
by (ALLGOALS |
|
6
8ce8c4d13d4d
Installation of new simplifier for ZF. Deleted all congruence rules not
lcp
parents:
0
diff
changeset
|
140 |
(asm_simp_tac |
4091 | 141 |
(simpset() addsimps (prems@distrib_simps@[le0_iff, le_succ_iff])))); |
760 | 142 |
qed "nat_induct_from_lemma"; |
0 | 143 |
|
144 |
(*Induction starting from m rather than 0*) |
|
145 |
val prems = goal Nat.thy |
|
30 | 146 |
"[| m le n; m: nat; n: nat; \ |
0 | 147 |
\ P(m); \ |
30 | 148 |
\ !!x. [| x: nat; m le x; P(x) |] ==> P(succ(x)) \ |
0 | 149 |
\ |] ==> P(n)"; |
150 |
by (rtac (nat_induct_from_lemma RS mp RS mp) 1); |
|
151 |
by (REPEAT (ares_tac prems 1)); |
|
760 | 152 |
qed "nat_induct_from"; |
0 | 153 |
|
154 |
(*Induction suitable for subtraction and less-than*) |
|
155 |
val prems = goal Nat.thy |
|
156 |
"[| m: nat; n: nat; \ |
|
30 | 157 |
\ !!x. x: nat ==> P(x,0); \ |
158 |
\ !!y. y: nat ==> P(0,succ(y)); \ |
|
0 | 159 |
\ !!x y. [| x: nat; y: nat; P(x,y) |] ==> P(succ(x),succ(y)) \ |
160 |
\ |] ==> P(m,n)"; |
|
161 |
by (res_inst_tac [("x","m")] bspec 1); |
|
162 |
by (resolve_tac prems 2); |
|
163 |
by (nat_ind_tac "n" prems 1); |
|
164 |
by (rtac ballI 2); |
|
165 |
by (nat_ind_tac "x" [] 2); |
|
166 |
by (REPEAT (ares_tac (prems@[ballI]) 1 ORELSE etac bspec 1)); |
|
760 | 167 |
qed "diff_induct"; |
0 | 168 |
|
15
6c6d2f6e3185
ex/{bin.ML,comb.ML,prop.ML}: replaced NewSext by Syntax.simple_sext
lcp
parents:
6
diff
changeset
|
169 |
(** Induction principle analogous to trancl_induct **) |
6c6d2f6e3185
ex/{bin.ML,comb.ML,prop.ML}: replaced NewSext by Syntax.simple_sext
lcp
parents:
6
diff
changeset
|
170 |
|
5147
825877190618
More tidying and removal of "\!\!... from Goal commands
paulson
parents:
5137
diff
changeset
|
171 |
Goal "m: nat ==> P(m,succ(m)) --> (ALL x: nat. P(m,x) --> P(m,succ(x))) --> \ |
30 | 172 |
\ (ALL n:nat. m<n --> P(m,n))"; |
15
6c6d2f6e3185
ex/{bin.ML,comb.ML,prop.ML}: replaced NewSext by Syntax.simple_sext
lcp
parents:
6
diff
changeset
|
173 |
by (etac nat_induct 1); |
4243 | 174 |
by (ALLGOALS (*blast_tac gives PROOF FAILED*) |
15
6c6d2f6e3185
ex/{bin.ML,comb.ML,prop.ML}: replaced NewSext by Syntax.simple_sext
lcp
parents:
6
diff
changeset
|
175 |
(EVERY' [rtac (impI RS impI), rtac (nat_induct RS ballI), assume_tac, |
4243 | 176 |
best_tac le_cs, best_tac le_cs])); |
760 | 177 |
qed "succ_lt_induct_lemma"; |
15
6c6d2f6e3185
ex/{bin.ML,comb.ML,prop.ML}: replaced NewSext by Syntax.simple_sext
lcp
parents:
6
diff
changeset
|
178 |
|
6c6d2f6e3185
ex/{bin.ML,comb.ML,prop.ML}: replaced NewSext by Syntax.simple_sext
lcp
parents:
6
diff
changeset
|
179 |
val prems = goal Nat.thy |
1461 | 180 |
"[| m<n; n: nat; \ |
181 |
\ P(m,succ(m)); \ |
|
182 |
\ !!x. [| x: nat; P(m,x) |] ==> P(m,succ(x)) \ |
|
15
6c6d2f6e3185
ex/{bin.ML,comb.ML,prop.ML}: replaced NewSext by Syntax.simple_sext
lcp
parents:
6
diff
changeset
|
183 |
\ |] ==> P(m,n)"; |
6c6d2f6e3185
ex/{bin.ML,comb.ML,prop.ML}: replaced NewSext by Syntax.simple_sext
lcp
parents:
6
diff
changeset
|
184 |
by (res_inst_tac [("P4","P")] |
30 | 185 |
(succ_lt_induct_lemma RS mp RS mp RS bspec RS mp) 1); |
186 |
by (REPEAT (ares_tac (prems @ [ballI, impI, lt_nat_in_nat]) 1)); |
|
760 | 187 |
qed "succ_lt_induct"; |
15
6c6d2f6e3185
ex/{bin.ML,comb.ML,prop.ML}: replaced NewSext by Syntax.simple_sext
lcp
parents:
6
diff
changeset
|
188 |
|
0 | 189 |
(** nat_case **) |
190 |
||
5067 | 191 |
Goalw [nat_case_def] "nat_case(a,b,0) = a"; |
4091 | 192 |
by (blast_tac (claset() addIs [the_equality]) 1); |
760 | 193 |
qed "nat_case_0"; |
0 | 194 |
|
5067 | 195 |
Goalw [nat_case_def] "nat_case(a,b,succ(m)) = b(m)"; |
4091 | 196 |
by (blast_tac (claset() addIs [the_equality]) 1); |
760 | 197 |
qed "nat_case_succ"; |
0 | 198 |
|
2469 | 199 |
Addsimps [nat_case_0, nat_case_succ]; |
200 |
||
0 | 201 |
val major::prems = goal Nat.thy |
202 |
"[| n: nat; a: C(0); !!m. m: nat ==> b(m): C(succ(m)) \ |
|
6
8ce8c4d13d4d
Installation of new simplifier for ZF. Deleted all congruence rules not
lcp
parents:
0
diff
changeset
|
203 |
\ |] ==> nat_case(a,b,n) : C(n)"; |
0 | 204 |
by (rtac (major RS nat_induct) 1); |
4091 | 205 |
by (ALLGOALS (asm_simp_tac (simpset() addsimps prems))); |
760 | 206 |
qed "nat_case_type"; |
0 | 207 |
|
208 |
||
30 | 209 |
(** nat_rec -- used to define eclose and transrec, then obsolete; |
210 |
rec, from arith.ML, has fewer typing conditions **) |
|
0 | 211 |
|
212 |
val nat_rec_trans = wf_Memrel RS (nat_rec_def RS def_wfrec RS trans); |
|
213 |
||
5067 | 214 |
Goal "nat_rec(0,a,b) = a"; |
0 | 215 |
by (rtac nat_rec_trans 1); |
216 |
by (rtac nat_case_0 1); |
|
760 | 217 |
qed "nat_rec_0"; |
0 | 218 |
|
219 |
val [prem] = goal Nat.thy |
|
220 |
"m: nat ==> nat_rec(succ(m),a,b) = b(m, nat_rec(m,a,b))"; |
|
221 |
by (rtac nat_rec_trans 1); |
|
4091 | 222 |
by (simp_tac (simpset() addsimps [prem, Memrel_iff, vimage_singleton_iff]) 1); |
760 | 223 |
qed "nat_rec_succ"; |
0 | 224 |
|
225 |
(** The union of two natural numbers is a natural number -- their maximum **) |
|
226 |
||
5137 | 227 |
Goal "[| i: nat; j: nat |] ==> i Un j: nat"; |
30 | 228 |
by (rtac (Un_least_lt RS ltD) 1); |
229 |
by (REPEAT (ares_tac [ltI, Ord_nat] 1)); |
|
760 | 230 |
qed "Un_nat_type"; |
0 | 231 |
|
5137 | 232 |
Goal "[| i: nat; j: nat |] ==> i Int j: nat"; |
30 | 233 |
by (rtac (Int_greatest_lt RS ltD) 1); |
234 |
by (REPEAT (ares_tac [ltI, Ord_nat] 1)); |
|
760 | 235 |
qed "Int_nat_type"; |