author  lcp 
Tue, 21 Jun 1994 17:20:34 +0200  
changeset 435  ca5356bd315a 
parent 127  eec6bb9c58ea 
child 437  435875e4b21d 
permissions  rwrr 
0  1 
(* Title: ZF/arith.ML 
2 
ID: $Id$ 

3 
Author: Lawrence C Paulson, Cambridge University Computer Laboratory 

4 
Copyright 1992 University of Cambridge 

5 

6 
For arith.thy. Arithmetic operators and their definitions 

7 

8 
Proofs about elementary arithmetic: addition, multiplication, etc. 

9 

10 
Could prove def_rec_0, def_rec_succ... 

11 
*) 

12 

13 
open Arith; 

14 

15 
(*"Difference" is subtraction of natural numbers. 

16 
There are no negative numbers; we have 

17 
m # n = 0 iff m<=n and m # n = succ(k) iff m>n. 

18 
Also, rec(m, 0, %z w.z) is pred(m). 

19 
*) 

20 

21 
(** rec  better than nat_rec; the succ case has no type requirement! **) 

22 

23 
val rec_trans = rec_def RS def_transrec RS trans; 

24 

25 
goal Arith.thy "rec(0,a,b) = a"; 

26 
by (rtac rec_trans 1); 

27 
by (rtac nat_case_0 1); 

28 
val rec_0 = result(); 

29 

30 
goal Arith.thy "rec(succ(m),a,b) = b(m, rec(m,a,b))"; 

31 
by (rtac rec_trans 1); 

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

32 
by (simp_tac (ZF_ss addsimps [nat_case_succ, nat_succI]) 1); 
0  33 
val rec_succ = result(); 
34 

35 
val major::prems = goal Arith.thy 

36 
"[ n: nat; \ 

37 
\ a: C(0); \ 

38 
\ !!m z. [ m: nat; z: C(m) ] ==> b(m,z): C(succ(m)) \ 

39 
\ ] ==> rec(n,a,b) : C(n)"; 

40 
by (rtac (major RS nat_induct) 1); 

41 
by (ALLGOALS 

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

42 
(asm_simp_tac (ZF_ss addsimps (prems@[rec_0,rec_succ])))); 
0  43 
val rec_type = result(); 
44 

435  45 
val nat_le_refl = nat_into_Ord RS le_refl; 
25
3ac1c0c0016e
ordinal: DEFINITION of < and le to replace : and <= on ordinals! Many
lcp
parents:
14
diff
changeset

46 

3ac1c0c0016e
ordinal: DEFINITION of < and le to replace : and <= on ordinals! Many
lcp
parents:
14
diff
changeset

47 
val nat_typechecks = [rec_type, nat_0I, nat_1I, nat_succI, Ord_nat]; 
0  48 

25
3ac1c0c0016e
ordinal: DEFINITION of < and le to replace : and <= on ordinals! Many
lcp
parents:
14
diff
changeset

49 
val nat_simps = [rec_0, rec_succ, not_lt0, nat_0_le, le0_iff, succ_le_iff, 
3ac1c0c0016e
ordinal: DEFINITION of < and le to replace : and <= on ordinals! Many
lcp
parents:
14
diff
changeset

50 
nat_le_refl]; 
3ac1c0c0016e
ordinal: DEFINITION of < and le to replace : and <= on ordinals! Many
lcp
parents:
14
diff
changeset

51 

3ac1c0c0016e
ordinal: DEFINITION of < and le to replace : and <= on ordinals! Many
lcp
parents:
14
diff
changeset

52 
val nat_ss = ZF_ss addsimps (nat_simps @ nat_typechecks); 
0  53 

54 

55 
(** Addition **) 

56 

57 
val add_type = prove_goalw Arith.thy [add_def] 

58 
"[ m:nat; n:nat ] ==> m #+ n : nat" 

59 
(fn prems=> [ (typechk_tac (prems@nat_typechecks@ZF_typechecks)) ]); 

60 

61 
val add_0 = prove_goalw Arith.thy [add_def] 

62 
"0 #+ n = n" 

63 
(fn _ => [ (rtac rec_0 1) ]); 

64 

65 
val add_succ = prove_goalw Arith.thy [add_def] 

66 
"succ(m) #+ n = succ(m #+ n)" 

67 
(fn _=> [ (rtac rec_succ 1) ]); 

68 

69 
(** Multiplication **) 

70 

71 
val mult_type = prove_goalw Arith.thy [mult_def] 

72 
"[ m:nat; n:nat ] ==> m #* n : nat" 

73 
(fn prems=> 

74 
[ (typechk_tac (prems@[add_type]@nat_typechecks@ZF_typechecks)) ]); 

75 

76 
val mult_0 = prove_goalw Arith.thy [mult_def] 

77 
"0 #* n = 0" 

78 
(fn _ => [ (rtac rec_0 1) ]); 

