author  lcp 
Tue, 21 Jun 1994 17:20:34 +0200  
changeset 435  ca5356bd315a 
parent 120  09287f26bfb8 
child 484  70b789956bd3 
permissions  rwrr 
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 ZermeloFraenkel 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 

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); 
36 
val nat_1I = result(); 

37 

38 
goal Nat.thy "bool <= nat"; 

120  39 
by (REPEAT (ares_tac [subsetI,nat_0I,nat_1I] 1 
40 
ORELSE eresolve_tac [boolE,ssubst] 1)); 

0  41 
val bool_subset_nat = result(); 
42 

43 
val bool_into_nat = bool_subset_nat RS subsetD; 

44 

45 

46 
(** Injectivity properties and induction **) 

47 

48 
(*Mathematical induction*) 

49 
val major::prems = goal Nat.thy 

50 
"[ n: nat; P(0); !!x. [ x: nat; P(x) ] ==> P(succ(x)) ] ==> P(n)"; 

51 
by (rtac ([nat_def, nat_bnd_mono, major] MRS def_induct) 1); 

52 
by (fast_tac (ZF_cs addIs prems) 1); 

53 
val nat_induct = result(); 

54 

55 
(*Perform induction on n, then prove the n:nat subgoal using prems. *) 

56 
fun nat_ind_tac a prems i = 

57 
EVERY [res_inst_tac [("n",a)] nat_induct i, 

58 
rename_last_tac a ["1"] (i+2), 

59 
ares_tac prems i]; 

60 

61 
val major::prems = goal Nat.thy 

62 
"[ 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

63 
by (rtac (major RS (nat_unfold RS equalityD1 RS subsetD) RS UnE) 1); 
0  64 
by (DEPTH_SOLVE (eresolve_tac [singletonE,RepFunE] 1 
65 
ORELSE ares_tac prems 1)); 

66 
val natE = result(); 

67 

68 
val prems = goal Nat.thy "n: nat ==> Ord(n)"; 

69 
by (nat_ind_tac "n" prems 1); 

70 
by (REPEAT (ares_tac [Ord_0, Ord_succ] 1)); 

435  71 
val nat_into_Ord = result(); 
0  72 

30  73 
(* i: nat ==> 0 le i *) 
435  74 
val nat_0_le = nat_into_Ord RS Ord_0_le; 
75 

76 
val 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

77 

0  78 
goal Nat.thy "!!n. n: nat ==> n=0  0:n"; 
79 
by (etac nat_induct 1); 

80 
by (fast_tac ZF_cs 1); 

30  81 
by (fast_tac (ZF_cs addIs [nat_0_le]) 1); 
0  82 
val natE0 = result(); 
83 

84 
goal Nat.thy "Ord(nat)"; 

85 
by (rtac OrdI 1); 

435  86 
by (etac (nat_into_Ord RS Ord_is_Transset) 2); 
0  87 
by (rewtac Transset_def); 
88 
by (rtac ballI 1); 

89 
by (etac nat_induct 1); 

90 
by (REPEAT (ares_tac [empty_subsetI,succ_subsetI] 1)); 

91 
val Ord_nat = result(); 

92 

435  93 
goalw Nat.thy [Limit_def] "Limit(nat)"; 
94 
by (safe_tac (ZF_cs addSIs [ltI, nat_0I, nat_1I, nat_succI, Ord_nat])); 

95 
by (etac ltD 1); 

96 
val Limit_nat = result(); 

97 

15
6c6d2f6e3185
ex/{bin.ML,comb.ML,prop.ML}: replaced NewSext by Syntax.simple_sext
lcp
parents:
6
diff
changeset

98 
(* succ(i): nat ==> i: nat *) 
6c6d2f6e3185
ex/{bin.ML,comb.ML,prop.ML}: replaced NewSext by Syntax.simple_sext
lcp
parents:
6
diff
changeset

99 
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

100 

6c6d2f6e3185
ex/{bin.ML,comb.ML,prop.ML}: replaced NewSext by Syntax.simple_sext
lcp
parents:
6
diff
changeset

101 
(* [ succ(i): k; k: nat ] ==> i: k *) 
435  102 
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

103 

