author  haftmann 
Fri, 30 Dec 2016 18:02:27 +0100  
changeset 64712  38adf0c59c35 
parent 64447  e44f5c123f26 
child 64849  766db3539859 
permissions  rwrr 
923  1 
(* Title: HOL/Nat.thy 
63588  2 
Author: Tobias Nipkow 
3 
Author: Lawrence C Paulson 

4 
Author: Markus Wenzel 

923  5 
*) 
6 

60758  7 
section \<open>Natural numbers\<close> 
13449  8 

15131  9 
theory Nat 
64447  10 
imports Inductive Typedef Fun Rings 
15131  11 
begin 
13449  12 

57952  13 
named_theorems arith "arith facts  only ground formulas" 
48891  14 
ML_file "Tools/arith_data.ML" 
15 

16 

61799  17 
subsection \<open>Type \<open>ind\<close>\<close> 
13449  18 

19 
typedecl ind 

20 

63110  21 
axiomatization Zero_Rep :: ind and Suc_Rep :: "ind \<Rightarrow> ind" 
22 
\<comment> \<open>The axiom of infinity in 2 parts:\<close> 

63588  23 
where Suc_Rep_inject: "Suc_Rep x = Suc_Rep y \<Longrightarrow> x = y" 
24 
and Suc_Rep_not_Zero_Rep: "Suc_Rep x \<noteq> Zero_Rep" 

25 

19573  26 

60758  27 
subsection \<open>Type nat\<close> 
28 

29 
text \<open>Type definition\<close> 

13449  30 

63588  31 
inductive Nat :: "ind \<Rightarrow> bool" 
32 
where 

33 
Zero_RepI: "Nat Zero_Rep" 

34 
 Suc_RepI: "Nat i \<Longrightarrow> Nat (Suc_Rep i)" 

13449  35 

49834  36 
typedef nat = "{n. Nat n}" 
45696  37 
morphisms Rep_Nat Abs_Nat 
44278
1220ecb81e8f
observe distinction between sets and predicates more properly
haftmann
parents:
43595
diff
changeset

38 
using Nat.Zero_RepI by auto 
1220ecb81e8f
observe distinction between sets and predicates more properly
haftmann
parents:
43595
diff
changeset

39 

63588  40 
lemma Nat_Rep_Nat: "Nat (Rep_Nat n)" 
44278
1220ecb81e8f
observe distinction between sets and predicates more properly
haftmann
parents:
43595
diff
changeset

41 
using Rep_Nat by simp 
13449  42 

63588  43 
lemma Nat_Abs_Nat_inverse: "Nat n \<Longrightarrow> Rep_Nat (Abs_Nat n) = n" 
44278
1220ecb81e8f
observe distinction between sets and predicates more properly
haftmann
parents:
43595
diff
changeset

44 
using Abs_Nat_inverse by simp 
1220ecb81e8f
observe distinction between sets and predicates more properly
haftmann
parents:
43595
diff
changeset

45 

63588  46 
lemma Nat_Abs_Nat_inject: "Nat n \<Longrightarrow> Nat m \<Longrightarrow> Abs_Nat n = Abs_Nat m \<longleftrightarrow> n = m" 
44278
1220ecb81e8f
observe distinction between sets and predicates more properly
haftmann
parents:
43595
diff
changeset

47 
using Abs_Nat_inject by simp 
13449  48 

25510  49 
instantiation nat :: zero 
50 
begin 

51 

63588  52 
definition Zero_nat_def: "0 = Abs_Nat Zero_Rep" 
25510  53 

54 
instance .. 

55 

56 
end 

24995  57 

63588  58 
definition Suc :: "nat \<Rightarrow> nat" 
59 
where "Suc n = Abs_Nat (Suc_Rep (Rep_Nat n))" 

44278
1220ecb81e8f
observe distinction between sets and predicates more properly
haftmann
parents:
43595
diff
changeset

60 

27104
791607529f6d
rep_datatype command now takes list of constructors as input arguments
haftmann
parents:
26748
diff
changeset

61 
lemma Suc_not_Zero: "Suc m \<noteq> 0" 
63588  62 
by (simp add: Zero_nat_def Suc_def Suc_RepI Zero_RepI 
63 
Nat_Abs_Nat_inject Suc_Rep_not_Zero_Rep Nat_Rep_Nat) 

13449  64 

27104
791607529f6d
rep_datatype command now takes list of constructors as input arguments
haftmann
parents:
26748
diff
changeset

65 
lemma Zero_not_Suc: "0 \<noteq> Suc m" 
63588  66 
by (rule not_sym) (rule Suc_not_Zero) 
13449  67 

34208
a7acd6c68d9b
more regular axiom of infinity, with no (indirect) reference to overloaded constants
krauss
parents:
33657
diff
changeset

68 
lemma Suc_Rep_inject': "Suc_Rep x = Suc_Rep y \<longleftrightarrow> x = y" 
a7acd6c68d9b
more regular axiom of infinity, with no (indirect) reference to overloaded constants
krauss
parents:
33657
diff
changeset

69 
by (rule iffI, rule Suc_Rep_inject) simp_all 
a7acd6c68d9b
more regular axiom of infinity, with no (indirect) reference to overloaded constants
krauss
parents:
33657
diff
changeset

70 

55417
01fbfb60c33e
adapted to 'xxx_{case,rec}' renaming, to new theorem names, and to new variable names in theorems
blanchet
parents:
55415
diff
changeset

71 
lemma nat_induct0: 
63588  72 
assumes "P 0" 
73 
and "\<And>n. P n \<Longrightarrow> P (Suc n)" 

55417
01fbfb60c33e
adapted to 'xxx_{case,rec}' renaming, to new theorem names, and to new variable names in theorems
blanchet
parents:
55415
diff
changeset

74 
shows "P n" 
63588  75 
using assms 
76 
apply (unfold Zero_nat_def Suc_def) 

77 
apply (rule Rep_Nat_inverse [THEN subst]) \<comment> \<open>types force good instantiation\<close> 

78 
apply (erule Nat_Rep_Nat [THEN Nat.induct]) 

79 
apply (iprover elim: Nat_Abs_Nat_inverse [THEN subst]) 

80 
done 

81 

82 
free_constructors case_nat for "0 :: nat"  Suc pred 

83 
where "pred (0 :: nat) = (0 :: nat)" 

58189
9d714be4f028
added 'plugins' option to control which hooks are enabled
blanchet
parents:
57983
diff
changeset

84 
apply atomize_elim 
9d714be4f028
added 'plugins' option to control which hooks are enabled
blanchet
parents:
57983
diff
changeset