79 

80 
val mult_succ = prove_goalw Arith.thy [mult_def] 

81 
"succ(m) #* n = n #+ (m #* n)" 

82 
(fn _ => [ (rtac rec_succ 1) ]); 

83 

84 
(** Difference **) 

85 

86 
val diff_type = prove_goalw Arith.thy [diff_def] 

87 
"[ m:nat; n:nat ] ==> m # n : nat" 

88 
(fn prems=> [ (typechk_tac (prems@nat_typechecks@ZF_typechecks)) ]); 

89 

90 
val diff_0 = prove_goalw Arith.thy [diff_def] 

91 
"m # 0 = m" 

92 
(fn _ => [ (rtac rec_0 1) ]); 

93 

94 
val diff_0_eq_0 = prove_goalw Arith.thy [diff_def] 

95 
"n:nat ==> 0 # n = 0" 

96 
(fn [prem]=> 

97 
[ (rtac (prem RS nat_induct) 1), 

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

98 
(ALLGOALS (asm_simp_tac nat_ss)) ]); 
0  99 

100 
(*Must simplify BEFORE the induction!! (Else we get a critical pair) 

101 
succ(m) # succ(n) rewrites to pred(succ(m) # n) *) 

102 
val diff_succ_succ = prove_goalw Arith.thy [diff_def] 

103 
"[ m:nat; n:nat ] ==> succ(m) # succ(n) = m # n" 

104 
(fn prems=> 

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

105 
[ (asm_simp_tac (nat_ss addsimps prems) 1), 
0  106 
(nat_ind_tac "n" prems 1), 
6
8ce8c4d13d4d
Installation of new simplifier for ZF. Deleted all congruence rules not
lcp
parents:
0
diff
changeset

107 
(ALLGOALS (asm_simp_tac (nat_ss addsimps prems))) ]); 
0  108 

109 
val prems = goal Arith.thy 

25
3ac1c0c0016e
ordinal: DEFINITION of < and le to replace : and <= on ordinals! Many
lcp
parents:
14
diff
changeset

110 
"[ m:nat; n:nat ] ==> m # n le m"; 
3ac1c0c0016e
ordinal: DEFINITION of < and le to replace : and <= on ordinals! Many
lcp
parents:
14
diff
changeset

111 
by (rtac (prems MRS diff_induct) 1); 
3ac1c0c0016e
ordinal: DEFINITION of < and le to replace : and <= on ordinals! Many
lcp
parents:
14
diff
changeset

112 
by (etac leE 3); 
0  113 
by (ALLGOALS 
6
8ce8c4d13d4d
Installation of new simplifier for ZF. Deleted all congruence rules not
lcp
parents:
0
diff
changeset

114 
(asm_simp_tac 
25
3ac1c0c0016e
ordinal: DEFINITION of < and le to replace : and <= on ordinals! Many
lcp
parents:
14
diff
changeset

115 
(nat_ss addsimps (prems @ [le_iff, diff_0, diff_0_eq_0, 
435  116 
diff_succ_succ, nat_into_Ord])))); 
25
3ac1c0c0016e
ordinal: DEFINITION of < and le to replace : and <= on ordinals! Many
lcp
parents:
14
diff
changeset

117 
val diff_le_self = result(); 
0  118 

119 
(*** Simplification over add, mult, diff ***) 

120 

121 
val arith_typechecks = [add_type, mult_type, diff_type]; 

25
3ac1c0c0016e
ordinal: DEFINITION of < and le to replace : and <= on ordinals! Many
lcp
parents:
14
diff
changeset

122 
val arith_simps = [add_0, add_succ, 
3ac1c0c0016e
ordinal: DEFINITION of < and le to replace : and <= on ordinals! Many
lcp
parents:
14
diff
changeset

123 
mult_0, mult_succ, 
3ac1c0c0016e
ordinal: DEFINITION of < and le to replace : and <= on ordinals! Many
lcp
parents:
14
diff
changeset

124 
diff_0, diff_0_eq_0, diff_succ_succ]; 
0  125 

25
3ac1c0c0016e
ordinal: DEFINITION of < and le to replace : and <= on ordinals! Many
lcp
parents:
14
diff
changeset

126 
val arith_ss = nat_ss addsimps (arith_simps@arith_typechecks); 
0  127 

128 
(*** Addition ***) 

129 

130 
(*Associative law for addition*) 

131 
val add_assoc = prove_goal Arith.thy 

132 
"m:nat ==> (m #+ n) #+ k = m #+ (n #+ k)" 

133 
(fn prems=> 

134 
[ (nat_ind_tac "m" prems 1), 

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

135 
(ALLGOALS (asm_simp_tac (arith_ss addsimps prems))) ]); 
0  136 

137 
(*The following two lemmas are used for add_commute and sometimes 

138 
elsewhere, since they are safe for rewriting.*) 

139 
val add_0_right = prove_goal Arith.thy 

140 
"m:nat ==> m #+ 0 = m" 

141 
(fn prems=> 

142 
[ (nat_ind_tac "m" prems 1), 

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

143 
(ALLGOALS (asm_simp_tac (arith_ss addsimps prems))) ]); 
0  144 

145 
val add_succ_right = prove_goal Arith.thy 

146 
"m:nat ==> m #+ succ(n) = succ(m #+ n)" 

147 
(fn prems=> 

148 
[ (nat_ind_tac "m" prems 1), 

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

149 
(ALLGOALS (asm_simp_tac (arith_ss addsimps prems))) ]); 
0  150 

151 
(*Commutative law for addition*) 

152 
val add_commute = prove_goal Arith.thy 

435  153 
"!!m n. [ m:nat; n:nat ] ==> m #+ n = n #+ m" 
154 
(fn _ => 

155 
[ (nat_ind_tac "n" [] 1), 

0  156 
(ALLGOALS 
435  157 
(asm_simp_tac (arith_ss addsimps [add_0_right, add_succ_right]))) ]); 
158 

159 
val add_left_commute = prove_goal Arith.thy 

160 
"!!m n k. [ m:nat; n:nat; k:nat ] ==> m#+(n#+k)=n#+(m#+k)" 

161 
(fn _ => [rtac (add_commute RS trans) 1, 

162 
rtac (add_assoc RS trans) 3, 

163 
rtac (add_commute RS subst_context) 4, 

164 
REPEAT (ares_tac [add_type] 1)]); 

165 

166 
(*Addition is an ACoperator*) 

167 
val add_ac = [add_assoc, add_commute, add_left_commute]; 

0  168 

169 
(*Cancellation law on the left*) 

170 
val [knat,eqn] = goal Arith.thy 

171 
"[ k:nat; k #+ m = k #+ n ] ==> m=n"; 

172 
by (rtac (eqn RS rev_mp) 1); 

173 
by (nat_ind_tac "k" [knat] 1); 

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

174 
by (ALLGOALS (simp_tac arith_ss)); 
0  175 
by (fast_tac ZF_cs 1); 
176 
val add_left_cancel = result(); 

177 

178 
(*** Multiplication ***) 

179 

180 
(*right annihilation in product*) 

181 
val mult_0_right = prove_goal Arith.thy 

435  182 
"!!m. m:nat ==> m #* 0 = 0" 
183 
(fn _=> 

184 
[ (nat_ind_tac "m" [] 1), 

185 
(ALLGOALS (asm_simp_tac arith_ss)) ]); 

0  186 

187 
(*right successor law for multiplication*) 

188 
val mult_succ_right = prove_goal Arith.thy 

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

189 
"!!m n. [ m:nat; n:nat ] ==> m #* succ(n) = m #+ (m #* n)" 
435  190 
(fn _ => 
6
8ce8c4d13d4d
Installation of new simplifier for ZF. Deleted all congruence rules not
lcp
parents:
0
diff
changeset

191 
[ (nat_ind_tac "m" [] 1), 
435  192 
(ALLGOALS (asm_simp_tac (arith_ss addsimps add_ac))) ]); 
0  193 

194 
(*Commutative law for multiplication*) 

195 
val mult_commute = prove_goal Arith.thy 

196 
"[ m:nat; n:nat ] ==> m #* n = n #* m" 

197 
(fn prems=> 

198 
[ (nat_ind_tac "m" prems 1), 

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

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

200 
(arith_ss addsimps (prems@[mult_0_right, mult_succ_right])))) ]); 
0  201 