30  104 
goal Nat.thy "!!m n. [ m<n; n: nat ] ==> m: nat"; 
105 
by (etac ltE 1); 

106 
by (etac (Ord_nat RSN (3,Ord_trans)) 1); 

107 
by (assume_tac 1); 

108 
val lt_nat_in_nat = result(); 

109 

110 

0  111 
(** Variations on mathematical induction **) 
112 

113 
(*complete induction*) 

114 
val complete_induct = Ord_nat RSN (2, Ord_induct); 

115 

116 
val prems = goal Nat.thy 

117 
"[ m: nat; n: nat; \ 

30  118 
\ !!x. [ x: nat; m le x; P(x) ] ==> P(succ(x)) \ 
119 
\ ] ==> m le n > P(m) > P(n)"; 

0  120 
by (nat_ind_tac "n" prems 1); 
121 
by (ALLGOALS 

6
8ce8c4d13d4d
Installation of new simplifier for ZF. Deleted all congruence rules not
lcp
parents:
0
diff
changeset

122 
(asm_simp_tac 
30  123 
(ZF_ss addsimps (prems@distrib_rews@[le0_iff, le_succ_iff])))); 
0  124 
val nat_induct_from_lemma = result(); 
125 

126 
(*Induction starting from m rather than 0*) 

127 
val prems = goal Nat.thy 

30  128 
"[ m le n; m: nat; n: nat; \ 
0  129 
\ P(m); \ 
30  130 
\ !!x. [ x: nat; m le x; P(x) ] ==> P(succ(x)) \ 
0  131 
\ ] ==> P(n)"; 
132 
by (rtac (nat_induct_from_lemma RS mp RS mp) 1); 

133 
by (REPEAT (ares_tac prems 1)); 

134 
val nat_induct_from = result(); 

135 

136 
(*Induction suitable for subtraction and lessthan*) 

137 
val prems = goal Nat.thy 

138 
"[ m: nat; n: nat; \ 

30  139 
\ !!x. x: nat ==> P(x,0); \ 
140 
\ !!y. y: nat ==> P(0,succ(y)); \ 

0  141 
\ !!x y. [ x: nat; y: nat; P(x,y) ] ==> P(succ(x),succ(y)) \ 
142 
\ ] ==> P(m,n)"; 

143 
by (res_inst_tac [("x","m")] bspec 1); 

144 
by (resolve_tac prems 2); 

145 
by (nat_ind_tac "n" prems 1); 

146 
by (rtac ballI 2); 

147 
by (nat_ind_tac "x" [] 2); 

148 
by (REPEAT (ares_tac (prems@[ballI]) 1 ORELSE etac bspec 1)); 

149 
val diff_induct = result(); 

150 

15
6c6d2f6e3185
ex/{bin.ML,comb.ML,prop.ML}: replaced NewSext by Syntax.simple_sext
lcp
parents:
6
diff
changeset

151 
(** 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

152 

6c6d2f6e3185
ex/{bin.ML,comb.ML,prop.ML}: replaced NewSext by Syntax.simple_sext
lcp
parents:
6
diff
changeset

153 
goal Nat.thy 
6c6d2f6e3185
ex/{bin.ML,comb.ML,prop.ML}: replaced NewSext by Syntax.simple_sext
lcp
parents:
6
diff
changeset

154 
"!!m. m: nat ==> P(m,succ(m)) > (ALL x: nat. P(m,x) > P(m,succ(x))) > \ 
30  155 
\ (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

156 
by (etac nat_induct 1); 
6c6d2f6e3185
ex/{bin.ML,comb.ML,prop.ML}: replaced NewSext by Syntax.simple_sext
lcp
parents:
6
diff
changeset

157 
by (ALLGOALS 
6c6d2f6e3185
ex/{bin.ML,comb.ML,prop.ML}: replaced NewSext by Syntax.simple_sext
lcp
parents:
6
diff
changeset

158 
(EVERY' [rtac (impI RS impI), rtac (nat_induct RS ballI), assume_tac, 
30  159 
fast_tac lt_cs, fast_tac lt_cs])); 
160 
val succ_lt_induct_lemma = result(); 

15
6c6d2f6e3185
ex/{bin.ML,comb.ML,prop.ML}: replaced NewSext by Syntax.simple_sext
lcp
parents:
6
diff
changeset

161 

6c6d2f6e3185
ex/{bin.ML,comb.ML,prop.ML}: replaced NewSext by Syntax.simple_sext
lcp
parents:
6
diff
changeset

162 
val prems = goal Nat.thy 
30  163 
"[ m<n; n: nat; \ 
164 
\ P(m,succ(m)); \ 

165 
\ !!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

166 
\ ] ==> P(m,n)"; 
6c6d2f6e3185
ex/{bin.ML,comb.ML,prop.ML}: replaced NewSext by Syntax.simple_sext
lcp
parents:
6
diff
changeset