85 
apply (rename_tac n, induct_tac n rule: nat_induct0, auto) 
63588  86 
apply (simp add: Suc_def Nat_Abs_Nat_inject Nat_Rep_Nat Suc_RepI Suc_Rep_inject' Rep_Nat_inject) 
58189
9d714be4f028
added 'plugins' option to control which hooks are enabled
blanchet
parents:
57983
diff
changeset

87 
apply (simp only: Suc_not_Zero) 
9d714be4f028
added 'plugins' option to control which hooks are enabled
blanchet
parents:
57983
diff
changeset

88 
done 
55417
01fbfb60c33e
adapted to 'xxx_{case,rec}' renaming, to new theorem names, and to new variable names in theorems
blanchet
parents:
55415
diff
changeset

89 

61799  90 
\<comment> \<open>Avoid name clashes by prefixing the output of \<open>old_rep_datatype\<close> with \<open>old\<close>.\<close> 
60758  91 
setup \<open>Sign.mandatory_path "old"\<close> 
55417
01fbfb60c33e
adapted to 'xxx_{case,rec}' renaming, to new theorem names, and to new variable names in theorems
blanchet
parents:
55415
diff
changeset

92 

61076  93 
old_rep_datatype "0 :: nat" Suc 
63588  94 
apply (erule nat_induct0) 
95 
apply assumption 

96 
apply (rule nat.inject) 

97 
apply (rule nat.distinct(1)) 

98 
done 

55417
01fbfb60c33e
adapted to 'xxx_{case,rec}' renaming, to new theorem names, and to new variable names in theorems
blanchet
parents:
55415
diff
changeset

99 

60758  100 
setup \<open>Sign.parent_path\<close> 
101 

61799  102 
\<comment> \<open>But erase the prefix for properties that are not generated by \<open>free_constructors\<close>.\<close> 
60758  103 
setup \<open>Sign.mandatory_path "nat"\<close> 
55417
01fbfb60c33e
adapted to 'xxx_{case,rec}' renaming, to new theorem names, and to new variable names in theorems
blanchet
parents:
55415
diff
changeset

104 

63588  105 
declare old.nat.inject[iff del] 
106 
and old.nat.distinct(1)[simp del, induct_simp del] 

55417
01fbfb60c33e
adapted to 'xxx_{case,rec}' renaming, to new theorem names, and to new variable names in theorems
blanchet
parents:
55415
diff
changeset

107 

01fbfb60c33e
adapted to 'xxx_{case,rec}' renaming, to new theorem names, and to new variable names in theorems
blanchet
parents:
55415
diff
changeset

108 
lemmas induct = old.nat.induct 
01fbfb60c33e
adapted to 'xxx_{case,rec}' renaming, to new theorem names, and to new variable names in theorems
blanchet
parents:
55415
diff
changeset

109 
lemmas inducts = old.nat.inducts 
55642
63beb38e9258
adapted to renaming of datatype 'cases' and 'recs' to 'case' and 'rec'
blanchet
parents:
55575
diff
changeset

110 
lemmas rec = old.nat.rec 
63beb38e9258
adapted to renaming of datatype 'cases' and 'recs' to 'case' and 'rec'
blanchet
parents:
55575
diff
changeset

111 
lemmas simps = nat.inject nat.distinct nat.case nat.rec 
55417
01fbfb60c33e
adapted to 'xxx_{case,rec}' renaming, to new theorem names, and to new variable names in theorems
blanchet
parents:
55415
diff
changeset

112 

60758  113 
setup \<open>Sign.parent_path\<close> 
55417
01fbfb60c33e
adapted to 'xxx_{case,rec}' renaming, to new theorem names, and to new variable names in theorems
blanchet
parents:
55415
diff
changeset

114 

63110  115 
abbreviation rec_nat :: "'a \<Rightarrow> (nat \<Rightarrow> 'a \<Rightarrow> 'a) \<Rightarrow> nat \<Rightarrow> 'a" 
116 
where "rec_nat \<equiv> old.rec_nat" 

55417
01fbfb60c33e
adapted to 'xxx_{case,rec}' renaming, to new theorem names, and to new variable names in theorems
blanchet
parents:
55415
diff
changeset

117 

55424
9ab4129a76a3
remove hidden fact about hidden constant from code generator setup
blanchet
parents:
55423
diff
changeset

118 
declare nat.sel[code del] 
9ab4129a76a3
remove hidden fact about hidden constant from code generator setup
blanchet
parents:
55423
diff
changeset

119 

61799  120 
hide_const (open) Nat.pred \<comment> \<open>hide everything related to the selector\<close> 
55417
01fbfb60c33e
adapted to 'xxx_{case,rec}' renaming, to new theorem names, and to new variable names in theorems
blanchet
parents:
55415
diff
changeset

121 
hide_fact 
01fbfb60c33e
adapted to 'xxx_{case,rec}' renaming, to new theorem names, and to new variable names in theorems
blanchet
parents:
55415
diff
changeset

122 
nat.case_eq_if 
01fbfb60c33e
adapted to 'xxx_{case,rec}' renaming, to new theorem names, and to new variable names in theorems
blanchet
parents:
55415
diff
changeset

123 
nat.collapse 
01fbfb60c33e
adapted to 'xxx_{case,rec}' renaming, to new theorem names, and to new variable names in theorems
blanchet
parents:
55415
diff
changeset

124 
nat.expand 
01fbfb60c33e
adapted to 'xxx_{case,rec}' renaming, to new theorem names, and to new variable names in theorems
blanchet
parents:
55415
diff
changeset

125 
nat.sel 
57983
6edc3529bb4e
reordered some (co)datatype property names for more consistency
blanchet
parents:
57952
diff
changeset

126 
nat.exhaust_sel 
6edc3529bb4e
reordered some (co)datatype property names for more consistency
blanchet
parents:
57952
diff
changeset

127 
nat.split_sel 
6edc3529bb4e
reordered some (co)datatype property names for more consistency
blanchet
parents:
57952
diff
changeset

128 
nat.split_sel_asm 
55417
01fbfb60c33e
adapted to 'xxx_{case,rec}' renaming, to new theorem names, and to new variable names in theorems
blanchet
parents:
55415
diff
changeset

129 

01fbfb60c33e
adapted to 'xxx_{case,rec}' renaming, to new theorem names, and to new variable names in theorems
blanchet
parents:
55415
diff
changeset

130 
lemma nat_exhaust [case_names 0 Suc, cases type: nat]: 
63588  131 
"(y = 0 \<Longrightarrow> P) \<Longrightarrow> (\<And>nat. y = Suc nat \<Longrightarrow> P) \<Longrightarrow> P" 
61799  132 
\<comment> \<open>for backward compatibility  names of variables differ\<close> 
63588  133 
by (rule old.nat.exhaust) 
13449  134 

27104
791607529f6d
rep_datatype command now takes list of constructors as input arguments
haftmann
parents:
26748
diff
changeset

135 
lemma nat_induct [case_names 0 Suc, induct type: nat]: 
791607529f6d
rep_datatype command now takes list of constructors as input arguments
haftmann
parents:
26748
diff
changeset

136 
fixes n 
55417
01fbfb60c33e
adapted to 'xxx_{case,rec}' renaming, to new theorem names, and to new variable names in theorems
blanchet
parents:
55415
diff
changeset

137 
assumes "P 0" and "\<And>n. P n \<Longrightarrow> P (Suc n)" 
27104
791607529f6d
rep_datatype command now takes list of constructors as input arguments
haftmann
parents:
26748
diff
changeset

138 
shows "P n" 
63588  139 
\<comment> \<open>for backward compatibility  names of variables differ\<close> 
140 
using assms by (rule nat.induct) 

13449  141 

55417
01fbfb60c33e
adapted to 'xxx_{case,rec}' renaming, to new theorem names, and to new variable names in theorems
blanchet
parents:
55415
diff
changeset

142 
hide_fact 
01fbfb60c33e
adapted to 'xxx_{case,rec}' renaming, to new theorem names, and to new variable names in theorems
blanchet
parents:
55415
diff
changeset

143 
nat_exhaust 
01fbfb60c33e
adapted to 'xxx_{case,rec}' renaming, to new theorem names, and to new variable names in theorems
blanchet
parents:
55415
diff
changeset

144 
nat_induct0 
24995  145 

60758  146 
ML \<open> 
58389  147 
val nat_basic_lfp_sugar = 
148 
let 

149 
val ctr_sugar = the (Ctr_Sugar.ctr_sugar_of_global @{theory} @{type_name nat}); 

150 
val recx = Logic.varify_types_global @{term rec_nat}; 

151 
val C = body_type (fastype_of recx); 

152 
in 

153 
{T = HOLogic.natT, fp_res_index = 0, C = C, fun_arg_Tsss = [[], [[HOLogic.natT, C]]], 

154 
ctr_sugar = ctr_sugar, recx = recx, rec_thms = @{thms nat.rec}} 

155 
end; 

60758  156 
\<close> 
157 

158 
setup \<open> 

58389  159 
let 
160 
fun basic_lfp_sugars_of _ [@{typ nat}] _ _ ctxt = 

62326
3cf7a067599c
allow predicator instead of map function in 'primrec'
blanchet
parents:
62217
diff
changeset

161 
([], [0], [nat_basic_lfp_sugar], [], [], [], TrueI (*dummy*), [], false, ctxt) 
58389  162 
 basic_lfp_sugars_of bs arg_Ts callers callssss ctxt = 
163 
BNF_LFP_Rec_Sugar.default_basic_lfp_sugars_of bs arg_Ts callers callssss ctxt; 

164 
in 

165 
BNF_LFP_Rec_Sugar.register_lfp_rec_extension 

166 
{nested_simps = [], is_new_datatype = K (K true), basic_lfp_sugars_of = basic_lfp_sugars_of, 

167 
rewrite_nested_rec_call = NONE} 

168 
end 

60758  169 
\<close> 
170 

171 
text \<open>Injectiveness and distinctness lemmas\<close> 

24995  172 

27104
791607529f6d
rep_datatype command now takes list of constructors as input arguments
haftmann
parents:
26748
diff
changeset

173 
lemma inj_Suc[simp]: "inj_on Suc N" 
791607529f6d
rep_datatype command now takes list of constructors as input arguments
haftmann
parents:
26748
diff
changeset

174 
by (simp add: inj_on_def) 
791607529f6d
rep_datatype command now takes list of constructors as input arguments
haftmann
parents:
26748
diff
changeset

175 

26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

176 
lemma Suc_neq_Zero: "Suc m = 0 \<Longrightarrow> R" 
63588  177 
by (rule notE) (rule Suc_not_Zero) 
24995  178 

26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

179 
lemma Zero_neq_Suc: "0 = Suc m \<Longrightarrow> R" 
63588  180 
by (rule Suc_neq_Zero) (erule sym) 
24995  181 

26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

182 
lemma Suc_inject: "Suc x = Suc y \<Longrightarrow> x = y" 
63588  183 
by (rule inj_Suc [THEN injD]) 
24995  184 

14267
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14266
diff
changeset

185 
lemma n_not_Suc_n: "n \<noteq> Suc n" 
63588  186 
by (induct n) simp_all 
13449  187 

26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

188 
lemma Suc_n_not_n: "Suc n \<noteq> n" 
63588  189 
by (rule not_sym) (rule n_not_Suc_n) 
190 

191 
text \<open>A special form of induction for reasoning about @{term "m < n"} and @{term "m  n"}.\<close> 

63110  192 
lemma diff_induct: 
193 
assumes "\<And>x. P x 0" 

194 
and "\<And>y. P 0 (Suc y)" 

195 
and "\<And>x y. P x y \<Longrightarrow> P (Suc x) (Suc y)" 

196 
shows "P m n" 

63588  197 
proof (induct n arbitrary: m) 
198 
case 0 

199 
show ?case by (rule assms(1)) 

200 
next 

201 
case (Suc n) 

202 
show ?case 

203 
proof (induct m) 

204 
case 0 

205 
show ?case by (rule assms(2)) 

206 
next 

207 
case (Suc m) 

208 
from \<open>P m n\<close> show ?case by (rule assms(3)) 

209 
qed 

210 
qed 

13449  211 

24995  212 

60758  213 
subsection \<open>Arithmetic operators\<close> 
24995  214 

49388  215 
instantiation nat :: comm_monoid_diff 
25571
c9e39eafc7a0
instantiation target rather than legacy instance
haftmann
parents:
25563
diff
changeset

216 
begin 
24995  217 

63588  218 
primrec plus_nat 
219 
where 

220 
add_0: "0 + n = (n::nat)" 

221 
 add_Suc: "Suc m + n = Suc (m + n)" 

222 

223 
lemma add_0_right [simp]: "m + 0 = m" 

224 
for m :: nat 

26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

225 
by (induct m) simp_all 
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

226 

f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

227 
lemma add_Suc_right [simp]: "m + Suc n = Suc (m + n)" 
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

228 
by (induct m) simp_all 
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

229 

28514  230 
declare add_0 [code] 
231 

26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

232 
lemma add_Suc_shift [code]: "Suc m + n = m + Suc n" 
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

233 
by simp 
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

234 

63588  235 
primrec minus_nat 
236 
where 

237 
diff_0 [code]: "m  0 = (m::nat)" 

238 
 diff_Suc: "m  Suc n = (case m  n of 0 \<Rightarrow> 0  Suc k \<Rightarrow> k)" 

24995  239 

28514  240 
declare diff_Suc [simp del] 
26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

241 

63588  242 
lemma diff_0_eq_0 [simp, code]: "0  n = 0" 
243 
for n :: nat 

26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

244 
by (induct n) (simp_all add: diff_Suc) 
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

245 

f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

246 
lemma diff_Suc_Suc [simp, code]: "Suc m  Suc n = m  n" 
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

247 
by (induct n) (simp_all add: diff_Suc) 
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

248 

63110  249 
instance 
250 
proof 

26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

251 
fix n m q :: nat 
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

252 
show "(n + m) + q = n + (m + q)" by (induct n) simp_all 
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

253 
show "n + m = m + n" by (induct n) simp_all 
59815
cce82e360c2f
explicit commutative additive inverse operation;
haftmann
parents:
59582
diff
changeset

254 
show "m + n  m = n" by (induct m) simp_all 
cce82e360c2f
explicit commutative additive inverse operation;
haftmann
parents:
59582
diff
changeset

255 
show "n  m  q = n  (m + q)" by (induct q) (simp_all add: diff_Suc) 
26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

256 
show "0 + n = n" by simp 
49388  257 
show "0  n = 0" by simp 
26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

258 
qed 
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

259 

f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

260 
end 
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

261 

36176
3fe7e97ccca8
replaced generic 'hide' command by more conventional 'hide_class', 'hide_type', 'hide_const', 'hide_fact'  frees some popular keywords;
wenzelm
parents:
35828
diff
changeset

262 
hide_fact (open) add_0 add_0_right diff_0 
35047
1b2bae06c796
hide fact Nat.add_0_right; make add_0_right from Groups priority
haftmann
parents:
35028
diff
changeset

263 

26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

264 
instantiation nat :: comm_semiring_1_cancel 
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

265 
begin 
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

266 

63588  267 
definition One_nat_def [simp]: "1 = Suc 0" 
268 

269 
primrec times_nat 

270 
where 

271 
mult_0: "0 * n = (0::nat)" 

272 
 mult_Suc: "Suc m * n = n + (m * n)" 

273 

274 
lemma mult_0_right [simp]: "m * 0 = 0" 

275 
for m :: nat 

26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

276 
by (induct m) simp_all 
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

277 

f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

278 
lemma mult_Suc_right [simp]: "m * Suc n = m + (m * n)" 
57512
cc97b347b301
reduced name variants for assoc and commute on plus and mult
haftmann
parents:
57492
diff
changeset

279 
by (induct m) (simp_all add: add.left_commute) 
26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

280 

63588  281 
lemma add_mult_distrib: "(m + n) * k = (m * k) + (n * k)" 
282 
for m n k :: nat 

57512
cc97b347b301
reduced name variants for assoc and commute on plus and mult
haftmann
parents:
57492
diff
changeset

283 
by (induct m) (simp_all add: add.assoc) 
26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

284 

63110  285 
instance 
286 
proof 

287 
fix k n m q :: nat 

63588  288 
show "0 \<noteq> (1::nat)" 
289 
by simp 

290 
show "1 * n = n" 

291 
by simp 

292 
show "n * m = m * n" 

293 
by (induct n) simp_all 

294 
show "(n * m) * q = n * (m * q)" 

295 
by (induct n) (simp_all add: add_mult_distrib) 

296 
show "(n + m) * q = n * q + m * q" 

297 
by (rule add_mult_distrib) 

63110  298 
show "k * (m  n) = (k * m)  (k * n)" 
60562
24af00b010cf
Amalgamation of the class comm_semiring_1_diff_distrib into comm_semiring_1_cancel. Moving axiom le_add_diff_inverse2 from semiring_numeral_div to linordered_semidom.
paulson <lp15@cam.ac.uk>
parents:
60427
diff
changeset

299 
by (induct m n rule: diff_induct) simp_all 
26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

300 
qed 
25571
c9e39eafc7a0
instantiation target rather than legacy instance
haftmann
parents:
25563
diff
changeset

301 

c9e39eafc7a0
instantiation target rather than legacy instance
haftmann
parents:
25563
diff
changeset

302 
end 
24995  303 

60562
24af00b010cf
Amalgamation of the class comm_semiring_1_diff_distrib into comm_semiring_1_cancel. Moving axiom le_add_diff_inverse2 from semiring_numeral_div to linordered_semidom.
paulson <lp15@cam.ac.uk>
parents:
60427
diff
changeset

304 

60758  305 
subsubsection \<open>Addition\<close> 
26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

306 

61799  307 
text \<open>Reasoning about \<open>m + 0 = 0\<close>, etc.\<close> 
26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

308 

63588  309 
lemma add_is_0 [iff]: "m + n = 0 \<longleftrightarrow> m = 0 \<and> n = 0" 
310 
for m n :: nat 

26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

311 
by (cases m) simp_all 
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

312 

63110  313 
lemma add_is_1: "m + n = Suc 0 \<longleftrightarrow> m = Suc 0 \<and> n = 0  m = 0 \<and> n = Suc 0" 
26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

314 
by (cases m) simp_all 
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

315 

63110  316 
lemma one_is_add: "Suc 0 = m + n \<longleftrightarrow> m = Suc 0 \<and> n = 0  m = 0 \<and> n = Suc 0" 
26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

317 
by (rule trans, rule eq_commute, rule add_is_1) 
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

318 

63588  319 
lemma add_eq_self_zero: "m + n = m \<Longrightarrow> n = 0" 
320 
for m n :: nat 

26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

321 
by (induct m) simp_all 
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

322 

63588  323 
lemma inj_on_add_nat [simp]: "inj_on (\<lambda>n. n + k) N" 
324 
for k :: nat 

325 
proof (induct k) 

326 
case 0 

327 
then show ?case by simp 

328 
next 

329 
case (Suc k) 

330 
show ?case 

331 
using comp_inj_on [OF Suc inj_Suc] by (simp add: o_def) 

332 
qed 

26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

333 

47208  334 
lemma Suc_eq_plus1: "Suc n = n + 1" 
63588  335 
by simp 
47208  336 

337 
lemma Suc_eq_plus1_left: "Suc n = 1 + n" 

63588  338 
by simp 
47208  339 

26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

340 

60758  341 
subsubsection \<open>Difference\<close> 
26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

342 

f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

343 
lemma Suc_diff_diff [simp]: "(Suc m  n)  Suc k = m  n  k" 
62365  344 
by (simp add: diff_diff_add) 
26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

345 

30093  346 
lemma diff_Suc_1 [simp]: "Suc n  1 = n" 
63588  347 
by simp 
348 

30093  349 

60758  350 
subsubsection \<open>Multiplication\<close> 
26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

351 

63110  352 
lemma mult_is_0 [simp]: "m * n = 0 \<longleftrightarrow> m = 0 \<or> n = 0" for m n :: nat 
26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

353 
by (induct m) auto 
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

354 

63110  355 
lemma mult_eq_1_iff [simp]: "m * n = Suc 0 \<longleftrightarrow> m = Suc 0 \<and> n = Suc 0" 
63588  356 
proof (induct m) 
357 
case 0 

358 
then show ?case by simp 

359 
next 

360 
case (Suc m) 

361 
then show ?case by (induct n) auto 

362 
qed 

26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

363 

63110  364 
lemma one_eq_mult_iff [simp]: "Suc 0 = m * n \<longleftrightarrow> m = Suc 0 \<and> n = Suc 0" 
26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

365 
apply (rule trans) 
63588  366 
apply (rule_tac [2] mult_eq_1_iff) 
367 
apply fastforce 

26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

368 
done 
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

369 

63588  370 
lemma nat_mult_eq_1_iff [simp]: "m * n = 1 \<longleftrightarrow> m = 1 \<and> n = 1" 
371 
for m n :: nat 

30079
293b896b9c25
make proofs work whether or not One_nat_def is a simp rule; replace 1 with Suc 0 in the rhs of some simp rules
huffman
parents:
30056
diff
changeset

372 
unfolding One_nat_def by (rule mult_eq_1_iff) 
293b896b9c25
make proofs work whether or not One_nat_def is a simp rule; replace 1 with Suc 0 in the rhs of some simp rules
huffman
parents:
30056
diff
changeset

373 

63588  374 
lemma nat_1_eq_mult_iff [simp]: "1 = m * n \<longleftrightarrow> m = 1 \<and> n = 1" 
375 
for m n :: nat 

30079
293b896b9c25
make proofs work whether or not One_nat_def is a simp rule; replace 1 with Suc 0 in the rhs of some simp rules
huffman
parents:
30056
diff
changeset

376 
unfolding One_nat_def by (rule one_eq_mult_iff) 
293b896b9c25
make proofs work whether or not One_nat_def is a simp rule; replace 1 with Suc 0 in the rhs of some simp rules
huffman
parents:
30056
diff
changeset

377 

63588  378 
lemma mult_cancel1 [simp]: "k * m = k * n \<longleftrightarrow> m = n \<or> k = 0" 
379 
for k m n :: nat 

26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

380 
proof  
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

381 
have "k \<noteq> 0 \<Longrightarrow> k * m = k * n \<Longrightarrow> m = n" 
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

382 
proof (induct n arbitrary: m) 
63110  383 
case 0 
384 
then show "m = 0" by simp 

26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

385 
next 
63110  386 
case (Suc n) 
387 
then show "m = Suc n" 

388 
by (cases m) (simp_all add: eq_commute [of 0]) 

26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

389 
qed 
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

390 
then show ?thesis by auto 
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

391 
qed 
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

392 

63588  393 
lemma mult_cancel2 [simp]: "m * k = n * k \<longleftrightarrow> m = n \<or> k = 0" 
394 
for k m n :: nat 

57512
cc97b347b301
reduced name variants for assoc and commute on plus and mult
haftmann
parents:
57492
diff
changeset

395 
by (simp add: mult.commute) 
26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

396 

63110  397 
lemma Suc_mult_cancel1: "Suc k * m = Suc k * n \<longleftrightarrow> m = n" 
26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

398 
by (subst mult_cancel1) simp 
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

399 

24995  400 

60758  401 
subsection \<open>Orders on @{typ nat}\<close> 
402 

403 
subsubsection \<open>Operation definition\<close> 

24995  404 

26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

405 
instantiation nat :: linorder 
25510  406 
begin 
407 

63588  408 
primrec less_eq_nat 
409 
where 

410 
"(0::nat) \<le> n \<longleftrightarrow> True" 

411 
 "Suc m \<le> n \<longleftrightarrow> (case n of 0 \<Rightarrow> False  Suc n \<Rightarrow> m \<le> n)" 

26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

412 

28514  413 
declare less_eq_nat.simps [simp del] 
63110  414 

63588  415 
lemma le0 [iff]: "0 \<le> n" for 
416 
n :: nat 

63110  417 
by (simp add: less_eq_nat.simps) 
418 

63588  419 
lemma [code]: "0 \<le> n \<longleftrightarrow> True" 
420 
for n :: nat 

63110  421 
by simp 
26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

422 

63588  423 
definition less_nat 
424 
where less_eq_Suc_le: "n < m \<longleftrightarrow> Suc n \<le> m" 

26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

425 

f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

426 
lemma Suc_le_mono [iff]: "Suc n \<le> Suc m \<longleftrightarrow> n \<le> m" 
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

427 
by (simp add: less_eq_nat.simps(2)) 
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

428 

f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

429 
lemma Suc_le_eq [code]: "Suc m \<le> n \<longleftrightarrow> m < n" 
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

430 
unfolding less_eq_Suc_le .. 
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

431 

63588  432 
lemma le_0_eq [iff]: "n \<le> 0 \<longleftrightarrow> n = 0" 
433 
for n :: nat 

26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

434 
by (induct n) (simp_all add: less_eq_nat.simps(2)) 
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

435 

63588  436 
lemma not_less0 [iff]: "\<not> n < 0" 
437 
for n :: nat 

26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

438 
by (simp add: less_eq_Suc_le) 
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

439 

63588  440 
lemma less_nat_zero_code [code]: "n < 0 \<longleftrightarrow> False" 
441 
for n :: nat 

26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

442 
by simp 
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

443 

f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

444 
lemma Suc_less_eq [iff]: "Suc m < Suc n \<longleftrightarrow> m < n" 
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

445 
by (simp add: less_eq_Suc_le) 
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

446 

f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

447 
lemma less_Suc_eq_le [code]: "m < Suc n \<longleftrightarrow> m \<le> n" 
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

448 
by (simp add: less_eq_Suc_le) 
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

449 

56194  450 
lemma Suc_less_eq2: "Suc n < m \<longleftrightarrow> (\<exists>m'. m = Suc m' \<and> n < m')" 
451 
by (cases m) auto 

452 

26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

453 
lemma le_SucI: "m \<le> n \<Longrightarrow> m \<le> Suc n" 
63110  454 
by (induct m arbitrary: n) (simp_all add: less_eq_nat.simps(2) split: nat.splits) 
26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

455 

f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

456 
lemma Suc_leD: "Suc m \<le> n \<Longrightarrow> m \<le> n" 
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

457 
by (cases n) (auto intro: le_SucI) 
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

458 

f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

459 
lemma less_SucI: "m < n \<Longrightarrow> m < Suc n" 
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

460 
by (simp add: less_eq_Suc_le) (erule Suc_leD) 
24995  461 

26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

462 
lemma Suc_lessD: "Suc m < n \<Longrightarrow> m < n" 
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

463 
by (simp add: less_eq_Suc_le) (erule Suc_leD) 
25510  464 

26315
cb3badaa192e
removed redundant less_trans, less_linear, le_imp_less_or_eq, le_less_trans, less_le_trans (cf. Orderings.thy);
wenzelm
parents:
26300
diff
changeset

465 
instance 
cb3badaa192e
removed redundant less_trans, less_linear, le_imp_less_or_eq, le_less_trans, less_le_trans (cf. Orderings.thy);
wenzelm
parents:
26300
diff
changeset

466 
proof 
63110  467 
fix n m q :: nat 
60562
24af00b010cf
Amalgamation of the class comm_semiring_1_diff_distrib into comm_semiring_1_cancel. Moving axiom le_add_diff_inverse2 from semiring_numeral_div to linordered_semidom.
paulson <lp15@cam.ac.uk>
parents:
60427
diff
changeset

468 
show "n < m \<longleftrightarrow> n \<le> m \<and> \<not> m \<le> n" 
26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

469 
proof (induct n arbitrary: m) 
63110  470 
case 0 
63588  471 
then show ?case 
472 
by (cases m) (simp_all add: less_eq_Suc_le) 

26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

473 
next 
63110  474 
case (Suc n) 
63588  475 
then show ?case 
476 
by (cases m) (simp_all add: less_eq_Suc_le) 

26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

477 
qed 
63588  478 
show "n \<le> n" 
479 
by (induct n) simp_all 

63110  480 
then show "n = m" if "n \<le> m" and "m \<le> n" 
481 
using that by (induct n arbitrary: m) 

26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

482 
(simp_all add: less_eq_nat.simps(2) split: nat.splits) 
63110  483 
show "n \<le> q" if "n \<le> m" and "m \<le> q" 
484 
using that 

26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

485 
proof (induct n arbitrary: m q) 
63110  486 
case 0 
487 
show ?case by simp 

26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

488 
next 
63110  489 
case (Suc n) 
490 
then show ?case 

26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

491 
by (simp_all (no_asm_use) add: less_eq_nat.simps(2) split: nat.splits, clarify, 
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

492 
simp_all (no_asm_use) add: less_eq_nat.simps(2) split: nat.splits, clarify, 
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

493 
simp_all (no_asm_use) add: less_eq_nat.simps(2) split: nat.splits) 
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

494 
qed 
63110  495 
show "n \<le> m \<or> m \<le> n" 
26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

496 
by (induct n arbitrary: m) 
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

497 
(simp_all add: less_eq_nat.simps(2) split: nat.splits) 
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

498 
qed 
25510  499 

500 
end 

13449  501 

52729
412c9e0381a1
factored syntactic type classes for bot and top (by Alessandro Coglio)
haftmann
parents:
52435
diff
changeset

502 
instantiation nat :: order_bot 
29652  503 
begin 
504 

63588  505 
definition bot_nat :: nat 
506 
where "bot_nat = 0" 

507 

508 
instance 

509 
by standard (simp add: bot_nat_def) 

29652  510 

511 
end 

512 

51329
4a3c453f99a1
split dense into inner_dense_order and no_top/no_bot
hoelzl
parents:
51263
diff
changeset

513 
instance nat :: no_top 
61169  514 
by standard (auto intro: less_Suc_eq_le [THEN iffD2]) 
52289  515 

51329
4a3c453f99a1
split dense into inner_dense_order and no_top/no_bot
hoelzl
parents:
51263
diff
changeset

516 

60758  517 
subsubsection \<open>Introduction properties\<close> 
13449  518 

26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

519 
lemma lessI [iff]: "n < Suc n" 
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

520 
by (simp add: less_Suc_eq_le) 
13449  521 

26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

522 
lemma zero_less_Suc [iff]: "0 < Suc n" 
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

523 
by (simp add: less_Suc_eq_le) 
13449  524 

525 

60758  526 
subsubsection \<open>Elimination properties\<close> 
13449  527 

63588  528 
lemma less_not_refl: "\<not> n < n" 
529 
for n :: nat 

26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

530 
by (rule order_less_irrefl) 
13449  531 

63588  532 
lemma less_not_refl2: "n < m \<Longrightarrow> m \<noteq> n" 
533 
for m n :: nat 

60562
24af00b010cf
Amalgamation of the class comm_semiring_1_diff_distrib into comm_semiring_1_cancel. Moving axiom le_add_diff_inverse2 from semiring_numeral_div to linordered_semidom.
paulson <lp15@cam.ac.uk>
parents:
60427
diff
changeset

534 
by (rule not_sym) (rule less_imp_neq) 
13449  535 

63588  536 
lemma less_not_refl3: "s < t \<Longrightarrow> s \<noteq> t" 
537 
for s t :: nat 

26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

538 
by (rule less_imp_neq) 
13449  539 

63588  540 
lemma less_irrefl_nat: "n < n \<Longrightarrow> R" 
541 
for n :: nat 

26335
961bbcc9d85b
removed redundant Nat.less_not_sym, Nat.less_asym;
wenzelm
parents:
26315
diff
changeset

542 
by (rule notE, rule less_not_refl) 
13449  543 

63588  544 
lemma less_zeroE: "n < 0 \<Longrightarrow> R" 
545 
for n :: nat 

26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

546 
by (rule notE) (rule not_less0) 
13449  547 

63110  548 
lemma less_Suc_eq: "m < Suc n \<longleftrightarrow> m < n \<or> m = n" 
26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

549 
unfolding less_Suc_eq_le le_less .. 
13449  550 

30079
293b896b9c25
make proofs work whether or not One_nat_def is a simp rule; replace 1 with Suc 0 in the rhs of some simp rules
huffman
parents:
30056
diff
changeset

551 
lemma less_Suc0 [iff]: "(n < Suc 0) = (n = 0)" 
26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

552 
by (simp add: less_Suc_eq) 
13449  553 

63588  554 
lemma less_one [iff]: "n < 1 \<longleftrightarrow> n = 0" 
555 
for n :: nat 

30079
293b896b9c25
make proofs work whether or not One_nat_def is a simp rule; replace 1 with Suc 0 in the rhs of some simp rules
huffman
parents:
30056
diff
changeset

556 
unfolding One_nat_def by (rule less_Suc0) 
13449  557 

63110  558 
lemma Suc_mono: "m < n \<Longrightarrow> Suc m < Suc n" 
26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

559 
by simp 
13449  560 

63588  561 
text \<open>"Less than" is antisymmetric, sort of.\<close> 
562 
lemma less_antisym: "\<not> n < m \<Longrightarrow> n < Suc m \<Longrightarrow> m = n" 

26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

563 
unfolding not_less less_Suc_eq_le by (rule antisym) 
14302  564 

63588  565 
lemma nat_neq_iff: "m \<noteq> n \<longleftrightarrow> m < n \<or> n < m" 
566 
for m n :: nat 

26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

567 
by (rule linorder_neq_iff) 
13449  568 

569 

60758  570 
subsubsection \<open>Inductive (?) properties\<close> 
13449  571 

63110  572 
lemma Suc_lessI: "m < n \<Longrightarrow> Suc m \<noteq> n \<Longrightarrow> Suc m < n" 
60562
24af00b010cf
Amalgamation of the class comm_semiring_1_diff_distrib into comm_semiring_1_cancel. Moving axiom le_add_diff_inverse2 from semiring_numeral_div to linordered_semidom.
paulson <lp15@cam.ac.uk>
parents:
60427
diff
changeset

573 
unfolding less_eq_Suc_le [of m] le_less by simp 
13449  574 

26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

575 
lemma lessE: 
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

576 
assumes major: "i < k" 
63110  577 
and 1: "k = Suc i \<Longrightarrow> P" 
578 
and 2: "\<And>j. i < j \<Longrightarrow> k = Suc j \<Longrightarrow> P" 

26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

579 
shows P 
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

580 
proof  
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

581 
from major have "\<exists>j. i \<le> j \<and> k = Suc j" 
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

582 
unfolding less_eq_Suc_le by (induct k) simp_all 
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

583 
then have "(\<exists>j. i < j \<and> k = Suc j) \<or> k = Suc i" 
63110  584 
by (auto simp add: less_le) 
585 
with 1 2 show P by auto 

26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

586 
qed 
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

587 

63110  588 
lemma less_SucE: 
589 
assumes major: "m < Suc n" 

590 
and less: "m < n \<Longrightarrow> P" 

591 
and eq: "m = n \<Longrightarrow> P" 

592 
shows P 

26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

593 
apply (rule major [THEN lessE]) 
63588  594 
apply (rule eq) 
595 
apply blast 

596 
apply (rule less) 

597 
apply blast 

13449  598 
done 
599 

63110  600 
lemma Suc_lessE: 
601 
assumes major: "Suc i < k" 

602 
and minor: "\<And>j. i < j \<Longrightarrow> k = Suc j \<Longrightarrow> P" 

603 
shows P 

13449  604 
apply (rule major [THEN lessE]) 
63588  605 
apply (erule lessI [THEN minor]) 
606 
apply (erule Suc_lessD [THEN minor]) 

607 
apply assumption 

13449  608 
done 
609 

63110  610 
lemma Suc_less_SucD: "Suc m < Suc n \<Longrightarrow> m < n" 
26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

611 
by simp 
13449  612 

613 
lemma less_trans_Suc: 

63110  614 
assumes le: "i < j" 
615 
shows "j < k \<Longrightarrow> Suc i < k" 

63588  616 
proof (induct k) 
617 
case 0 

618 
then show ?case by simp 

619 
next 

620 
case (Suc k) 

621 
with le show ?case 

622 
by simp (auto simp add: less_Suc_eq dest: Suc_lessD) 

623 
qed 

624 

625 
text \<open>Can be used with \<open>less_Suc_eq\<close> to get @{prop "n = m \<or> n < m"}.\<close> 

26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

626 
lemma not_less_eq: "\<not> m < n \<longleftrightarrow> n < Suc m" 
63588  627 
by (simp only: not_less less_Suc_eq_le) 
13449  628 

26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

629 
lemma not_less_eq_eq: "\<not> m \<le> n \<longleftrightarrow> Suc n \<le> m" 
63588  630 
by (simp only: not_le Suc_le_eq) 
631 

632 
text \<open>Properties of "less than or equal".\<close> 

13449  633 

63110  634 
lemma le_imp_less_Suc: "m \<le> n \<Longrightarrow> m < Suc n" 
63588  635 
by (simp only: less_Suc_eq_le) 
13449  636 

63110  637 
lemma Suc_n_not_le_n: "\<not> Suc n \<le> n" 
63588  638 
by (simp add: not_le less_Suc_eq_le) 
639 

640 
lemma le_Suc_eq: "m \<le> Suc n \<longleftrightarrow> m \<le> n \<or> m = Suc n" 

26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

641 
by (simp add: less_Suc_eq_le [symmetric] less_Suc_eq) 
13449  642 

63110  643 
lemma le_SucE: "m \<le> Suc n \<Longrightarrow> (m \<le> n \<Longrightarrow> R) \<Longrightarrow> (m = Suc n \<Longrightarrow> R) \<Longrightarrow> R" 
26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

644 
by (drule le_Suc_eq [THEN iffD1], iprover+) 
13449  645 

63588  646 
lemma Suc_leI: "m < n \<Longrightarrow> Suc m \<le> n" 
647 
by (simp only: Suc_le_eq) 

648 

649 
text \<open>Stronger version of \<open>Suc_leD\<close>.\<close> 

63110  650 
lemma Suc_le_lessD: "Suc m \<le> n \<Longrightarrow> m < n" 
63588  651 
by (simp only: Suc_le_eq) 
13449  652 

63110  653 
lemma less_imp_le_nat: "m < n \<Longrightarrow> m \<le> n" for m n :: nat 
26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

654 
unfolding less_eq_Suc_le by (rule Suc_leD) 
13449  655 

61799  656 
text \<open>For instance, \<open>(Suc m < Suc n) = (Suc m \<le> n) = (m < n)\<close>\<close> 
26315
cb3badaa192e
removed redundant less_trans, less_linear, le_imp_less_or_eq, le_less_trans, less_le_trans (cf. Orderings.thy);
wenzelm
parents:
26300
diff
changeset

657 
lemmas le_simps = less_imp_le_nat less_Suc_eq_le Suc_le_eq 
13449  658 

659 

63110  660 
text \<open>Equivalence of \<open>m \<le> n\<close> and \<open>m < n \<or> m = n\<close>\<close> 
661 

63588  662 
lemma less_or_eq_imp_le: "m < n \<or> m = n \<Longrightarrow> m \<le> n" 
663 
for m n :: nat 

26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

664 
unfolding le_less . 
13449  665 

63588  666 
lemma le_eq_less_or_eq: "m \<le> n \<longleftrightarrow> m < n \<or> m = n" 
667 
for m n :: nat 

26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

668 
by (rule le_less) 
13449  669 

61799  670 
text \<open>Useful with \<open>blast\<close>.\<close> 
63588  671 
lemma eq_imp_le: "m = n \<Longrightarrow> m \<le> n" 
672 
for m n :: nat 

26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

673 
by auto 
13449  674 

63588  675 
lemma le_refl: "n \<le> n" 
676 
for n :: nat 

26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

677 
by simp 
13449  678 

63588  679 
lemma le_trans: "i \<le> j \<Longrightarrow> j \<le> k \<Longrightarrow> i \<le> k" 
680 
for i j k :: nat 

26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

681 
by (rule order_trans) 
13449  682 

63588  683 
lemma le_antisym: "m \<le> n \<Longrightarrow> n \<le> m \<Longrightarrow> m = n" 
684 
for m n :: nat 

26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

685 
by (rule antisym) 
13449  686 

63588  687 
lemma nat_less_le: "m < n \<longleftrightarrow> m \<le> n \<and> m \<noteq> n" 
688 
for m n :: nat 

26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

689 
by (rule less_le) 
13449  690 

63588  691 
lemma le_neq_implies_less: "m \<le> n \<Longrightarrow> m \<noteq> n \<Longrightarrow> m < n" 
692 
for m n :: nat 

26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

693 
unfolding less_le .. 
13449  694 

63588  695 
lemma nat_le_linear: "m \<le> n  n \<le> m" 
696 
for m n :: nat 

26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

697 
by (rule linear) 
14341
a09441bd4f1e
Ring_and_Field now requires axiom add_left_imp_eq for semirings.
paulson
parents:
14331
diff
changeset

698 

22718  699 
lemmas linorder_neqE_nat = linorder_neqE [where 'a = nat] 
15921  700 

63110  701 
lemma le_less_Suc_eq: "m \<le> n \<Longrightarrow> n < Suc m \<longleftrightarrow> n = m" 
26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

702 
unfolding less_Suc_eq_le by auto 
13449  703 

63110  704 
lemma not_less_less_Suc_eq: "\<not> n < m \<Longrightarrow> n < Suc m \<longleftrightarrow> n = m" 
26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset

705 
unfolding not_less by (rule le_less_Suc_eq) 
13449  706 

707 
lemmas not_less_simps = not_less_less_Suc_eq le_less_Suc_eq 

708 

63110  709 
lemma not0_implies_Suc: "n \<noteq> 0 \<Longrightarrow> \<exists>m. n = Suc m" 
710 
by (cases n) simp_all 

711 

712 
lemma gr0_implies_Suc: "n > 0 \<Longrightarrow> \<exists>m. n = Suc m" 

713 
by (cases n) simp_all 

714 

63588  715 
lemma gr_implies_not0: "m < n \<Longrightarrow> n \<noteq> 0" 
716 
for m n :: nat 

63110  717 
by (cases n) simp_all 
718 

63588  719 
lemma neq0_conv[iff]: "n \<noteq> 0 \<longleftrightarrow> 0 < n" 
720 
for n :: nat 

63110  721 
by (cases n) simp_all 
25140  722 

61799  723 
text \<open>This theorem is useful with \<open>blast\<close>\<close> 
63588  724 
lemma gr0I: "(n = 0 \<Longrightarrow> False) \<Longrightarrow> 0 < n" 
725 
for n :: nat 

726 
by (rule neq0_conv[THEN iffD1]) iprover 

63110  727 

728 
lemma gr0_conv_Suc: "0 < n \<longleftrightarrow> (\<exists>m. n = Suc m)" 

729 
by (fast intro: not0_implies_Suc) 

730 

63588  731 
lemma not_gr0 [iff]: "\<not> 0 < n \<longleftrightarrow> n = 0" 
732 
for n :: nat 

63110  733 
using neq0_conv by blast 
734 

735 
lemma Suc_le_D: "Suc n \<le> m' \<Longrightarrow> \<exists>m. m' = Suc m" 

736 
by (induct m') simp_all 

13449  737 

60758  738 
text \<open>Useful in certain inductive arguments\<close> 
63110  739 
lemma less_Suc_eq_0_disj: "m < Suc n \<longleftrightarrow> m = 0 \<or> (\<exists>j. m = Suc j \<and> j < n)" 
740 
by (cases m) simp_all 

13449  741 

64447  742 
lemma All_less_Suc: "(\<forall>i < Suc n. P i) = (P n \<and> (\<forall>i < n. P i))" 
743 
by (auto simp: less_Suc_eq) 

13449  744 

60758  745 
subsubsection \<open>Monotonicity of Addition\<close> 
13449  746 

63110  747 
lemma Suc_pred [simp]: "n > 0 \<Longrightarrow> Suc (n  Suc 0) = n" 
748 
by (simp add: diff_Suc split: nat.split) 

749 

750 
lemma Suc_diff_1 [simp]: "0 < n \<Longrightarrow> Suc (n  1) = n" 

751 
unfolding One_nat_def by (rule Suc_pred) 

752 

63588  753 
lemma nat_add_left_cancel_le [simp]: "k + m \<le> k + n \<longleftrightarrow> m \<le> n" 
754 
for k m n :: nat 

63110  755 
by (induct k) simp_all 
756 

63588  757 
lemma nat_add_left_cancel_less [simp]: "k + m < k + n \<longleftrightarrow> m < n" 
758 
for k m n :: nat 

63110  759 
by (induct k) simp_all 
760 

63588  761 
lemma add_gr_0 [iff]: "m + n > 0 \<longleftrightarrow> m > 0 \<or> n > 0" 
762 
for m n :: nat 

63110  763 
by (auto dest: gr0_implies_Suc) 
13449  764 

60758  765 
text \<open>strict, in 1st argument\<close> 
63588  766 
lemma add_less_mono1: "i < j \<Longrightarrow> i + k < j + k" 
767 
for i j k :: nat 

63110  768 
by (induct k) simp_all 
14341
a09441bd4f1e
Ring_and_Field now requires axiom add_left_imp_eq for semirings.
paulson
parents:
14331
diff
changeset

769 

60758  770 
text \<open>strict, in both arguments\<close> 
63588  771 
lemma add_less_mono: "i < j \<Longrightarrow> k < l \<Longrightarrow> i + k < j + l" 
772 
for i j k l :: nat 

14341
a09441bd4f1e
Ring_and_Field now requires axiom add_left_imp_eq for semirings.
paulson
parents:
14331
diff
changeset

773 
apply (rule add_less_mono1 [THEN less_trans], assumption+) 
63588  774 
apply (induct j) 
775 
apply simp_all 

14341
a09441bd4f1e
Ring_and_Field now requires axiom add_left_imp_eq for semirings.
paulson
parents:
14331
diff
changeset

776 
done 
a09441bd4f1e
Ring_and_Field now requires axiom add_left_imp_eq for semirings.
paulson
parents:
14331
diff
changeset

777 

61799  778 
text \<open>Deleted \<open>less_natE\<close>; use \<open>less_imp_Suc_add RS exE\<close>\<close> 
63110  779 
lemma less_imp_Suc_add: "m < n \<Longrightarrow> \<exists>k. n = Suc (m + k)" 
63588  780 
proof (induct n) 
781 
case 0 

782 
then show ?case by simp 

783 
next 

784 
case Suc 

785 
then show ?case 

786 
by (simp add: order_le_less) 

787 
(blast elim!: less_SucE intro!: Nat.add_0_right [symmetric] add_Suc_right [symmetric]) 

788 
qed 

789 

790 
lemma le_Suc_ex: "k \<le> l \<Longrightarrow> (\<exists>n. l = k + n)" 

791 
for k l :: nat 

56194  792 
by (auto simp: less_Suc_eq_le[symmetric] dest: less_imp_Suc_add) 
793 

61799  794 
text \<open>strict, in 1st argument; proof is by induction on \<open>k > 0\<close>\<close> 
62481
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset

795 
lemma mult_less_mono2: 
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset

796 
fixes i j :: nat 
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset

797 
assumes "i < j" and "0 < k" 
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset

798 
shows "k * i < k * j" 
63110  799 
using \<open>0 < k\<close> 
800 
proof (induct k) 

801 
case 0 

802 
then show ?case by simp 

62481
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset

803 
next 
63110  804 
case (Suc k) 
805 
with \<open>i < j\<close> show ?case 

62481
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset

806 
by (cases k) (simp_all add: add_less_mono) 
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset

807 
qed 
14341
a09441bd4f1e
Ring_and_Field now requires axiom add_left_imp_eq for semirings.
paulson
parents:
14331
diff
changeset

808 

60758  809 
text \<open>Addition is the inverse of subtraction: 
810 
if @{term "n \<le> m"} then @{term "n + (m  n) = m"}.\<close> 

63588  811 
lemma add_diff_inverse_nat: "\<not> m < n \<Longrightarrow> n + (m  n) = m" 
812 
for m n :: nat 

63110  813 
by (induct m n rule: diff_induct) simp_all 
814 

63588  815 
lemma nat_le_iff_add: "m \<le> n \<longleftrightarrow> (\<exists>k. n = m + k)" 
816 
for m n :: nat 

63110  817 
using nat_add_left_cancel_le[of m 0] by (auto dest: le_Suc_ex) 
62376
85f38d5f8807
Rename ordered_comm_monoid_add to ordered_cancel_comm_monoid_add. Introduce ordreed_comm_monoid_add, canonically_ordered_comm_monoid and dioid. Setup nat, entat and ennreal as dioids.
hoelzl
parents:
62365
diff
changeset

818 

63588  819 
text \<open>The naturals form an ordered \<open>semidom\<close> and a \<open>dioid\<close>.\<close> 
62376
85f38d5f8807
Rename ordered_comm_monoid_add to ordered_cancel_comm_monoid_add. Introduce ordreed_comm_monoid_add, canonically_ordered_comm_monoid and dioid. Setup nat, entat and ennreal as dioids.
hoelzl
parents:
62365
diff
changeset

820 

35028
108662d50512
more consistent naming of type classes involving orderings (and lattices)  c.f. NEWS
haftmann
parents:
34208
diff
changeset

821 
instance nat :: linordered_semidom 
14341
a09441bd4f1e
Ring_and_Field now requires axiom add_left_imp_eq for semirings.
paulson
parents:
14331
diff
changeset

822 
proof 
63110  823 
fix m n q :: nat 
63588  824 
show "0 < (1::nat)" 
825 
by simp 

826 
show "m \<le> n \<Longrightarrow> q + m \<le> q + n" 

827 
by simp 

828 
show "m < n \<Longrightarrow> 0 < q \<Longrightarrow> q * m < q * n" 

829 
by (simp add: mult_less_mono2) 

830 
show "m \<noteq> 0 \<Longrightarrow> n \<noteq> 0 \<Longrightarrow> m * n \<noteq> 0" 

831 
by simp 

63110  832 
show "n \<le> m \<Longrightarrow> (m  n) + n = m" 
60562
24af00b010cf
Amalgamation of the class comm_semiring_1_diff_distrib into comm_semiring_1_cancel. Moving axiom le_add_diff_inverse2 from semiring_numeral_div to linordered_semidom.
paulson <lp15@cam.ac.uk>
parents:
60427
diff
changeset

833 
by (simp add: add_diff_inverse_nat add.commute linorder_not_less) 
62376
85f38d5f8807
Rename ordered_comm_monoid_add to ordered_cancel_comm_monoid_add. Introduce ordreed_comm_monoid_add, canonically_ordered_comm_monoid and dioid. Setup nat, entat and ennreal as dioids.
hoelzl
parents:
62365
diff
changeset

834 
qed 
85f38d5f8807
Rename ordered_comm_monoid_add to ordered_cancel_comm_monoid_add. Introduce ordreed_comm_monoid_add, canonically_ordered_comm_monoid and dioid. Setup nat, entat and ennreal as dioids.
hoelzl
parents:
62365
diff
changeset

835 

85f38d5f8807
Rename ordered_comm_monoid_add to ordered_cancel_comm_monoid_add. Introduce ordreed_comm_monoid_add, canonically_ordered_comm_monoid and dioid. Setup nat, entat and ennreal as dioids.
hoelzl
parents:
62365
diff
changeset

836 
instance nat :: dioid 
63110  837 
by standard (rule nat_le_iff_add) 
63588  838 

63145  839 
declare le0[simp del] \<comment> \<open>This is now @{thm zero_le}\<close> 
840 
declare le_0_eq[simp del] \<comment> \<open>This is now @{thm le_zero_eq}\<close> 

841 
declare not_less0[simp del] \<comment> \<open>This is now @{thm not_less_zero}\<close> 

842 
declare not_gr0[simp del] \<comment> \<open>This is now @{thm not_gr_zero}\<close> 

62376
85f38d5f8807
Rename ordered_comm_monoid_add to ordered_cancel_comm_monoid_add. Introduce ordreed_comm_monoid_add, canonically_ordered_comm_monoid and dioid. Setup nat, entat and ennreal as dioids.
hoelzl
parents:
62365
diff
changeset

843 

63110  844 
instance nat :: ordered_cancel_comm_monoid_add .. 
845 
instance nat :: ordered_cancel_comm_monoid_diff .. 

846 

44817  847 

60758  848 
subsubsection \<open>@{term min} and @{term max}\<close> 
44817  849 

850 
lemma mono_Suc: "mono Suc" 

63110  851 
by (rule monoI) simp 
852 

63588  853 
lemma min_0L [simp]: "min 0 n = 0" 
854 
for n :: nat 

63110  855 
by (rule min_absorb1) simp 
856 

63588  857 
lemma min_0R [simp]: "min n 0 = 0" 
858 
for n :: nat 

63110  859 
by (rule min_absorb2) simp 
44817  860 

861 
lemma min_Suc_Suc [simp]: "min (Suc m) (Suc n) = Suc (min m n)" 

63110  862 
by (simp add: mono_Suc min_of_mono) 
863 

864 
lemma min_Suc1: "min (Suc n) m = (case m of 0 \<Rightarrow> 0  Suc m' \<Rightarrow> Suc(min n m'))" 

865 
by (simp split: nat.split) 

866 

867 
lemma min_Suc2: "min m (Suc n) = (case m of 0 \<Rightarrow> 0  Suc m' \<Rightarrow> Suc(min m' n))" 

868 
by (simp split: nat.split) 

869 

63588  870 
lemma max_0L [simp]: "max 0 n = n" 
871 
for n :: nat 

63110  872 
by (rule max_absorb2) simp 
873 

63588  874 
lemma max_0R [simp]: "max n 0 = n" 
875 
for n :: nat 

63110  876 
by (rule max_absorb1) simp 
877 

878 
lemma max_Suc_Suc [simp]: "max (Suc m) (Suc n) = Suc (max m n)" 

879 
by (simp add: mono_Suc max_of_mono) 

880 

881 
lemma max_Suc1: "max (Suc n) m = (case m of 0 \<Rightarrow> Suc n  Suc m' \<Rightarrow> Suc (max n m'))" 

882 
by (simp split: nat.split) 

883 

884 
lemma max_Suc2: "max m (Suc n) = (case m of 0 \<Rightarrow> Suc n  Suc m' \<Rightarrow> Suc (max m' n))" 

885 
by (simp split: nat.split) 

886 

63588  887 
lemma nat_mult_min_left: "min m n * q = min (m * q) (n * q)" 
888 
for m n q :: nat 

63110  889 
by (simp add: min_def not_le) 
890 
(auto dest: mult_right_le_imp_le mult_right_less_imp_less le_less_trans) 

891 

63588  892 
lemma nat_mult_min_right: "m * min n q = min (m * n) (m * q)" 
893 
for m n q :: nat 

63110  894 
by (simp add: min_def not_le) 
895 
(auto dest: mult_left_le_imp_le mult_left_less_imp_less le_less_trans) 

896 

63588  897 
lemma nat_add_max_left: "max m n + q = max (m + q) (n + q)" 
898 
for m n q :: nat 

44817  899 
by (simp add: max_def) 
900 

63588  901 
lemma nat_add_max_right: "m + max n q = max (m + n) (m + q)" 
902 
for m n q :: nat 

44817  903 
by (simp add: max_def) 
904 

63588  905 
lemma nat_mult_max_left: "max m n * q = max (m * q) (n * q)" 
906 
for m n q :: nat 

63110  907 
by (simp add: max_def not_le) 
908 
(auto dest: mult_right_le_imp_le mult_right_less_imp_less le_less_trans) 

909 

63588  910 
lemma nat_mult_max_right: "m * max n q = max (m * n) (m * q)" 
911 
for m n q :: nat 

63110  912 
by (simp add: max_def not_le) 
913 
(auto dest: mult_left_le_imp_le mult_left_less_imp_less le_less_trans) 

14267
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14266
diff
changeset

914 

b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14266
diff
changeset

915 

60758  916 
subsubsection \<open>Additional theorems about @{term "op \<le>"}\<close> 
917 

918 
text \<open>Complete induction, aka courseofvalues induction\<close> 

26748
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
26335
diff
changeset

919 

63110  920 
instance nat :: wellorder 
921 
proof 

27823  922 
fix P and n :: nat 
63110  923 
assume step: "(\<And>m. m < n \<Longrightarrow> P m) \<Longrightarrow> P n" for n :: nat 
27823  924 
have "\<And>q. q \<le> n \<Longrightarrow> P q" 
925 
proof (induct n) 

926 
case (0 n) 

26748
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
26335
diff
changeset

927 
have "P 0" by (rule step) auto 
63588  928 
with 0 show ?case by auto 
26748
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
26335
diff
changeset

929 
next 
27823  930 
case (Suc m n) 
63588  931 
then have "n \<le> m \<or> n = Suc m" 
932 
by (simp add: le_Suc_eq) 

63110  933 
then show ?case 
26748
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
26335
diff
changeset

934 
proof 
63110  935 
assume "n \<le> m" 
936 
then show "P n" by (rule Suc(1)) 

26748
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
26335
diff
changeset

937 
next 
27823  938 
assume n: "n = Suc m" 
63110  939 
show "P n" by (rule step) (rule Suc(1), simp add: n le_simps) 
26748
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
26335
diff
changeset

940 
qed 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
26335
diff
changeset

941 
qed 
27823  942 
then show "P n" by auto 
26748
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
26335
diff
changeset

943 
qed 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
26335
diff
changeset

944 

57015  945 

63588  946 
lemma Least_eq_0[simp]: "P 0 \<Longrightarrow> Least P = 0" 
947 
for P :: "nat \<Rightarrow> bool" 

63110  948 
by (rule Least_equality[OF _ le0]) 
949 

950 
lemma Least_Suc: "P n \<Longrightarrow> \<not> P 0 \<Longrightarrow> (LEAST n. P n) = Suc (LEAST m. P (Suc m))" 

63588  951 
apply (cases n) 
952 
apply auto 

27823  953 
apply (frule LeastI) 
63588  954 
apply (drule_tac P = "\<lambda>x. P (Suc x)" in LeastI) 
27823  955 
apply (subgoal_tac " (LEAST x. P x) \<le> Suc (LEAST x. P (Suc x))") 
63588  956 
apply (erule_tac [2] Least_le) 
957 
apply (cases "LEAST x. P x") 

958 
apply auto 

959 
apply (drule_tac P = "\<lambda>x. P (Suc x)" in Least_le) 

27823  960 
apply (blast intro: order_antisym) 
961 
done 

962 

63110  963 
lemma Least_Suc2: "P n \<Longrightarrow> Q m \<Longrightarrow> \<not> P 0 \<Longrightarrow> \<forall>k. P (Suc k) = Q k \<Longrightarrow> Least P = Suc (Least Q)" 
63588  964 
by (erule (1) Least_Suc [THEN ssubst]) simp 
965 

966 
lemma ex_least_nat_le: "\<not> P 0 \<Longrightarrow> P n \<Longrightarrow> \<exists>k\<le>n. (\<forall>i<k. \<not> P i) \<and> P k" 

967 
for P :: "nat \<Rightarrow> bool" 

27823  968 
apply (cases n) 
969 
apply blast 

63110  970 
apply (rule_tac x="LEAST k. P k" in exI) 
27823  971 
apply (blast intro: Least_le dest: not_less_Least intro: LeastI_ex) 
972 
done 

973 

63588  974 
lemma ex_least_nat_less: "\<not> P 0 \<Longrightarrow> P n \<Longrightarrow> \<exists>k<n. (\<forall>i\<le>k. \<not> P i) \<and> P (k + 1)" 
975 
for P :: "nat \<Rightarrow> bool" 

27823  976 
apply (cases n) 
977 
apply blast 

978 
apply (frule (1) ex_least_nat_le) 

979 
apply (erule exE) 

980 
apply (case_tac k) 

981 
apply simp 

982 
apply (rename_tac k1) 

983 
apply (rule_tac x=k1 in exI) 

984 
apply (auto simp add: less_eq_Suc_le) 

985 
done 

986 

26748
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
26335
diff
changeset

987 
lemma nat_less_induct: 
63110  988 
fixes P :: "nat \<Rightarrow> bool" 
989 
assumes "\<And>n. \<forall>m. m < n \<longrightarrow> P m \<Longrightarrow> P n" 

990 
shows "P n" 

26748
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
26335
diff
changeset

991 
using assms less_induct by blast 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
26335
diff
changeset

992 

4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
26335
diff
changeset

993 
lemma measure_induct_rule [case_names less]: 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
26335
diff
changeset

994 
fixes f :: "'a \<Rightarrow> nat" 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
26335
diff
changeset

995 
assumes step: "\<And>x. (\<And>y. f y < f x \<Longrightarrow> P y) \<Longrightarrow> P x" 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
26335
diff
changeset

996 
shows "P a" 
63110  997 
by (induct m \<equiv> "f a" arbitrary: a rule: less_induct) (auto intro: step) 
26748
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
26335
diff
changeset

998 

60758  999 
text \<open>old style induction rules:\<close> 
26748
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
26335
diff
changeset

1000 
lemma measure_induct: 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
26335
diff
changeset

1001 
fixes f :: "'a \<Rightarrow> nat" 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
26335
diff
changeset

1002 
shows "(\<And>x. \<forall>y. f y < f x \<longrightarrow> P y \<Longrightarrow> P x) \<Longrightarrow> P a" 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
26335
diff
changeset

1003 
by (rule measure_induct_rule [of f P a]) iprover 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
26335
diff
changeset

1004 

4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
26335
diff
changeset

1005 
lemma full_nat_induct: 
63110  1006 
assumes step: "\<And>n. (\<forall>m. Suc m \<le> n \<longrightarrow> P m) \<Longrightarrow> P n" 
26748
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
26335
diff
changeset

1007 
shows "P n" 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
26335
diff
changeset

1008 
by (rule less_induct) (auto intro: step simp:le_simps) 
14267
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14266
diff
changeset

1009 

63110  1010 
text\<open>An induction rule for establishing binary relations\<close> 
62683  1011 
lemma less_Suc_induct [consumes 1]: 
63110  1012 
assumes less: "i < j" 
1013 
and step: "\<And>i. P i (Suc i)" 

1014 
and trans: "\<And>i j k. i < j \<Longrightarrow> j < k \<Longrightarrow> P i j \<Longrightarrow> P j k \<Longrightarrow> P i k" 

19870  1015 
shows "P i j" 
1016 
proof  

63110  1017 
from less obtain k where j: "j = Suc (i + k)" 
1018 
by (auto dest: less_imp_Suc_add) 

22718  1019 
have "P i (Suc (i + k))" 
19870  1020 
proof (induct k) 
22718  1021 
case 0 
1022 
show ?case by (simp add: step) 

19870  1023 
next 
1024 
case (Suc k) 

31714  1025 
have "0 + i < Suc k + i" by (rule add_less_mono1) simp 
63110  1026 
then have "i < Suc (i + k)" by (simp add: add.commute) 
31714  1027 
from trans[OF this lessI Suc step] 
1028 
show ?case by simp 

19870  1029 
qed 
63110  1030 
then show "P i j" by (simp add: j) 
19870  1031 
qed 
1032 

63111  1033 
text \<open> 
1034 
The method of infinite descent, frequently used in number theory. 

1035 
Provided by Roelof Oosterhuis. 

1036 
\<open>P n\<close> is true for all natural numbers if 

1037 
\<^item> case ``0'': given \<open>n = 0\<close> prove \<open>P n\<close> 

1038 
\<^item> case ``smaller'': given \<open>n > 0\<close> and \<open>\<not> P n\<close> prove there exists 

1039 
a smaller natural number \<open>m\<close> such that \<open>\<not> P m\<close>. 

1040 
\<close> 

1041 

63110  1042 
lemma infinite_descent: "(\<And>n. \<not> P n \<Longrightarrow> \<exists>m<n. \<not> P m) \<Longrightarrow> P n" for P :: "nat \<Rightarrow> bool" 
63111  1043 
\<comment> \<open>compact version without explicit base case\<close> 
63110  1044 
by (induct n rule: less_induct) auto 
26748
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
26335
diff
changeset

1045 

63111  1046 
lemma infinite_descent0 [case_names 0 smaller]: 
63110  1047 
fixes P :: "nat \<Rightarrow> bool" 
63111  1048 
assumes "P 0" 
1049 
and "\<And>n. n > 0 \<Longrightarrow> \<not> P n \<Longrightarrow> \<exists>m. m < n \<and> \<not> P m" 

63110  1050 
shows "P n" 
1051 
apply (rule infinite_descent) 

1052 
using assms 

1053 
apply (case_tac "n > 0") 

63588  1054 
apply auto 
63110  1055 
done 
26748
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
26335
diff
changeset

1056 

60758  1057 
text \<open> 
63111  1058 
Infinite descent using a mapping to \<open>nat\<close>: 
1059 
\<open>P x\<close> is true for all \<open>x \<in> D\<close> if there exists a \<open>V \<in> D \<Rightarrow> nat\<close> and 

1060 
\<^item> case ``0'': given \<open>V x = 0\<close> prove \<open>P x\<close> 

1061 
\<^item> ``smaller'': given \<open>V x > 0\<close> and \<open>\<not> P x\<close> prove 

1062 
there exists a \<open>y \<in> D\<close> such that \<open>V y < V x\<close> and \<open>\<not> P y\<close>. 

1063 
\<close> 

26748
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
26335
diff
changeset

1064 
corollary infinite_descent0_measure [case_names 0 smaller]: 
63110  1065 
fixes V :: "'a \<Rightarrow> nat" 
1066 
assumes 1: "\<And>x. V x = 0 \<Longrightarrow> P x" 

1067 
and 2: "\<And>x. V x > 0 \<Longrightarrow> \<not> P x \<Longrightarrow> \<exists>y. V y < V x \<and> \<not> P y" 

26748
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
26335
diff
changeset

1068 
shows "P x" 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
26335
diff
changeset

1069 
proof  
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
26335
diff
changeset

1070 
obtain n where "n = V x" by auto 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
26335
diff
changeset

1071 
moreover have "\<And>x. V x = n \<Longrightarrow> P x" 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
26335
diff
changeset

1072 
proof (induct n rule: infinite_descent0) 
63110  1073 
case 0 
1074 
with 1 show "P x" by auto 

1075 
next 

26748
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
26335
diff
changeset

1076 
case (smaller n) 
63110  1077 
then obtain x where *: "V x = n " and "V x > 0 \<and> \<not> P x" by auto 
1078 
with 2 obtain y where "V y < V x \<and> \<not> P y" by auto 

63111  1079 
with * obtain m where "m = V y \<and> m < n \<and> \<not> P y" by auto 
26748
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
26335
diff
changeset

1080 
then show ?case by auto 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
26335
diff
changeset

1081 
qed 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
26335
diff
changeset

1082 
ultimately show "P x" by auto 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
26335
diff
changeset

1083 
qed 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
26335
diff
changeset

1084 

63588  1085 
text \<open>Again, without explicit base case:\<close> 
26748
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
26335
diff
changeset

1086 
lemma infinite_descent_measure: 
63110  1087 
fixes V :: "'a \<Rightarrow> nat" 
1088 
assumes "\<And>x. \<not> P x \<Longrightarrow> \<exists>y. V y < V x \<and> \<not> P y" 

1089 
shows "P x" 

26748
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
26335
diff
changeset

1090 
proof  
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
26335
diff
changeset

1091 
from assms obtain n where "n = V x" by auto 
63110  1092 
moreover have "\<And>x. V x = n \<Longrightarrow> P x" 
26748
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
26335
diff
changeset

1093 
proof (induct n rule: infinite_descent, auto) 
63111  1094 
show "\<exists>m < V x. \<exists>y. V y = m \<and> \<not> P y" if "\<not> P x" for x 
1095 
using assms and that by auto 

26748
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
26335
diff
changeset

1096 
qed 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
26335
diff
changeset

1097 
ultimately show "P x" by auto 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
26335
diff
changeset

1098 
qed 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
26335
diff
changeset

1099 

63111  1100 
text \<open>A (clumsy) way of lifting \<open><\<close> monotonicity to \<open>\<le>\<close> monotonicity\<close> 
14267
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14266
diff
changeset

1101 
lemma less_mono_imp_le_mono: 
63110  1102 
fixes f :: "nat \<Rightarrow> nat" 
1103 
and i j :: nat 

1104 
assumes "\<And>i j::nat. i < j \<Longrightarrow> f i < f j" 

1105 
and "i \<le> j" 

1106 
shows "f i \<le> f j" 

1107 
using assms by (auto simp add: order_le_less) 

24438  1108 

14267
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14266
diff
changeset

1109 

60758  1110 
text \<open>nonstrict, in 1st argument\<close> 
63588  1111 
lemma add_le_mono1: "i \<le> j \<Longrightarrow> i + k \<le> j + k" 
1112 
for i j k :: nat 

63110  1113 
by (rule add_right_mono) 
14267
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14266
diff
changeset

1114 

60758  1115 
text \<open>nonstrict, in both arguments\<close> 
63588  1116 
lemma add_le_mono: "i \<le> j \<Longrightarrow> k \<le> l \<Longrightarrow> i + k \<le> j + l" 
1117 
for i j k l :: nat 

63110  1118 
by (rule add_mono) 
1119 

63588  1120 
lemma le_add2: "n \<le> m + n" 
1121 
for m n :: nat 

62608  1122 
by simp 
13449  1123 

63588  1124 
lemma le_add1: "n \<le> n + m" 
1125 
for m n :: nat 

62608  1126 
by simp 
13449  1127 

1128 
lemma less_add_Suc1: "i < Suc (i + m)" 

63110  1129 
by (rule le_less_trans, rule le_add1, rule lessI) 
13449  1130 

1131 
lemma less_add_Suc2: "i < Suc (m + i)" 

63110  1132 
by (rule le_less_trans, rule le_add2, rule lessI) 
1133 

1134 
lemma less_iff_Suc_add: "m < n \<longleftrightarrow> (\<exists>k. n = Suc (m + k))" 

1135 
by (iprover intro!: less_add_Suc1 less_imp_Suc_add) 

1136 

63588  1137 
lemma trans_le_add1: "i \<le> j \<Longrightarrow> i \<le> j + m" 
1138 
for i j m :: nat 

63110  1139 
by (rule le_trans, assumption, rule le_add1) 
1140 

63588  1141 
lemma trans_le_add2: "i \<le> j \<Longrightarrow> i \<le> m + j" 
1142 
for i j m :: nat 

63110  1143 
by (rule le_trans, assumption, rule le_add2) 
1144 

63588  1145 
lemma trans_less_add1: "i < j \<Longrightarrow> i < j + m" 
1146 
for i j m :: nat 

63110  1147 
by (rule less_le_trans, assumption, rule le_add1) 
1148 

63588  1149 
lemma trans_less_add2: "i < j \<Longrightarrow> i < m + j" 
1150 
for i j m :: nat 

63110  1151 
by (rule less_le_trans, assumption, rule le_add2) 
1152 

63588  1153 
lemma add_lessD1: "i + j < k \<Longrightarrow> i < k" 
1154 
for i j k :: nat 

63110  1155 
by (rule le_less_trans [of _ "i+j"]) (simp_all add: le_add1) 
1156 

63588  1157 
lemma not_add_less1 [iff]: "\<not> i + j < i" 
1158 
for i j :: nat 

63110  1159 
apply (rule notI) 
1160 
apply (drule add_lessD1) 

1161 
apply (erule less_irrefl [THEN notE]) 

1162 
done 

1163 

63588  1164 
lemma not_add_less2 [iff]: "\<not> j + i < i" 
1165 
for i j :: nat 

63110  1166 
by (simp add: add.commute) 
1167 

63588  1168 
lemma add_leD1: "m + k \<le> n \<Longrightarrow> m \<le> n" 
1169 
for k m n :: nat 

1170 
by (rule order_trans [of _ "m + k"]) (simp_all add: le_add1) 

1171 

1172 
lemma add_leD2: "m + k \<le> n \<Longrightarrow> k \<le> n" 

1173 
for k m n :: nat 

63110  1174 
apply (simp add: add.commute) 
1175 
apply (erule add_leD1) 

1176 
done 

1177 

63588  1178 
lemma add_leE: "m + k \<le> n \<Longrightarrow> (m \<le> n \<Longrightarrow> k \<le> n \<Longrightarrow> R) \<Longrightarrow> R" 
1179 
for k m n :: nat 

63110  1180 
by (blast dest: add_leD1 add_leD2) 
1181 

1182 
text \<open>needs \<open>\<And>k\<close> for \<open>ac_simps\<close> to work\<close> 

63588  1183 
lemma less_add_eq_less: "\<And>k. k < l \<Longrightarrow> m + l = k + n \<Longrightarrow> m < n" 
1184 
for l m n :: nat 

63110  1185 
by (force simp del: add_Suc_right simp add: less_iff_Suc_add add_Suc_right [symmetric] ac_simps) 
13449  1186 

1187 

60758  1188 
subsubsection \<open>More results about difference\<close> 
13449  1189 

63110  1190 
lemma Suc_diff_le: "n \<le> m \<Longrightarrow> Suc m  n = Suc (m  n)" 
1191 
by (induct m n rule: diff_induct) simp_all 

13449  1192 

1193 
lemma diff_less_Suc: "m  n < Suc m" 

63588  1194 
apply (induct m n rule: diff_induct) 
1195 
apply (erule_tac [3] less_SucE) 

1196 
apply (simp_all add: less_Suc_eq) 

1197 
done 

1198 

1199 
lemma diff_le_self [simp]: "m  n \<le> m" 

1200 
for m n :: nat 

63110  1201 
by (induct m n rule: diff_induct) (simp_all add: le_SucI) 
1202 

63588  1203 
lemma less_imp_diff_less: "j < k \<Longrightarrow> j  n < k" 
1204 
for j k n :: nat 

63110  1205 
by (rule le_less_trans, rule diff_le_self) 
1206 

1207 
lemma diff_Suc_less [simp]: "0 < n \<Longrightarrow> n  Suc i < n" 

1208 
by (cases n) (auto simp add: le_simps) 

1209 

63588  1210 
lemma diff_add_assoc: "k \<le> j \<Longrightarrow> (i + j)  k = i + (j  k)" 
1211 
for i j k :: nat 

63110  1212 
by (induct j k rule: diff_induct) simp_all 
1213 

63588  1214 
lemma add_diff_assoc [simp]: "k \<le> j \<Longrightarrow> i + (j  k) = i + j  k" 
1215 
for i j k :: nat 

62481
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset

1216 
by (fact diff_add_assoc [symmetric]) 
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset

1217 

63588  1218 
lemma diff_add_assoc2: "k \<le> j \<Longrightarrow> (j + i)  k = (j  k) + i" 
1219 
for i j k :: nat 

62481
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset

1220 
by (simp add: ac_simps) 
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset

1221 

63588  1222 
lemma add_diff_assoc2 [simp]: "k \<le> j \<Longrightarrow> j  k + i = j + i  k" 
1223 
for i j k :: nat 

62481
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset

1224 
by (fact diff_add_assoc2 [symmetric]) 
13449  1225 

63588  1226 
lemma le_imp_diff_is_add: "i \<le> j \<Longrightarrow> (j  i = k) = (j = k + i)" 
1227 
for i j k :: nat 

63110  1228 
by auto 
1229 

63588  1230 
lemma diff_is_0_eq [simp]: "m  n = 0 \<longleftrightarrow> m \<le> n" 
1231 
for m n :: nat 

63110  1232 
by (induct m n rule: diff_induct) simp_all 
1233 

63588  1234 
lemma diff_is_0_eq' [simp]: "m \<le> n \<Longrightarrow> m  n = 0" 
1235 
for m n :: nat 

63110  1236 
by (rule iffD2, rule diff_is_0_eq) 
1237 

63588  1238 
lemma zero_less_diff [simp]: "0 < n  m \<longleftrightarrow> m < n" 
1239 
for m n :: nat 

63110  1240 
by (induct m n rule: diff_induct) simp_all 
13449  1241 

22718  1242 
lemma less_imp_add_positive: 
1243 
assumes "i < j" 

63110  1244 
shows "\<exists>k::nat. 0 < k \<and> i + k = j" 
22718  1245 
proof 
63110  1246 
from assms show "0 < j  i \<and> i + (j  i) = j" 
23476  1247 
by (simp add: order_less_imp_le) 
22718  1248 
qed 
9436
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
7702
diff
changeset

1249 

60758  1250 
text \<open>a nice rewrite for bounded subtraction\<close> 
63588  1251 
lemma nat_minus_add_max: "n  m + m = max n m" 
1252 
for m n :: nat 

1253 
by (simp add: max_def not_le order_less_imp_le) 

13449  1254 

63110  1255 
lemma nat_diff_split: "P (a  b) \<longleftrightarrow> (a < b \<longrightarrow> P 0) \<and> (\<forall>d. a = b + d \<longrightarrow> P d)" 
1256 
for a b :: nat 

63588  1257 
\<comment> \<open>elimination of \<open>\<close> on \<open>nat\<close>\<close> 
1258 
by (cases "a < b") (auto simp add: not_less le_less dest!: add_eq_self_zero [OF sym]) 

13449  1259 

63110  1260 
lemma nat_diff_split_asm: "P (a  b) \<longleftrightarrow> \<not> (a < b \<and> \<not> P 0 \<or> (\<exists>d. a = b + d \<and> \<not> P d))" 
1261 
for a b :: nat 

63588  1262 
\<comment> \<open>elimination of \<open>\<close> on \<open>nat\<close> in assumptions\<close> 
62365  1263 
by (auto split: nat_diff_split) 
13449  1264 

63110  1265 
lemma Suc_pred': "0 < n \<Longrightarrow> n = Suc(n  1)" 
47255
30a1692557b0
removed Nat_Numeral.thy, moving all theorems elsewhere
huffman
parents:
47208
diff
changeset

1266 
by simp 
30a1692557b0
removed Nat_Numeral.thy, moving all theorems elsewhere
huffman
parents:
47208
diff
changeset

1267 

63110  1268 
lemma add_eq_if: "m + n = (if m = 0 then n else Suc ((m  1) + n))" 
47255
30a1692557b0
removed Nat_Numeral.thy, moving all theorems elsewhere
huffman
parents:
47208
diff
changeset

1269 
unfolding One_nat_def by (cases m) simp_all 
30a1692557b0
removed Nat_Numeral.thy, moving all theorems elsewhere
huffman
parents:
47208
diff
changeset

1270 

63588  1271 
lemma mult_eq_if: "m * n = (if m = 0 then 0 else n + ((m  1) * n))" 
1272 
for m n :: nat 

1273 
by (cases m) simp_all 

47255
30a1692557b0
removed Nat_Numeral.thy, moving all theorems elsewhere
huffman
parents:
47208
diff
changeset

1274 

63110  1275 
lemma Suc_diff_eq_diff_pred: "0 < n \<Longrightarrow> Suc m  n = m  (n  1)" 
63588  1276 
by (cases n) simp_all 
47255
30a1692557b0
removed Nat_Numeral.thy, moving all theorems elsewhere
huffman
parents:
47208
diff
changeset

1277 

30a1692557b0
removed Nat_Numeral.thy, moving all theorems elsewhere
huffman
parents:
47208
diff
changeset

1278 
lemma diff_Suc_eq_diff_pred: "m  Suc n = (m  1)  n" 
63588  1279 
by (cases m) simp_all 
1280 

1281 
lemma Let_Suc [simp]: "Let (Suc n) f \<equiv> f (Suc n)" 

47255
30a1692557b0
removed Nat_Numeral.thy, moving all theorems elsewhere
huffman
parents:
47208
diff
changeset

1282 
by (fact Let_def) 
30a1692557b0
removed Nat_Numeral.thy, moving all theorems elsewhere
huffman
parents:
47208
diff
changeset

1283 

13449  1284 

60758  1285 
subsubsection \<open>Monotonicity of multiplication\<close> 
13449  1286 

63588  1287 
lemma mult_le_mono1: "i \<le> j \<Longrightarrow> i * k \<le> j * k" 
1288 
for i j k :: nat 

63110  1289 
by (simp add: mult_right_mono) 
1290 

63588  1291 
lemma mult_le_mono2: "i \<le> j \<Longrightarrow> k * i \<le> k * j" 
1292 
for i j k :: nat 

63110  1293 
by (simp add: mult_left_mono) 
13449  1294 

61799  1295 
text \<open>\<open>\<le>\<close> monotonicity, BOTH arguments\<close> 
63588  1296 
lemma mult_le_mono: "i \<le> j \<Longrightarrow> k \<le> l \<Longrightarrow> i * k \<le> j * l" 
1297 
for i j k l :: nat 

63110  1298 
by (simp add: mult_mono) 
1299 

63588  1300 
lemma mult_less_mono1: "i < j \<Longrightarrow> 0 < k \<Longrightarrow> i * k < j * k" 
1301 
for i j k :: nat 

63110  1302 
by (simp add: mult_strict_right_mono) 
13449  1303 

63588  1304 
text \<open>Differs from the standard \<open>zero_less_mult_iff\<close> in that there are no negative numbers.\<close> 
1305 
lemma nat_0_less_mult_iff [simp]: "0 < m * n \<longleftrightarrow> 0 < m \<and> 0 < n" 

1306 
for m n :: nat 

1307 
proof (induct m) 

1308 
case 0 

1309 
then show ?case by simp 

1310 
next 

1311 
case (Suc m) 

1312 
then show ?case by (cases n) simp_all 

1313 
qed 

13449  1314 

63110  1315 
lemma one_le_mult_iff [simp]: "Suc 0 \<le> m * n \<longleftrightarrow> Suc 0 \<le> m \<and> Suc 0 \<le> n" 
63588  1316 
proof (induct m) 