202 
(*addition distributes over multiplication*) 

203 
val add_mult_distrib = prove_goal Arith.thy 

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

204 
"!!m n. [ m:nat; k:nat ] ==> (m #+ n) #* k = (m #* k) #+ (n #* k)" 
1c0926788772
ex/{bin.ML,comb.ML,prop.ML}: replaced NewSext by Syntax.simple_sext
lcp
parents:
6
diff
changeset

205 
(fn _=> 
1c0926788772
ex/{bin.ML,comb.ML,prop.ML}: replaced NewSext by Syntax.simple_sext
lcp
parents:
6
diff
changeset

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

207 
(ALLGOALS (asm_simp_tac (arith_ss addsimps [add_assoc RS sym]))) ]); 
0  208 

209 
(*Distributive law on the left; requires an extra typing premise*) 

210 
val add_mult_distrib_left = prove_goal Arith.thy 

435  211 
"!!m. [ m:nat; n:nat; k:nat ] ==> k #* (m #+ n) = (k #* m) #+ (k #* n)" 
0  212 
(fn prems=> 
435  213 
[ (nat_ind_tac "m" [] 1), 
214 
(asm_simp_tac (arith_ss addsimps [mult_0_right]) 1), 

215 
(asm_simp_tac (arith_ss addsimps ([mult_succ_right] @ add_ac)) 1) ]); 

