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