167 
by (res_inst_tac [("P4","P")] 
30  168 
(succ_lt_induct_lemma RS mp RS mp RS bspec RS mp) 1); 
169 
by (REPEAT (ares_tac (prems @ [ballI, impI, lt_nat_in_nat]) 1)); 

170 
val succ_lt_induct = result(); 

15
6c6d2f6e3185
ex/{bin.ML,comb.ML,prop.ML}: replaced NewSext by Syntax.simple_sext
lcp
parents:
6
diff
changeset

171 

0  172 
(** nat_case **) 
173 

6
8ce8c4d13d4d
Installation of new simplifier for ZF. Deleted all congruence rules not
lcp
parents:
0
diff
changeset

174 
goalw Nat.thy [nat_case_def] "nat_case(a,b,0) = a"; 
0  175 
by (fast_tac (ZF_cs addIs [the_equality]) 1); 
176 
val nat_case_0 = result(); 

177 

6
8ce8c4d13d4d
Installation of new simplifier for ZF. Deleted all congruence rules not
lcp
parents:
0
diff
changeset

178 
goalw Nat.thy [nat_case_def] "nat_case(a,b,succ(m)) = b(m)"; 
0  179 
by (fast_tac (ZF_cs addIs [the_equality]) 1); 
180 
val nat_case_succ = result(); 

181 

182 
val major::prems = goal Nat.thy 

183 
"[ 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

184 
\ ] ==> nat_case(a,b,n) : C(n)"; 
0  185 
by (rtac (major RS nat_induct) 1); 
30  186 
by (ALLGOALS 
187 
(asm_simp_tac (ZF_ss addsimps (prems @ [nat_case_0, nat_case_succ])))); 

0  188 
val nat_case_type = result(); 
189 

190 

30  191 
(** nat_rec  used to define eclose and transrec, then obsolete; 
192 
rec, from arith.ML, has fewer typing conditions **) 

0  193 

194 
val nat_rec_trans = wf_Memrel RS (nat_rec_def RS def_wfrec RS trans); 

195 

196 
goal Nat.thy "nat_rec(0,a,b) = a"; 

197 
by (rtac nat_rec_trans 1); 

198 
by (rtac nat_case_0 1); 

199 
val nat_rec_0 = result(); 

200 

201 
val [prem] = goal Nat.thy 

202 
"m: nat ==> nat_rec(succ(m),a,b) = b(m, nat_rec(m,a,b))"; 

203 
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

204 
by (simp_tac (ZF_ss addsimps [prem, nat_case_succ, nat_succI, Memrel_iff, 
6c6d2f6e3185
ex/{bin.ML,comb.ML,prop.ML}: replaced NewSext by Syntax.simple_sext
lcp
parents:
6
diff
changeset

205 
vimage_singleton_iff]) 1); 
0  206 
val nat_rec_succ = result(); 
207 

208 
(** The union of two natural numbers is a natural number  their maximum **) 

209 

30  210 
goal Nat.thy "!!i j. [ i: nat; j: nat ] ==> i Un j: nat"; 
211 
by (rtac (Un_least_lt RS ltD) 1); 

212 
by (REPEAT (ares_tac [ltI, Ord_nat] 1)); 

213 
val Un_nat_type = result(); 

0  214 

30  215 
goal Nat.thy "!!i j. [ i: nat; j: nat ] ==> i Int j: nat"; 
216 
by (rtac (Int_greatest_lt RS ltD) 1); 

217 
by (REPEAT (ares_tac [ltI, Ord_nat] 1)); 

218 
val Int_nat_type = result(); 