0  216 

217 
(*Associative law for multiplication*) 

218 
val mult_assoc = prove_goal Arith.thy 

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

219 
"!!m n k. [ m:nat; n:nat; k:nat ] ==> (m #* n) #* k = m #* (n #* k)" 
1c0926788772
ex/{bin.ML,comb.ML,prop.ML}: replaced NewSext by Syntax.simple_sext
lcp
parents:
6
diff
changeset

220 
(fn _=> 
1c0926788772
ex/{bin.ML,comb.ML,prop.ML}: replaced NewSext by Syntax.simple_sext
lcp
parents:
6
diff
changeset

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

222 
(ALLGOALS (asm_simp_tac (arith_ss addsimps [add_mult_distrib]))) ]); 
0  223 

224 

225 
(*** Difference ***) 

226 

227 
val diff_self_eq_0 = prove_goal Arith.thy 

228 
"m:nat ==> m # m = 0" 

229 
(fn prems=> 

230 
[ (nat_ind_tac "m" prems 1), 

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

231 
(ALLGOALS (asm_simp_tac (arith_ss addsimps prems))) ]); 
0  232 

25
3ac1c0c0016e
ordinal: DEFINITION of < and le to replace : and <= on ordinals! Many
lcp
parents:
14
diff
changeset

233 
(*Addition is the inverse of subtraction*) 
3ac1c0c0016e
ordinal: DEFINITION of < and le to replace : and <= on ordinals! Many
lcp
parents:
14
diff
changeset

234 
goal Arith.thy "!!m n. [ n le m; m:nat ] ==> n #+ (m#n) = m"; 
3ac1c0c0016e
ordinal: DEFINITION of < and le to replace : and <= on ordinals! Many
lcp
parents:
14
diff
changeset

235 
by (forward_tac [lt_nat_in_nat] 1); 
127  236 
by (etac nat_succI 1); 
25
3ac1c0c0016e
ordinal: DEFINITION of < and le to replace : and <= on ordinals! Many
lcp
parents:
14
diff
changeset

237 
by (etac rev_mp 1); 
0  238 
by (res_inst_tac [("m","m"),("n","n")] diff_induct 1); 
25
3ac1c0c0016e
ordinal: DEFINITION of < and le to replace : and <= on ordinals! Many
lcp
parents:
14
diff
changeset

239 
by (ALLGOALS (asm_simp_tac arith_ss)); 
0  240 
val add_diff_inverse = result(); 
241 

242 
(*Subtraction is the inverse of addition. *) 

243 
val [mnat,nnat] = goal Arith.thy 

244 
"[ m:nat; n:nat ] ==> (n#+m) #n = m"; 

245 
by (rtac (nnat RS nat_induct) 1); 

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

246 
by (ALLGOALS (asm_simp_tac (arith_ss addsimps [mnat]))); 
0  247 
val diff_add_inverse = result(); 
248 

249 
val [mnat,nnat] = goal Arith.thy 

250 
"[ m:nat; n:nat ] ==> n # (n#+m) = 0"; 

251 
by (rtac (nnat RS nat_induct) 1); 

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

252 
by (ALLGOALS (asm_simp_tac (arith_ss addsimps [mnat]))); 
0  253 
val diff_add_0 = result(); 
254 

255 

256 
(*** Remainder ***) 

257 

25
3ac1c0c0016e
ordinal: DEFINITION of < and le to replace : and <= on ordinals! Many
lcp
parents:
14
diff
changeset

258 
goal Arith.thy "!!m n. [ 0<n; n le m; m:nat ] ==> m # n < m"; 
3ac1c0c0016e
ordinal: DEFINITION of < and le to replace : and <= on ordinals! Many
lcp
parents:
14
diff
changeset

259 
by (forward_tac [lt_nat_in_nat] 1 THEN etac nat_succI 1); 
0  260 
by (etac rev_mp 1); 
261 
by (etac rev_mp 1); 

262 
by (res_inst_tac [("m","m"),("n","n")] diff_induct 1); 

25
3ac1c0c0016e
ordinal: DEFINITION of < and le to replace : and <= on ordinals! Many
lcp
parents:
14
diff
changeset

263 
by (ALLGOALS (asm_simp_tac (nat_ss addsimps [diff_le_self,diff_succ_succ]))); 
0  264 
val div_termination = result(); 
265 

25
3ac1c0c0016e
ordinal: DEFINITION of < and le to replace : and <= on ordinals! Many
lcp
parents:
14
diff
changeset

266 
val div_rls = (*for mod and div*) 
3ac1c0c0016e
ordinal: DEFINITION of < and le to replace : and <= on ordinals! Many
lcp
parents:
14
diff
changeset

267 
nat_typechecks @ 
3ac1c0c0016e
ordinal: DEFINITION of < and le to replace : and <= on ordinals! Many
lcp
parents:
14
diff
changeset

