author | lcp |
Thu, 30 Sep 1993 10:10:21 +0100 | |
changeset 14 | 1c0926788772 |
parent 6 | 8ce8c4d13d4d |
child 30 | d49df4181f0d |
permissions | -rw-r--r-- |
0 | 1 |
(* Title: ZF/nat.ML |
2 |
ID: $Id$ |
|
3 |
Author: Lawrence C Paulson, Cambridge University Computer Laboratory |
|
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); |
|
16 |
val nat_bnd_mono = result(); |
|
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"; |
|
24 |
by (rtac (nat_unfold RS ssubst) 1); |
|
25 |
by (rtac (singletonI RS UnI1) 1); |
|
26 |
val nat_0I = result(); |
|
27 |
||
28 |
val prems = goal Nat.thy "n : nat ==> succ(n) : nat"; |
|
29 |
by (rtac (nat_unfold RS ssubst) 1); |
|
30 |
by (rtac (RepFunI RS UnI2) 1); |
|
31 |
by (resolve_tac prems 1); |
|
32 |
val nat_succI = result(); |
|
33 |
||
14
1c0926788772
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); |
36 |
val nat_1I = result(); |
|
37 |
||
38 |
goal Nat.thy "bool <= nat"; |
|
39 |
by (REPEAT (ares_tac [subsetI,nat_0I,nat_1I] 1 ORELSE etac boolE 1)); |
|
40 |
val bool_subset_nat = result(); |
|
41 |
||
42 |
val bool_into_nat = bool_subset_nat RS subsetD; |
|
43 |
||
44 |
||
45 |
(** Injectivity properties and induction **) |
|
46 |
||
47 |
(*Mathematical induction*) |
|
48 |
val major::prems = goal Nat.thy |
|
49 |
"[| n: nat; P(0); !!x. [| x: nat; P(x) |] ==> P(succ(x)) |] ==> P(n)"; |
|
50 |
by (rtac ([nat_def, nat_bnd_mono, major] MRS def_induct) 1); |
|
51 |
by (fast_tac (ZF_cs addIs prems) 1); |
|
52 |
val nat_induct = result(); |
|
53 |
||
54 |
(*Perform induction on n, then prove the n:nat subgoal using prems. *) |
|
55 |
fun nat_ind_tac a prems i = |
|
56 |
EVERY [res_inst_tac [("n",a)] nat_induct i, |
|
57 |
rename_last_tac a ["1"] (i+2), |
|
58 |
ares_tac prems i]; |
|
59 |
||
60 |
val major::prems = goal Nat.thy |
|
61 |
"[| n: nat; n=0 ==> P; !!x. [| x: nat; n=succ(x) |] ==> P |] ==> P"; |
|
14
1c0926788772
ex/{bin.ML,comb.ML,prop.ML}: replaced NewSext by Syntax.simple_sext
lcp
parents:
6
diff
changeset
|
62 |
by (rtac (major RS (nat_unfold RS equalityD1 RS subsetD) RS UnE) 1); |
0 | 63 |
by (DEPTH_SOLVE (eresolve_tac [singletonE,RepFunE] 1 |
64 |
ORELSE ares_tac prems 1)); |
|
65 |
val natE = result(); |
|
66 |
||
67 |
val prems = goal Nat.thy "n: nat ==> Ord(n)"; |
|
68 |
by (nat_ind_tac "n" prems 1); |
|
69 |
by (REPEAT (ares_tac [Ord_0, Ord_succ] 1)); |
|
70 |
val naturals_are_ordinals = result(); |
|
71 |
||
14
1c0926788772
ex/{bin.ML,comb.ML,prop.ML}: replaced NewSext by Syntax.simple_sext
lcp
parents:
6
diff
changeset
|
72 |
(* i: nat ==> 0: succ(i) *) |
1c0926788772
ex/{bin.ML,comb.ML,prop.ML}: replaced NewSext by Syntax.simple_sext
lcp
parents:
6
diff
changeset
|
73 |
val nat_0_in_succ = naturals_are_ordinals RS Ord_0_in_succ; |
1c0926788772
ex/{bin.ML,comb.ML,prop.ML}: replaced NewSext by Syntax.simple_sext
lcp
parents:
6
diff
changeset
|
74 |
|
0 | 75 |
goal Nat.thy "!!n. n: nat ==> n=0 | 0:n"; |
76 |
by (etac nat_induct 1); |
|
77 |
by (fast_tac ZF_cs 1); |
|
14
1c0926788772
ex/{bin.ML,comb.ML,prop.ML}: replaced NewSext by Syntax.simple_sext
lcp
parents:
6
diff
changeset
|
78 |
by (fast_tac (ZF_cs addIs [nat_0_in_succ]) 1); |
0 | 79 |
val natE0 = result(); |
80 |
||
81 |
goal Nat.thy "Ord(nat)"; |
|
82 |
by (rtac OrdI 1); |
|
83 |
by (etac (naturals_are_ordinals RS Ord_is_Transset) 2); |
|
84 |
by (rewtac Transset_def); |
|
85 |
by (rtac ballI 1); |
|
86 |
by (etac nat_induct 1); |
|
87 |
by (REPEAT (ares_tac [empty_subsetI,succ_subsetI] 1)); |
|
88 |
val Ord_nat = result(); |
|
89 |
||
14
1c0926788772
ex/{bin.ML,comb.ML,prop.ML}: replaced NewSext by Syntax.simple_sext
lcp
parents:
6
diff
changeset
|
90 |
(* succ(i): nat ==> i: nat *) |
1c0926788772
ex/{bin.ML,comb.ML,prop.ML}: replaced NewSext by Syntax.simple_sext
lcp
parents:
6
diff
changeset
|
91 |
val succ_natD = [succI1, asm_rl, Ord_nat] MRS Ord_trans; |
1c0926788772
ex/{bin.ML,comb.ML,prop.ML}: replaced NewSext by Syntax.simple_sext
lcp
parents:
6
diff
changeset
|
92 |
|
1c0926788772
ex/{bin.ML,comb.ML,prop.ML}: replaced NewSext by Syntax.simple_sext
lcp
parents:
6
diff
changeset
|
93 |
(* [| succ(i): k; k: nat |] ==> i: k *) |
1c0926788772
ex/{bin.ML,comb.ML,prop.ML}: replaced NewSext by Syntax.simple_sext
lcp
parents:
6
diff
changeset
|
94 |
val succ_in_naturalD = [succI1, asm_rl, naturals_are_ordinals] MRS Ord_trans; |
1c0926788772
ex/{bin.ML,comb.ML,prop.ML}: replaced NewSext by Syntax.simple_sext
lcp
parents:
6
diff
changeset
|
95 |
|
0 | 96 |
(** Variations on mathematical induction **) |
97 |
||
98 |
(*complete induction*) |
|
99 |
val complete_induct = Ord_nat RSN (2, Ord_induct); |
|
100 |
||
101 |
val prems = goal Nat.thy |
|
102 |
"[| m: nat; n: nat; \ |
|
103 |
\ !!x. [| x: nat; m<=x; P(x) |] ==> P(succ(x)) \ |
|
104 |
\ |] ==> m <= n --> P(m) --> P(n)"; |
|
105 |
by (nat_ind_tac "n" prems 1); |
|
106 |
by (ALLGOALS |
|
6
8ce8c4d13d4d
Installation of new simplifier for ZF. Deleted all congruence rules not
lcp
parents:
0
diff
changeset
|
107 |
(asm_simp_tac |
8ce8c4d13d4d
Installation of new simplifier for ZF. Deleted all congruence rules not
lcp
parents:
0
diff
changeset
|
108 |
(ZF_ss addsimps (prems@distrib_rews@[subset_empty_iff, subset_succ_iff, |
14
1c0926788772
ex/{bin.ML,comb.ML,prop.ML}: replaced NewSext by Syntax.simple_sext
lcp
parents:
6
diff
changeset
|
109 |
naturals_are_ordinals])))); |
0 | 110 |
val nat_induct_from_lemma = result(); |
111 |
||
112 |
(*Induction starting from m rather than 0*) |
|
113 |
val prems = goal Nat.thy |
|
114 |
"[| m <= n; m: nat; n: nat; \ |
|
115 |
\ P(m); \ |
|
116 |
\ !!x. [| x: nat; m<=x; P(x) |] ==> P(succ(x)) \ |
|
117 |
\ |] ==> P(n)"; |
|
118 |
by (rtac (nat_induct_from_lemma RS mp RS mp) 1); |
|
119 |
by (REPEAT (ares_tac prems 1)); |
|
120 |
val nat_induct_from = result(); |
|
121 |
||
122 |
(*Induction suitable for subtraction and less-than*) |
|
123 |
val prems = goal Nat.thy |
|
124 |
"[| m: nat; n: nat; \ |
|
125 |
\ !!x. [| x: nat |] ==> P(x,0); \ |
|
126 |
\ !!y. [| y: nat |] ==> P(0,succ(y)); \ |
|
127 |
\ !!x y. [| x: nat; y: nat; P(x,y) |] ==> P(succ(x),succ(y)) \ |
|
128 |
\ |] ==> P(m,n)"; |
|
129 |
by (res_inst_tac [("x","m")] bspec 1); |
|
130 |
by (resolve_tac prems 2); |
|
131 |
by (nat_ind_tac "n" prems 1); |
|
132 |
by (rtac ballI 2); |
|
133 |
by (nat_ind_tac "x" [] 2); |
|
134 |
by (REPEAT (ares_tac (prems@[ballI]) 1 ORELSE etac bspec 1)); |
|
135 |
val diff_induct = result(); |
|
136 |
||
14
1c0926788772
ex/{bin.ML,comb.ML,prop.ML}: replaced NewSext by Syntax.simple_sext
lcp
parents:
6
diff
changeset
|
137 |
(** Induction principle analogous to trancl_induct **) |
1c0926788772
ex/{bin.ML,comb.ML,prop.ML}: replaced NewSext by Syntax.simple_sext
lcp
parents:
6
diff
changeset
|
138 |
|
1c0926788772
ex/{bin.ML,comb.ML,prop.ML}: replaced NewSext by Syntax.simple_sext
lcp
parents:
6
diff
changeset
|
139 |
goal Nat.thy |
1c0926788772
ex/{bin.ML,comb.ML,prop.ML}: replaced NewSext by Syntax.simple_sext
lcp
parents:
6
diff
changeset
|
140 |
"!!m. m: nat ==> P(m,succ(m)) --> (ALL x: nat. P(m,x) --> P(m,succ(x))) --> \ |
1c0926788772
ex/{bin.ML,comb.ML,prop.ML}: replaced NewSext by Syntax.simple_sext
lcp
parents:
6
diff
changeset
|
141 |
\ (ALL n:nat. m:n --> P(m,n))"; |
1c0926788772
ex/{bin.ML,comb.ML,prop.ML}: replaced NewSext by Syntax.simple_sext
lcp
parents:
6
diff
changeset
|
142 |
by (etac nat_induct 1); |
1c0926788772
ex/{bin.ML,comb.ML,prop.ML}: replaced NewSext by Syntax.simple_sext
lcp
parents:
6
diff
changeset
|
143 |
by (ALLGOALS |
1c0926788772
ex/{bin.ML,comb.ML,prop.ML}: replaced NewSext by Syntax.simple_sext
lcp
parents:
6
diff
changeset
|
144 |
(EVERY' [rtac (impI RS impI), rtac (nat_induct RS ballI), assume_tac, |
1c0926788772
ex/{bin.ML,comb.ML,prop.ML}: replaced NewSext by Syntax.simple_sext
lcp
parents:
6
diff
changeset
|
145 |
fast_tac ZF_cs, fast_tac ZF_cs])); |
1c0926788772
ex/{bin.ML,comb.ML,prop.ML}: replaced NewSext by Syntax.simple_sext
lcp
parents:
6
diff
changeset
|
146 |
val succ_less_induct_lemma = result(); |
1c0926788772
ex/{bin.ML,comb.ML,prop.ML}: replaced NewSext by Syntax.simple_sext
lcp
parents:
6
diff
changeset
|
147 |
|
1c0926788772
ex/{bin.ML,comb.ML,prop.ML}: replaced NewSext by Syntax.simple_sext
lcp
parents:
6
diff
changeset
|
148 |
val prems = goal Nat.thy |
1c0926788772
ex/{bin.ML,comb.ML,prop.ML}: replaced NewSext by Syntax.simple_sext
lcp
parents:
6
diff
changeset
|
149 |
"[| m: n; n: nat; \ |
1c0926788772
ex/{bin.ML,comb.ML,prop.ML}: replaced NewSext by Syntax.simple_sext
lcp
parents:
6
diff
changeset
|
150 |
\ P(m,succ(m)); \ |
1c0926788772
ex/{bin.ML,comb.ML,prop.ML}: replaced NewSext by Syntax.simple_sext
lcp
parents:
6
diff
changeset
|
151 |
\ !!x. [| x: nat; P(m,x) |] ==> P(m,succ(x)) \ |
1c0926788772
ex/{bin.ML,comb.ML,prop.ML}: replaced NewSext by Syntax.simple_sext
lcp
parents:
6
diff
changeset
|
152 |
\ |] ==> P(m,n)"; |
1c0926788772
ex/{bin.ML,comb.ML,prop.ML}: replaced NewSext by Syntax.simple_sext
lcp
parents:
6
diff
changeset
|
153 |
by (res_inst_tac [("P4","P")] |
1c0926788772
ex/{bin.ML,comb.ML,prop.ML}: replaced NewSext by Syntax.simple_sext
lcp
parents:
6
diff
changeset
|
154 |
(succ_less_induct_lemma RS mp RS mp RS bspec RS mp) 1); |
1c0926788772
ex/{bin.ML,comb.ML,prop.ML}: replaced NewSext by Syntax.simple_sext
lcp
parents:
6
diff
changeset
|
155 |
by (rtac (Ord_nat RSN (3,Ord_trans)) 1); |
1c0926788772
ex/{bin.ML,comb.ML,prop.ML}: replaced NewSext by Syntax.simple_sext
lcp
parents:
6
diff
changeset
|
156 |
by (REPEAT (ares_tac (prems @ [ballI,impI]) 1)); |
1c0926788772
ex/{bin.ML,comb.ML,prop.ML}: replaced NewSext by Syntax.simple_sext
lcp
parents:
6
diff
changeset
|
157 |
val succ_less_induct = result(); |
1c0926788772
ex/{bin.ML,comb.ML,prop.ML}: replaced NewSext by Syntax.simple_sext
lcp
parents:
6
diff
changeset
|
158 |
|
0 | 159 |
(** nat_case **) |
160 |
||
6
8ce8c4d13d4d
Installation of new simplifier for ZF. Deleted all congruence rules not
lcp
parents:
0
diff
changeset
|
161 |
goalw Nat.thy [nat_case_def] "nat_case(a,b,0) = a"; |
0 | 162 |
by (fast_tac (ZF_cs addIs [the_equality]) 1); |
163 |
val nat_case_0 = result(); |
|
164 |
||
6
8ce8c4d13d4d
Installation of new simplifier for ZF. Deleted all congruence rules not
lcp
parents:
0
diff
changeset
|
165 |
goalw Nat.thy [nat_case_def] "nat_case(a,b,succ(m)) = b(m)"; |
0 | 166 |
by (fast_tac (ZF_cs addIs [the_equality]) 1); |
167 |
val nat_case_succ = result(); |
|
168 |
||
169 |
val major::prems = goal Nat.thy |
|
170 |
"[| 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
|
171 |
\ |] ==> nat_case(a,b,n) : C(n)"; |
0 | 172 |
by (rtac (major RS nat_induct) 1); |
173 |
by (REPEAT (resolve_tac [nat_case_0 RS ssubst, |
|
174 |
nat_case_succ RS ssubst] 1 |
|
175 |
THEN resolve_tac prems 1)); |
|
176 |
by (assume_tac 1); |
|
177 |
val nat_case_type = result(); |
|
178 |
||
179 |
||
180 |
(** nat_rec -- used to define eclose and transrec, then obsolete **) |
|
181 |
||
182 |
val nat_rec_trans = wf_Memrel RS (nat_rec_def RS def_wfrec RS trans); |
|
183 |
||
184 |
goal Nat.thy "nat_rec(0,a,b) = a"; |
|
185 |
by (rtac nat_rec_trans 1); |
|
186 |
by (rtac nat_case_0 1); |
|
187 |
val nat_rec_0 = result(); |
|
188 |
||
189 |
val [prem] = goal Nat.thy |
|
190 |
"m: nat ==> nat_rec(succ(m),a,b) = b(m, nat_rec(m,a,b))"; |
|
191 |
by (rtac nat_rec_trans 1); |
|
14
1c0926788772
ex/{bin.ML,comb.ML,prop.ML}: replaced NewSext by Syntax.simple_sext
lcp
parents:
6
diff
changeset
|
192 |
by (simp_tac (ZF_ss addsimps [prem, nat_case_succ, nat_succI, Memrel_iff, |
1c0926788772
ex/{bin.ML,comb.ML,prop.ML}: replaced NewSext by Syntax.simple_sext
lcp
parents:
6
diff
changeset
|
193 |
vimage_singleton_iff]) 1); |
0 | 194 |
val nat_rec_succ = result(); |
195 |
||
196 |
(** The union of two natural numbers is a natural number -- their maximum **) |
|
197 |
||
14
1c0926788772
ex/{bin.ML,comb.ML,prop.ML}: replaced NewSext by Syntax.simple_sext
lcp
parents:
6
diff
changeset
|
198 |
(* [| i : nat; j : nat |] ==> i Un j : nat *) |
0 | 199 |
val Un_nat_type = standard (Ord_nat RSN (3,Ord_member_UnI)); |
200 |
||
14
1c0926788772
ex/{bin.ML,comb.ML,prop.ML}: replaced NewSext by Syntax.simple_sext
lcp
parents:
6
diff
changeset
|
201 |
(* [| i : nat; j : nat |] ==> i Int j : nat *) |
0 | 202 |
val Int_nat_type = standard (Ord_nat RSN (3,Ord_member_IntI)); |
203 |