268 
[Ord_transrec_type, apply_type, div_termination RS ltD, if_type, 
435  269 
nat_into_Ord, not_lt_iff_le RS iffD1]; 
25
3ac1c0c0016e
ordinal: DEFINITION of < and le to replace : and <= on ordinals! Many
lcp
parents:
14
diff
changeset

270 

435  271 
val div_ss = ZF_ss addsimps [nat_into_Ord, div_termination RS ltD, 
25
3ac1c0c0016e
ordinal: DEFINITION of < and le to replace : and <= on ordinals! Many
lcp
parents:
14
diff
changeset

272 
not_lt_iff_le RS iffD2]; 
0  273 

274 
(*Type checking depends upon termination!*) 

25
3ac1c0c0016e
ordinal: DEFINITION of < and le to replace : and <= on ordinals! Many
lcp
parents:
14
diff
changeset

275 
goalw Arith.thy [mod_def] "!!m n. [ 0<n; m:nat; n:nat ] ==> m mod n : nat"; 
3ac1c0c0016e
ordinal: DEFINITION of < and le to replace : and <= on ordinals! Many
lcp
parents:
14
diff
changeset

276 
by (REPEAT (ares_tac div_rls 1 ORELSE etac lt_trans 1)); 
0  277 
val mod_type = result(); 
278 

25
3ac1c0c0016e
ordinal: DEFINITION of < and le to replace : and <= on ordinals! Many
lcp
parents:
14
diff
changeset

279 
goal Arith.thy "!!m n. [ 0<n; m<n ] ==> m mod n = m"; 
0  280 
by (rtac (mod_def RS def_transrec RS trans) 1); 
25
3ac1c0c0016e
ordinal: DEFINITION of < and le to replace : and <= on ordinals! Many
lcp
parents:
14
diff
changeset

281 
by (asm_simp_tac div_ss 1); 
0  282 
val mod_less = result(); 
283 

25
3ac1c0c0016e
ordinal: DEFINITION of < and le to replace : and <= on ordinals! Many
lcp
parents:
14
diff
changeset

284 
goal Arith.thy "!!m n. [ 0<n; n le m; m:nat ] ==> m mod n = (m#n) mod n"; 
3ac1c0c0016e
ordinal: DEFINITION of < and le to replace : and <= on ordinals! Many
lcp
parents:
14
diff
changeset

285 
by (forward_tac [lt_nat_in_nat] 1 THEN etac nat_succI 1); 
0  286 
by (rtac (mod_def RS def_transrec RS trans) 1); 
25
3ac1c0c0016e
ordinal: DEFINITION of < and le to replace : and <= on ordinals! Many
lcp
parents:
14
diff
changeset

287 
by (asm_simp_tac div_ss 1); 
0  288 
val mod_geq = result(); 
289 

290 
(*** Quotient ***) 

291 

292 
(*Type checking depends upon termination!*) 

25
3ac1c0c0016e
ordinal: DEFINITION of < and le to replace : and <= on ordinals! Many
lcp
parents:
14
diff
changeset

293 
goalw Arith.thy [div_def] 
3ac1c0c0016e
ordinal: DEFINITION of < and le to replace : and <= on ordinals! Many
lcp
parents:
14
diff
changeset

294 
"!!m n. [ 0<n; m:nat; n:nat ] ==> m div n : nat"; 
3ac1c0c0016e
ordinal: DEFINITION of < and le to replace : and <= on ordinals! Many
lcp
parents:
14
diff
changeset

295 
by (REPEAT (ares_tac div_rls 1 ORELSE etac lt_trans 1)); 
0  296 
val div_type = result(); 
297 

25
3ac1c0c0016e
ordinal: DEFINITION of < and le to replace : and <= on ordinals! Many
lcp
parents:
14
diff
changeset

298 
goal Arith.thy "!!m n. [ 0<n; m<n ] ==> m div n = 0"; 
0  299 
by (rtac (div_def RS def_transrec RS trans) 1); 
25
3ac1c0c0016e
ordinal: DEFINITION of < and le to replace : and <= on ordinals! Many
lcp
parents:
14
diff
changeset

300 
by (asm_simp_tac div_ss 1); 
0  301 
val div_less = result(); 
302 

25
3ac1c0c0016e
ordinal: DEFINITION of < and le to replace : and <= on ordinals! Many
lcp
parents:
14
diff
changeset

303 
goal Arith.thy 
3ac1c0c0016e
ordinal: DEFINITION of < and le to replace : and <= on ordinals! Many
lcp
parents:
14
diff
changeset

304 
"!!m n. [ 0<n; n le m; m:nat ] ==> m div n = succ((m#n) div n)"; 
3ac1c0c0016e
ordinal: DEFINITION of < and le to replace : and <= on ordinals! Many
lcp
parents:
14
diff
changeset

305 
by (forward_tac [lt_nat_in_nat] 1 THEN etac nat_succI 1); 
0  306 
by (rtac (div_def RS def_transrec RS trans) 1); 
25
3ac1c0c0016e
ordinal: DEFINITION of < and le to replace : and <= on ordinals! Many
lcp
parents:
14
diff
changeset

307 
by (asm_simp_tac div_ss 1); 
0  308 
val div_geq = result(); 
309 

310 
(*Main Result.*) 

25
3ac1c0c0016e
ordinal: DEFINITION of < and le to replace : and <= on ordinals! Many
lcp
parents:
14
diff
changeset

311 
goal Arith.thy 
3ac1c0c0016e
ordinal: DEFINITION of < and le to replace : and <= on ordinals! Many
lcp
parents:
14
diff
changeset

312 
"!!m n. [ 0<n; m:nat; n:nat ] ==> (m div n)#*n #+ m mod n = m"; 
3ac1c0c0016e
ordinal: DEFINITION of < and le to replace : and <= on ordinals! Many
lcp
parents:
14
diff
changeset

313 
by (etac complete_induct 1); 
3ac1c0c0016e
ordinal: DEFINITION of < and le to replace : and <= on ordinals! Many
lcp
parents:
14
diff
changeset

314 
by (res_inst_tac [("Q","x<n")] (excluded_middle RS disjE) 1); 
3ac1c0c0016e
ordinal: DEFINITION of < and le to replace : and <= on ordinals! Many
lcp
parents:
14
diff
changeset

315 
(*case x<n*) 
3ac1c0c0016e
ordinal: DEFINITION of < and le to replace : and <= on ordinals! Many
lcp
parents:
14
diff
changeset

316 
by (asm_simp_tac (arith_ss addsimps [mod_less, div_less]) 2); 
3ac1c0c0016e
ordinal: DEFINITION of < and le to replace : and <= on ordinals! Many
lcp
parents:
14
diff
changeset

317 
(*case n le x*) 
3ac1c0c0016e
ordinal: DEFINITION of < and le to replace : and <= on ordinals! Many
lcp
parents:
14
diff
changeset

318 
by (asm_full_simp_tac 
435  319 
(arith_ss addsimps [not_lt_iff_le, nat_into_Ord, 
25
3ac1c0c0016e
ordinal: DEFINITION of < and le to replace : and <= on ordinals! Many
lcp
parents:
14
diff
changeset

320 
mod_geq, div_geq, add_assoc, 
3ac1c0c0016e
ordinal: DEFINITION of < and le to replace : and <= on ordinals! Many
lcp
parents:
14
diff
changeset

321 
div_termination RS ltD, add_diff_inverse]) 1); 
0  322 
val mod_div_equality = result(); 
323 

324 

25
3ac1c0c0016e
ordinal: DEFINITION of < and le to replace : and <= on ordinals! Many
lcp
parents:
14
diff
changeset

325 
(**** Additional theorems about "le" ****) 
0  326 

25
3ac1c0c0016e
ordinal: DEFINITION of < and le to replace : and <= on ordinals! Many
lcp
parents:
14
diff
changeset

327 
goal Arith.thy "!!m n. [ m:nat; n:nat ] ==> m le m #+ n"; 
3ac1c0c0016e
ordinal: DEFINITION of < and le to replace : and <= on ordinals! Many
lcp
parents:
14
diff
changeset

328 
by (etac nat_induct 1); 
3ac1c0c0016e
ordinal: DEFINITION of < and le to replace : and <= on ordinals! Many
lcp
parents:
14
diff
changeset

329 
by (ALLGOALS (asm_simp_tac arith_ss)); 
3ac1c0c0016e
ordinal: DEFINITION of < and le to replace : and <= on ordinals! Many
lcp
parents:
14
diff
changeset

330 
val add_le_self = result(); 
14
1c0926788772
ex/{bin.ML,comb.ML,prop.ML}: replaced NewSext by Syntax.simple_sext
lcp
parents:
6
diff
changeset

331 

25
3ac1c0c0016e
ordinal: DEFINITION of < and le to replace : and <= on ordinals! Many
lcp
parents:
14
diff
changeset

332 
goal Arith.thy "!!m n. [ m:nat; n:nat ] ==> m le n #+ m"; 
14
1c0926788772
ex/{bin.ML,comb.ML,prop.ML}: replaced NewSext by Syntax.simple_sext
lcp
parents:
6
diff
changeset

333 
by (rtac (add_commute RS ssubst) 1); 
25
3ac1c0c0016e
ordinal: DEFINITION of < and le to replace : and <= on ordinals! Many
lcp
parents:
14
diff
changeset

334 
by (REPEAT (ares_tac [add_le_self] 1)); 
3ac1c0c0016e
ordinal: DEFINITION of < and le to replace : and <= on ordinals! Many
lcp
parents:
14
diff
changeset

335 
val add_le_self2 = result(); 
14
1c0926788772
ex/{bin.ML,comb.ML,prop.ML}: replaced NewSext by Syntax.simple_sext
lcp
parents:
6
diff
changeset

336 

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

337 
(** Monotonicity of addition **) 
1c0926788772
ex/{bin.ML,comb.ML,prop.ML}: replaced NewSext by Syntax.simple_sext
lcp
parents:
6
diff
changeset

338 

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

339 
(*strict, in 1st argument*) 
25
3ac1c0c0016e
ordinal: DEFINITION of < and le to replace : and <= on ordinals! Many
lcp
parents:
14
diff
changeset

340 
goal Arith.thy "!!i j k. [ i<j; j:nat; k:nat ] ==> i#+k < j#+k"; 
3ac1c0c0016e
ordinal: DEFINITION of < and le to replace : and <= on ordinals! Many
lcp
parents:
14
diff
changeset

341 
by (forward_tac [lt_nat_in_nat] 1); 
127  342 
by (assume_tac 1); 
25
3ac1c0c0016e
ordinal: DEFINITION of < and le to replace : and <= on ordinals! Many
lcp
parents:
14
diff
changeset

343 
by (etac succ_lt_induct 1); 
3ac1c0c0016e
ordinal: DEFINITION of < and le to replace : and <= on ordinals! Many
lcp
parents:
14
diff
changeset

344 
by (ALLGOALS (asm_simp_tac (arith_ss addsimps [leI]))); 
3ac1c0c0016e
ordinal: DEFINITION of < and le to replace : and <= on ordinals! Many
lcp
parents:
14
diff
changeset

345 
val add_lt_mono1 = result(); 
14
1c0926788772
ex/{bin.ML,comb.ML,prop.ML}: replaced NewSext by Syntax.simple_sext
lcp
parents:
6
diff
changeset

346 

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

347 
(*strict, in both arguments*) 
25
3ac1c0c0016e
ordinal: DEFINITION of < and le to replace : and <= on ordinals! Many
lcp
parents:
14
diff
changeset

348 
goal Arith.thy "!!i j k l. [ i<j; k<l; j:nat; l:nat ] ==> i#+k < j#+l"; 
3ac1c0c0016e
ordinal: DEFINITION of < and le to replace : and <= on ordinals! Many
lcp
parents:
14
diff
changeset

349 
by (rtac (add_lt_mono1 RS lt_trans) 1); 
3ac1c0c0016e
ordinal: DEFINITION of < and le to replace : and <= on ordinals! Many
lcp
parents:
14
diff
changeset

350 
by (REPEAT (eresolve_tac [asm_rl, lt_nat_in_nat] 1)); 
14
1c0926788772
ex/{bin.ML,comb.ML,prop.ML}: replaced NewSext by Syntax.simple_sext
lcp
parents:
6
diff
changeset

351 
by (EVERY [rtac (add_commute RS ssubst) 1, 
1c0926788772
ex/{bin.ML,comb.ML,prop.ML}: replaced NewSext by Syntax.simple_sext
lcp
parents:
6
diff
changeset

352 
rtac (add_commute RS ssubst) 3, 
25
3ac1c0c0016e
ordinal: DEFINITION of < and le to replace : and <= on ordinals! Many
lcp
parents:
14
diff
changeset

353 
rtac add_lt_mono1 5]); 
3ac1c0c0016e
ordinal: DEFINITION of < and le to replace : and <= on ordinals! Many
lcp
parents:
14
diff
changeset

354 
by (REPEAT (eresolve_tac [asm_rl, lt_nat_in_nat] 1)); 
3ac1c0c0016e
ordinal: DEFINITION of < and le to replace : and <= on ordinals! Many
lcp
parents:
14
diff
changeset

355 
val add_lt_mono = result(); 
14
1c0926788772
ex/{bin.ML,comb.ML,prop.ML}: replaced NewSext by Syntax.simple_sext
lcp
parents:
6
diff
changeset

356 

25
3ac1c0c0016e
ordinal: DEFINITION of < and le to replace : and <= on ordinals! Many
lcp
parents:
14
diff
changeset

357 
(*A [clumsy] way of lifting < monotonicity to le monotonicity *) 
435  358 
val lt_mono::ford::prems = goal Ordinal.thy 
25
3ac1c0c0016e
ordinal: DEFINITION of < and le to replace : and <= on ordinals! Many
lcp
parents:
14
diff
changeset

359 
"[ !!i j. [ i<j; j:k ] ==> f(i) < f(j); \ 
3ac1c0c0016e
ordinal: DEFINITION of < and le to replace : and <= on ordinals! Many
lcp
parents:
14
diff
changeset

360 
\ !!i. i:k ==> Ord(f(i)); \ 
3ac1c0c0016e
ordinal: DEFINITION of < and le to replace : and <= on ordinals! Many
lcp
parents:
14
diff
changeset

361 
\ i le j; j:k \ 
3ac1c0c0016e
ordinal: DEFINITION of < and le to replace : and <= on ordinals! Many
lcp
parents:
14
diff
changeset

362 
\ ] ==> f(i) le f(j)"; 
14
1c0926788772
ex/{bin.ML,comb.ML,prop.ML}: replaced NewSext by Syntax.simple_sext
lcp
parents:
6
diff
changeset

363 
by (cut_facts_tac prems 1); 
25
3ac1c0c0016e
ordinal: DEFINITION of < and le to replace : and <= on ordinals! Many
lcp
parents:
14
diff
changeset

364 
by (fast_tac (lt_cs addSIs [lt_mono,ford] addSEs [leE]) 1); 
3ac1c0c0016e
ordinal: DEFINITION of < and le to replace : and <= on ordinals! Many
lcp
parents:
14
diff
changeset

365 
val Ord_lt_mono_imp_le_mono = result(); 
14
1c0926788772
ex/{bin.ML,comb.ML,prop.ML}: replaced NewSext by Syntax.simple_sext
lcp
parents:
6
diff
changeset

366 

25
3ac1c0c0016e
ordinal: DEFINITION of < and le to replace : and <= on ordinals! Many
lcp
parents:
14
diff
changeset

367 
(*le monotonicity, 1st argument*) 
14
1c0926788772
ex/{bin.ML,comb.ML,prop.ML}: replaced NewSext by Syntax.simple_sext
lcp
parents:
6
diff
changeset

368 
goal Arith.thy 
25
3ac1c0c0016e
ordinal: DEFINITION of < and le to replace : and <= on ordinals! Many
lcp
parents:
14
diff
changeset

369 
"!!i j k. [ i le j; j:nat; k:nat ] ==> i#+k le j#+k"; 
3ac1c0c0016e
ordinal: DEFINITION of < and le to replace : and <= on ordinals! Many
lcp
parents:
14
diff
changeset

370 
by (res_inst_tac [("f", "%j.j#+k")] Ord_lt_mono_imp_le_mono 1); 
435  371 
by (REPEAT (ares_tac [add_lt_mono1, add_type RS nat_into_Ord] 1)); 
25
3ac1c0c0016e
ordinal: DEFINITION of < and le to replace : and <= on ordinals! Many
lcp
parents:
14
diff
changeset

372 
val add_le_mono1 = result(); 
14
1c0926788772
ex/{bin.ML,comb.ML,prop.ML}: replaced NewSext by Syntax.simple_sext
lcp
parents:
6
diff
changeset

373 

25
3ac1c0c0016e
ordinal: DEFINITION of < and le to replace : and <= on ordinals! Many
lcp
parents:
14
diff
changeset

374 
(* le monotonicity, BOTH arguments*) 
14
1c0926788772
ex/{bin.ML,comb.ML,prop.ML}: replaced NewSext by Syntax.simple_sext
lcp
parents:
6
diff
changeset

375 
goal Arith.thy 
25
3ac1c0c0016e
ordinal: DEFINITION of < and le to replace : and <= on ordinals! Many
lcp
parents:
14
diff
changeset

376 
"!!i j k. [ i le j; k le l; j:nat; l:nat ] ==> i#+k le j#+l"; 
3ac1c0c0016e
ordinal: DEFINITION of < and le to replace : and <= on ordinals! Many
lcp
parents:
14
diff
changeset

377 
by (rtac (add_le_mono1 RS le_trans) 1); 
3ac1c0c0016e
ordinal: DEFINITION of < and le to replace : and <= on ordinals! Many
lcp
parents:
14
diff
changeset

378 
by (REPEAT (eresolve_tac [asm_rl, lt_nat_in_nat, nat_succI] 1)); 
14
1c0926788772
ex/{bin.ML,comb.ML,prop.ML}: replaced NewSext by Syntax.simple_sext
lcp
parents:
6
diff
changeset

379 
by (EVERY [rtac (add_commute RS ssubst) 1, 
1c0926788772
ex/{bin.ML,comb.ML,prop.ML}: replaced NewSext by Syntax.simple_sext
lcp
parents:
6
diff
changeset

380 
rtac (add_commute RS ssubst) 3, 
25
3ac1c0c0016e
ordinal: DEFINITION of < and le to replace : and <= on ordinals! Many
lcp
parents:
14
diff
changeset

381 
rtac add_le_mono1 5]); 
3ac1c0c0016e
ordinal: DEFINITION of < and le to replace : and <= on ordinals! Many
lcp
parents:
14
diff
changeset

382 
by (REPEAT (eresolve_tac [asm_rl, lt_nat_in_nat, nat_succI] 1)); 
3ac1c0c0016e
ordinal: DEFINITION of < and le to replace : and <= on ordinals! Many
lcp
parents:
14
diff
changeset

383 
val add_le_mono = result(); 