author | wenzelm |
Mon, 12 Oct 2020 16:19:11 +0200 | |
changeset 72455 | 7bf67a58f54a |
parent 71852 | 76784f47c60f |
child 73411 | 1f1366966296 |
permissions | -rw-r--r-- |
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 |
|
61799 | 13 |
subsection \<open>Type \<open>ind\<close>\<close> |
13449 | 14 |
|
15 |
typedecl ind |
|
16 |
||
63110 | 17 |
axiomatization Zero_Rep :: ind and Suc_Rep :: "ind \<Rightarrow> ind" |
18 |
\<comment> \<open>The axiom of infinity in 2 parts:\<close> |
|
63588 | 19 |
where Suc_Rep_inject: "Suc_Rep x = Suc_Rep y \<Longrightarrow> x = y" |
20 |
and Suc_Rep_not_Zero_Rep: "Suc_Rep x \<noteq> Zero_Rep" |
|
21 |
||
19573 | 22 |
|
60758 | 23 |
subsection \<open>Type nat\<close> |
24 |
||
25 |
text \<open>Type definition\<close> |
|
13449 | 26 |
|
63588 | 27 |
inductive Nat :: "ind \<Rightarrow> bool" |
28 |
where |
|
29 |
Zero_RepI: "Nat Zero_Rep" |
|
30 |
| Suc_RepI: "Nat i \<Longrightarrow> Nat (Suc_Rep i)" |
|
13449 | 31 |
|
49834 | 32 |
typedef nat = "{n. Nat n}" |
45696 | 33 |
morphisms Rep_Nat Abs_Nat |
44278
1220ecb81e8f
observe distinction between sets and predicates more properly
haftmann
parents:
43595
diff
changeset
|
34 |
using Nat.Zero_RepI by auto |
1220ecb81e8f
observe distinction between sets and predicates more properly
haftmann
parents:
43595
diff
changeset
|
35 |
|
63588 | 36 |
lemma Nat_Rep_Nat: "Nat (Rep_Nat n)" |
44278
1220ecb81e8f
observe distinction between sets and predicates more properly
haftmann
parents:
43595
diff
changeset
|
37 |
using Rep_Nat by simp |
13449 | 38 |
|
63588 | 39 |
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
|
40 |
using Abs_Nat_inverse by simp |
1220ecb81e8f
observe distinction between sets and predicates more properly
haftmann
parents:
43595
diff
changeset
|
41 |
|
63588 | 42 |
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
|
43 |
using Abs_Nat_inject by simp |
13449 | 44 |
|
25510 | 45 |
instantiation nat :: zero |
46 |
begin |
|
47 |
||
63588 | 48 |
definition Zero_nat_def: "0 = Abs_Nat Zero_Rep" |
25510 | 49 |
|
50 |
instance .. |
|
51 |
||
52 |
end |
|
24995 | 53 |
|
63588 | 54 |
definition Suc :: "nat \<Rightarrow> nat" |
55 |
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
|
56 |
|
27104
791607529f6d
rep_datatype command now takes list of constructors as input arguments
haftmann
parents:
26748
diff
changeset
|
57 |
lemma Suc_not_Zero: "Suc m \<noteq> 0" |
63588 | 58 |
by (simp add: Zero_nat_def Suc_def Suc_RepI Zero_RepI |
59 |
Nat_Abs_Nat_inject Suc_Rep_not_Zero_Rep Nat_Rep_Nat) |
|
13449 | 60 |
|
27104
791607529f6d
rep_datatype command now takes list of constructors as input arguments
haftmann
parents:
26748
diff
changeset
|
61 |
lemma Zero_not_Suc: "0 \<noteq> Suc m" |
63588 | 62 |
by (rule not_sym) (rule Suc_not_Zero) |
13449 | 63 |
|
34208
a7acd6c68d9b
more regular axiom of infinity, with no (indirect) reference to overloaded constants
krauss
parents:
33657
diff
changeset
|
64 |
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
|
65 |
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
|
66 |
|
55417
01fbfb60c33e
adapted to 'xxx_{case,rec}' renaming, to new theorem names, and to new variable names in theorems
blanchet
parents:
55415
diff
changeset
|
67 |
lemma nat_induct0: |
71585 | 68 |
assumes "P 0" 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
|
69 |
shows "P n" |
71585 | 70 |
proof - |
71 |
have "P (Abs_Nat (Rep_Nat n))" |
|
72 |
using assms unfolding Zero_nat_def Suc_def |
|
73 |
by (iprover intro: Nat_Rep_Nat [THEN Nat.induct] elim: Nat_Abs_Nat_inverse [THEN subst]) |
|
74 |
then show ?thesis |
|
75 |
by (simp add: Rep_Nat_inverse) |
|
76 |
qed |
|
63588 | 77 |
|
78 |
free_constructors case_nat for "0 :: nat" | Suc pred |
|
79 |
where "pred (0 :: nat) = (0 :: nat)" |
|
58189
9d714be4f028
added 'plugins' option to control which hooks are enabled
blanchet
parents:
57983
diff
changeset
|
80 |
apply atomize_elim |
9d714be4f028
added 'plugins' option to control which hooks are enabled
blanchet
parents:
57983
diff
changeset
|
81 |
apply (rename_tac n, induct_tac n rule: nat_induct0, auto) |
63588 | 82 |
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
|
83 |
apply (simp only: Suc_not_Zero) |
9d714be4f028
added 'plugins' option to control which hooks are enabled
blanchet
parents:
57983
diff
changeset
|
84 |
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
|
85 |
|
61799 | 86 |
\<comment> \<open>Avoid name clashes by prefixing the output of \<open>old_rep_datatype\<close> with \<open>old\<close>.\<close> |
60758 | 87 |
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
|
88 |
|
61076 | 89 |
old_rep_datatype "0 :: nat" Suc |
71585 | 90 |
by (erule nat_induct0) auto |
55417
01fbfb60c33e
adapted to 'xxx_{case,rec}' renaming, to new theorem names, and to new variable names in theorems
blanchet
parents:
55415
diff
changeset
|
91 |
|
60758 | 92 |
setup \<open>Sign.parent_path\<close> |
93 |
||
61799 | 94 |
\<comment> \<open>But erase the prefix for properties that are not generated by \<open>free_constructors\<close>.\<close> |
60758 | 95 |
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
|
96 |
|
63588 | 97 |
declare old.nat.inject[iff del] |
98 |
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
|
99 |
|
01fbfb60c33e
adapted to 'xxx_{case,rec}' renaming, to new theorem names, and to new variable names in theorems
blanchet
parents:
55415
diff
changeset
|
100 |
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
|
101 |
lemmas inducts = old.nat.inducts |
55642
63beb38e9258
adapted to renaming of datatype 'cases' and 'recs' to 'case' and 'rec'
blanchet
parents:
55575
diff
changeset
|
102 |
lemmas rec = old.nat.rec |
63beb38e9258
adapted to renaming of datatype 'cases' and 'recs' to 'case' and 'rec'
blanchet
parents:
55575
diff
changeset
|
103 |
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
|
104 |
|
60758 | 105 |
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
|
106 |
|
63110 | 107 |
abbreviation rec_nat :: "'a \<Rightarrow> (nat \<Rightarrow> 'a \<Rightarrow> 'a) \<Rightarrow> nat \<Rightarrow> 'a" |
108 |
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
|
109 |
|
55424
9ab4129a76a3
remove hidden fact about hidden constant from code generator setup
blanchet
parents:
55423
diff
changeset
|
110 |
declare nat.sel[code del] |
9ab4129a76a3
remove hidden fact about hidden constant from code generator setup
blanchet
parents:
55423
diff
changeset
|
111 |
|
61799 | 112 |
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
|
113 |
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
|
114 |
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
|
115 |
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
|
116 |
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
|
117 |
nat.sel |
57983
6edc3529bb4e
reordered some (co)datatype property names for more consistency
blanchet
parents:
57952
diff
changeset
|
118 |
nat.exhaust_sel |
6edc3529bb4e
reordered some (co)datatype property names for more consistency
blanchet
parents:
57952
diff
changeset
|
119 |
nat.split_sel |
6edc3529bb4e
reordered some (co)datatype property names for more consistency
blanchet
parents:
57952
diff
changeset
|
120 |
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
|
121 |
|
01fbfb60c33e
adapted to 'xxx_{case,rec}' renaming, to new theorem names, and to new variable names in theorems
blanchet
parents:
55415
diff
changeset
|
122 |
lemma nat_exhaust [case_names 0 Suc, cases type: nat]: |
63588 | 123 |
"(y = 0 \<Longrightarrow> P) \<Longrightarrow> (\<And>nat. y = Suc nat \<Longrightarrow> P) \<Longrightarrow> P" |
61799 | 124 |
\<comment> \<open>for backward compatibility -- names of variables differ\<close> |
63588 | 125 |
by (rule old.nat.exhaust) |
13449 | 126 |
|
27104
791607529f6d
rep_datatype command now takes list of constructors as input arguments
haftmann
parents:
26748
diff
changeset
|
127 |
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
|
128 |
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
|
129 |
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
|
130 |
shows "P n" |
63588 | 131 |
\<comment> \<open>for backward compatibility -- names of variables differ\<close> |
132 |
using assms by (rule nat.induct) |
|
13449 | 133 |
|
55417
01fbfb60c33e
adapted to 'xxx_{case,rec}' renaming, to new theorem names, and to new variable names in theorems
blanchet
parents:
55415
diff
changeset
|
134 |
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
|
135 |
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
|
136 |
nat_induct0 |
24995 | 137 |
|
60758 | 138 |
ML \<open> |
58389 | 139 |
val nat_basic_lfp_sugar = |
140 |
let |
|
69593 | 141 |
val ctr_sugar = the (Ctr_Sugar.ctr_sugar_of_global \<^theory> \<^type_name>\<open>nat\<close>); |
142 |
val recx = Logic.varify_types_global \<^term>\<open>rec_nat\<close>; |
|
58389 | 143 |
val C = body_type (fastype_of recx); |
144 |
in |
|
145 |
{T = HOLogic.natT, fp_res_index = 0, C = C, fun_arg_Tsss = [[], [[HOLogic.natT, C]]], |
|
146 |
ctr_sugar = ctr_sugar, recx = recx, rec_thms = @{thms nat.rec}} |
|
147 |
end; |
|
60758 | 148 |
\<close> |
149 |
||
150 |
setup \<open> |
|
58389 | 151 |
let |
69593 | 152 |
fun basic_lfp_sugars_of _ [\<^typ>\<open>nat\<close>] _ _ ctxt = |
62326
3cf7a067599c
allow predicator instead of map function in 'primrec'
blanchet
parents:
62217
diff
changeset
|
153 |
([], [0], [nat_basic_lfp_sugar], [], [], [], TrueI (*dummy*), [], false, ctxt) |
58389 | 154 |
| basic_lfp_sugars_of bs arg_Ts callers callssss ctxt = |
155 |
BNF_LFP_Rec_Sugar.default_basic_lfp_sugars_of bs arg_Ts callers callssss ctxt; |
|
156 |
in |
|
157 |
BNF_LFP_Rec_Sugar.register_lfp_rec_extension |
|
66290 | 158 |
{nested_simps = [], special_endgame_tac = K (K (K (K no_tac))), is_new_datatype = K (K true), |
159 |
basic_lfp_sugars_of = basic_lfp_sugars_of, rewrite_nested_rec_call = NONE} |
|
58389 | 160 |
end |
60758 | 161 |
\<close> |
162 |
||
163 |
text \<open>Injectiveness and distinctness lemmas\<close> |
|
24995 | 164 |
|
66936 | 165 |
lemma inj_Suc [simp]: |
166 |
"inj_on Suc N" |
|
27104
791607529f6d
rep_datatype command now takes list of constructors as input arguments
haftmann
parents:
26748
diff
changeset
|
167 |
by (simp add: inj_on_def) |
791607529f6d
rep_datatype command now takes list of constructors as input arguments
haftmann
parents:
26748
diff
changeset
|
168 |
|
66936 | 169 |
lemma bij_betw_Suc [simp]: |
170 |
"bij_betw Suc M N \<longleftrightarrow> Suc ` M = N" |
|
171 |
by (simp add: bij_betw_def) |
|
172 |
||
26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
173 |
lemma Suc_neq_Zero: "Suc m = 0 \<Longrightarrow> R" |
63588 | 174 |
by (rule notE) (rule Suc_not_Zero) |
24995 | 175 |
|
26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
176 |
lemma Zero_neq_Suc: "0 = Suc m \<Longrightarrow> R" |
63588 | 177 |
by (rule Suc_neq_Zero) (erule sym) |
24995 | 178 |
|
26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
179 |
lemma Suc_inject: "Suc x = Suc y \<Longrightarrow> x = y" |
63588 | 180 |
by (rule inj_Suc [THEN injD]) |
24995 | 181 |
|
14267
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14266
diff
changeset
|
182 |
lemma n_not_Suc_n: "n \<noteq> Suc n" |
63588 | 183 |
by (induct n) simp_all |
13449 | 184 |
|
26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
185 |
lemma Suc_n_not_n: "Suc n \<noteq> n" |
63588 | 186 |
by (rule not_sym) (rule n_not_Suc_n) |
187 |
||
69593 | 188 |
text \<open>A special form of induction for reasoning about \<^term>\<open>m < n\<close> and \<^term>\<open>m - n\<close>.\<close> |
63110 | 189 |
lemma diff_induct: |
190 |
assumes "\<And>x. P x 0" |
|
191 |
and "\<And>y. P 0 (Suc y)" |
|
192 |
and "\<And>x y. P x y \<Longrightarrow> P (Suc x) (Suc y)" |
|
193 |
shows "P m n" |
|
63588 | 194 |
proof (induct n arbitrary: m) |
195 |
case 0 |
|
196 |
show ?case by (rule assms(1)) |
|
197 |
next |
|
198 |
case (Suc n) |
|
199 |
show ?case |
|
200 |
proof (induct m) |
|
201 |
case 0 |
|
202 |
show ?case by (rule assms(2)) |
|
203 |
next |
|
204 |
case (Suc m) |
|
205 |
from \<open>P m n\<close> show ?case by (rule assms(3)) |
|
206 |
qed |
|
207 |
qed |
|
13449 | 208 |
|
24995 | 209 |
|
60758 | 210 |
subsection \<open>Arithmetic operators\<close> |
24995 | 211 |
|
49388 | 212 |
instantiation nat :: comm_monoid_diff |
25571
c9e39eafc7a0
instantiation target rather than legacy instance
haftmann
parents:
25563
diff
changeset
|
213 |
begin |
24995 | 214 |
|
63588 | 215 |
primrec plus_nat |
216 |
where |
|
217 |
add_0: "0 + n = (n::nat)" |
|
218 |
| add_Suc: "Suc m + n = Suc (m + n)" |
|
219 |
||
220 |
lemma add_0_right [simp]: "m + 0 = m" |
|
221 |
for m :: nat |
|
26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
222 |
by (induct m) simp_all |
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
223 |
|
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
224 |
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
|
225 |
by (induct m) simp_all |
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
226 |
|
28514 | 227 |
declare add_0 [code] |
228 |
||
26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
229 |
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
|
230 |
by simp |
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
231 |
|
63588 | 232 |
primrec minus_nat |
233 |
where |
|
234 |
diff_0 [code]: "m - 0 = (m::nat)" |
|
235 |
| diff_Suc: "m - Suc n = (case m - n of 0 \<Rightarrow> 0 | Suc k \<Rightarrow> k)" |
|
24995 | 236 |
|
28514 | 237 |
declare diff_Suc [simp del] |
26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
238 |
|
63588 | 239 |
lemma diff_0_eq_0 [simp, code]: "0 - n = 0" |
240 |
for n :: nat |
|
26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
241 |
by (induct n) (simp_all add: diff_Suc) |
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
242 |
|
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
243 |
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
|
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 |
|
63110 | 246 |
instance |
247 |
proof |
|
26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
248 |
fix n m q :: nat |
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
249 |
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
|
250 |
show "n + m = m + n" by (induct n) simp_all |
59815
cce82e360c2f
explicit commutative additive inverse operation;
haftmann
parents:
59582
diff
changeset
|
251 |
show "m + n - m = n" by (induct m) simp_all |
cce82e360c2f
explicit commutative additive inverse operation;
haftmann
parents:
59582
diff
changeset
|
252 |
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
|
253 |
show "0 + n = n" by simp |
49388 | 254 |
show "0 - n = 0" by simp |
26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
255 |
qed |
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
256 |
|
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
257 |
end |
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
258 |
|
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
|
259 |
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
|
260 |
|
26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
261 |
instantiation nat :: comm_semiring_1_cancel |
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
262 |
begin |
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
263 |
|
63588 | 264 |
definition One_nat_def [simp]: "1 = Suc 0" |
265 |
||
266 |
primrec times_nat |
|
267 |
where |
|
268 |
mult_0: "0 * n = (0::nat)" |
|
269 |
| mult_Suc: "Suc m * n = n + (m * n)" |
|
270 |
||
271 |
lemma mult_0_right [simp]: "m * 0 = 0" |
|
272 |
for m :: nat |
|
26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
273 |
by (induct m) simp_all |
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
274 |
|
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
275 |
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
|
276 |
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
|
277 |
|
63588 | 278 |
lemma add_mult_distrib: "(m + n) * k = (m * k) + (n * k)" |
279 |
for m n k :: nat |
|
57512
cc97b347b301
reduced name variants for assoc and commute on plus and mult
haftmann
parents:
57492
diff
changeset
|
280 |
by (induct m) (simp_all add: add.assoc) |
26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
281 |
|
63110 | 282 |
instance |
283 |
proof |
|
284 |
fix k n m q :: nat |
|
63588 | 285 |
show "0 \<noteq> (1::nat)" |
286 |
by simp |
|
287 |
show "1 * n = n" |
|
288 |
by simp |
|
289 |
show "n * m = m * n" |
|
290 |
by (induct n) simp_all |
|
291 |
show "(n * m) * q = n * (m * q)" |
|
292 |
by (induct n) (simp_all add: add_mult_distrib) |
|
293 |
show "(n + m) * q = n * q + m * q" |
|
294 |
by (rule add_mult_distrib) |
|
63110 | 295 |
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
|
296 |
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
|
297 |
qed |
25571
c9e39eafc7a0
instantiation target rather than legacy instance
haftmann
parents:
25563
diff
changeset
|
298 |
|
c9e39eafc7a0
instantiation target rather than legacy instance
haftmann
parents:
25563
diff
changeset
|
299 |
end |
24995 | 300 |
|
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
|
301 |
|
60758 | 302 |
subsubsection \<open>Addition\<close> |
26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
303 |
|
61799 | 304 |
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
|
305 |
|
63588 | 306 |
lemma add_is_0 [iff]: "m + n = 0 \<longleftrightarrow> m = 0 \<and> n = 0" |
307 |
for m n :: nat |
|
26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
308 |
by (cases m) simp_all |
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
309 |
|
67091 | 310 |
lemma add_is_1: "m + n = Suc 0 \<longleftrightarrow> m = Suc 0 \<and> n = 0 \<or> m = 0 \<and> n = Suc 0" |
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 |
|
67091 | 313 |
lemma one_is_add: "Suc 0 = m + n \<longleftrightarrow> m = Suc 0 \<and> n = 0 \<or> m = 0 \<and> n = Suc 0" |
26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
314 |
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
|
315 |
|
63588 | 316 |
lemma add_eq_self_zero: "m + n = m \<Longrightarrow> n = 0" |
317 |
for m n :: nat |
|
26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
318 |
by (induct m) simp_all |
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
319 |
|
66936 | 320 |
lemma plus_1_eq_Suc: |
321 |
"plus 1 = Suc" |
|
322 |
by (simp add: fun_eq_iff) |
|
26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
323 |
|
47208 | 324 |
lemma Suc_eq_plus1: "Suc n = n + 1" |
63588 | 325 |
by simp |
47208 | 326 |
|
327 |
lemma Suc_eq_plus1_left: "Suc n = 1 + n" |
|
63588 | 328 |
by simp |
47208 | 329 |
|
26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
330 |
|
60758 | 331 |
subsubsection \<open>Difference\<close> |
26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
332 |
|
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
333 |
lemma Suc_diff_diff [simp]: "(Suc m - n) - Suc k = m - n - k" |
62365 | 334 |
by (simp add: diff_diff_add) |
26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
335 |
|
30093 | 336 |
lemma diff_Suc_1 [simp]: "Suc n - 1 = n" |
63588 | 337 |
by simp |
338 |
||
30093 | 339 |
|
60758 | 340 |
subsubsection \<open>Multiplication\<close> |
26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
341 |
|
63110 | 342 |
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
|
343 |
by (induct m) auto |
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
344 |
|
63110 | 345 |
lemma mult_eq_1_iff [simp]: "m * n = Suc 0 \<longleftrightarrow> m = Suc 0 \<and> n = Suc 0" |
63588 | 346 |
proof (induct m) |
347 |
case 0 |
|
348 |
then show ?case by simp |
|
349 |
next |
|
350 |
case (Suc m) |
|
351 |
then show ?case by (induct n) auto |
|
352 |
qed |
|
26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
353 |
|
63110 | 354 |
lemma one_eq_mult_iff [simp]: "Suc 0 = m * n \<longleftrightarrow> m = Suc 0 \<and> n = Suc 0" |
71585 | 355 |
by (simp add: eq_commute flip: mult_eq_1_iff) |
356 |
||
357 |
lemma nat_mult_eq_1_iff [simp]: "m * n = 1 \<longleftrightarrow> m = 1 \<and> n = 1" |
|
358 |
and nat_1_eq_mult_iff [simp]: "1 = m * n \<longleftrightarrow> m = 1 \<and> n = 1" for m n :: nat |
|
359 |
by auto |
|
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
|
360 |
|
63588 | 361 |
lemma mult_cancel1 [simp]: "k * m = k * n \<longleftrightarrow> m = n \<or> k = 0" |
362 |
for k m n :: nat |
|
26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
363 |
proof - |
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
364 |
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
|
365 |
proof (induct n arbitrary: m) |
63110 | 366 |
case 0 |
367 |
then show "m = 0" by simp |
|
26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
368 |
next |
63110 | 369 |
case (Suc n) |
370 |
then show "m = Suc n" |
|
371 |
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
|
372 |
qed |
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
373 |
then show ?thesis by auto |
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
374 |
qed |
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
375 |
|
63588 | 376 |
lemma mult_cancel2 [simp]: "m * k = n * k \<longleftrightarrow> m = n \<or> k = 0" |
377 |
for k m n :: nat |
|
57512
cc97b347b301
reduced name variants for assoc and commute on plus and mult
haftmann
parents:
57492
diff
changeset
|
378 |
by (simp add: mult.commute) |
26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
379 |
|
63110 | 380 |
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
|
381 |
by (subst mult_cancel1) simp |
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
382 |
|
24995 | 383 |
|
69593 | 384 |
subsection \<open>Orders on \<^typ>\<open>nat\<close>\<close> |
60758 | 385 |
|
386 |
subsubsection \<open>Operation definition\<close> |
|
24995 | 387 |
|
26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
388 |
instantiation nat :: linorder |
25510 | 389 |
begin |
390 |
||
63588 | 391 |
primrec less_eq_nat |
392 |
where |
|
393 |
"(0::nat) \<le> n \<longleftrightarrow> True" |
|
394 |
| "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
|
395 |
|
28514 | 396 |
declare less_eq_nat.simps [simp del] |
63110 | 397 |
|
63588 | 398 |
lemma le0 [iff]: "0 \<le> n" for |
399 |
n :: nat |
|
63110 | 400 |
by (simp add: less_eq_nat.simps) |
401 |
||
63588 | 402 |
lemma [code]: "0 \<le> n \<longleftrightarrow> True" |
403 |
for n :: nat |
|
63110 | 404 |
by simp |
26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
405 |
|
63588 | 406 |
definition less_nat |
407 |
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
|
408 |
|
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
409 |
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
|
410 |
by (simp add: less_eq_nat.simps(2)) |
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
411 |
|
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
412 |
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
|
413 |
unfolding less_eq_Suc_le .. |
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
414 |
|
63588 | 415 |
lemma le_0_eq [iff]: "n \<le> 0 \<longleftrightarrow> n = 0" |
416 |
for n :: nat |
|
26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
417 |
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
|
418 |
|
63588 | 419 |
lemma not_less0 [iff]: "\<not> n < 0" |
420 |
for n :: nat |
|
26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
421 |
by (simp add: less_eq_Suc_le) |
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
422 |
|
63588 | 423 |
lemma less_nat_zero_code [code]: "n < 0 \<longleftrightarrow> False" |
424 |
for n :: nat |
|
26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
425 |
by simp |
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
426 |
|
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
427 |
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
|
428 |
by (simp add: less_eq_Suc_le) |
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
429 |
|
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
430 |
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
|
431 |
by (simp add: less_eq_Suc_le) |
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
432 |
|
56194 | 433 |
lemma Suc_less_eq2: "Suc n < m \<longleftrightarrow> (\<exists>m'. m = Suc m' \<and> n < m')" |
434 |
by (cases m) auto |
|
435 |
||
26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
436 |
lemma le_SucI: "m \<le> n \<Longrightarrow> m \<le> Suc n" |
63110 | 437 |
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
|
438 |
|
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
439 |
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
|
440 |
by (cases n) (auto intro: le_SucI) |
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
441 |
|
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
442 |
lemma less_SucI: "m < n \<Longrightarrow> m < Suc n" |
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
443 |
by (simp add: less_eq_Suc_le) (erule Suc_leD) |
24995 | 444 |
|
26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
445 |
lemma Suc_lessD: "Suc m < n \<Longrightarrow> m < n" |
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
446 |
by (simp add: less_eq_Suc_le) (erule Suc_leD) |
25510 | 447 |
|
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
|
448 |
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
|
449 |
proof |
63110 | 450 |
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
|
451 |
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
|
452 |
proof (induct n arbitrary: m) |
63110 | 453 |
case 0 |
63588 | 454 |
then show ?case |
455 |
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
|
456 |
next |
63110 | 457 |
case (Suc n) |
63588 | 458 |
then show ?case |
459 |
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
|
460 |
qed |
63588 | 461 |
show "n \<le> n" |
462 |
by (induct n) simp_all |
|
63110 | 463 |
then show "n = m" if "n \<le> m" and "m \<le> n" |
464 |
using that by (induct n arbitrary: m) |
|
26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
465 |
(simp_all add: less_eq_nat.simps(2) split: nat.splits) |
63110 | 466 |
show "n \<le> q" if "n \<le> m" and "m \<le> q" |
467 |
using that |
|
26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
468 |
proof (induct n arbitrary: m q) |
63110 | 469 |
case 0 |
470 |
show ?case by simp |
|
26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
471 |
next |
63110 | 472 |
case (Suc n) |
473 |
then show ?case |
|
26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
474 |
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
|
475 |
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
|
476 |
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
|
477 |
qed |
63110 | 478 |
show "n \<le> m \<or> m \<le> n" |
26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
479 |
by (induct n arbitrary: m) |
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
480 |
(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
|
481 |
qed |
25510 | 482 |
|
483 |
end |
|
13449 | 484 |
|
52729
412c9e0381a1
factored syntactic type classes for bot and top (by Alessandro Coglio)
haftmann
parents:
52435
diff
changeset
|
485 |
instantiation nat :: order_bot |
29652 | 486 |
begin |
487 |
||
63588 | 488 |
definition bot_nat :: nat |
489 |
where "bot_nat = 0" |
|
490 |
||
491 |
instance |
|
492 |
by standard (simp add: bot_nat_def) |
|
29652 | 493 |
|
494 |
end |
|
495 |
||
51329
4a3c453f99a1
split dense into inner_dense_order and no_top/no_bot
hoelzl
parents:
51263
diff
changeset
|
496 |
instance nat :: no_top |
61169 | 497 |
by standard (auto intro: less_Suc_eq_le [THEN iffD2]) |
52289 | 498 |
|
51329
4a3c453f99a1
split dense into inner_dense_order and no_top/no_bot
hoelzl
parents:
51263
diff
changeset
|
499 |
|
60758 | 500 |
subsubsection \<open>Introduction properties\<close> |
13449 | 501 |
|
26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
502 |
lemma lessI [iff]: "n < Suc n" |
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
503 |
by (simp add: less_Suc_eq_le) |
13449 | 504 |
|
26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
505 |
lemma zero_less_Suc [iff]: "0 < Suc n" |
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
506 |
by (simp add: less_Suc_eq_le) |
13449 | 507 |
|
508 |
||
60758 | 509 |
subsubsection \<open>Elimination properties\<close> |
13449 | 510 |
|
63588 | 511 |
lemma less_not_refl: "\<not> n < n" |
512 |
for n :: nat |
|
26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
513 |
by (rule order_less_irrefl) |
13449 | 514 |
|
63588 | 515 |
lemma less_not_refl2: "n < m \<Longrightarrow> m \<noteq> n" |
516 |
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
|
517 |
by (rule not_sym) (rule less_imp_neq) |
13449 | 518 |
|
63588 | 519 |
lemma less_not_refl3: "s < t \<Longrightarrow> s \<noteq> t" |
520 |
for s t :: nat |
|
26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
521 |
by (rule less_imp_neq) |
13449 | 522 |
|
63588 | 523 |
lemma less_irrefl_nat: "n < n \<Longrightarrow> R" |
524 |
for n :: nat |
|
26335
961bbcc9d85b
removed redundant Nat.less_not_sym, Nat.less_asym;
wenzelm
parents:
26315
diff
changeset
|
525 |
by (rule notE, rule less_not_refl) |
13449 | 526 |
|
63588 | 527 |
lemma less_zeroE: "n < 0 \<Longrightarrow> R" |
528 |
for n :: nat |
|
26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
529 |
by (rule notE) (rule not_less0) |
13449 | 530 |
|
63110 | 531 |
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
|
532 |
unfolding less_Suc_eq_le le_less .. |
13449 | 533 |
|
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
|
534 |
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
|
535 |
by (simp add: less_Suc_eq) |
13449 | 536 |
|
63588 | 537 |
lemma less_one [iff]: "n < 1 \<longleftrightarrow> n = 0" |
538 |
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
|
539 |
unfolding One_nat_def by (rule less_Suc0) |
13449 | 540 |
|
63110 | 541 |
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
|
542 |
by simp |
13449 | 543 |
|
63588 | 544 |
text \<open>"Less than" is antisymmetric, sort of.\<close> |
545 |
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
|
546 |
unfolding not_less less_Suc_eq_le by (rule antisym) |
14302 | 547 |
|
63588 | 548 |
lemma nat_neq_iff: "m \<noteq> n \<longleftrightarrow> m < n \<or> n < m" |
549 |
for m n :: nat |
|
26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
550 |
by (rule linorder_neq_iff) |
13449 | 551 |
|
552 |
||
60758 | 553 |
subsubsection \<open>Inductive (?) properties\<close> |
13449 | 554 |
|
63110 | 555 |
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
|
556 |
unfolding less_eq_Suc_le [of m] le_less by simp |
13449 | 557 |
|
26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
558 |
lemma lessE: |
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
559 |
assumes major: "i < k" |
63110 | 560 |
and 1: "k = Suc i \<Longrightarrow> P" |
561 |
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
|
562 |
shows P |
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
563 |
proof - |
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
564 |
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
|
565 |
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
|
566 |
then have "(\<exists>j. i < j \<and> k = Suc j) \<or> k = Suc i" |
63110 | 567 |
by (auto simp add: less_le) |
568 |
with 1 2 show P by auto |
|
26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
569 |
qed |
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
570 |
|
63110 | 571 |
lemma less_SucE: |
572 |
assumes major: "m < Suc n" |
|
573 |
and less: "m < n \<Longrightarrow> P" |
|
574 |
and eq: "m = n \<Longrightarrow> P" |
|
575 |
shows P |
|
71585 | 576 |
proof (rule major [THEN lessE]) |
577 |
show "Suc n = Suc m \<Longrightarrow> P" |
|
578 |
using eq by blast |
|
579 |
show "\<And>j. \<lbrakk>m < j; Suc n = Suc j\<rbrakk> \<Longrightarrow> P" |
|
580 |
by (blast intro: less) |
|
581 |
qed |
|
13449 | 582 |
|
63110 | 583 |
lemma Suc_lessE: |
584 |
assumes major: "Suc i < k" |
|
585 |
and minor: "\<And>j. i < j \<Longrightarrow> k = Suc j \<Longrightarrow> P" |
|
586 |
shows P |
|
71585 | 587 |
proof (rule major [THEN lessE]) |
588 |
show "k = Suc (Suc i) \<Longrightarrow> P" |
|
589 |
using lessI minor by iprover |
|
590 |
show "\<And>j. \<lbrakk>Suc i < j; k = Suc j\<rbrakk> \<Longrightarrow> P" |
|
591 |
using Suc_lessD minor by iprover |
|
592 |
qed |
|
13449 | 593 |
|
63110 | 594 |
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
|
595 |
by simp |
13449 | 596 |
|
597 |
lemma less_trans_Suc: |
|
63110 | 598 |
assumes le: "i < j" |
599 |
shows "j < k \<Longrightarrow> Suc i < k" |
|
63588 | 600 |
proof (induct k) |
601 |
case 0 |
|
602 |
then show ?case by simp |
|
603 |
next |
|
604 |
case (Suc k) |
|
605 |
with le show ?case |
|
606 |
by simp (auto simp add: less_Suc_eq dest: Suc_lessD) |
|
607 |
qed |
|
608 |
||
69593 | 609 |
text \<open>Can be used with \<open>less_Suc_eq\<close> to get \<^prop>\<open>n = m \<or> n < m\<close>.\<close> |
26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
610 |
lemma not_less_eq: "\<not> m < n \<longleftrightarrow> n < Suc m" |
63588 | 611 |
by (simp only: not_less less_Suc_eq_le) |
13449 | 612 |
|
26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
613 |
lemma not_less_eq_eq: "\<not> m \<le> n \<longleftrightarrow> Suc n \<le> m" |
63588 | 614 |
by (simp only: not_le Suc_le_eq) |
615 |
||
616 |
text \<open>Properties of "less than or equal".\<close> |
|
13449 | 617 |
|
63110 | 618 |
lemma le_imp_less_Suc: "m \<le> n \<Longrightarrow> m < Suc n" |
63588 | 619 |
by (simp only: less_Suc_eq_le) |
13449 | 620 |
|
63110 | 621 |
lemma Suc_n_not_le_n: "\<not> Suc n \<le> n" |
63588 | 622 |
by (simp add: not_le less_Suc_eq_le) |
623 |
||
624 |
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
|
625 |
by (simp add: less_Suc_eq_le [symmetric] less_Suc_eq) |
13449 | 626 |
|
63110 | 627 |
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
|
628 |
by (drule le_Suc_eq [THEN iffD1], iprover+) |
13449 | 629 |
|
63588 | 630 |
lemma Suc_leI: "m < n \<Longrightarrow> Suc m \<le> n" |
631 |
by (simp only: Suc_le_eq) |
|
632 |
||
633 |
text \<open>Stronger version of \<open>Suc_leD\<close>.\<close> |
|
63110 | 634 |
lemma Suc_le_lessD: "Suc m \<le> n \<Longrightarrow> m < n" |
63588 | 635 |
by (simp only: Suc_le_eq) |
13449 | 636 |
|
63110 | 637 |
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
|
638 |
unfolding less_eq_Suc_le by (rule Suc_leD) |
13449 | 639 |
|
61799 | 640 |
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
|
641 |
lemmas le_simps = less_imp_le_nat less_Suc_eq_le Suc_le_eq |
13449 | 642 |
|
643 |
||
63110 | 644 |
text \<open>Equivalence of \<open>m \<le> n\<close> and \<open>m < n \<or> m = n\<close>\<close> |
645 |
||
63588 | 646 |
lemma less_or_eq_imp_le: "m < n \<or> m = n \<Longrightarrow> m \<le> n" |
647 |
for m n :: nat |
|
26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
648 |
unfolding le_less . |
13449 | 649 |
|
63588 | 650 |
lemma le_eq_less_or_eq: "m \<le> n \<longleftrightarrow> m < n \<or> m = n" |
651 |
for m n :: nat |
|
26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
652 |
by (rule le_less) |
13449 | 653 |
|
61799 | 654 |
text \<open>Useful with \<open>blast\<close>.\<close> |
63588 | 655 |
lemma eq_imp_le: "m = n \<Longrightarrow> m \<le> n" |
656 |
for m n :: nat |
|
26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
657 |
by auto |
13449 | 658 |
|
63588 | 659 |
lemma le_refl: "n \<le> n" |
660 |
for n :: nat |
|
26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
661 |
by simp |
13449 | 662 |
|
63588 | 663 |
lemma le_trans: "i \<le> j \<Longrightarrow> j \<le> k \<Longrightarrow> i \<le> k" |
664 |
for i j k :: nat |
|
26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
665 |
by (rule order_trans) |
13449 | 666 |
|
63588 | 667 |
lemma le_antisym: "m \<le> n \<Longrightarrow> n \<le> m \<Longrightarrow> m = n" |
668 |
for m n :: nat |
|
26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
669 |
by (rule antisym) |
13449 | 670 |
|
63588 | 671 |
lemma nat_less_le: "m < n \<longleftrightarrow> m \<le> n \<and> m \<noteq> n" |
672 |
for m n :: nat |
|
26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
673 |
by (rule less_le) |
13449 | 674 |
|
63588 | 675 |
lemma le_neq_implies_less: "m \<le> n \<Longrightarrow> m \<noteq> n \<Longrightarrow> m < n" |
676 |
for m n :: nat |
|
26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
677 |
unfolding less_le .. |
13449 | 678 |
|
67091 | 679 |
lemma nat_le_linear: "m \<le> n \<or> n \<le> m" |
63588 | 680 |
for m n :: nat |
26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
681 |
by (rule linear) |
14341
a09441bd4f1e
Ring_and_Field now requires axiom add_left_imp_eq for semirings.
paulson
parents:
14331
diff
changeset
|
682 |
|
22718 | 683 |
lemmas linorder_neqE_nat = linorder_neqE [where 'a = nat] |
15921 | 684 |
|
63110 | 685 |
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
|
686 |
unfolding less_Suc_eq_le by auto |
13449 | 687 |
|
63110 | 688 |
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
|
689 |
unfolding not_less by (rule le_less_Suc_eq) |
13449 | 690 |
|
691 |
lemmas not_less_simps = not_less_less_Suc_eq le_less_Suc_eq |
|
692 |
||
63110 | 693 |
lemma not0_implies_Suc: "n \<noteq> 0 \<Longrightarrow> \<exists>m. n = Suc m" |
694 |
by (cases n) simp_all |
|
695 |
||
696 |
lemma gr0_implies_Suc: "n > 0 \<Longrightarrow> \<exists>m. n = Suc m" |
|
697 |
by (cases n) simp_all |
|
698 |
||
63588 | 699 |
lemma gr_implies_not0: "m < n \<Longrightarrow> n \<noteq> 0" |
700 |
for m n :: nat |
|
63110 | 701 |
by (cases n) simp_all |
702 |
||
63588 | 703 |
lemma neq0_conv[iff]: "n \<noteq> 0 \<longleftrightarrow> 0 < n" |
704 |
for n :: nat |
|
63110 | 705 |
by (cases n) simp_all |
25140 | 706 |
|
61799 | 707 |
text \<open>This theorem is useful with \<open>blast\<close>\<close> |
63588 | 708 |
lemma gr0I: "(n = 0 \<Longrightarrow> False) \<Longrightarrow> 0 < n" |
709 |
for n :: nat |
|
710 |
by (rule neq0_conv[THEN iffD1]) iprover |
|
63110 | 711 |
|
712 |
lemma gr0_conv_Suc: "0 < n \<longleftrightarrow> (\<exists>m. n = Suc m)" |
|
713 |
by (fast intro: not0_implies_Suc) |
|
714 |
||
63588 | 715 |
lemma not_gr0 [iff]: "\<not> 0 < n \<longleftrightarrow> n = 0" |
716 |
for n :: nat |
|
63110 | 717 |
using neq0_conv by blast |
718 |
||
719 |
lemma Suc_le_D: "Suc n \<le> m' \<Longrightarrow> \<exists>m. m' = Suc m" |
|
720 |
by (induct m') simp_all |
|
13449 | 721 |
|
60758 | 722 |
text \<open>Useful in certain inductive arguments\<close> |
63110 | 723 |
lemma less_Suc_eq_0_disj: "m < Suc n \<longleftrightarrow> m = 0 \<or> (\<exists>j. m = Suc j \<and> j < n)" |
724 |
by (cases m) simp_all |
|
13449 | 725 |
|
64447 | 726 |
lemma All_less_Suc: "(\<forall>i < Suc n. P i) = (P n \<and> (\<forall>i < n. P i))" |
71404
f2b783abfbe7
A few lemmas connected with orderings
paulson <lp15@cam.ac.uk>
parents:
70490
diff
changeset
|
727 |
by (auto simp: less_Suc_eq) |
13449 | 728 |
|
66386 | 729 |
lemma All_less_Suc2: "(\<forall>i < Suc n. P i) = (P 0 \<and> (\<forall>i < n. P(Suc i)))" |
71404
f2b783abfbe7
A few lemmas connected with orderings
paulson <lp15@cam.ac.uk>
parents:
70490
diff
changeset
|
730 |
by (auto simp: less_Suc_eq_0_disj) |
66386 | 731 |
|
732 |
lemma Ex_less_Suc: "(\<exists>i < Suc n. P i) = (P n \<or> (\<exists>i < n. P i))" |
|
71404
f2b783abfbe7
A few lemmas connected with orderings
paulson <lp15@cam.ac.uk>
parents:
70490
diff
changeset
|
733 |
by (auto simp: less_Suc_eq) |
66386 | 734 |
|
735 |
lemma Ex_less_Suc2: "(\<exists>i < Suc n. P i) = (P 0 \<or> (\<exists>i < n. P(Suc i)))" |
|
71404
f2b783abfbe7
A few lemmas connected with orderings
paulson <lp15@cam.ac.uk>
parents:
70490
diff
changeset
|
736 |
by (auto simp: less_Suc_eq_0_disj) |
f2b783abfbe7
A few lemmas connected with orderings
paulson <lp15@cam.ac.uk>
parents:
70490
diff
changeset
|
737 |
|
f2b783abfbe7
A few lemmas connected with orderings
paulson <lp15@cam.ac.uk>
parents:
70490
diff
changeset
|
738 |
text \<open>@{term mono} (non-strict) doesn't imply increasing, as the function could be constant\<close> |
f2b783abfbe7
A few lemmas connected with orderings
paulson <lp15@cam.ac.uk>
parents:
70490
diff
changeset
|
739 |
lemma strict_mono_imp_increasing: |
f2b783abfbe7
A few lemmas connected with orderings
paulson <lp15@cam.ac.uk>
parents:
70490
diff
changeset
|
740 |
fixes n::nat |
f2b783abfbe7
A few lemmas connected with orderings
paulson <lp15@cam.ac.uk>
parents:
70490
diff
changeset
|
741 |
assumes "strict_mono f" shows "f n \<ge> n" |
f2b783abfbe7
A few lemmas connected with orderings
paulson <lp15@cam.ac.uk>
parents:
70490
diff
changeset
|
742 |
proof (induction n) |
f2b783abfbe7
A few lemmas connected with orderings
paulson <lp15@cam.ac.uk>
parents:
70490
diff
changeset
|
743 |
case 0 |
f2b783abfbe7
A few lemmas connected with orderings
paulson <lp15@cam.ac.uk>
parents:
70490
diff
changeset
|
744 |
then show ?case |
f2b783abfbe7
A few lemmas connected with orderings
paulson <lp15@cam.ac.uk>
parents:
70490
diff
changeset
|
745 |
by auto |
f2b783abfbe7
A few lemmas connected with orderings
paulson <lp15@cam.ac.uk>
parents:
70490
diff
changeset
|
746 |
next |
f2b783abfbe7
A few lemmas connected with orderings
paulson <lp15@cam.ac.uk>
parents:
70490
diff
changeset
|
747 |
case (Suc n) |
f2b783abfbe7
A few lemmas connected with orderings
paulson <lp15@cam.ac.uk>
parents:
70490
diff
changeset
|
748 |
then show ?case |
f2b783abfbe7
A few lemmas connected with orderings
paulson <lp15@cam.ac.uk>
parents:
70490
diff
changeset
|
749 |
unfolding not_less_eq_eq [symmetric] |
f2b783abfbe7
A few lemmas connected with orderings
paulson <lp15@cam.ac.uk>
parents:
70490
diff
changeset
|
750 |
using Suc_n_not_le_n assms order_trans strict_mono_less_eq by blast |
f2b783abfbe7
A few lemmas connected with orderings
paulson <lp15@cam.ac.uk>
parents:
70490
diff
changeset
|
751 |
qed |
66386 | 752 |
|
60758 | 753 |
subsubsection \<open>Monotonicity of Addition\<close> |
13449 | 754 |
|
63110 | 755 |
lemma Suc_pred [simp]: "n > 0 \<Longrightarrow> Suc (n - Suc 0) = n" |
756 |
by (simp add: diff_Suc split: nat.split) |
|
757 |
||
758 |
lemma Suc_diff_1 [simp]: "0 < n \<Longrightarrow> Suc (n - 1) = n" |
|
759 |
unfolding One_nat_def by (rule Suc_pred) |
|
760 |
||
63588 | 761 |
lemma nat_add_left_cancel_le [simp]: "k + m \<le> k + n \<longleftrightarrow> m \<le> n" |
762 |
for k m n :: nat |
|
63110 | 763 |
by (induct k) simp_all |
764 |
||
63588 | 765 |
lemma nat_add_left_cancel_less [simp]: "k + m < k + n \<longleftrightarrow> m < n" |
766 |
for k m n :: nat |
|
63110 | 767 |
by (induct k) simp_all |
768 |
||
63588 | 769 |
lemma add_gr_0 [iff]: "m + n > 0 \<longleftrightarrow> m > 0 \<or> n > 0" |
770 |
for m n :: nat |
|
63110 | 771 |
by (auto dest: gr0_implies_Suc) |
13449 | 772 |
|
60758 | 773 |
text \<open>strict, in 1st argument\<close> |
63588 | 774 |
lemma add_less_mono1: "i < j \<Longrightarrow> i + k < j + k" |
775 |
for i j k :: nat |
|
63110 | 776 |
by (induct k) simp_all |
14341
a09441bd4f1e
Ring_and_Field now requires axiom add_left_imp_eq for semirings.
paulson
parents:
14331
diff
changeset
|
777 |
|
60758 | 778 |
text \<open>strict, in both arguments\<close> |
71585 | 779 |
lemma add_less_mono: |
780 |
fixes i j k l :: nat |
|
781 |
assumes "i < j" "k < l" shows "i + k < j + l" |
|
782 |
proof - |
|
783 |
have "i + k < j + k" |
|
784 |
by (simp add: add_less_mono1 assms) |
|
785 |
also have "... < j + l" |
|
786 |
using \<open>i < j\<close> by (induction j) (auto simp: assms) |
|
787 |
finally show ?thesis . |
|
788 |
qed |
|
14341
a09441bd4f1e
Ring_and_Field now requires axiom add_left_imp_eq for semirings.
paulson
parents:
14331
diff
changeset
|
789 |
|
63110 | 790 |
lemma less_imp_Suc_add: "m < n \<Longrightarrow> \<exists>k. n = Suc (m + k)" |
63588 | 791 |
proof (induct n) |
792 |
case 0 |
|
793 |
then show ?case by simp |
|
794 |
next |
|
795 |
case Suc |
|
796 |
then show ?case |
|
797 |
by (simp add: order_le_less) |
|
798 |
(blast elim!: less_SucE intro!: Nat.add_0_right [symmetric] add_Suc_right [symmetric]) |
|
799 |
qed |
|
800 |
||
801 |
lemma le_Suc_ex: "k \<le> l \<Longrightarrow> (\<exists>n. l = k + n)" |
|
802 |
for k l :: nat |
|
56194 | 803 |
by (auto simp: less_Suc_eq_le[symmetric] dest: less_imp_Suc_add) |
804 |
||
71425
f2da99316b86
more rules for natural deduction from inequalities
haftmann
parents:
71407
diff
changeset
|
805 |
lemma less_natE: |
f2da99316b86
more rules for natural deduction from inequalities
haftmann
parents:
71407
diff
changeset
|
806 |
assumes \<open>m < n\<close> |
f2da99316b86
more rules for natural deduction from inequalities
haftmann
parents:
71407
diff
changeset
|
807 |
obtains q where \<open>n = Suc (m + q)\<close> |
f2da99316b86
more rules for natural deduction from inequalities
haftmann
parents:
71407
diff
changeset
|
808 |
using assms by (auto dest: less_imp_Suc_add intro: that) |
f2da99316b86
more rules for natural deduction from inequalities
haftmann
parents:
71407
diff
changeset
|
809 |
|
61799 | 810 |
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
|
811 |
lemma mult_less_mono2: |
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
812 |
fixes i j :: nat |
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
813 |
assumes "i < j" and "0 < k" |
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
814 |
shows "k * i < k * j" |
63110 | 815 |
using \<open>0 < k\<close> |
816 |
proof (induct k) |
|
817 |
case 0 |
|
818 |
then show ?case by simp |
|
62481
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
819 |
next |
63110 | 820 |
case (Suc k) |
821 |
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
|
822 |
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
|
823 |
qed |
14341
a09441bd4f1e
Ring_and_Field now requires axiom add_left_imp_eq for semirings.
paulson
parents:
14331
diff
changeset
|
824 |
|
60758 | 825 |
text \<open>Addition is the inverse of subtraction: |
69593 | 826 |
if \<^term>\<open>n \<le> m\<close> then \<^term>\<open>n + (m - n) = m\<close>.\<close> |
63588 | 827 |
lemma add_diff_inverse_nat: "\<not> m < n \<Longrightarrow> n + (m - n) = m" |
828 |
for m n :: nat |
|
63110 | 829 |
by (induct m n rule: diff_induct) simp_all |
830 |
||
63588 | 831 |
lemma nat_le_iff_add: "m \<le> n \<longleftrightarrow> (\<exists>k. n = m + k)" |
832 |
for m n :: nat |
|
63110 | 833 |
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
|
834 |
|
63588 | 835 |
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
|
836 |
|
35028
108662d50512
more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
haftmann
parents:
34208
diff
changeset
|
837 |
instance nat :: linordered_semidom |
14341
a09441bd4f1e
Ring_and_Field now requires axiom add_left_imp_eq for semirings.
paulson
parents:
14331
diff
changeset
|
838 |
proof |
63110 | 839 |
fix m n q :: nat |
63588 | 840 |
show "0 < (1::nat)" |
841 |
by simp |
|
842 |
show "m \<le> n \<Longrightarrow> q + m \<le> q + n" |
|
843 |
by simp |
|
844 |
show "m < n \<Longrightarrow> 0 < q \<Longrightarrow> q * m < q * n" |
|
845 |
by (simp add: mult_less_mono2) |
|
846 |
show "m \<noteq> 0 \<Longrightarrow> n \<noteq> 0 \<Longrightarrow> m * n \<noteq> 0" |
|
847 |
by simp |
|
63110 | 848 |
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
|
849 |
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
|
850 |
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
|
851 |
|
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
|
852 |
instance nat :: dioid |
63110 | 853 |
by standard (rule nat_le_iff_add) |
63588 | 854 |
|
63145 | 855 |
declare le0[simp del] \<comment> \<open>This is now @{thm zero_le}\<close> |
856 |
declare le_0_eq[simp del] \<comment> \<open>This is now @{thm le_zero_eq}\<close> |
|
857 |
declare not_less0[simp del] \<comment> \<open>This is now @{thm not_less_zero}\<close> |
|
858 |
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
|
859 |
|
63110 | 860 |
instance nat :: ordered_cancel_comm_monoid_add .. |
861 |
instance nat :: ordered_cancel_comm_monoid_diff .. |
|
862 |
||
44817 | 863 |
|
69593 | 864 |
subsubsection \<open>\<^term>\<open>min\<close> and \<^term>\<open>max\<close>\<close> |
44817 | 865 |
|
71851 | 866 |
global_interpretation bot_nat_0: ordering_top \<open>(\<ge>)\<close> \<open>(>)\<close> \<open>0::nat\<close> |
867 |
by standard simp |
|
868 |
||
869 |
global_interpretation max_nat: semilattice_neutr_order max \<open>0::nat\<close> \<open>(\<ge>)\<close> \<open>(>)\<close> |
|
870 |
by standard (simp add: max_def) |
|
871 |
||
44817 | 872 |
lemma mono_Suc: "mono Suc" |
63110 | 873 |
by (rule monoI) simp |
874 |
||
63588 | 875 |
lemma min_0L [simp]: "min 0 n = 0" |
876 |
for n :: nat |
|
63110 | 877 |
by (rule min_absorb1) simp |
878 |
||
63588 | 879 |
lemma min_0R [simp]: "min n 0 = 0" |
880 |
for n :: nat |
|
63110 | 881 |
by (rule min_absorb2) simp |
44817 | 882 |
|
883 |
lemma min_Suc_Suc [simp]: "min (Suc m) (Suc n) = Suc (min m n)" |
|
63110 | 884 |
by (simp add: mono_Suc min_of_mono) |
885 |
||
886 |
lemma min_Suc1: "min (Suc n) m = (case m of 0 \<Rightarrow> 0 | Suc m' \<Rightarrow> Suc(min n m'))" |
|
887 |
by (simp split: nat.split) |
|
888 |
||
889 |
lemma min_Suc2: "min m (Suc n) = (case m of 0 \<Rightarrow> 0 | Suc m' \<Rightarrow> Suc(min m' n))" |
|
890 |
by (simp split: nat.split) |
|
891 |
||
63588 | 892 |
lemma max_0L [simp]: "max 0 n = n" |
893 |
for n :: nat |
|
71851 | 894 |
by (fact max_nat.left_neutral) |
63110 | 895 |
|
63588 | 896 |
lemma max_0R [simp]: "max n 0 = n" |
897 |
for n :: nat |
|
71851 | 898 |
by (fact max_nat.right_neutral) |
63110 | 899 |
|
900 |
lemma max_Suc_Suc [simp]: "max (Suc m) (Suc n) = Suc (max m n)" |
|
901 |
by (simp add: mono_Suc max_of_mono) |
|
902 |
||
903 |
lemma max_Suc1: "max (Suc n) m = (case m of 0 \<Rightarrow> Suc n | Suc m' \<Rightarrow> Suc (max n m'))" |
|
904 |
by (simp split: nat.split) |
|
905 |
||
906 |
lemma max_Suc2: "max m (Suc n) = (case m of 0 \<Rightarrow> Suc n | Suc m' \<Rightarrow> Suc (max m' n))" |
|
907 |
by (simp split: nat.split) |
|
908 |
||
63588 | 909 |
lemma nat_mult_min_left: "min m n * q = min (m * q) (n * q)" |
910 |
for m n q :: nat |
|
63110 | 911 |
by (simp add: min_def not_le) |
912 |
(auto dest: mult_right_le_imp_le mult_right_less_imp_less le_less_trans) |
|
913 |
||
63588 | 914 |
lemma nat_mult_min_right: "m * min n q = min (m * n) (m * q)" |
915 |
for m n q :: nat |
|
63110 | 916 |
by (simp add: min_def not_le) |
917 |
(auto dest: mult_left_le_imp_le mult_left_less_imp_less le_less_trans) |
|
918 |
||
63588 | 919 |
lemma nat_add_max_left: "max m n + q = max (m + q) (n + q)" |
920 |
for m n q :: nat |
|
44817 | 921 |
by (simp add: max_def) |
922 |
||
63588 | 923 |
lemma nat_add_max_right: "m + max n q = max (m + n) (m + q)" |
924 |
for m n q :: nat |
|
44817 | 925 |
by (simp add: max_def) |
926 |
||
63588 | 927 |
lemma nat_mult_max_left: "max m n * q = max (m * q) (n * q)" |
928 |
for m n q :: nat |
|
63110 | 929 |
by (simp add: max_def not_le) |
930 |
(auto dest: mult_right_le_imp_le mult_right_less_imp_less le_less_trans) |
|
931 |
||
63588 | 932 |
lemma nat_mult_max_right: "m * max n q = max (m * n) (m * q)" |
933 |
for m n q :: nat |
|
63110 | 934 |
by (simp add: max_def not_le) |
935 |
(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
|
936 |
|
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14266
diff
changeset
|
937 |
|
69593 | 938 |
subsubsection \<open>Additional theorems about \<^term>\<open>(\<le>)\<close>\<close> |
60758 | 939 |
|
940 |
text \<open>Complete induction, aka course-of-values induction\<close> |
|
26748
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
26335
diff
changeset
|
941 |
|
63110 | 942 |
instance nat :: wellorder |
943 |
proof |
|
27823 | 944 |
fix P and n :: nat |
63110 | 945 |
assume step: "(\<And>m. m < n \<Longrightarrow> P m) \<Longrightarrow> P n" for n :: nat |
27823 | 946 |
have "\<And>q. q \<le> n \<Longrightarrow> P q" |
947 |
proof (induct n) |
|
948 |
case (0 n) |
|
26748
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
26335
diff
changeset
|
949 |
have "P 0" by (rule step) auto |
63588 | 950 |
with 0 show ?case by auto |
26748
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
26335
diff
changeset
|
951 |
next |
27823 | 952 |
case (Suc m n) |
63588 | 953 |
then have "n \<le> m \<or> n = Suc m" |
954 |
by (simp add: le_Suc_eq) |
|
63110 | 955 |
then show ?case |
26748
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
26335
diff
changeset
|
956 |
proof |
63110 | 957 |
assume "n \<le> m" |
958 |
then show "P n" by (rule Suc(1)) |
|
26748
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
26335
diff
changeset
|
959 |
next |
27823 | 960 |
assume n: "n = Suc m" |
63110 | 961 |
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
|
962 |
qed |
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
26335
diff
changeset
|
963 |
qed |
27823 | 964 |
then show "P n" by auto |
26748
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
26335
diff
changeset
|
965 |
qed |
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
26335
diff
changeset
|
966 |
|
57015 | 967 |
|
63588 | 968 |
lemma Least_eq_0[simp]: "P 0 \<Longrightarrow> Least P = 0" |
969 |
for P :: "nat \<Rightarrow> bool" |
|
63110 | 970 |
by (rule Least_equality[OF _ le0]) |
971 |
||
71585 | 972 |
lemma Least_Suc: |
973 |
assumes "P n" "\<not> P 0" |
|
974 |
shows "(LEAST n. P n) = Suc (LEAST m. P (Suc m))" |
|
975 |
proof (cases n) |
|
976 |
case (Suc m) |
|
977 |
show ?thesis |
|
978 |
proof (rule antisym) |
|
979 |
show "(LEAST x. P x) \<le> Suc (LEAST x. P (Suc x))" |
|
980 |
using assms Suc by (force intro: LeastI Least_le) |
|
981 |
have \<section>: "P (LEAST x. P x)" |
|
982 |
by (blast intro: LeastI assms) |
|
983 |
show "Suc (LEAST m. P (Suc m)) \<le> (LEAST n. P n)" |
|
984 |
proof (cases "(LEAST n. P n)") |
|
985 |
case 0 |
|
986 |
then show ?thesis |
|
987 |
using \<section> by (simp add: assms) |
|
988 |
next |
|
989 |
case Suc |
|
990 |
with \<section> show ?thesis |
|
991 |
by (auto simp: Least_le) |
|
992 |
qed |
|
993 |
qed |
|
994 |
qed (use assms in auto) |
|
27823 | 995 |
|
63110 | 996 |
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 | 997 |
by (erule (1) Least_Suc [THEN ssubst]) simp |
998 |
||
71585 | 999 |
lemma ex_least_nat_le: |
1000 |
fixes P :: "nat \<Rightarrow> bool" |
|
1001 |
assumes "P n" "\<not> P 0" |
|
1002 |
shows "\<exists>k\<le>n. (\<forall>i<k. \<not> P i) \<and> P k" |
|
1003 |
proof (cases n) |
|
1004 |
case (Suc m) |
|
1005 |
with assms show ?thesis |
|
1006 |
by (blast intro: Least_le LeastI_ex dest: not_less_Least) |
|
1007 |
qed (use assms in auto) |
|
1008 |
||
1009 |
lemma ex_least_nat_less: |
|
1010 |
fixes P :: "nat \<Rightarrow> bool" |
|
1011 |
assumes "P n" "\<not> P 0" |
|
1012 |
shows "\<exists>k<n. (\<forall>i\<le>k. \<not> P i) \<and> P (Suc k)" |
|
1013 |
proof (cases n) |
|
1014 |
case (Suc m) |
|
1015 |
then obtain k where k: "k \<le> n" "\<forall>i<k. \<not> P i" "P k" |
|
1016 |
using ex_least_nat_le [OF assms] by blast |
|
1017 |
show ?thesis |
|
1018 |
by (cases k) (use assms k less_eq_Suc_le in auto) |
|
1019 |
qed (use assms in auto) |
|
1020 |
||
27823 | 1021 |
|
26748
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
26335
diff
changeset
|
1022 |
lemma nat_less_induct: |
63110 | 1023 |
fixes P :: "nat \<Rightarrow> bool" |
1024 |
assumes "\<And>n. \<forall>m. m < n \<longrightarrow> P m \<Longrightarrow> P n" |
|
1025 |
shows "P n" |
|
26748
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
26335
diff
changeset
|
1026 |
using assms less_induct by blast |
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
26335
diff
changeset
|
1027 |
|
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
26335
diff
changeset
|
1028 |
lemma measure_induct_rule [case_names less]: |
64876 | 1029 |
fixes f :: "'a \<Rightarrow> 'b::wellorder" |
26748
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
26335
diff
changeset
|
1030 |
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
|
1031 |
shows "P a" |
63110 | 1032 |
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
|
1033 |
|
60758 | 1034 |
text \<open>old style induction rules:\<close> |
26748
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
26335
diff
changeset
|
1035 |
lemma measure_induct: |
64876 | 1036 |
fixes f :: "'a \<Rightarrow> 'b::wellorder" |
26748
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
26335
diff
changeset
|
1037 |
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
|
1038 |
by (rule measure_induct_rule [of f P a]) iprover |
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
26335
diff
changeset
|
1039 |
|
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
26335
diff
changeset
|
1040 |
lemma full_nat_induct: |
63110 | 1041 |
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
|
1042 |
shows "P n" |
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
26335
diff
changeset
|
1043 |
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
|
1044 |
|
63110 | 1045 |
text\<open>An induction rule for establishing binary relations\<close> |
62683 | 1046 |
lemma less_Suc_induct [consumes 1]: |
63110 | 1047 |
assumes less: "i < j" |
1048 |
and step: "\<And>i. P i (Suc i)" |
|
1049 |
and trans: "\<And>i j k. i < j \<Longrightarrow> j < k \<Longrightarrow> P i j \<Longrightarrow> P j k \<Longrightarrow> P i k" |
|
19870 | 1050 |
shows "P i j" |
1051 |
proof - |
|
63110 | 1052 |
from less obtain k where j: "j = Suc (i + k)" |
1053 |
by (auto dest: less_imp_Suc_add) |
|
22718 | 1054 |
have "P i (Suc (i + k))" |
19870 | 1055 |
proof (induct k) |
22718 | 1056 |
case 0 |
1057 |
show ?case by (simp add: step) |
|
19870 | 1058 |
next |
1059 |
case (Suc k) |
|
31714 | 1060 |
have "0 + i < Suc k + i" by (rule add_less_mono1) simp |
63110 | 1061 |
then have "i < Suc (i + k)" by (simp add: add.commute) |
31714 | 1062 |
from trans[OF this lessI Suc step] |
1063 |
show ?case by simp |
|
19870 | 1064 |
qed |
63110 | 1065 |
then show "P i j" by (simp add: j) |
19870 | 1066 |
qed |
1067 |
||
63111 | 1068 |
text \<open> |
1069 |
The method of infinite descent, frequently used in number theory. |
|
1070 |
Provided by Roelof Oosterhuis. |
|
1071 |
\<open>P n\<close> is true for all natural numbers if |
|
1072 |
\<^item> case ``0'': given \<open>n = 0\<close> prove \<open>P n\<close> |
|
1073 |
\<^item> case ``smaller'': given \<open>n > 0\<close> and \<open>\<not> P n\<close> prove there exists |
|
1074 |
a smaller natural number \<open>m\<close> such that \<open>\<not> P m\<close>. |
|
1075 |
\<close> |
|
1076 |
||
63110 | 1077 |
lemma infinite_descent: "(\<And>n. \<not> P n \<Longrightarrow> \<exists>m<n. \<not> P m) \<Longrightarrow> P n" for P :: "nat \<Rightarrow> bool" |
63111 | 1078 |
\<comment> \<open>compact version without explicit base case\<close> |
63110 | 1079 |
by (induct n rule: less_induct) auto |
26748
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
26335
diff
changeset
|
1080 |
|
63111 | 1081 |
lemma infinite_descent0 [case_names 0 smaller]: |
63110 | 1082 |
fixes P :: "nat \<Rightarrow> bool" |
63111 | 1083 |
assumes "P 0" |
1084 |
and "\<And>n. n > 0 \<Longrightarrow> \<not> P n \<Longrightarrow> \<exists>m. m < n \<and> \<not> P m" |
|
63110 | 1085 |
shows "P n" |
71585 | 1086 |
proof (rule infinite_descent) |
1087 |
show "\<And>n. \<not> P n \<Longrightarrow> \<exists>m<n. \<not> P m" |
|
1088 |
using assms by (case_tac "n > 0") auto |
|
1089 |
qed |
|
26748
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
26335
diff
changeset
|
1090 |
|
60758 | 1091 |
text \<open> |
63111 | 1092 |
Infinite descent using a mapping to \<open>nat\<close>: |
1093 |
\<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 |
|
1094 |
\<^item> case ``0'': given \<open>V x = 0\<close> prove \<open>P x\<close> |
|
1095 |
\<^item> ``smaller'': given \<open>V x > 0\<close> and \<open>\<not> P x\<close> prove |
|
1096 |
there exists a \<open>y \<in> D\<close> such that \<open>V y < V x\<close> and \<open>\<not> P y\<close>. |
|
1097 |
\<close> |
|
26748
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
26335
diff
changeset
|
1098 |
corollary infinite_descent0_measure [case_names 0 smaller]: |
63110 | 1099 |
fixes V :: "'a \<Rightarrow> nat" |
1100 |
assumes 1: "\<And>x. V x = 0 \<Longrightarrow> P x" |
|
1101 |
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
|
1102 |
shows "P x" |
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
26335
diff
changeset
|
1103 |
proof - |
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
26335
diff
changeset
|
1104 |
obtain n where "n = V x" by auto |
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
26335
diff
changeset
|
1105 |
moreover have "\<And>x. V x = n \<Longrightarrow> P x" |
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
26335
diff
changeset
|
1106 |
proof (induct n rule: infinite_descent0) |
63110 | 1107 |
case 0 |
1108 |
with 1 show "P x" by auto |
|
1109 |
next |
|
26748
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
26335
diff
changeset
|
1110 |
case (smaller n) |
63110 | 1111 |
then obtain x where *: "V x = n " and "V x > 0 \<and> \<not> P x" by auto |
1112 |
with 2 obtain y where "V y < V x \<and> \<not> P y" by auto |
|
63111 | 1113 |
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
|
1114 |
then show ?case by auto |
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
26335
diff
changeset
|
1115 |
qed |
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
26335
diff
changeset
|
1116 |
ultimately show "P x" by auto |
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
26335
diff
changeset
|
1117 |
qed |
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
26335
diff
changeset
|
1118 |
|
63588 | 1119 |
text \<open>Again, without explicit base case:\<close> |
26748
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
26335
diff
changeset
|
1120 |
lemma infinite_descent_measure: |
63110 | 1121 |
fixes V :: "'a \<Rightarrow> nat" |
1122 |
assumes "\<And>x. \<not> P x \<Longrightarrow> \<exists>y. V y < V x \<and> \<not> P y" |
|
1123 |
shows "P x" |
|
26748
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
26335
diff
changeset
|
1124 |
proof - |
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
26335
diff
changeset
|
1125 |
from assms obtain n where "n = V x" by auto |
63110 | 1126 |
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
|
1127 |
proof (induct n rule: infinite_descent, auto) |
63111 | 1128 |
show "\<exists>m < V x. \<exists>y. V y = m \<and> \<not> P y" if "\<not> P x" for x |
1129 |
using assms and that by auto |
|
26748
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
26335
diff
changeset
|
1130 |
qed |
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
26335
diff
changeset
|
1131 |
ultimately show "P x" by auto |
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
26335
diff
changeset
|
1132 |
qed |
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents:
26335
diff
changeset
|
1133 |
|
63111 | 1134 |
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
|
1135 |
lemma less_mono_imp_le_mono: |
63110 | 1136 |
fixes f :: "nat \<Rightarrow> nat" |
1137 |
and i j :: nat |
|
1138 |
assumes "\<And>i j::nat. i < j \<Longrightarrow> f i < f j" |
|
1139 |
and "i \<le> j" |
|
1140 |
shows "f i \<le> f j" |
|
1141 |
using assms by (auto simp add: order_le_less) |
|
24438 | 1142 |
|
14267
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14266
diff
changeset
|
1143 |
|
60758 | 1144 |
text \<open>non-strict, in 1st argument\<close> |
63588 | 1145 |
lemma add_le_mono1: "i \<le> j \<Longrightarrow> i + k \<le> j + k" |
1146 |
for i j k :: nat |
|
63110 | 1147 |
by (rule add_right_mono) |
14267
b963e9cee2a0
More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents:
14266
diff
changeset
|
1148 |
|
60758 | 1149 |
text \<open>non-strict, in both arguments\<close> |
63588 | 1150 |
lemma add_le_mono: "i \<le> j \<Longrightarrow> k \<le> l \<Longrightarrow> i + k \<le> j + l" |
1151 |
for i j k l :: nat |
|
63110 | 1152 |
by (rule add_mono) |
1153 |
||
63588 | 1154 |
lemma le_add2: "n \<le> m + n" |
1155 |
for m n :: nat |
|
62608 | 1156 |
by simp |
13449 | 1157 |
|
63588 | 1158 |
lemma le_add1: "n \<le> n + m" |
1159 |
for m n :: nat |
|
62608 | 1160 |
by simp |
13449 | 1161 |
|
1162 |
lemma less_add_Suc1: "i < Suc (i + m)" |
|
63110 | 1163 |
by (rule le_less_trans, rule le_add1, rule lessI) |
13449 | 1164 |
|
1165 |
lemma less_add_Suc2: "i < Suc (m + i)" |
|
63110 | 1166 |
by (rule le_less_trans, rule le_add2, rule lessI) |
1167 |
||
1168 |
lemma less_iff_Suc_add: "m < n \<longleftrightarrow> (\<exists>k. n = Suc (m + k))" |
|
1169 |
by (iprover intro!: less_add_Suc1 less_imp_Suc_add) |
|
1170 |
||
63588 | 1171 |
lemma trans_le_add1: "i \<le> j \<Longrightarrow> i \<le> j + m" |
1172 |
for i j m :: nat |
|
63110 | 1173 |
by (rule le_trans, assumption, rule le_add1) |
1174 |
||
63588 | 1175 |
lemma trans_le_add2: "i \<le> j \<Longrightarrow> i \<le> m + j" |
1176 |
for i j m :: nat |
|
63110 | 1177 |
by (rule le_trans, assumption, rule le_add2) |
1178 |
||
63588 | 1179 |
lemma trans_less_add1: "i < j \<Longrightarrow> i < j + m" |
1180 |
for i j m :: nat |
|
63110 | 1181 |
by (rule less_le_trans, assumption, rule le_add1) |
1182 |
||
63588 | 1183 |
lemma trans_less_add2: "i < j \<Longrightarrow> i < m + j" |
1184 |
for i j m :: nat |
|
63110 | 1185 |
by (rule less_le_trans, assumption, rule le_add2) |
1186 |
||
63588 | 1187 |
lemma add_lessD1: "i + j < k \<Longrightarrow> i < k" |
1188 |
for i j k :: nat |
|
63110 | 1189 |
by (rule le_less_trans [of _ "i+j"]) (simp_all add: le_add1) |
1190 |
||
63588 | 1191 |
lemma not_add_less1 [iff]: "\<not> i + j < i" |
1192 |
for i j :: nat |
|
71585 | 1193 |
by simp |
63110 | 1194 |
|
63588 | 1195 |
lemma not_add_less2 [iff]: "\<not> j + i < i" |
1196 |
for i j :: nat |
|
71585 | 1197 |
by simp |
63110 | 1198 |
|
63588 | 1199 |
lemma add_leD1: "m + k \<le> n \<Longrightarrow> m \<le> n" |
1200 |
for k m n :: nat |
|
1201 |
by (rule order_trans [of _ "m + k"]) (simp_all add: le_add1) |
|
1202 |
||
1203 |
lemma add_leD2: "m + k \<le> n \<Longrightarrow> k \<le> n" |
|
1204 |
for k m n :: nat |
|
71585 | 1205 |
by (force simp add: add.commute dest: add_leD1) |
63110 | 1206 |
|
63588 | 1207 |
lemma add_leE: "m + k \<le> n \<Longrightarrow> (m \<le> n \<Longrightarrow> k \<le> n \<Longrightarrow> R) \<Longrightarrow> R" |
1208 |
for k m n :: nat |
|
63110 | 1209 |
by (blast dest: add_leD1 add_leD2) |
1210 |
||
1211 |
text \<open>needs \<open>\<And>k\<close> for \<open>ac_simps\<close> to work\<close> |
|
63588 | 1212 |
lemma less_add_eq_less: "\<And>k. k < l \<Longrightarrow> m + l = k + n \<Longrightarrow> m < n" |
1213 |
for l m n :: nat |
|
63110 | 1214 |
by (force simp del: add_Suc_right simp add: less_iff_Suc_add add_Suc_right [symmetric] ac_simps) |
13449 | 1215 |
|
1216 |
||
60758 | 1217 |
subsubsection \<open>More results about difference\<close> |
13449 | 1218 |
|
63110 | 1219 |
lemma Suc_diff_le: "n \<le> m \<Longrightarrow> Suc m - n = Suc (m - n)" |
1220 |
by (induct m n rule: diff_induct) simp_all |
|
13449 | 1221 |
|
1222 |
lemma diff_less_Suc: "m - n < Suc m" |
|
71585 | 1223 |
by (induct m n rule: diff_induct) (auto simp: less_Suc_eq) |
63588 | 1224 |
|
1225 |
lemma diff_le_self [simp]: "m - n \<le> m" |
|
1226 |
for m n :: nat |
|
63110 | 1227 |
by (induct m n rule: diff_induct) (simp_all add: le_SucI) |
1228 |
||
63588 | 1229 |
lemma less_imp_diff_less: "j < k \<Longrightarrow> j - n < k" |
1230 |
for j k n :: nat |
|
63110 | 1231 |
by (rule le_less_trans, rule diff_le_self) |
1232 |
||
1233 |
lemma diff_Suc_less [simp]: "0 < n \<Longrightarrow> n - Suc i < n" |
|
1234 |
by (cases n) (auto simp add: le_simps) |
|
1235 |
||
63588 | 1236 |
lemma diff_add_assoc: "k \<le> j \<Longrightarrow> (i + j) - k = i + (j - k)" |
1237 |
for i j k :: nat |
|
71404
f2b783abfbe7
A few lemmas connected with orderings
paulson <lp15@cam.ac.uk>
parents:
70490
diff
changeset
|
1238 |
by (fact ordered_cancel_comm_monoid_diff_class.diff_add_assoc) |
63110 | 1239 |
|
63588 | 1240 |
lemma add_diff_assoc [simp]: "k \<le> j \<Longrightarrow> i + (j - k) = i + j - k" |
1241 |
for i j k :: nat |
|
71404
f2b783abfbe7
A few lemmas connected with orderings
paulson <lp15@cam.ac.uk>
parents:
70490
diff
changeset
|
1242 |
by (fact ordered_cancel_comm_monoid_diff_class.add_diff_assoc) |
62481
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
1243 |
|
63588 | 1244 |
lemma diff_add_assoc2: "k \<le> j \<Longrightarrow> (j + i) - k = (j - k) + i" |
1245 |
for i j k :: nat |
|
71404
f2b783abfbe7
A few lemmas connected with orderings
paulson <lp15@cam.ac.uk>
parents:
70490
diff
changeset
|
1246 |
by (fact ordered_cancel_comm_monoid_diff_class.diff_add_assoc2) |
62481
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
1247 |
|
63588 | 1248 |
lemma add_diff_assoc2 [simp]: "k \<le> j \<Longrightarrow> j - k + i = j + i - k" |
1249 |
for i j k :: nat |
|
71404
f2b783abfbe7
A few lemmas connected with orderings
paulson <lp15@cam.ac.uk>
parents:
70490
diff
changeset
|
1250 |
by (fact ordered_cancel_comm_monoid_diff_class.add_diff_assoc2) |
13449 | 1251 |
|
63588 | 1252 |
lemma le_imp_diff_is_add: "i \<le> j \<Longrightarrow> (j - i = k) = (j = k + i)" |
1253 |
for i j k :: nat |
|
63110 | 1254 |
by auto |
1255 |
||
63588 | 1256 |
lemma diff_is_0_eq [simp]: "m - n = 0 \<longleftrightarrow> m \<le> n" |
1257 |
for m n :: nat |
|
63110 | 1258 |
by (induct m n rule: diff_induct) simp_all |
1259 |
||
63588 | 1260 |
lemma diff_is_0_eq' [simp]: "m \<le> n \<Longrightarrow> m - n = 0" |
1261 |
for m n :: nat |
|
63110 | 1262 |
by (rule iffD2, rule diff_is_0_eq) |
1263 |
||
63588 | 1264 |
lemma zero_less_diff [simp]: "0 < n - m \<longleftrightarrow> m < n" |
1265 |
for m n :: nat |
|
63110 | 1266 |
by (induct m n rule: diff_induct) simp_all |
13449 | 1267 |
|
22718 | 1268 |
lemma less_imp_add_positive: |
1269 |
assumes "i < j" |
|
63110 | 1270 |
shows "\<exists>k::nat. 0 < k \<and> i + k = j" |
22718 | 1271 |
proof |
63110 | 1272 |
from assms show "0 < j - i \<and> i + (j - i) = j" |
23476 | 1273 |
by (simp add: order_less_imp_le) |
22718 | 1274 |
qed |
9436
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
7702
diff
changeset
|
1275 |
|
60758 | 1276 |
text \<open>a nice rewrite for bounded subtraction\<close> |
63588 | 1277 |
lemma nat_minus_add_max: "n - m + m = max n m" |
1278 |
for m n :: nat |
|
1279 |
by (simp add: max_def not_le order_less_imp_le) |
|
13449 | 1280 |
|
63110 | 1281 |
lemma nat_diff_split: "P (a - b) \<longleftrightarrow> (a < b \<longrightarrow> P 0) \<and> (\<forall>d. a = b + d \<longrightarrow> P d)" |
1282 |
for a b :: nat |
|
63588 | 1283 |
\<comment> \<open>elimination of \<open>-\<close> on \<open>nat\<close>\<close> |
1284 |
by (cases "a < b") (auto simp add: not_less le_less dest!: add_eq_self_zero [OF sym]) |
|
13449 | 1285 |
|
63110 | 1286 |
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))" |
1287 |
for a b :: nat |
|
63588 | 1288 |
\<comment> \<open>elimination of \<open>-\<close> on \<open>nat\<close> in assumptions\<close> |
62365 | 1289 |
by (auto split: nat_diff_split) |
13449 | 1290 |
|
63110 | 1291 |
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
|
1292 |
by simp |
30a1692557b0
removed Nat_Numeral.thy, moving all theorems elsewhere
huffman
parents:
47208
diff
changeset
|
1293 |
|
63110 | 1294 |
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
|
1295 |
unfolding One_nat_def by (cases m) simp_all |
30a1692557b0
removed Nat_Numeral.thy, moving all theorems elsewhere
huffman
parents:
47208
diff
changeset
|
1296 |
|
63588 | 1297 |
lemma mult_eq_if: "m * n = (if m = 0 then 0 else n + ((m - 1) * n))" |
1298 |
for m n :: nat |
|
1299 |
by (cases m) simp_all |
|
47255
30a1692557b0
removed Nat_Numeral.thy, moving all theorems elsewhere
huffman
parents:
47208
diff
changeset
|
1300 |
|
63110 | 1301 |
lemma Suc_diff_eq_diff_pred: "0 < n \<Longrightarrow> Suc m - n = m - (n - 1)" |
63588 | 1302 |
by (cases n) simp_all |
47255
30a1692557b0
removed Nat_Numeral.thy, moving all theorems elsewhere
huffman
parents:
47208
diff
changeset
|
1303 |
|
30a1692557b0
removed Nat_Numeral.thy, moving all theorems elsewhere
huffman
parents:
47208
diff
changeset
|
1304 |
lemma diff_Suc_eq_diff_pred: "m - Suc n = (m - 1) - n" |
63588 | 1305 |
by (cases m) simp_all |
1306 |
||
1307 |
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
|
1308 |
by (fact Let_def) |
30a1692557b0
removed Nat_Numeral.thy, moving all theorems elsewhere
huffman
parents:
47208
diff
changeset
|
1309 |
|
13449 | 1310 |
|
60758 | 1311 |
subsubsection \<open>Monotonicity of multiplication\<close> |
13449 | 1312 |
|
63588 | 1313 |
lemma mult_le_mono1: "i \<le> j \<Longrightarrow> i * k \<le> j * k" |
1314 |
for i j k :: nat |
|
63110 | 1315 |
by (simp add: mult_right_mono) |
1316 |
||
63588 | 1317 |
lemma mult_le_mono2: "i \<le> j \<Longrightarrow> k * i \<le> k * j" |
1318 |
for i j k :: nat |
|
63110 | 1319 |
by (simp add: mult_left_mono) |
13449 | 1320 |
|
61799 | 1321 |
text \<open>\<open>\<le>\<close> monotonicity, BOTH arguments\<close> |
63588 | 1322 |
lemma mult_le_mono: "i \<le> j \<Longrightarrow> k \<le> l \<Longrightarrow> i * k \<le> j * l" |
1323 |
for i j k l :: nat |
|
63110 | 1324 |
by (simp add: mult_mono) |
1325 |
||
63588 | 1326 |
lemma mult_less_mono1: "i < j \<Longrightarrow> 0 < k \<Longrightarrow> i * k < j * k" |
1327 |
for i j k :: nat |
|
63110 | 1328 |
by (simp add: mult_strict_right_mono) |
13449 | 1329 |
|
63588 | 1330 |
text \<open>Differs from the standard \<open>zero_less_mult_iff\<close> in that there are no negative numbers.\<close> |
1331 |
lemma nat_0_less_mult_iff [simp]: "0 < m * n \<longleftrightarrow> 0 < m \<and> 0 < n" |
|
1332 |
for m n :: nat |
|
1333 |
proof (induct m) |
|
1334 |
case 0 |
|
1335 |
then show ?case by simp |
|
1336 |
next |
|
1337 |
case (Suc m) |
|
1338 |
then show ?case by (cases n) simp_all |
|
1339 |
qed |
|
13449 | 1340 |
|
63110 | 1341 |
lemma one_le_mult_iff [simp]: "Suc 0 \<le> m * n \<longleftrightarrow> Suc 0 \<le> m \<and> Suc 0 \<le> n" |
63588 | 1342 |
proof (induct m) |
1343 |
case 0 |
|
1344 |
then show ?case by simp |
|
1345 |
next |
|
1346 |
case (Suc m) |
|
1347 |
then show ?case by (cases n) simp_all |
|
1348 |
qed |
|
1349 |
||
1350 |
lemma mult_less_cancel2 [simp]: "m * k < n * k \<longleftrightarrow> 0 < k \<and> m < n" |
|
1351 |
for k m n :: nat |
|
71585 | 1352 |
proof (intro iffI conjI) |
1353 |
assume m: "m * k < n * k" |
|
1354 |
then show "0 < k" |
|
1355 |
by (cases k) auto |
|
1356 |
show "m < n" |
|
1357 |
proof (cases k) |
|
1358 |
case 0 |
|
1359 |
then show ?thesis |
|
1360 |
using m by auto |
|
1361 |
next |
|
1362 |
case (Suc k') |
|
1363 |
then show ?thesis |
|
1364 |
using m |
|
1365 |
by (simp flip: linorder_not_le) (blast intro: add_mono mult_le_mono1) |
|
1366 |
qed |
|
1367 |
next |
|
1368 |
assume "0 < k \<and> m < n" |
|
1369 |
then show "m * k < n * k" |
|
1370 |
by (blast intro: mult_less_mono1) |
|
1371 |
qed |
|
13449 | 1372 |
|
63588 | 1373 |
lemma mult_less_cancel1 [simp]: "k * m < k * n \<longleftrightarrow> 0 < k \<and> m < n" |
1374 |
for k m n :: nat |
|
63110 | 1375 |
by (simp add: mult.commute [of k]) |
1376 |
||
63588 | 1377 |
lemma mult_le_cancel1 [simp]: "k * m \<le> k * n \<longleftrightarrow> (0 < k \<longrightarrow> m \<le> n)" |
1378 |
for k m n :: nat |
|
63110 | 1379 |
by (simp add: linorder_not_less [symmetric], auto) |
1380 |
||
63588 | 1381 |
lemma mult_le_cancel2 [simp]: "m * k \<le> n * k \<longleftrightarrow> (0 < k \<longrightarrow> m \<le> n)" |
1382 |
for k m n :: nat |
|
63110 | 1383 |
by (simp add: linorder_not_less [symmetric], auto) |
1384 |
||
1385 |
lemma Suc_mult_less_cancel1: "Suc k * m < Suc k * n \<longleftrightarrow> m < n" |
|
1386 |
by (subst mult_less_cancel1) simp |
|
1387 |
||
1388 |
lemma Suc_mult_le_cancel1: "Suc k * m \<le> Suc k * n \<longleftrightarrow> m \<le> n" |
|
1389 |
by (subst mult_le_cancel1) simp |
|
1390 |
||
63588 | 1391 |
lemma le_square: "m \<le> m * m" |
1392 |
for m :: nat |
|
26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
1393 |
by (cases m) (auto intro: le_add1) |
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
1394 |
|
63588 | 1395 |
lemma le_cube: "m \<le> m * (m * m)" |
1396 |
for m :: nat |
|
26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
1397 |
by (cases m) (auto intro: le_add1) |
13449 | 1398 |
|
61799 | 1399 |
text \<open>Lemma for \<open>gcd\<close>\<close> |
71585 | 1400 |
lemma mult_eq_self_implies_10: |
1401 |
fixes m n :: nat |
|
1402 |
assumes "m = m * n" shows "n = 1 \<or> m = 0" |
|
1403 |
proof (rule disjCI) |
|
1404 |
assume "m \<noteq> 0" |
|
1405 |
show "n = 1" |
|
1406 |
proof (cases n "1::nat" rule: linorder_cases) |
|
1407 |
case greater |
|
1408 |
show ?thesis |
|
1409 |
using assms mult_less_mono2 [OF greater, of m] \<open>m \<noteq> 0\<close> by auto |
|
1410 |
qed (use assms \<open>m \<noteq> 0\<close> in auto) |
|
1411 |
qed |
|
9436
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
7702
diff
changeset
|
1412 |
|
51263
31e786e0e6a7
turned example into library for comparing growth of functions
haftmann
parents:
51173
diff
changeset
|
1413 |
lemma mono_times_nat: |
31e786e0e6a7
turned example into library for comparing growth of functions
haftmann
parents:
51173
diff
changeset
|
1414 |
fixes n :: nat |
31e786e0e6a7
turned example into library for comparing growth of functions
haftmann
parents:
51173
diff
changeset
|
1415 |
assumes "n > 0" |
31e786e0e6a7
turned example into library for comparing growth of functions
haftmann
parents:
51173
diff
changeset
|
1416 |
shows "mono (times n)" |
31e786e0e6a7
turned example into library for comparing growth of functions
haftmann
parents:
51173
diff
changeset
|
1417 |
proof |
31e786e0e6a7
turned example into library for comparing growth of functions
haftmann
parents:
51173
diff
changeset
|
1418 |
fix m q :: nat |
31e786e0e6a7
turned example into library for comparing growth of functions
haftmann
parents:
51173
diff
changeset
|
1419 |
assume "m \<le> q" |
31e786e0e6a7
turned example into library for comparing growth of functions
haftmann
parents:
51173
diff
changeset
|
1420 |
with assms show "n * m \<le> n * q" by simp |
31e786e0e6a7
turned example into library for comparing growth of functions
haftmann
parents:
51173
diff
changeset
|
1421 |
qed |
31e786e0e6a7
turned example into library for comparing growth of functions
haftmann
parents:
51173
diff
changeset
|
1422 |
|
69593 | 1423 |
text \<open>The lattice order on \<^typ>\<open>nat\<close>.\<close> |
24995 | 1424 |
|
26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
1425 |
instantiation nat :: distrib_lattice |
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
1426 |
begin |
24995 | 1427 |
|
63110 | 1428 |
definition "(inf :: nat \<Rightarrow> nat \<Rightarrow> nat) = min" |
1429 |
||
1430 |
definition "(sup :: nat \<Rightarrow> nat \<Rightarrow> nat) = max" |
|
1431 |
||
1432 |
instance |
|
1433 |
by intro_classes |
|
1434 |
(auto simp add: inf_nat_def sup_nat_def max_def not_le min_def |
|
1435 |
intro: order_less_imp_le antisym elim!: order_trans order_less_trans) |
|
24995 | 1436 |
|
26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
1437 |
end |
24995 | 1438 |
|
1439 |
||
60758 | 1440 |
subsection \<open>Natural operation of natural numbers on functions\<close> |
1441 |
||
1442 |
text \<open> |
|
30971 | 1443 |
We use the same logical constant for the power operations on |
1444 |
functions and relations, in order to share the same syntax. |
|
60758 | 1445 |
\<close> |
30971 | 1446 |
|
45965
2af982715e5c
generalized type signature to permit overloading on `set`
haftmann
parents:
45933
diff
changeset
|
1447 |
consts compow :: "nat \<Rightarrow> 'a \<Rightarrow> 'a" |
30971 | 1448 |
|
63110 | 1449 |
abbreviation compower :: "'a \<Rightarrow> nat \<Rightarrow> 'a" (infixr "^^" 80) |
1450 |
where "f ^^ n \<equiv> compow n f" |
|
30971 | 1451 |
|
1452 |
notation (latex output) |
|
1453 |
compower ("(_\<^bsup>_\<^esup>)" [1000] 1000) |
|
1454 |
||
63588 | 1455 |
text \<open>\<open>f ^^ n = f \<circ> \<dots> \<circ> f\<close>, the \<open>n\<close>-fold composition of \<open>f\<close>\<close> |
30971 | 1456 |
|
1457 |
overloading |
|
63110 | 1458 |
funpow \<equiv> "compow :: nat \<Rightarrow> ('a \<Rightarrow> 'a) \<Rightarrow> ('a \<Rightarrow> 'a)" |
30971 | 1459 |
begin |
30954
cf50e67bc1d1
power operation on functions in theory Nat; power operation on relations in theory Transitive_Closure
haftmann
parents:
30686
diff
changeset
|
1460 |
|
63588 | 1461 |
primrec funpow :: "nat \<Rightarrow> ('a \<Rightarrow> 'a) \<Rightarrow> 'a \<Rightarrow> 'a" |
1462 |
where |
|
1463 |
"funpow 0 f = id" |
|
1464 |
| "funpow (Suc n) f = f \<circ> funpow n f" |
|
30954
cf50e67bc1d1
power operation on functions in theory Nat; power operation on relations in theory Transitive_Closure
haftmann
parents:
30686
diff
changeset
|
1465 |
|
30971 | 1466 |
end |
1467 |
||
62217 | 1468 |
lemma funpow_0 [simp]: "(f ^^ 0) x = x" |
1469 |
by simp |
|
1470 |
||
63110 | 1471 |
lemma funpow_Suc_right: "f ^^ Suc n = f ^^ n \<circ> f" |
49723
bbc2942ba09f
alternative simplification of ^^ to the righthand side;
haftmann
parents:
49388
diff
changeset
|
1472 |
proof (induct n) |
63110 | 1473 |
case 0 |
1474 |
then show ?case by simp |
|
49723
bbc2942ba09f
alternative simplification of ^^ to the righthand side;
haftmann
parents:
49388
diff
changeset
|
1475 |
next |
bbc2942ba09f
alternative simplification of ^^ to the righthand side;
haftmann
parents:
49388
diff
changeset
|
1476 |
fix n |
bbc2942ba09f
alternative simplification of ^^ to the righthand side;
haftmann
parents:
49388
diff
changeset
|
1477 |
assume "f ^^ Suc n = f ^^ n \<circ> f" |
bbc2942ba09f
alternative simplification of ^^ to the righthand side;
haftmann
parents:
49388
diff
changeset
|
1478 |
then show "f ^^ Suc (Suc n) = f ^^ Suc n \<circ> f" |
bbc2942ba09f
alternative simplification of ^^ to the righthand side;
haftmann
parents:
49388
diff
changeset
|
1479 |
by (simp add: o_assoc) |
bbc2942ba09f
alternative simplification of ^^ to the righthand side;
haftmann
parents:
49388
diff
changeset
|
1480 |
qed |
bbc2942ba09f
alternative simplification of ^^ to the righthand side;
haftmann
parents:
49388
diff
changeset
|
1481 |
|
bbc2942ba09f
alternative simplification of ^^ to the righthand side;
haftmann
parents:
49388
diff
changeset
|
1482 |
lemmas funpow_simps_right = funpow.simps(1) funpow_Suc_right |
bbc2942ba09f
alternative simplification of ^^ to the righthand side;
haftmann
parents:
49388
diff
changeset
|
1483 |
|
63588 | 1484 |
text \<open>For code generation.\<close> |
30971 | 1485 |
|
63110 | 1486 |
definition funpow :: "nat \<Rightarrow> ('a \<Rightarrow> 'a) \<Rightarrow> 'a \<Rightarrow> 'a" |
1487 |
where funpow_code_def [code_abbrev]: "funpow = compow" |
|
30954
cf50e67bc1d1
power operation on functions in theory Nat; power operation on relations in theory Transitive_Closure
haftmann
parents:
30686
diff
changeset
|
1488 |
|
30971 | 1489 |
lemma [code]: |
63110 | 1490 |
"funpow (Suc n) f = f \<circ> funpow n f" |
30971 | 1491 |
"funpow 0 f = id" |
37430 | 1492 |
by (simp_all add: funpow_code_def) |
30971 | 1493 |
|
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
|
1494 |
hide_const (open) funpow |
30954
cf50e67bc1d1
power operation on functions in theory Nat; power operation on relations in theory Transitive_Closure
haftmann
parents:
30686
diff
changeset
|
1495 |
|
63110 | 1496 |
lemma funpow_add: "f ^^ (m + n) = f ^^ m \<circ> f ^^ n" |
30954
cf50e67bc1d1
power operation on functions in theory Nat; power operation on relations in theory Transitive_Closure
haftmann
parents:
30686
diff
changeset
|
1497 |
by (induct m) simp_all |
cf50e67bc1d1
power operation on functions in theory Nat; power operation on relations in theory Transitive_Closure
haftmann
parents:
30686
diff
changeset
|
1498 |
|
63588 | 1499 |
lemma funpow_mult: "(f ^^ m) ^^ n = f ^^ (m * n)" |
1500 |
for f :: "'a \<Rightarrow> 'a" |
|
37430 | 1501 |
by (induct n) (simp_all add: funpow_add) |
1502 |
||
63110 | 1503 |
lemma funpow_swap1: "f ((f ^^ n) x) = (f ^^ n) (f x)" |
30954
cf50e67bc1d1
power operation on functions in theory Nat; power operation on relations in theory Transitive_Closure
haftmann
parents:
30686
diff
changeset
|
1504 |
proof - |
30971 | 1505 |
have "f ((f ^^ n) x) = (f ^^ (n + 1)) x" by simp |
63588 | 1506 |
also have "\<dots> = (f ^^ n \<circ> f ^^ 1) x" by (simp only: funpow_add) |
30971 | 1507 |
also have "\<dots> = (f ^^ n) (f x)" by simp |
30954
cf50e67bc1d1
power operation on functions in theory Nat; power operation on relations in theory Transitive_Closure
haftmann
parents:
30686
diff
changeset
|
1508 |
finally show ?thesis . |
cf50e67bc1d1
power operation on functions in theory Nat; power operation on relations in theory Transitive_Closure
haftmann
parents:
30686
diff
changeset
|
1509 |
qed |
cf50e67bc1d1
power operation on functions in theory Nat; power operation on relations in theory Transitive_Closure
haftmann
parents:
30686
diff
changeset
|
1510 |
|
63588 | 1511 |
lemma comp_funpow: "comp f ^^ n = comp (f ^^ n)" |
1512 |
for f :: "'a \<Rightarrow> 'a" |
|
38621
d6cb7e625d75
more concise characterization of of_nat operation and class semiring_char_0
haftmann
parents:
37767
diff
changeset
|
1513 |
by (induct n) simp_all |
30954
cf50e67bc1d1
power operation on functions in theory Nat; power operation on relations in theory Transitive_Closure
haftmann
parents:
30686
diff
changeset
|
1514 |
|
67399 | 1515 |
lemma Suc_funpow[simp]: "Suc ^^ n = ((+) n)" |
54496
178922b63b58
add lemmas Suc_funpow and id_funpow to simpset; add lemma map_add_upt
hoelzl
parents:
54411
diff
changeset
|
1516 |
by (induct n) simp_all |
178922b63b58
add lemmas Suc_funpow and id_funpow to simpset; add lemma map_add_upt
hoelzl
parents:
54411
diff
changeset
|
1517 |
|
178922b63b58
add lemmas Suc_funpow and id_funpow to simpset; add lemma map_add_upt
hoelzl
parents:
54411
diff
changeset
|
1518 |
lemma id_funpow[simp]: "id ^^ n = id" |
178922b63b58
add lemmas Suc_funpow and id_funpow to simpset; add lemma map_add_upt
hoelzl
parents:
54411
diff
changeset
|
1519 |
by (induct n) simp_all |
38621
d6cb7e625d75
more concise characterization of of_nat operation and class semiring_char_0
haftmann
parents:
37767
diff
changeset
|
1520 |
|
63110 | 1521 |
lemma funpow_mono: "mono f \<Longrightarrow> A \<le> B \<Longrightarrow> (f ^^ n) A \<le> (f ^^ n) B" |
63561
fba08009ff3e
add lemmas contributed by Peter Gammie
Andreas Lochbihler
parents:
63197
diff
changeset
|
1522 |
for f :: "'a \<Rightarrow> ('a::order)" |
59000 | 1523 |
by (induct n arbitrary: A B) |
1524 |
(auto simp del: funpow.simps(2) simp add: funpow_Suc_right mono_def) |
|
1525 |
||
63561
fba08009ff3e
add lemmas contributed by Peter Gammie
Andreas Lochbihler
parents:
63197
diff
changeset
|
1526 |
lemma funpow_mono2: |
fba08009ff3e
add lemmas contributed by Peter Gammie
Andreas Lochbihler
parents:
63197
diff
changeset
|
1527 |
assumes "mono f" |
63588 | 1528 |
and "i \<le> j" |
1529 |
and "x \<le> y" |
|
1530 |
and "x \<le> f x" |
|
63561
fba08009ff3e
add lemmas contributed by Peter Gammie
Andreas Lochbihler
parents:
63197
diff
changeset
|
1531 |
shows "(f ^^ i) x \<le> (f ^^ j) y" |
63588 | 1532 |
using assms(2,3) |
1533 |
proof (induct j arbitrary: y) |
|
1534 |
case 0 |
|
1535 |
then show ?case by simp |
|
1536 |
next |
|
63561
fba08009ff3e
add lemmas contributed by Peter Gammie
Andreas Lochbihler
parents:
63197
diff
changeset
|
1537 |
case (Suc j) |
fba08009ff3e
add lemmas contributed by Peter Gammie
Andreas Lochbihler
parents:
63197
diff
changeset
|
1538 |
show ?case |
fba08009ff3e
add lemmas contributed by Peter Gammie
Andreas Lochbihler
parents:
63197
diff
changeset
|
1539 |
proof(cases "i = Suc j") |
fba08009ff3e
add lemmas contributed by Peter Gammie
Andreas Lochbihler
parents:
63197
diff
changeset
|
1540 |
case True |
fba08009ff3e
add lemmas contributed by Peter Gammie
Andreas Lochbihler
parents:
63197
diff
changeset
|
1541 |
with assms(1) Suc show ?thesis |
fba08009ff3e
add lemmas contributed by Peter Gammie
Andreas Lochbihler
parents:
63197
diff
changeset
|
1542 |
by (simp del: funpow.simps add: funpow_simps_right monoD funpow_mono) |
fba08009ff3e
add lemmas contributed by Peter Gammie
Andreas Lochbihler
parents:
63197
diff
changeset
|
1543 |
next |
fba08009ff3e
add lemmas contributed by Peter Gammie
Andreas Lochbihler
parents:
63197
diff
changeset
|
1544 |
case False |
fba08009ff3e
add lemmas contributed by Peter Gammie
Andreas Lochbihler
parents:
63197
diff
changeset
|
1545 |
with assms(1,4) Suc show ?thesis |
fba08009ff3e
add lemmas contributed by Peter Gammie
Andreas Lochbihler
parents:
63197
diff
changeset
|
1546 |
by (simp del: funpow.simps add: funpow_simps_right le_eq_less_or_eq less_Suc_eq_le) |
63588 | 1547 |
(simp add: Suc.hyps monoD order_subst1) |
63561
fba08009ff3e
add lemmas contributed by Peter Gammie
Andreas Lochbihler
parents:
63197
diff
changeset
|
1548 |
qed |
63588 | 1549 |
qed |
63561
fba08009ff3e
add lemmas contributed by Peter Gammie
Andreas Lochbihler
parents:
63197
diff
changeset
|
1550 |
|
68610 | 1551 |
lemma inj_fn[simp]: |
1552 |
fixes f::"'a \<Rightarrow> 'a" |
|
1553 |
assumes "inj f" |
|
1554 |
shows "inj (f^^n)" |
|
1555 |
proof (induction n) |
|
69700
7a92cbec7030
new material about summations and powers, along with some tweaks
paulson <lp15@cam.ac.uk>
parents:
69661
diff
changeset
|
1556 |
case Suc thus ?case using inj_compose[OF assms Suc.IH] by (simp del: comp_apply) |
68610 | 1557 |
qed simp |
1558 |
||
1559 |
lemma surj_fn[simp]: |
|
1560 |
fixes f::"'a \<Rightarrow> 'a" |
|
1561 |
assumes "surj f" |
|
1562 |
shows "surj (f^^n)" |
|
1563 |
proof (induction n) |
|
1564 |
case Suc thus ?case by (simp add: comp_surj[OF Suc.IH assms] del: comp_apply) |
|
1565 |
qed simp |
|
1566 |
||
1567 |
lemma bij_fn[simp]: |
|
1568 |
fixes f::"'a \<Rightarrow> 'a" |
|
1569 |
assumes "bij f" |
|
1570 |
shows "bij (f^^n)" |
|
1571 |
by (rule bijI[OF inj_fn[OF bij_is_inj[OF assms]] surj_fn[OF bij_is_surj[OF assms]]]) |
|
1572 |
||
63110 | 1573 |
|
60758 | 1574 |
subsection \<open>Kleene iteration\<close> |
45833 | 1575 |
|
52729
412c9e0381a1
factored syntactic type classes for bot and top (by Alessandro Coglio)
haftmann
parents:
52435
diff
changeset
|
1576 |
lemma Kleene_iter_lpfp: |
63588 | 1577 |
fixes f :: "'a::order_bot \<Rightarrow> 'a" |
63110 | 1578 |
assumes "mono f" |
1579 |
and "f p \<le> p" |
|
63588 | 1580 |
shows "(f ^^ k) bot \<le> p" |
1581 |
proof (induct k) |
|
63110 | 1582 |
case 0 |
1583 |
show ?case by simp |
|
45833 | 1584 |
next |
1585 |
case Suc |
|
63588 | 1586 |
show ?case |
1587 |
using monoD[OF assms(1) Suc] assms(2) by simp |
|
45833 | 1588 |
qed |
1589 |
||
63110 | 1590 |
lemma lfp_Kleene_iter: |
1591 |
assumes "mono f" |
|
63588 | 1592 |
and "(f ^^ Suc k) bot = (f ^^ k) bot" |
1593 |
shows "lfp f = (f ^^ k) bot" |
|
63110 | 1594 |
proof (rule antisym) |
63588 | 1595 |
show "lfp f \<le> (f ^^ k) bot" |
63110 | 1596 |
proof (rule lfp_lowerbound) |
63588 | 1597 |
show "f ((f ^^ k) bot) \<le> (f ^^ k) bot" |
63110 | 1598 |
using assms(2) by simp |
45833 | 1599 |
qed |
63588 | 1600 |
show "(f ^^ k) bot \<le> lfp f" |
45833 | 1601 |
using Kleene_iter_lpfp[OF assms(1)] lfp_unfold[OF assms(1)] by simp |
1602 |
qed |
|
1603 |
||
63588 | 1604 |
lemma mono_pow: "mono f \<Longrightarrow> mono (f ^^ n)" |
1605 |
for f :: "'a \<Rightarrow> 'a::complete_lattice" |
|
63110 | 1606 |
by (induct n) (auto simp: mono_def) |
60636
ee18efe9b246
add named theorems order_continuous_intros; lfp/gfp_funpow; bounded variant for lfp/gfp transfer
hoelzl
parents:
60562
diff
changeset
|
1607 |
|
ee18efe9b246
add named theorems order_continuous_intros; lfp/gfp_funpow; bounded variant for lfp/gfp transfer
hoelzl
parents:
60562
diff
changeset
|
1608 |
lemma lfp_funpow: |
63110 | 1609 |
assumes f: "mono f" |
1610 |
shows "lfp (f ^^ Suc n) = lfp f" |
|
60636
ee18efe9b246
add named theorems order_continuous_intros; lfp/gfp_funpow; bounded variant for lfp/gfp transfer
hoelzl
parents:
60562
diff
changeset
|
1611 |
proof (rule antisym) |
ee18efe9b246
add named theorems order_continuous_intros; lfp/gfp_funpow; bounded variant for lfp/gfp transfer
hoelzl
parents:
60562
diff
changeset
|
1612 |
show "lfp f \<le> lfp (f ^^ Suc n)" |
ee18efe9b246
add named theorems order_continuous_intros; lfp/gfp_funpow; bounded variant for lfp/gfp transfer
hoelzl
parents:
60562
diff
changeset
|
1613 |
proof (rule lfp_lowerbound) |
ee18efe9b246
add named theorems order_continuous_intros; lfp/gfp_funpow; bounded variant for lfp/gfp transfer
hoelzl
parents:
60562
diff
changeset
|
1614 |
have "f (lfp (f ^^ Suc n)) = lfp (\<lambda>x. f ((f ^^ n) x))" |
ee18efe9b246
add named theorems order_continuous_intros; lfp/gfp_funpow; bounded variant for lfp/gfp transfer
hoelzl
parents:
60562
diff
changeset
|
1615 |
unfolding funpow_Suc_right by (simp add: lfp_rolling f mono_pow comp_def) |
ee18efe9b246
add named theorems order_continuous_intros; lfp/gfp_funpow; bounded variant for lfp/gfp transfer
hoelzl
parents:
60562
diff
changeset
|
1616 |
then show "f (lfp (f ^^ Suc n)) \<le> lfp (f ^^ Suc n)" |
ee18efe9b246
add named theorems order_continuous_intros; lfp/gfp_funpow; bounded variant for lfp/gfp transfer
hoelzl
parents:
60562
diff
changeset
|
1617 |
by (simp add: comp_def) |
ee18efe9b246
add named theorems order_continuous_intros; lfp/gfp_funpow; bounded variant for lfp/gfp transfer
hoelzl
parents:
60562
diff
changeset
|
1618 |
qed |
63588 | 1619 |
have "(f ^^ n) (lfp f) = lfp f" for n |
63979 | 1620 |
by (induct n) (auto intro: f lfp_fixpoint) |
63588 | 1621 |
then show "lfp (f ^^ Suc n) \<le> lfp f" |
60636
ee18efe9b246
add named theorems order_continuous_intros; lfp/gfp_funpow; bounded variant for lfp/gfp transfer
hoelzl
parents:
60562
diff
changeset
|
1622 |
by (intro lfp_lowerbound) (simp del: funpow.simps) |
ee18efe9b246
add named theorems order_continuous_intros; lfp/gfp_funpow; bounded variant for lfp/gfp transfer
hoelzl
parents:
60562
diff
changeset
|
1623 |
qed |
ee18efe9b246
add named theorems order_continuous_intros; lfp/gfp_funpow; bounded variant for lfp/gfp transfer
hoelzl
parents:
60562
diff
changeset
|
1624 |
|
ee18efe9b246
add named theorems order_continuous_intros; lfp/gfp_funpow; bounded variant for lfp/gfp transfer
hoelzl
parents:
60562
diff
changeset
|
1625 |
lemma gfp_funpow: |
63110 | 1626 |
assumes f: "mono f" |
1627 |
shows "gfp (f ^^ Suc n) = gfp f" |
|
60636
ee18efe9b246
add named theorems order_continuous_intros; lfp/gfp_funpow; bounded variant for lfp/gfp transfer
hoelzl
parents:
60562
diff
changeset
|
1628 |
proof (rule antisym) |
ee18efe9b246
add named theorems order_continuous_intros; lfp/gfp_funpow; bounded variant for lfp/gfp transfer
hoelzl
parents:
60562
diff
changeset
|
1629 |
show "gfp f \<ge> gfp (f ^^ Suc n)" |
ee18efe9b246
add named theorems order_continuous_intros; lfp/gfp_funpow; bounded variant for lfp/gfp transfer
hoelzl
parents:
60562
diff
changeset
|
1630 |
proof (rule gfp_upperbound) |
ee18efe9b246
add named theorems order_continuous_intros; lfp/gfp_funpow; bounded variant for lfp/gfp transfer
hoelzl
parents:
60562
diff
changeset
|
1631 |
have "f (gfp (f ^^ Suc n)) = gfp (\<lambda>x. f ((f ^^ n) x))" |
ee18efe9b246
add named theorems order_continuous_intros; lfp/gfp_funpow; bounded variant for lfp/gfp transfer
hoelzl
parents:
60562
diff
changeset
|
1632 |
unfolding funpow_Suc_right by (simp add: gfp_rolling f mono_pow comp_def) |
ee18efe9b246
add named theorems order_continuous_intros; lfp/gfp_funpow; bounded variant for lfp/gfp transfer
hoelzl
parents:
60562
diff
changeset
|
1633 |
then show "f (gfp (f ^^ Suc n)) \<ge> gfp (f ^^ Suc n)" |
ee18efe9b246
add named theorems order_continuous_intros; lfp/gfp_funpow; bounded variant for lfp/gfp transfer
hoelzl
parents:
60562
diff
changeset
|
1634 |
by (simp add: comp_def) |
ee18efe9b246
add named theorems order_continuous_intros; lfp/gfp_funpow; bounded variant for lfp/gfp transfer
hoelzl
parents:
60562
diff
changeset
|
1635 |
qed |
63588 | 1636 |
have "(f ^^ n) (gfp f) = gfp f" for n |
63979 | 1637 |
by (induct n) (auto intro: f gfp_fixpoint) |
63588 | 1638 |
then show "gfp (f ^^ Suc n) \<ge> gfp f" |
60636
ee18efe9b246
add named theorems order_continuous_intros; lfp/gfp_funpow; bounded variant for lfp/gfp transfer
hoelzl
parents:
60562
diff
changeset
|
1639 |
by (intro gfp_upperbound) (simp del: funpow.simps) |
ee18efe9b246
add named theorems order_continuous_intros; lfp/gfp_funpow; bounded variant for lfp/gfp transfer
hoelzl
parents:
60562
diff
changeset
|
1640 |
qed |
45833 | 1641 |
|
63561
fba08009ff3e
add lemmas contributed by Peter Gammie
Andreas Lochbihler
parents:
63197
diff
changeset
|
1642 |
lemma Kleene_iter_gpfp: |
63588 | 1643 |
fixes f :: "'a::order_top \<Rightarrow> 'a" |
63561
fba08009ff3e
add lemmas contributed by Peter Gammie
Andreas Lochbihler
parents:
63197
diff
changeset
|
1644 |
assumes "mono f" |
63588 | 1645 |
and "p \<le> f p" |
1646 |
shows "p \<le> (f ^^ k) top" |
|
1647 |
proof (induct k) |
|
1648 |
case 0 |
|
1649 |
show ?case by simp |
|
63561
fba08009ff3e
add lemmas contributed by Peter Gammie
Andreas Lochbihler
parents:
63197
diff
changeset
|
1650 |
next |
fba08009ff3e
add lemmas contributed by Peter Gammie
Andreas Lochbihler
parents:
63197
diff
changeset
|
1651 |
case Suc |
63588 | 1652 |
show ?case |
1653 |
using monoD[OF assms(1) Suc] assms(2) by simp |
|
63561
fba08009ff3e
add lemmas contributed by Peter Gammie
Andreas Lochbihler
parents:
63197
diff
changeset
|
1654 |
qed |
fba08009ff3e
add lemmas contributed by Peter Gammie
Andreas Lochbihler
parents:
63197
diff
changeset
|
1655 |
|
fba08009ff3e
add lemmas contributed by Peter Gammie
Andreas Lochbihler
parents:
63197
diff
changeset
|
1656 |
lemma gfp_Kleene_iter: |
fba08009ff3e
add lemmas contributed by Peter Gammie
Andreas Lochbihler
parents:
63197
diff
changeset
|
1657 |
assumes "mono f" |
63588 | 1658 |
and "(f ^^ Suc k) top = (f ^^ k) top" |
1659 |
shows "gfp f = (f ^^ k) top" |
|
1660 |
(is "?lhs = ?rhs") |
|
1661 |
proof (rule antisym) |
|
1662 |
have "?rhs \<le> f ?rhs" |
|
1663 |
using assms(2) by simp |
|
1664 |
then show "?rhs \<le> ?lhs" |
|
1665 |
by (rule gfp_upperbound) |
|
63561
fba08009ff3e
add lemmas contributed by Peter Gammie
Andreas Lochbihler
parents:
63197
diff
changeset
|
1666 |
show "?lhs \<le> ?rhs" |
fba08009ff3e
add lemmas contributed by Peter Gammie
Andreas Lochbihler
parents:
63197
diff
changeset
|
1667 |
using Kleene_iter_gpfp[OF assms(1)] gfp_unfold[OF assms(1)] by simp |
fba08009ff3e
add lemmas contributed by Peter Gammie
Andreas Lochbihler
parents:
63197
diff
changeset
|
1668 |
qed |
fba08009ff3e
add lemmas contributed by Peter Gammie
Andreas Lochbihler
parents:
63197
diff
changeset
|
1669 |
|
63110 | 1670 |
|
69593 | 1671 |
subsection \<open>Embedding of the naturals into any \<open>semiring_1\<close>: \<^term>\<open>of_nat\<close>\<close> |
24196 | 1672 |
|
1673 |
context semiring_1 |
|
1674 |
begin |
|
1675 |
||
63110 | 1676 |
definition of_nat :: "nat \<Rightarrow> 'a" |
1677 |
where "of_nat n = (plus 1 ^^ n) 0" |
|
38621
d6cb7e625d75
more concise characterization of of_nat operation and class semiring_char_0
haftmann
parents:
37767
diff
changeset
|
1678 |
|
d6cb7e625d75
more concise characterization of of_nat operation and class semiring_char_0
haftmann
parents:
37767
diff
changeset
|
1679 |
lemma of_nat_simps [simp]: |
d6cb7e625d75
more concise characterization of of_nat operation and class semiring_char_0
haftmann
parents:
37767
diff
changeset
|
1680 |
shows of_nat_0: "of_nat 0 = 0" |
d6cb7e625d75
more concise characterization of of_nat operation and class semiring_char_0
haftmann
parents:
37767
diff
changeset
|
1681 |
and of_nat_Suc: "of_nat (Suc m) = 1 + of_nat m" |
d6cb7e625d75
more concise characterization of of_nat operation and class semiring_char_0
haftmann
parents:
37767
diff
changeset
|
1682 |
by (simp_all add: of_nat_def) |
25193 | 1683 |
|
1684 |
lemma of_nat_1 [simp]: "of_nat 1 = 1" |
|
38621
d6cb7e625d75
more concise characterization of of_nat operation and class semiring_char_0
haftmann
parents:
37767
diff
changeset
|
1685 |
by (simp add: of_nat_def) |
25193 | 1686 |
|
1687 |
lemma of_nat_add [simp]: "of_nat (m + n) = of_nat m + of_nat n" |
|
57514
bdc2c6b40bf2
prefer ac_simps collections over separate name bindings for add and mult
haftmann
parents:
57512
diff
changeset
|
1688 |
by (induct m) (simp_all add: ac_simps) |
25193 | 1689 |
|
61649
268d88ec9087
Tweaks for "real": Removal of [iff] status for some lemmas, adding [simp] for others. Plus fixes.
paulson <lp15@cam.ac.uk>
parents:
61531
diff
changeset
|
1690 |
lemma of_nat_mult [simp]: "of_nat (m * n) = of_nat m * of_nat n" |
57514
bdc2c6b40bf2
prefer ac_simps collections over separate name bindings for add and mult
haftmann
parents:
57512
diff
changeset
|
1691 |
by (induct m) (simp_all add: ac_simps distrib_right) |
25193 | 1692 |
|
61531
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61378
diff
changeset
|
1693 |
lemma mult_of_nat_commute: "of_nat x * y = y * of_nat x" |
63110 | 1694 |
by (induct x) (simp_all add: algebra_simps) |
61531
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61378
diff
changeset
|
1695 |
|
63588 | 1696 |
primrec of_nat_aux :: "('a \<Rightarrow> 'a) \<Rightarrow> nat \<Rightarrow> 'a \<Rightarrow> 'a" |
1697 |
where |
|
1698 |
"of_nat_aux inc 0 i = i" |
|
1699 |
| "of_nat_aux inc (Suc n) i = of_nat_aux inc n (inc i)" \<comment> \<open>tail recursive\<close> |
|
25928 | 1700 |
|
63110 | 1701 |
lemma of_nat_code: "of_nat n = of_nat_aux (\<lambda>i. i + 1) n 0" |
28514 | 1702 |
proof (induct n) |
63110 | 1703 |
case 0 |
1704 |
then show ?case by simp |
|
28514 | 1705 |
next |
1706 |
case (Suc n) |
|
1707 |
have "\<And>i. of_nat_aux (\<lambda>i. i + 1) n (i + 1) = of_nat_aux (\<lambda>i. i + 1) n i + 1" |
|
1708 |
by (induct n) simp_all |
|
1709 |
from this [of 0] have "of_nat_aux (\<lambda>i. i + 1) n 1 = of_nat_aux (\<lambda>i. i + 1) n 0 + 1" |
|
1710 |
by simp |
|
63588 | 1711 |
with Suc show ?case |
1712 |
by (simp add: add.commute) |
|
28514 | 1713 |
qed |
30966 | 1714 |
|
66816
212a3334e7da
more fundamental definition of div and mod on int
haftmann
parents:
66810
diff
changeset
|
1715 |
lemma of_nat_of_bool [simp]: |
212a3334e7da
more fundamental definition of div and mod on int
haftmann
parents:
66810
diff
changeset
|
1716 |
"of_nat (of_bool P) = of_bool P" |
212a3334e7da
more fundamental definition of div and mod on int
haftmann
parents:
66810
diff
changeset
|
1717 |
by auto |
212a3334e7da
more fundamental definition of div and mod on int
haftmann
parents:
66810
diff
changeset
|
1718 |
|
24196 | 1719 |
end |
1720 |
||
45231
d85a2fdc586c
replacing code_inline by code_unfold, removing obsolete code_unfold, code_inline del now that the ancient code generator is removed
bulwahn
parents:
44890
diff
changeset
|
1721 |
declare of_nat_code [code] |
30966 | 1722 |
|
71407 | 1723 |
context semiring_1_cancel |
62481
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
1724 |
begin |
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
1725 |
|
71407 | 1726 |
lemma of_nat_diff: |
1727 |
\<open>of_nat (m - n) = of_nat m - of_nat n\<close> if \<open>n \<le> m\<close> |
|
1728 |
proof - |
|
1729 |
from that obtain q where \<open>m = n + q\<close> |
|
1730 |
by (blast dest: le_Suc_ex) |
|
1731 |
then show ?thesis |
|
1732 |
by simp |
|
1733 |
qed |
|
62481
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
1734 |
|
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
1735 |
end |
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
1736 |
|
63110 | 1737 |
text \<open>Class for unital semirings with characteristic zero. |
60758 | 1738 |
Includes non-ordered rings like the complex numbers.\<close> |
26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
1739 |
|
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
1740 |
class semiring_char_0 = semiring_1 + |
38621
d6cb7e625d75
more concise characterization of of_nat operation and class semiring_char_0
haftmann
parents:
37767
diff
changeset
|
1741 |
assumes inj_of_nat: "inj of_nat" |
26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
1742 |
begin |
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
1743 |
|
38621
d6cb7e625d75
more concise characterization of of_nat operation and class semiring_char_0
haftmann
parents:
37767
diff
changeset
|
1744 |
lemma of_nat_eq_iff [simp]: "of_nat m = of_nat n \<longleftrightarrow> m = n" |
d6cb7e625d75
more concise characterization of of_nat operation and class semiring_char_0
haftmann
parents:
37767
diff
changeset
|
1745 |
by (auto intro: inj_of_nat injD) |
d6cb7e625d75
more concise characterization of of_nat operation and class semiring_char_0
haftmann
parents:
37767
diff
changeset
|
1746 |
|
63110 | 1747 |
text \<open>Special cases where either operand is zero\<close> |
26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
1748 |
|
54147
97a8ff4e4ac9
killed most "no_atp", to make Sledgehammer more complete
blanchet
parents:
53986
diff
changeset
|
1749 |
lemma of_nat_0_eq_iff [simp]: "0 = of_nat n \<longleftrightarrow> 0 = n" |
38621
d6cb7e625d75
more concise characterization of of_nat operation and class semiring_char_0
haftmann
parents:
37767
diff
changeset
|
1750 |
by (fact of_nat_eq_iff [of 0 n, unfolded of_nat_0]) |
26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
1751 |
|
54147
97a8ff4e4ac9
killed most "no_atp", to make Sledgehammer more complete
blanchet
parents:
53986
diff
changeset
|
1752 |
lemma of_nat_eq_0_iff [simp]: "of_nat m = 0 \<longleftrightarrow> m = 0" |
38621
d6cb7e625d75
more concise characterization of of_nat operation and class semiring_char_0
haftmann
parents:
37767
diff
changeset
|
1753 |
by (fact of_nat_eq_iff [of m 0, unfolded of_nat_0]) |
26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
1754 |
|
65583
8d53b3bebab4
Further new material. The simprule status of some exp and ln identities was reverted.
paulson <lp15@cam.ac.uk>
parents:
64876
diff
changeset
|
1755 |
lemma of_nat_1_eq_iff [simp]: "1 = of_nat n \<longleftrightarrow> n=1" |
8d53b3bebab4
Further new material. The simprule status of some exp and ln identities was reverted.
paulson <lp15@cam.ac.uk>
parents:
64876
diff
changeset
|
1756 |
using of_nat_eq_iff by fastforce |
8d53b3bebab4
Further new material. The simprule status of some exp and ln identities was reverted.
paulson <lp15@cam.ac.uk>
parents:
64876
diff
changeset
|
1757 |
|
8d53b3bebab4
Further new material. The simprule status of some exp and ln identities was reverted.
paulson <lp15@cam.ac.uk>
parents:
64876
diff
changeset
|
1758 |
lemma of_nat_eq_1_iff [simp]: "of_nat n = 1 \<longleftrightarrow> n=1" |
8d53b3bebab4
Further new material. The simprule status of some exp and ln identities was reverted.
paulson <lp15@cam.ac.uk>
parents:
64876
diff
changeset
|
1759 |
using of_nat_eq_iff by fastforce |
8d53b3bebab4
Further new material. The simprule status of some exp and ln identities was reverted.
paulson <lp15@cam.ac.uk>
parents:
64876
diff
changeset
|
1760 |
|
63588 | 1761 |
lemma of_nat_neq_0 [simp]: "of_nat (Suc n) \<noteq> 0" |
60353
838025c6e278
implicit partial divison operation in integral domains
haftmann
parents:
60175
diff
changeset
|
1762 |
unfolding of_nat_eq_0_iff by simp |
838025c6e278
implicit partial divison operation in integral domains
haftmann
parents:
60175
diff
changeset
|
1763 |
|
63588 | 1764 |
lemma of_nat_0_neq [simp]: "0 \<noteq> of_nat (Suc 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
|
1765 |
unfolding of_nat_0_eq_iff by simp |
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
|
1766 |
|
26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
1767 |
end |
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
1768 |
|
62481
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
1769 |
class ring_char_0 = ring_1 + semiring_char_0 |
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
1770 |
|
67691
db202a00a29c
fixing ennreal using add_mono1; shifting results from linordered_semidom to linordered_nonzero_semiring
paulson <lp15@cam.ac.uk>
parents:
67673
diff
changeset
|
1771 |
context linordered_nonzero_semiring |
25193 | 1772 |
begin |
1773 |
||
47489 | 1774 |
lemma of_nat_0_le_iff [simp]: "0 \<le> of_nat n" |
1775 |
by (induct n) simp_all |
|
25193 | 1776 |
|
47489 | 1777 |
lemma of_nat_less_0_iff [simp]: "\<not> of_nat m < 0" |
1778 |
by (simp add: not_less) |
|
25193 | 1779 |
|
67691
db202a00a29c
fixing ennreal using add_mono1; shifting results from linordered_semidom to linordered_nonzero_semiring
paulson <lp15@cam.ac.uk>
parents:
67673
diff
changeset
|
1780 |
lemma of_nat_mono[simp]: "i \<le> j \<Longrightarrow> of_nat i \<le> of_nat j" |
db202a00a29c
fixing ennreal using add_mono1; shifting results from linordered_semidom to linordered_nonzero_semiring
paulson <lp15@cam.ac.uk>
parents:
67673
diff
changeset
|
1781 |
by (auto simp: le_iff_add intro!: add_increasing2) |
db202a00a29c
fixing ennreal using add_mono1; shifting results from linordered_semidom to linordered_nonzero_semiring
paulson <lp15@cam.ac.uk>
parents:
67673
diff
changeset
|
1782 |
|
25193 | 1783 |
lemma of_nat_less_iff [simp]: "of_nat m < of_nat n \<longleftrightarrow> m < n" |
67691
db202a00a29c
fixing ennreal using add_mono1; shifting results from linordered_semidom to linordered_nonzero_semiring
paulson <lp15@cam.ac.uk>
parents:
67673
diff
changeset
|
1784 |
proof(induct m n rule: diff_induct) |
db202a00a29c
fixing ennreal using add_mono1; shifting results from linordered_semidom to linordered_nonzero_semiring
paulson <lp15@cam.ac.uk>
parents:
67673
diff
changeset
|
1785 |
case (1 m) then show ?case |
db202a00a29c
fixing ennreal using add_mono1; shifting results from linordered_semidom to linordered_nonzero_semiring
paulson <lp15@cam.ac.uk>
parents:
67673
diff
changeset
|
1786 |
by auto |
db202a00a29c
fixing ennreal using add_mono1; shifting results from linordered_semidom to linordered_nonzero_semiring
paulson <lp15@cam.ac.uk>
parents:
67673
diff
changeset
|
1787 |
next |
db202a00a29c
fixing ennreal using add_mono1; shifting results from linordered_semidom to linordered_nonzero_semiring
paulson <lp15@cam.ac.uk>
parents:
67673
diff
changeset
|
1788 |
case (2 n) then show ?case |
db202a00a29c
fixing ennreal using add_mono1; shifting results from linordered_semidom to linordered_nonzero_semiring
paulson <lp15@cam.ac.uk>
parents:
67673
diff
changeset
|
1789 |
by (simp add: add_pos_nonneg) |
db202a00a29c
fixing ennreal using add_mono1; shifting results from linordered_semidom to linordered_nonzero_semiring
paulson <lp15@cam.ac.uk>
parents:
67673
diff
changeset
|
1790 |
next |
db202a00a29c
fixing ennreal using add_mono1; shifting results from linordered_semidom to linordered_nonzero_semiring
paulson <lp15@cam.ac.uk>
parents:
67673
diff
changeset
|
1791 |
case (3 m n) |
db202a00a29c
fixing ennreal using add_mono1; shifting results from linordered_semidom to linordered_nonzero_semiring
paulson <lp15@cam.ac.uk>
parents:
67673
diff
changeset
|
1792 |
then show ?case |
db202a00a29c
fixing ennreal using add_mono1; shifting results from linordered_semidom to linordered_nonzero_semiring
paulson <lp15@cam.ac.uk>
parents:
67673
diff
changeset
|
1793 |
by (auto simp: add_commute [of 1] add_mono1 not_less add_right_mono leD) |
db202a00a29c
fixing ennreal using add_mono1; shifting results from linordered_semidom to linordered_nonzero_semiring
paulson <lp15@cam.ac.uk>
parents:
67673
diff
changeset
|
1794 |
qed |
25193 | 1795 |
|
26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
1796 |
lemma of_nat_le_iff [simp]: "of_nat m \<le> of_nat n \<longleftrightarrow> m \<le> n" |
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
1797 |
by (simp add: not_less [symmetric] linorder_not_less [symmetric]) |
25193 | 1798 |
|
47489 | 1799 |
lemma less_imp_of_nat_less: "m < n \<Longrightarrow> of_nat m < of_nat n" |
1800 |
by simp |
|
1801 |
||
1802 |
lemma of_nat_less_imp_less: "of_nat m < of_nat n \<Longrightarrow> m < n" |
|
1803 |
by simp |
|
1804 |
||
67691
db202a00a29c
fixing ennreal using add_mono1; shifting results from linordered_semidom to linordered_nonzero_semiring
paulson <lp15@cam.ac.uk>
parents:
67673
diff
changeset
|
1805 |
text \<open>Every \<open>linordered_nonzero_semiring\<close> has characteristic zero.\<close> |
63110 | 1806 |
|
1807 |
subclass semiring_char_0 |
|
1808 |
by standard (auto intro!: injI simp add: eq_iff) |
|
1809 |
||
1810 |
text \<open>Special cases where either operand is zero\<close> |
|
25193 | 1811 |
|
54147
97a8ff4e4ac9
killed most "no_atp", to make Sledgehammer more complete
blanchet
parents:
53986
diff
changeset
|
1812 |
lemma of_nat_le_0_iff [simp]: "of_nat m \<le> 0 \<longleftrightarrow> m = 0" |
25193 | 1813 |
by (rule of_nat_le_iff [of _ 0, simplified]) |
1814 |
||
26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
1815 |
lemma of_nat_0_less_iff [simp]: "0 < of_nat n \<longleftrightarrow> 0 < n" |
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
1816 |
by (rule of_nat_less_iff [of 0, simplified]) |
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
1817 |
|
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
1818 |
end |
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
1819 |
|
70356
4a327c061870
streamlined setup for linear algebra, particularly removed redundant rule declarations
haftmann
parents:
69700
diff
changeset
|
1820 |
context linordered_nonzero_semiring |
4a327c061870
streamlined setup for linear algebra, particularly removed redundant rule declarations
haftmann
parents:
69700
diff
changeset
|
1821 |
begin |
4a327c061870
streamlined setup for linear algebra, particularly removed redundant rule declarations
haftmann
parents:
69700
diff
changeset
|
1822 |
|
4a327c061870
streamlined setup for linear algebra, particularly removed redundant rule declarations
haftmann
parents:
69700
diff
changeset
|
1823 |
lemma of_nat_max: "of_nat (max x y) = max (of_nat x) (of_nat y)" |
4a327c061870
streamlined setup for linear algebra, particularly removed redundant rule declarations
haftmann
parents:
69700
diff
changeset
|
1824 |
by (auto simp: max_def ord_class.max_def) |
4a327c061870
streamlined setup for linear algebra, particularly removed redundant rule declarations
haftmann
parents:
69700
diff
changeset
|
1825 |
|
4a327c061870
streamlined setup for linear algebra, particularly removed redundant rule declarations
haftmann
parents:
69700
diff
changeset
|
1826 |
lemma of_nat_min: "of_nat (min x y) = min (of_nat x) (of_nat y)" |
4a327c061870
streamlined setup for linear algebra, particularly removed redundant rule declarations
haftmann
parents:
69700
diff
changeset
|
1827 |
by (auto simp: min_def ord_class.min_def) |
4a327c061870
streamlined setup for linear algebra, particularly removed redundant rule declarations
haftmann
parents:
69700
diff
changeset
|
1828 |
|
4a327c061870
streamlined setup for linear algebra, particularly removed redundant rule declarations
haftmann
parents:
69700
diff
changeset
|
1829 |
end |
67691
db202a00a29c
fixing ennreal using add_mono1; shifting results from linordered_semidom to linordered_nonzero_semiring
paulson <lp15@cam.ac.uk>
parents:
67673
diff
changeset
|
1830 |
|
db202a00a29c
fixing ennreal using add_mono1; shifting results from linordered_semidom to linordered_nonzero_semiring
paulson <lp15@cam.ac.uk>
parents:
67673
diff
changeset
|
1831 |
context linordered_semidom |
db202a00a29c
fixing ennreal using add_mono1; shifting results from linordered_semidom to linordered_nonzero_semiring
paulson <lp15@cam.ac.uk>
parents:
67673
diff
changeset
|
1832 |
begin |
70356
4a327c061870
streamlined setup for linear algebra, particularly removed redundant rule declarations
haftmann
parents:
69700
diff
changeset
|
1833 |
|
67691
db202a00a29c
fixing ennreal using add_mono1; shifting results from linordered_semidom to linordered_nonzero_semiring
paulson <lp15@cam.ac.uk>
parents:
67673
diff
changeset
|
1834 |
subclass linordered_nonzero_semiring .. |
70356
4a327c061870
streamlined setup for linear algebra, particularly removed redundant rule declarations
haftmann
parents:
69700
diff
changeset
|
1835 |
|
67691
db202a00a29c
fixing ennreal using add_mono1; shifting results from linordered_semidom to linordered_nonzero_semiring
paulson <lp15@cam.ac.uk>
parents:
67673
diff
changeset
|
1836 |
subclass semiring_char_0 .. |
70356
4a327c061870
streamlined setup for linear algebra, particularly removed redundant rule declarations
haftmann
parents:
69700
diff
changeset
|
1837 |
|
67691
db202a00a29c
fixing ennreal using add_mono1; shifting results from linordered_semidom to linordered_nonzero_semiring
paulson <lp15@cam.ac.uk>
parents:
67673
diff
changeset
|
1838 |
end |
db202a00a29c
fixing ennreal using add_mono1; shifting results from linordered_semidom to linordered_nonzero_semiring
paulson <lp15@cam.ac.uk>
parents:
67673
diff
changeset
|
1839 |
|
35028
108662d50512
more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
haftmann
parents:
34208
diff
changeset
|
1840 |
context linordered_idom |
26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
1841 |
begin |
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
1842 |
|
70356
4a327c061870
streamlined setup for linear algebra, particularly removed redundant rule declarations
haftmann
parents:
69700
diff
changeset
|
1843 |
lemma abs_of_nat [simp]: |
4a327c061870
streamlined setup for linear algebra, particularly removed redundant rule declarations
haftmann
parents:
69700
diff
changeset
|
1844 |
"\<bar>of_nat n\<bar> = of_nat n" |
4a327c061870
streamlined setup for linear algebra, particularly removed redundant rule declarations
haftmann
parents:
69700
diff
changeset
|
1845 |
by (simp add: abs_if) |
26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
1846 |
|
66816
212a3334e7da
more fundamental definition of div and mod on int
haftmann
parents:
66810
diff
changeset
|
1847 |
lemma sgn_of_nat [simp]: |
212a3334e7da
more fundamental definition of div and mod on int
haftmann
parents:
66810
diff
changeset
|
1848 |
"sgn (of_nat n) = of_bool (n > 0)" |
212a3334e7da
more fundamental definition of div and mod on int
haftmann
parents:
66810
diff
changeset
|
1849 |
by simp |
212a3334e7da
more fundamental definition of div and mod on int
haftmann
parents:
66810
diff
changeset
|
1850 |
|
25193 | 1851 |
end |
1852 |
||
1853 |
lemma of_nat_id [simp]: "of_nat n = n" |
|
35216 | 1854 |
by (induct n) simp_all |
25193 | 1855 |
|
1856 |
lemma of_nat_eq_id [simp]: "of_nat = id" |
|
39302
d7728f65b353
renamed lemmas: ext_iff -> fun_eq_iff, set_ext_iff -> set_eq_iff, set_ext -> set_eqI
nipkow
parents:
39198
diff
changeset
|
1857 |
by (auto simp add: fun_eq_iff) |
25193 | 1858 |
|
1859 |
||
60758 | 1860 |
subsection \<open>The set of natural numbers\<close> |
25193 | 1861 |
|
26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
1862 |
context semiring_1 |
25193 | 1863 |
begin |
1864 |
||
61070 | 1865 |
definition Nats :: "'a set" ("\<nat>") |
1866 |
where "\<nat> = range of_nat" |
|
25193 | 1867 |
|
26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
1868 |
lemma of_nat_in_Nats [simp]: "of_nat n \<in> \<nat>" |
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
1869 |
by (simp add: Nats_def) |
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
1870 |
|
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
1871 |
lemma Nats_0 [simp]: "0 \<in> \<nat>" |
71585 | 1872 |
using of_nat_0 [symmetric] unfolding Nats_def |
1873 |
by (rule range_eqI) |
|
25193 | 1874 |
|
26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
1875 |
lemma Nats_1 [simp]: "1 \<in> \<nat>" |
71585 | 1876 |
using of_nat_1 [symmetric] unfolding Nats_def |
1877 |
by (rule range_eqI) |
|
25193 | 1878 |
|
26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
1879 |
lemma Nats_add [simp]: "a \<in> \<nat> \<Longrightarrow> b \<in> \<nat> \<Longrightarrow> a + b \<in> \<nat>" |
71585 | 1880 |
unfolding Nats_def using of_nat_add [symmetric] |
1881 |
by (blast intro: range_eqI) |
|
26072
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
1882 |
|
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
haftmann
parents:
25928
diff
changeset
|
1883 |
lemma Nats_mult [simp]: "a \<in> \<nat> \<Longrightarrow> b \<in> \<nat> \<Longrightarrow> a * b \<in> \<nat>" |
71585 | 1884 |
unfolding Nats_def using of_nat_mult [symmetric] |
1885 |
by (blast intro: range_eqI) |
|
25193 | 1886 |
|
35633 | 1887 |
lemma Nats_cases [cases set: Nats]: |
1888 |
assumes "x \<in> \<nat>" |
|
1889 |
obtains (of_nat) n where "x = of_nat n" |
|
1890 |
unfolding Nats_def |
|
1891 |
proof - |
|
60758 | 1892 |
from \<open>x \<in> \<nat>\<close> have "x \<in> range of_nat" unfolding Nats_def . |
35633 | 1893 |
then obtain n where "x = of_nat n" .. |
1894 |
then show thesis .. |
|
1895 |
qed |
|
1896 |
||
63588 | 1897 |
lemma Nats_induct [case_names of_nat, induct set: Nats]: "x \<in> \<nat> \<Longrightarrow> (\<And>n. P (of_nat n)) \<Longrightarrow> P x" |
35633 | 1898 |
by (rule Nats_cases) auto |
1899 |
||
25193 | 1900 |
end |
1901 |
||
70365
4df0628e8545
a few new lemmas and a bit of tidying
paulson <lp15@cam.ac.uk>
parents:
70356
diff
changeset
|
1902 |
lemma Nats_diff [simp]: |
4df0628e8545
a few new lemmas and a bit of tidying
paulson <lp15@cam.ac.uk>
parents:
70356
diff
changeset
|
1903 |
fixes a:: "'a::linordered_idom" |
4df0628e8545
a few new lemmas and a bit of tidying
paulson <lp15@cam.ac.uk>
parents:
70356
diff
changeset
|
1904 |
assumes "a \<in> \<nat>" "b \<in> \<nat>" "b \<le> a" shows "a - b \<in> \<nat>" |
4df0628e8545
a few new lemmas and a bit of tidying
paulson <lp15@cam.ac.uk>
parents:
70356
diff
changeset
|
1905 |
proof - |
4df0628e8545
a few new lemmas and a bit of tidying
paulson <lp15@cam.ac.uk>
parents:
70356
diff
changeset
|
1906 |
obtain i where i: "a = of_nat i" |
4df0628e8545
a few new lemmas and a bit of tidying
paulson <lp15@cam.ac.uk>
parents:
70356
diff
changeset
|
1907 |
using Nats_cases assms by blast |
4df0628e8545
a few new lemmas and a bit of tidying
paulson <lp15@cam.ac.uk>
parents:
70356
diff
changeset
|
1908 |
obtain j where j: "b = of_nat j" |
4df0628e8545
a few new lemmas and a bit of tidying
paulson <lp15@cam.ac.uk>
parents:
70356
diff
changeset
|
1909 |
using Nats_cases assms by blast |
4df0628e8545
a few new lemmas and a bit of tidying
paulson <lp15@cam.ac.uk>
parents:
70356
diff
changeset
|
1910 |
have "j \<le> i" |
4df0628e8545
a few new lemmas and a bit of tidying
paulson <lp15@cam.ac.uk>
parents:
70356
diff
changeset
|
1911 |
using \<open>b \<le> a\<close> i j of_nat_le_iff by blast |
4df0628e8545
a few new lemmas and a bit of tidying
paulson <lp15@cam.ac.uk>
parents:
70356
diff
changeset
|
1912 |
then have *: "of_nat i - of_nat j = (of_nat (i-j) :: 'a)" |
4df0628e8545
a few new lemmas and a bit of tidying
paulson <lp15@cam.ac.uk>
parents:
70356
diff
changeset
|
1913 |
by (simp add: of_nat_diff) |
4df0628e8545
a few new lemmas and a bit of tidying
paulson <lp15@cam.ac.uk>
parents:
70356
diff
changeset
|
1914 |
then show ?thesis |
4df0628e8545
a few new lemmas and a bit of tidying
paulson <lp15@cam.ac.uk>
parents:
70356
diff
changeset
|
1915 |
by (simp add: * i j) |
4df0628e8545
a few new lemmas and a bit of tidying
paulson <lp15@cam.ac.uk>
parents:
70356
diff
changeset
|
1916 |
qed |
4df0628e8545
a few new lemmas and a bit of tidying
paulson <lp15@cam.ac.uk>
parents:
70356
diff
changeset
|
1917 |
|
25193 | 1918 |
|
60758 | 1919 |
subsection \<open>Further arithmetic facts concerning the natural numbers\<close> |
21243 | 1920 |
|
22845 | 1921 |
lemma subst_equals: |
63110 | 1922 |
assumes "t = s" and "u = t" |
22845 | 1923 |
shows "u = s" |
63110 | 1924 |
using assms(2,1) by (rule trans) |
22845 | 1925 |
|
70490 | 1926 |
locale nat_arith |
1927 |
begin |
|
1928 |
||
1929 |
lemma add1: "(A::'a::comm_monoid_add) \<equiv> k + a \<Longrightarrow> A + b \<equiv> k + (a + b)" |
|
1930 |
by (simp only: ac_simps) |
|
1931 |
||
1932 |
lemma add2: "(B::'a::comm_monoid_add) \<equiv> k + b \<Longrightarrow> a + B \<equiv> k + (a + b)" |
|
1933 |
by (simp only: ac_simps) |
|
1934 |
||
1935 |
lemma suc1: "A == k + a \<Longrightarrow> Suc A \<equiv> k + Suc a" |
|
1936 |
by (simp only: add_Suc_right) |
|
1937 |
||
1938 |
lemma rule0: "(a::'a::comm_monoid_add) \<equiv> a + 0" |
|
1939 |
by (simp only: add_0_right) |
|
1940 |
||
1941 |
end |
|
1942 |
||
69605 | 1943 |
ML_file \<open>Tools/nat_arith.ML\<close> |
48559
686cc7c47589
give Nat_Arith simprocs proper name bindings by using simproc_setup
huffman
parents:
47988
diff
changeset
|
1944 |
|
686cc7c47589
give Nat_Arith simprocs proper name bindings by using simproc_setup
huffman
parents:
47988
diff
changeset
|
1945 |
simproc_setup nateq_cancel_sums |
686cc7c47589
give Nat_Arith simprocs proper name bindings by using simproc_setup
huffman
parents:
47988
diff
changeset
|
1946 |
("(l::nat) + m = n" | "(l::nat) = m + n" | "Suc m = n" | "m = Suc n") = |
60758 | 1947 |
\<open>fn phi => try o Nat_Arith.cancel_eq_conv\<close> |
48559
686cc7c47589
give Nat_Arith simprocs proper name bindings by using simproc_setup
huffman
parents:
47988
diff
changeset
|
1948 |
|
686cc7c47589
give Nat_Arith simprocs proper name bindings by using simproc_setup
huffman
parents:
47988
diff
changeset
|
1949 |
simproc_setup natless_cancel_sums |
686cc7c47589
give Nat_Arith simprocs proper name bindings by using simproc_setup
huffman
parents:
47988
diff
changeset
|
1950 |
("(l::nat) + m < n" | "(l::nat) < m + n" | "Suc m < n" | "m < Suc n") = |
60758 | 1951 |
\<open>fn phi => try o Nat_Arith.cancel_less_conv\<close> |
48559
686cc7c47589
give Nat_Arith simprocs proper name bindings by using simproc_setup
huffman
parents:
47988
diff
changeset
|
1952 |
|
686cc7c47589
give Nat_Arith simprocs proper name bindings by using simproc_setup
huffman
parents:
47988
diff
changeset
|
1953 |
simproc_setup natle_cancel_sums |
686cc7c47589
give Nat_Arith simprocs proper name bindings by using simproc_setup
huffman
parents:
47988
diff
changeset
|
1954 |
("(l::nat) + m \<le> n" | "(l::nat) \<le> m + n" | "Suc m \<le> n" | "m \<le> Suc n") = |
60758 | 1955 |
\<open>fn phi => try o Nat_Arith.cancel_le_conv\<close> |
48559
686cc7c47589
give Nat_Arith simprocs proper name bindings by using simproc_setup
huffman
parents:
47988
diff
changeset
|
1956 |
|
686cc7c47589
give Nat_Arith simprocs proper name bindings by using simproc_setup
huffman
parents:
47988
diff
changeset
|
1957 |
simproc_setup natdiff_cancel_sums |
686cc7c47589
give Nat_Arith simprocs proper name bindings by using simproc_setup
huffman
parents:
47988
diff
changeset
|
1958 |
("(l::nat) + m - n" | "(l::nat) - (m + n)" | "Suc m - n" | "m - Suc n") = |
60758 | 1959 |
\<open>fn phi => try o Nat_Arith.cancel_diff_conv\<close> |
24091 | 1960 |
|
27625 | 1961 |
context order |
1962 |
begin |
|
1963 |
||
1964 |
lemma lift_Suc_mono_le: |
|
63588 | 1965 |
assumes mono: "\<And>n. f n \<le> f (Suc n)" |
1966 |
and "n \<le> n'" |
|
27627 | 1967 |
shows "f n \<le> f n'" |
1968 |
proof (cases "n < n'") |
|
1969 |
case True |
|
53986 | 1970 |
then show ?thesis |
62683 | 1971 |
by (induct n n' rule: less_Suc_induct) (auto intro: mono) |
63110 | 1972 |
next |
1973 |
case False |
|
1974 |
with \<open>n \<le> n'\<close> show ?thesis by auto |
|
1975 |
qed |
|
27625 | 1976 |
|
56020
f92479477c52
introduced antimono; incseq, decseq are now abbreviations for mono and antimono; renamed Library/Continuity to Library/Order_Continuity; removed up_cont; renamed down_cont to down_continuity and generalized to complete_lattices
hoelzl
parents:
55642
diff
changeset
|
1977 |
lemma lift_Suc_antimono_le: |
63588 | 1978 |
assumes mono: "\<And>n. f n \<ge> f (Suc n)" |
1979 |
and "n \<le> n'" |
|
56020
f92479477c52
introduced antimono; incseq, decseq are now abbreviations for mono and antimono; renamed Library/Continuity to Library/Order_Continuity; removed up_cont; renamed down_cont to down_continuity and generalized to complete_lattices
hoelzl
parents:
55642
diff
changeset
|
1980 |
shows "f n \<ge> f n'" |
f92479477c52
introduced antimono; incseq, decseq are now abbreviations for mono and antimono; renamed Library/Continuity to Library/Order_Continuity; removed up_cont; renamed down_cont to down_continuity and generalized to complete_lattices
hoelzl
parents:
55642
diff
changeset
|
1981 |
proof (cases "n < n'") |
f92479477c52
introduced antimono; incseq, decseq are now abbreviations for mono and antimono; renamed Library/Continuity to Library/Order_Continuity; removed up_cont; renamed down_cont to down_continuity and generalized to complete_lattices
hoelzl
parents:
55642
diff
changeset
|
1982 |
case True |
f92479477c52
introduced antimono; incseq, decseq are now abbreviations for mono and antimono; renamed Library/Continuity to Library/Order_Continuity; removed up_cont; renamed down_cont to down_continuity and generalized to complete_lattices
hoelzl
parents:
55642
diff
changeset
|
1983 |
then show ?thesis |
62683 | 1984 |
by (induct n n' rule: less_Suc_induct) (auto intro: mono) |
63110 | 1985 |
next |
1986 |
case False |
|
1987 |
with \<open>n \<le> n'\<close> show ?thesis by auto |
|
1988 |
qed |
|
56020
f92479477c52
introduced antimono; incseq, decseq are now abbreviations for mono and antimono; renamed Library/Continuity to Library/Order_Continuity; removed up_cont; renamed down_cont to down_continuity and generalized to complete_lattices
hoelzl
parents:
55642
diff
changeset
|
1989 |
|
27625 | 1990 |
lemma lift_Suc_mono_less: |
63588 | 1991 |
assumes mono: "\<And>n. f n < f (Suc n)" |
1992 |
and "n < n'" |
|
27627 | 1993 |
shows "f n < f n'" |
63110 | 1994 |
using \<open>n < n'\<close> by (induct n n' rule: less_Suc_induct) (auto intro: mono) |
1995 |
||
1996 |
lemma lift_Suc_mono_less_iff: "(\<And>n. f n < f (Suc n)) \<Longrightarrow> f n < f m \<longleftrightarrow> n < m" |
|
53986 | 1997 |
by (blast intro: less_asym' lift_Suc_mono_less [of f] |
1998 |
dest: linorder_not_less[THEN iffD1] le_eq_less_or_eq [THEN iffD1]) |
|
27789 | 1999 |
|
27625 | 2000 |
end |
2001 |
||
63110 | 2002 |
lemma mono_iff_le_Suc: "mono f \<longleftrightarrow> (\<forall>n. f n \<le> f (Suc n))" |
37387
3581483cca6c
qualified types "+" and nat; qualified constants Ball, Bex, Suc, curry; modernized some specifications
haftmann
parents:
36977
diff
changeset
|
2003 |
unfolding mono_def by (auto intro: lift_Suc_mono_le [of f]) |
27625 | 2004 |
|
63110 | 2005 |
lemma antimono_iff_le_Suc: "antimono f \<longleftrightarrow> (\<forall>n. f (Suc n) \<le> f n)" |
56020
f92479477c52
introduced antimono; incseq, decseq are now abbreviations for mono and antimono; renamed Library/Continuity to Library/Order_Continuity; removed up_cont; renamed down_cont to down_continuity and generalized to complete_lattices
hoelzl
parents:
55642
diff
changeset
|
2006 |
unfolding antimono_def by (auto intro: lift_Suc_antimono_le [of f]) |
f92479477c52
introduced antimono; incseq, decseq are now abbreviations for mono and antimono; renamed Library/Continuity to Library/Order_Continuity; removed up_cont; renamed down_cont to down_continuity and generalized to complete_lattices
hoelzl
parents:
55642
diff
changeset
|
2007 |
|
27789 | 2008 |
lemma mono_nat_linear_lb: |
53986 | 2009 |
fixes f :: "nat \<Rightarrow> nat" |
2010 |
assumes "\<And>m n. m < n \<Longrightarrow> f m < f n" |
|
2011 |
shows "f m + k \<le> f (m + k)" |
|
2012 |
proof (induct k) |
|
63110 | 2013 |
case 0 |
2014 |
then show ?case by simp |
|
53986 | 2015 |
next |
2016 |
case (Suc k) |
|
2017 |
then have "Suc (f m + k) \<le> Suc (f (m + k))" by simp |
|
2018 |
also from assms [of "m + k" "Suc (m + k)"] have "Suc (f (m + k)) \<le> f (Suc (m + k))" |
|
2019 |
by (simp add: Suc_le_eq) |
|
2020 |
finally show ?case by simp |
|
2021 |
qed |
|
27789 | 2022 |
|
2023 |
||
63110 | 2024 |
text \<open>Subtraction laws, mostly by Clemens Ballarin\<close> |
21243 | 2025 |
|
62481
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
2026 |
lemma diff_less_mono: |
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
2027 |
fixes a b c :: nat |
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
2028 |
assumes "a < b" and "c \<le> a" |
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
2029 |
shows "a - c < b - c" |
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
2030 |
proof - |
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
2031 |
from assms obtain d e where "b = c + (d + e)" and "a = c + e" and "d > 0" |
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
2032 |
by (auto dest!: le_Suc_ex less_imp_Suc_add simp add: ac_simps) |
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
2033 |
then show ?thesis by simp |
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
2034 |
qed |
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
2035 |
|
63588 | 2036 |
lemma less_diff_conv: "i < j - k \<longleftrightarrow> i + k < j" |
2037 |
for i j k :: nat |
|
63110 | 2038 |
by (cases "k \<le> j") (auto simp add: not_le dest: less_imp_Suc_add le_Suc_ex) |
2039 |
||
63588 | 2040 |
lemma less_diff_conv2: "k \<le> j \<Longrightarrow> j - k < i \<longleftrightarrow> j < i + k" |
2041 |
for j k i :: nat |
|
62481
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
2042 |
by (auto dest: le_Suc_ex) |
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
2043 |
|
63588 | 2044 |
lemma le_diff_conv: "j - k \<le> i \<longleftrightarrow> j \<le> i + k" |
2045 |
for j k i :: nat |
|
63110 | 2046 |
by (cases "k \<le> j") (auto simp add: not_le dest!: less_imp_Suc_add le_Suc_ex) |
2047 |
||
63588 | 2048 |
lemma diff_diff_cancel [simp]: "i \<le> n \<Longrightarrow> n - (n - i) = i" |
2049 |
for i n :: nat |
|
63110 | 2050 |
by (auto dest: le_Suc_ex) |
2051 |
||
63588 | 2052 |
lemma diff_less [simp]: "0 < n \<Longrightarrow> 0 < m \<Longrightarrow> m - n < m" |
2053 |
for i n :: nat |
|
62481
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
2054 |
by (auto dest: less_imp_Suc_add) |
21243 | 2055 |
|
60758 | 2056 |
text \<open>Simplification of relational expressions involving subtraction\<close> |
21243 | 2057 |
|
63588 | 2058 |
lemma diff_diff_eq: "k \<le> m \<Longrightarrow> k \<le> n \<Longrightarrow> m - k - (n - k) = m - n" |
2059 |
for m n k :: nat |
|
62481
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
2060 |
by (auto dest!: le_Suc_ex) |
21243 | 2061 |
|
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
|
2062 |
hide_fact (open) diff_diff_eq |
35064
1bdef0c013d3
hide fact names clashing with fact names from Group.thy
haftmann
parents:
35047
diff
changeset
|
2063 |
|
63588 | 2064 |
lemma eq_diff_iff: "k \<le> m \<Longrightarrow> k \<le> n \<Longrightarrow> m - k = n - k \<longleftrightarrow> m = n" |
2065 |
for m n k :: nat |
|
62481
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
2066 |
by (auto dest: le_Suc_ex) |
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
2067 |
|
63588 | 2068 |
lemma less_diff_iff: "k \<le> m \<Longrightarrow> k \<le> n \<Longrightarrow> m - k < n - k \<longleftrightarrow> m < n" |
2069 |
for m n k :: nat |
|
62481
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
2070 |
by (auto dest!: le_Suc_ex) |
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
2071 |
|
63588 | 2072 |
lemma le_diff_iff: "k \<le> m \<Longrightarrow> k \<le> n \<Longrightarrow> m - k \<le> n - k \<longleftrightarrow> m \<le> n" |
2073 |
for m n k :: nat |
|
62481
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
2074 |
by (auto dest!: le_Suc_ex) |
21243 | 2075 |
|
63588 | 2076 |
lemma le_diff_iff': "a \<le> c \<Longrightarrow> b \<le> c \<Longrightarrow> c - a \<le> c - b \<longleftrightarrow> b \<le> a" |
2077 |
for a b c :: nat |
|
63099
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
63040
diff
changeset
|
2078 |
by (force dest: le_Suc_ex) |
63110 | 2079 |
|
2080 |
||
2081 |
text \<open>(Anti)Monotonicity of subtraction -- by Stephan Merz\<close> |
|
2082 |
||
63588 | 2083 |
lemma diff_le_mono: "m \<le> n \<Longrightarrow> m - l \<le> n - l" |
2084 |
for m n l :: nat |
|
63648 | 2085 |
by (auto dest: less_imp_le less_imp_Suc_add split: nat_diff_split) |
62481
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
2086 |
|
63588 | 2087 |
lemma diff_le_mono2: "m \<le> n \<Longrightarrow> l - n \<le> l - m" |
2088 |
for m n l :: nat |
|
63648 | 2089 |
by (auto dest: less_imp_le le_Suc_ex less_imp_Suc_add less_le_trans split: nat_diff_split) |
62481
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
2090 |
|
63588 | 2091 |
lemma diff_less_mono2: "m < n \<Longrightarrow> m < l \<Longrightarrow> l - n < l - m" |
2092 |
for m n l :: nat |
|
63648 | 2093 |
by (auto dest: less_imp_Suc_add split: nat_diff_split) |
62481
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
2094 |
|
63588 | 2095 |
lemma diffs0_imp_equal: "m - n = 0 \<Longrightarrow> n - m = 0 \<Longrightarrow> m = n" |
2096 |
for m n :: nat |
|
63648 | 2097 |
by (simp split: nat_diff_split) |
62481
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
2098 |
|
63588 | 2099 |
lemma min_diff: "min (m - i) (n - i) = min m n - i" |
2100 |
for m n i :: nat |
|
62481
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
2101 |
by (cases m n rule: le_cases) |
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
2102 |
(auto simp add: not_le min.absorb1 min.absorb2 min.absorb_iff1 [symmetric] diff_le_mono) |
26143
314c0bcb7df7
Added useful general lemmas from the work with the HeapMonad
bulwahn
parents:
26101
diff
changeset
|
2103 |
|
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
|
2104 |
lemma inj_on_diff_nat: |
63110 | 2105 |
fixes k :: nat |
68618
3db8520941a4
de-applying (mostly Set_Interval)
paulson <lp15@cam.ac.uk>
parents:
68610
diff
changeset
|
2106 |
assumes "\<And>n. n \<in> N \<Longrightarrow> k \<le> n" |
26143
314c0bcb7df7
Added useful general lemmas from the work with the HeapMonad
bulwahn
parents:
26101
diff
changeset
|
2107 |
shows "inj_on (\<lambda>n. n - k) N" |
314c0bcb7df7
Added useful general lemmas from the work with the HeapMonad
bulwahn
parents:
26101
diff
changeset
|
2108 |
proof (rule inj_onI) |
314c0bcb7df7
Added useful general lemmas from the work with the HeapMonad
bulwahn
parents:
26101
diff
changeset
|
2109 |
fix x y |
314c0bcb7df7
Added useful general lemmas from the work with the HeapMonad
bulwahn
parents:
26101
diff
changeset
|
2110 |
assume a: "x \<in> N" "y \<in> N" "x - k = y - k" |
63110 | 2111 |
with assms have "x - k + k = y - k + k" by auto |
2112 |
with a assms show "x = y" by (auto simp add: eq_diff_iff) |
|
26143
314c0bcb7df7
Added useful general lemmas from the work with the HeapMonad
bulwahn
parents:
26101
diff
changeset
|
2113 |
qed |
314c0bcb7df7
Added useful general lemmas from the work with the HeapMonad
bulwahn
parents:
26101
diff
changeset
|
2114 |
|
63110 | 2115 |
text \<open>Rewriting to pull differences out\<close> |
2116 |
||
63588 | 2117 |
lemma diff_diff_right [simp]: "k \<le> j \<Longrightarrow> i - (j - k) = i + k - j" |
2118 |
for i j k :: nat |
|
62481
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
2119 |
by (fact diff_diff_right) |
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
2120 |
|
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
2121 |
lemma diff_Suc_diff_eq1 [simp]: |
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
2122 |
assumes "k \<le> j" |
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
2123 |
shows "i - Suc (j - k) = i + k - Suc j" |
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
2124 |
proof - |
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
2125 |
from assms have *: "Suc (j - k) = Suc j - k" |
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
2126 |
by (simp add: Suc_diff_le) |
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
2127 |
from assms have "k \<le> Suc j" |
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
2128 |
by (rule order_trans) simp |
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
2129 |
with diff_diff_right [of k "Suc j" i] * show ?thesis |
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
2130 |
by simp |
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
2131 |
qed |
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
2132 |
|
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
2133 |
lemma diff_Suc_diff_eq2 [simp]: |
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
2134 |
assumes "k \<le> j" |
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
2135 |
shows "Suc (j - k) - i = Suc j - (k + i)" |
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
2136 |
proof - |
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
2137 |
from assms obtain n where "j = k + n" |
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
2138 |
by (auto dest: le_Suc_ex) |
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
2139 |
moreover have "Suc n - i = (k + Suc n) - (k + i)" |
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
2140 |
using add_diff_cancel_left [of k "Suc n" i] by simp |
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
2141 |
ultimately show ?thesis by simp |
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
2142 |
qed |
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
2143 |
|
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
2144 |
lemma Suc_diff_Suc: |
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
2145 |
assumes "n < m" |
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
2146 |
shows "Suc (m - Suc n) = m - n" |
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
2147 |
proof - |
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
2148 |
from assms obtain q where "m = n + Suc q" |
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
2149 |
by (auto dest: less_imp_Suc_add) |
63040 | 2150 |
moreover define r where "r = Suc q" |
62481
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
2151 |
ultimately have "Suc (m - Suc n) = r" and "m = n + r" |
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
2152 |
by simp_all |
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
2153 |
then show ?thesis by simp |
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
2154 |
qed |
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
2155 |
|
63110 | 2156 |
lemma one_less_mult: "Suc 0 < n \<Longrightarrow> Suc 0 < m \<Longrightarrow> Suc 0 < m * n" |
62481
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
2157 |
using less_1_mult [of n m] by (simp add: ac_simps) |
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
2158 |
|
63110 | 2159 |
lemma n_less_m_mult_n: "0 < n \<Longrightarrow> Suc 0 < m \<Longrightarrow> n < m * n" |
62481
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
2160 |
using mult_strict_right_mono [of 1 m n] by simp |
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
2161 |
|
63110 | 2162 |
lemma n_less_n_mult_m: "0 < n \<Longrightarrow> Suc 0 < m \<Longrightarrow> n < n * m" |
62481
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
2163 |
using mult_strict_left_mono [of 1 m n] by simp |
21243 | 2164 |
|
63110 | 2165 |
|
67050 | 2166 |
text \<open>Induction starting beyond zero\<close> |
2167 |
||
2168 |
lemma nat_induct_at_least [consumes 1, case_names base Suc]: |
|
2169 |
"P n" if "n \<ge> m" "P m" "\<And>n. n \<ge> m \<Longrightarrow> P n \<Longrightarrow> P (Suc n)" |
|
2170 |
proof - |
|
2171 |
define q where "q = n - m" |
|
2172 |
with \<open>n \<ge> m\<close> have "n = m + q" |
|
2173 |
by simp |
|
2174 |
moreover have "P (m + q)" |
|
2175 |
by (induction q) (use that in simp_all) |
|
2176 |
ultimately show "P n" |
|
2177 |
by simp |
|
2178 |
qed |
|
2179 |
||
2180 |
lemma nat_induct_non_zero [consumes 1, case_names 1 Suc]: |
|
2181 |
"P n" if "n > 0" "P 1" "\<And>n. n > 0 \<Longrightarrow> P n \<Longrightarrow> P (Suc n)" |
|
2182 |
proof - |
|
2183 |
from \<open>n > 0\<close> have "n \<ge> 1" |
|
2184 |
by (cases n) simp_all |
|
2185 |
moreover note \<open>P 1\<close> |
|
2186 |
moreover have "\<And>n. n \<ge> 1 \<Longrightarrow> P n \<Longrightarrow> P (Suc n)" |
|
2187 |
using \<open>\<And>n. n > 0 \<Longrightarrow> P n \<Longrightarrow> P (Suc n)\<close> |
|
2188 |
by (simp add: Suc_le_eq) |
|
2189 |
ultimately show "P n" |
|
2190 |
by (rule nat_induct_at_least) |
|
2191 |
qed |
|
2192 |
||
2193 |
||
60758 | 2194 |
text \<open>Specialized induction principles that work "backwards":\<close> |
23001
3608f0362a91
added induction principles for induction "backwards": P (Suc n) ==> P n
krauss
parents:
22920
diff
changeset
|
2195 |
|
62481
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
2196 |
lemma inc_induct [consumes 1, case_names base step]: |
54411 | 2197 |
assumes less: "i \<le> j" |
63110 | 2198 |
and base: "P j" |
2199 |
and step: "\<And>n. i \<le> n \<Longrightarrow> n < j \<Longrightarrow> P (Suc n) \<Longrightarrow> P n" |
|
23001
3608f0362a91
added induction principles for induction "backwards": P (Suc n) ==> P n
krauss
parents:
22920
diff
changeset
|
2200 |
shows "P i" |
54411 | 2201 |
using less step |
62481
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
2202 |
proof (induct "j - i" arbitrary: i) |
23001
3608f0362a91
added induction principles for induction "backwards": P (Suc n) ==> P n
krauss
parents:
22920
diff
changeset
|
2203 |
case (0 i) |
62481
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
2204 |
then have "i = j" by simp |
23001
3608f0362a91
added induction principles for induction "backwards": P (Suc n) ==> P n
krauss
parents:
22920
diff
changeset
|
2205 |
with base show ?case by simp |
3608f0362a91
added induction principles for induction "backwards": P (Suc n) ==> P n
krauss
parents:
22920
diff
changeset
|
2206 |
next |
54411 | 2207 |
case (Suc d n) |
62481
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
2208 |
from Suc.hyps have "n \<noteq> j" by auto |
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
2209 |
with Suc have "n < j" by (simp add: less_le) |
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
2210 |
from \<open>Suc d = j - n\<close> have "d + 1 = j - n" by simp |
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
2211 |
then have "d + 1 - 1 = j - n - 1" by simp |
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
2212 |
then have "d = j - n - 1" by simp |
63588 | 2213 |
then have "d = j - (n + 1)" by (simp add: diff_diff_eq) |
2214 |
then have "d = j - Suc n" by simp |
|
2215 |
moreover from \<open>n < j\<close> have "Suc n \<le> j" by (simp add: Suc_le_eq) |
|
62481
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
2216 |
ultimately have "P (Suc n)" |
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
2217 |
proof (rule Suc.hyps) |
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
2218 |
fix q |
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
2219 |
assume "Suc n \<le> q" |
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
2220 |
then have "n \<le> q" by (simp add: Suc_le_eq less_imp_le) |
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
2221 |
moreover assume "q < j" |
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
2222 |
moreover assume "P (Suc q)" |
63588 | 2223 |
ultimately show "P q" by (rule Suc.prems) |
62481
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
2224 |
qed |
63588 | 2225 |
with order_refl \<open>n < j\<close> show "P n" by (rule Suc.prems) |
23001
3608f0362a91
added induction principles for induction "backwards": P (Suc n) ==> P n
krauss
parents:
22920
diff
changeset
|
2226 |
qed |
63110 | 2227 |
|
62481
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
2228 |
lemma strict_inc_induct [consumes 1, case_names base step]: |
23001
3608f0362a91
added induction principles for induction "backwards": P (Suc n) ==> P n
krauss
parents:
22920
diff
changeset
|
2229 |
assumes less: "i < j" |
63110 | 2230 |
and base: "\<And>i. j = Suc i \<Longrightarrow> P i" |
2231 |
and step: "\<And>i. i < j \<Longrightarrow> P (Suc i) \<Longrightarrow> P i" |
|
23001
3608f0362a91
added induction principles for induction "backwards": P (Suc n) ==> P n
krauss
parents:
22920
diff
changeset
|
2232 |
shows "P i" |
62481
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
2233 |
using less proof (induct "j - i - 1" arbitrary: i) |
23001
3608f0362a91
added induction principles for induction "backwards": P (Suc n) ==> P n
krauss
parents:
22920
diff
changeset
|
2234 |
case (0 i) |
62481
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
2235 |
from \<open>i < j\<close> obtain n where "j = i + n" and "n > 0" |
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
2236 |
by (auto dest!: less_imp_Suc_add) |
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
2237 |
with 0 have "j = Suc i" |
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
2238 |
by (auto intro: order_antisym simp add: Suc_le_eq) |
23001
3608f0362a91
added induction principles for induction "backwards": P (Suc n) ==> P n
krauss
parents:
22920
diff
changeset
|
2239 |
with base show ?case by simp |
3608f0362a91
added induction principles for induction "backwards": P (Suc n) ==> P n
krauss
parents:
22920
diff
changeset
|
2240 |
next |
3608f0362a91
added induction principles for induction "backwards": P (Suc n) ==> P n
krauss
parents:
22920
diff
changeset
|
2241 |
case (Suc d i) |
62481
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
2242 |
from \<open>Suc d = j - i - 1\<close> have *: "Suc d = j - Suc i" |
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
2243 |
by (simp add: diff_diff_add) |
63588 | 2244 |
then have "Suc d - 1 = j - Suc i - 1" by simp |
2245 |
then have "d = j - Suc i - 1" by simp |
|
2246 |
moreover from * have "j - Suc i \<noteq> 0" by auto |
|
2247 |
then have "Suc i < j" by (simp add: not_le) |
|
2248 |
ultimately have "P (Suc i)" by (rule Suc.hyps) |
|
62481
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
2249 |
with \<open>i < j\<close> show "P i" by (rule step) |
23001
3608f0362a91
added induction principles for induction "backwards": P (Suc n) ==> P n
krauss
parents:
22920
diff
changeset
|
2250 |
qed |
3608f0362a91
added induction principles for induction "backwards": P (Suc n) ==> P n
krauss
parents:
22920
diff
changeset
|
2251 |
|
63110 | 2252 |
lemma zero_induct_lemma: "P k \<Longrightarrow> (\<And>n. P (Suc n) \<Longrightarrow> P n) \<Longrightarrow> P (k - i)" |
23001
3608f0362a91
added induction principles for induction "backwards": P (Suc n) ==> P n
krauss
parents:
22920
diff
changeset
|
2253 |
using inc_induct[of "k - i" k P, simplified] by blast |
3608f0362a91
added induction principles for induction "backwards": P (Suc n) ==> P n
krauss
parents:
22920
diff
changeset
|
2254 |
|
63110 | 2255 |
lemma zero_induct: "P k \<Longrightarrow> (\<And>n. P (Suc n) \<Longrightarrow> P n) \<Longrightarrow> P 0" |
23001
3608f0362a91
added induction principles for induction "backwards": P (Suc n) ==> P n
krauss
parents:
22920
diff
changeset
|
2256 |
using inc_induct[of 0 k P] by blast |
21243 | 2257 |
|
63588 | 2258 |
text \<open>Further induction rule similar to @{thm inc_induct}.\<close> |
27625 | 2259 |
|
62481
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
2260 |
lemma dec_induct [consumes 1, case_names base step]: |
54411 | 2261 |
"i \<le> j \<Longrightarrow> P i \<Longrightarrow> (\<And>n. i \<le> n \<Longrightarrow> n < j \<Longrightarrow> P n \<Longrightarrow> P (Suc n)) \<Longrightarrow> P j" |
62481
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
2262 |
proof (induct j arbitrary: i) |
63110 | 2263 |
case 0 |
2264 |
then show ?case by simp |
|
62481
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
2265 |
next |
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
2266 |
case (Suc j) |
63110 | 2267 |
from Suc.prems consider "i \<le> j" | "i = Suc j" |
2268 |
by (auto simp add: le_Suc_eq) |
|
2269 |
then show ?case |
|
2270 |
proof cases |
|
2271 |
case 1 |
|
62481
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
2272 |
moreover have "j < Suc j" by simp |
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
2273 |
moreover have "P j" using \<open>i \<le> j\<close> \<open>P i\<close> |
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
2274 |
proof (rule Suc.hyps) |
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
2275 |
fix q |
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
2276 |
assume "i \<le> q" |
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
2277 |
moreover assume "q < j" then have "q < Suc j" |
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
2278 |
by (simp add: less_Suc_eq) |
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
2279 |
moreover assume "P q" |
63588 | 2280 |
ultimately show "P (Suc q)" by (rule Suc.prems) |
62481
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
2281 |
qed |
63588 | 2282 |
ultimately show "P (Suc j)" by (rule Suc.prems) |
62481
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
2283 |
next |
63110 | 2284 |
case 2 |
62481
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
2285 |
with \<open>P i\<close> show "P (Suc j)" by simp |
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
2286 |
qed |
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
2287 |
qed |
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
2288 |
|
66295
1ec601d9c829
moved transitive_stepwise_le into Nat, where it belongs
paulson <lp15@cam.ac.uk>
parents:
66290
diff
changeset
|
2289 |
lemma transitive_stepwise_le: |
1ec601d9c829
moved transitive_stepwise_le into Nat, where it belongs
paulson <lp15@cam.ac.uk>
parents:
66290
diff
changeset
|
2290 |
assumes "m \<le> n" "\<And>x. R x x" "\<And>x y z. R x y \<Longrightarrow> R y z \<Longrightarrow> R x z" and "\<And>n. R n (Suc n)" |
1ec601d9c829
moved transitive_stepwise_le into Nat, where it belongs
paulson <lp15@cam.ac.uk>
parents:
66290
diff
changeset
|
2291 |
shows "R m n" |
1ec601d9c829
moved transitive_stepwise_le into Nat, where it belongs
paulson <lp15@cam.ac.uk>
parents:
66290
diff
changeset
|
2292 |
using \<open>m \<le> n\<close> |
1ec601d9c829
moved transitive_stepwise_le into Nat, where it belongs
paulson <lp15@cam.ac.uk>
parents:
66290
diff
changeset
|
2293 |
by (induction rule: dec_induct) (use assms in blast)+ |
1ec601d9c829
moved transitive_stepwise_le into Nat, where it belongs
paulson <lp15@cam.ac.uk>
parents:
66290
diff
changeset
|
2294 |
|
59000 | 2295 |
|
65963 | 2296 |
subsubsection \<open>Greatest operator\<close> |
2297 |
||
2298 |
lemma ex_has_greatest_nat: |
|
2299 |
"P (k::nat) \<Longrightarrow> \<forall>y. P y \<longrightarrow> y \<le> b \<Longrightarrow> \<exists>x. P x \<and> (\<forall>y. P y \<longrightarrow> y \<le> x)" |
|
2300 |
proof (induction "b-k" arbitrary: b k rule: less_induct) |
|
2301 |
case less |
|
2302 |
show ?case |
|
2303 |
proof cases |
|
2304 |
assume "\<exists>n>k. P n" |
|
2305 |
then obtain n where "n>k" "P n" by blast |
|
2306 |
have "n \<le> b" using \<open>P n\<close> less.prems(2) by auto |
|
2307 |
hence "b-n < b-k" |
|
2308 |
by(rule diff_less_mono2[OF \<open>k<n\<close> less_le_trans[OF \<open>k<n\<close>]]) |
|
2309 |
from less.hyps[OF this \<open>P n\<close> less.prems(2)] |
|
2310 |
show ?thesis . |
|
2311 |
next |
|
2312 |
assume "\<not> (\<exists>n>k. P n)" |
|
2313 |
hence "\<forall>y. P y \<longrightarrow> y \<le> k" by (auto simp: not_less) |
|
2314 |
thus ?thesis using less.prems(1) by auto |
|
2315 |
qed |
|
2316 |
qed |
|
2317 |
||
71585 | 2318 |
lemma |
2319 |
fixes k::nat |
|
2320 |
assumes "P k" and minor: "\<And>y. P y \<Longrightarrow> y \<le> b" |
|
2321 |
shows GreatestI_nat: "P (Greatest P)" |
|
2322 |
and Greatest_le_nat: "k \<le> Greatest P" |
|
2323 |
proof - |
|
2324 |
obtain x where "P x" "\<And>y. P y \<Longrightarrow> y \<le> x" |
|
2325 |
using assms ex_has_greatest_nat by blast |
|
2326 |
with \<open>P k\<close> show "P (Greatest P)" "k \<le> Greatest P" |
|
2327 |
using GreatestI2_order by blast+ |
|
2328 |
qed |
|
65963 | 2329 |
|
65965 | 2330 |
lemma GreatestI_ex_nat: |
71585 | 2331 |
"\<lbrakk> \<exists>k::nat. P k; \<And>y. P y \<Longrightarrow> y \<le> b \<rbrakk> \<Longrightarrow> P (Greatest P)" |
2332 |
by (blast intro: GreatestI_nat) |
|
65963 | 2333 |
|
2334 |
||
63110 | 2335 |
subsection \<open>Monotonicity of \<open>funpow\<close>\<close> |
59000 | 2336 |
|
63588 | 2337 |
lemma funpow_increasing: "m \<le> n \<Longrightarrow> mono f \<Longrightarrow> (f ^^ n) \<top> \<le> (f ^^ m) \<top>" |
2338 |
for f :: "'a::{lattice,order_top} \<Rightarrow> 'a" |
|
59000 | 2339 |
by (induct rule: inc_induct) |
63588 | 2340 |
(auto simp del: funpow.simps(2) simp add: funpow_Suc_right |
2341 |
intro: order_trans[OF _ funpow_mono]) |
|
2342 |
||
2343 |
lemma funpow_decreasing: "m \<le> n \<Longrightarrow> mono f \<Longrightarrow> (f ^^ m) \<bottom> \<le> (f ^^ n) \<bottom>" |
|
2344 |
for f :: "'a::{lattice,order_bot} \<Rightarrow> 'a" |
|
59000 | 2345 |
by (induct rule: dec_induct) |
63588 | 2346 |
(auto simp del: funpow.simps(2) simp add: funpow_Suc_right |
2347 |
intro: order_trans[OF _ funpow_mono]) |
|
2348 |
||
2349 |
lemma mono_funpow: "mono Q \<Longrightarrow> mono (\<lambda>i. (Q ^^ i) \<bottom>)" |
|
2350 |
for Q :: "'a::{lattice,order_bot} \<Rightarrow> 'a" |
|
59000 | 2351 |
by (auto intro!: funpow_decreasing simp: mono_def) |
58377
c6f93b8d2d8e
moved old 'size' generator together with 'old_datatype'
blanchet
parents:
58306
diff
changeset
|
2352 |
|
63588 | 2353 |
lemma antimono_funpow: "mono Q \<Longrightarrow> antimono (\<lambda>i. (Q ^^ i) \<top>)" |
2354 |
for Q :: "'a::{lattice,order_top} \<Rightarrow> 'a" |
|
60175 | 2355 |
by (auto intro!: funpow_increasing simp: antimono_def) |
2356 |
||
63110 | 2357 |
|
69593 | 2358 |
subsection \<open>The divides relation on \<^typ>\<open>nat\<close>\<close> |
33274
b6ff7db522b5
moved lemmas for dvd on nat to theories Nat and Power
haftmann
parents:
32772
diff
changeset
|
2359 |
|
63110 | 2360 |
lemma dvd_1_left [iff]: "Suc 0 dvd k" |
62365 | 2361 |
by (simp add: dvd_def) |
2362 |
||
63110 | 2363 |
lemma dvd_1_iff_1 [simp]: "m dvd Suc 0 \<longleftrightarrow> m = Suc 0" |
62365 | 2364 |
by (simp add: dvd_def) |
2365 |
||
63588 | 2366 |
lemma nat_dvd_1_iff_1 [simp]: "m dvd 1 \<longleftrightarrow> m = 1" |
2367 |
for m :: nat |
|
62365 | 2368 |
by (simp add: dvd_def) |
2369 |
||
63588 | 2370 |
lemma dvd_antisym: "m dvd n \<Longrightarrow> n dvd m \<Longrightarrow> m = n" |
2371 |
for m n :: nat |
|
63110 | 2372 |
unfolding dvd_def by (force dest: mult_eq_self_implies_10 simp add: mult.assoc) |
2373 |
||
63588 | 2374 |
lemma dvd_diff_nat [simp]: "k dvd m \<Longrightarrow> k dvd n \<Longrightarrow> k dvd (m - n)" |
2375 |
for k m n :: nat |
|
63110 | 2376 |
unfolding dvd_def by (blast intro: right_diff_distrib' [symmetric]) |
2377 |
||
71585 | 2378 |
lemma dvd_diffD: |
2379 |
fixes k m n :: nat |
|
2380 |
assumes "k dvd m - n" "k dvd n" "n \<le> m" |
|
2381 |
shows "k dvd m" |
|
2382 |
proof - |
|
2383 |
have "k dvd n + (m - n)" |
|
2384 |
using assms by (blast intro: dvd_add) |
|
2385 |
with assms show ?thesis |
|
2386 |
by simp |
|
2387 |
qed |
|
33274
b6ff7db522b5
moved lemmas for dvd on nat to theories Nat and Power
haftmann
parents:
32772
diff
changeset
|
2388 |
|
63588 | 2389 |
lemma dvd_diffD1: "k dvd m - n \<Longrightarrow> k dvd m \<Longrightarrow> n \<le> m \<Longrightarrow> k dvd n" |
2390 |
for k m n :: nat |
|
62365 | 2391 |
by (drule_tac m = m in dvd_diff_nat) auto |
2392 |
||
2393 |
lemma dvd_mult_cancel: |
|
2394 |
fixes m n k :: nat |
|
2395 |
assumes "k * m dvd k * n" and "0 < k" |
|
2396 |
shows "m dvd n" |
|
2397 |
proof - |
|
2398 |
from assms(1) obtain q where "k * n = (k * m) * q" .. |
|
2399 |
then have "k * n = k * (m * q)" by (simp add: ac_simps) |
|
62481
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
2400 |
with \<open>0 < k\<close> have "n = m * q" by (auto simp add: mult_left_cancel) |
62365 | 2401 |
then show ?thesis .. |
2402 |
qed |
|
63110 | 2403 |
|
71585 | 2404 |
lemma dvd_mult_cancel1: |
2405 |
fixes m n :: nat |
|
2406 |
assumes "0 < m" |
|
2407 |
shows "m * n dvd m \<longleftrightarrow> n = 1" |
|
2408 |
proof |
|
2409 |
assume "m * n dvd m" |
|
2410 |
then have "m * n dvd m * 1" |
|
2411 |
by simp |
|
2412 |
then have "n dvd 1" |
|
2413 |
by (iprover intro: assms dvd_mult_cancel) |
|
2414 |
then show "n = 1" |
|
2415 |
by auto |
|
2416 |
qed auto |
|
33274
b6ff7db522b5
moved lemmas for dvd on nat to theories Nat and Power
haftmann
parents:
32772
diff
changeset
|
2417 |
|
63588 | 2418 |
lemma dvd_mult_cancel2: "0 < m \<Longrightarrow> n * m dvd m \<longleftrightarrow> n = 1" |
2419 |
for m n :: nat |
|
62365 | 2420 |
using dvd_mult_cancel1 [of m n] by (simp add: ac_simps) |
2421 |
||
63588 | 2422 |
lemma dvd_imp_le: "k dvd n \<Longrightarrow> 0 < n \<Longrightarrow> k \<le> n" |
2423 |
for k n :: nat |
|
62365 | 2424 |
by (auto elim!: dvdE) (auto simp add: gr0_conv_Suc) |
33274
b6ff7db522b5
moved lemmas for dvd on nat to theories Nat and Power
haftmann
parents:
32772
diff
changeset
|
2425 |
|
63588 | 2426 |
lemma nat_dvd_not_less: "0 < m \<Longrightarrow> m < n \<Longrightarrow> \<not> n dvd m" |
2427 |
for m n :: nat |
|
62365 | 2428 |
by (auto elim!: dvdE) (auto simp add: gr0_conv_Suc) |
33274
b6ff7db522b5
moved lemmas for dvd on nat to theories Nat and Power
haftmann
parents:
32772
diff
changeset
|
2429 |
|
54222 | 2430 |
lemma less_eq_dvd_minus: |
51173 | 2431 |
fixes m n :: nat |
54222 | 2432 |
assumes "m \<le> n" |
2433 |
shows "m dvd n \<longleftrightarrow> m dvd n - m" |
|
51173 | 2434 |
proof - |
54222 | 2435 |
from assms have "n = m + (n - m)" by simp |
51173 | 2436 |
then obtain q where "n = m + q" .. |
58647 | 2437 |
then show ?thesis by (simp add: add.commute [of m]) |
51173 | 2438 |
qed |
2439 |
||
63588 | 2440 |
lemma dvd_minus_self: "m dvd n - m \<longleftrightarrow> n < m \<or> m dvd n" |
2441 |
for m n :: nat |
|
62481
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents:
62378
diff
changeset
|
2442 |
by (cases "n < m") (auto elim!: dvdE simp add: not_less le_imp_diff_is_add dest: less_imp_le) |
51173 | 2443 |
|
2444 |
lemma dvd_minus_add: |
|
2445 |
fixes m n q r :: nat |
|
2446 |
assumes "q \<le> n" "q \<le> r * m" |
|
2447 |
shows "m dvd n - q \<longleftrightarrow> m dvd n + (r * m - q)" |
|
2448 |
proof - |
|
2449 |
have "m dvd n - q \<longleftrightarrow> m dvd r * m + (n - q)" |
|
58649
a62065b5e1e2
generalized and consolidated some theorems concerning divisibility
haftmann
parents:
58647
diff
changeset
|
2450 |
using dvd_add_times_triv_left_iff [of m r] by simp |
53374
a14d2a854c02
tuned proofs -- clarified flow of facts wrt. calculation;
wenzelm
parents:
52729
diff
changeset
|
2451 |
also from assms have "\<dots> \<longleftrightarrow> m dvd r * m + n - q" by simp |
a14d2a854c02
tuned proofs -- clarified flow of facts wrt. calculation;
wenzelm
parents:
52729
diff
changeset
|
2452 |
also from assms have "\<dots> \<longleftrightarrow> m dvd (r * m - q) + n" by simp |
57512
cc97b347b301
reduced name variants for assoc and commute on plus and mult
haftmann
parents:
57492
diff
changeset
|
2453 |
also have "\<dots> \<longleftrightarrow> m dvd n + (r * m - q)" by (simp add: add.commute) |
51173 | 2454 |
finally show ?thesis . |
2455 |
qed |
|
2456 |
||
33274
b6ff7db522b5
moved lemmas for dvd on nat to theories Nat and Power
haftmann
parents:
32772
diff
changeset
|
2457 |
|
62365 | 2458 |
subsection \<open>Aliasses\<close> |
44817 | 2459 |
|
63588 | 2460 |
lemma nat_mult_1: "1 * n = n" |
2461 |
for n :: nat |
|
58647 | 2462 |
by (fact mult_1_left) |
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
|
2463 |
|
63588 | 2464 |
lemma nat_mult_1_right: "n * 1 = n" |
2465 |
for n :: nat |
|
58647 | 2466 |
by (fact mult_1_right) |
71588
f3fe59e61f3d
put back Nat.le_diff_conv2 because AUTO2 doesn't work with Groups.le_diff_conv2
paulson <lp15@cam.ac.uk>
parents:
71585
diff
changeset
|
2467 |
|
63588 | 2468 |
lemma diff_mult_distrib: "(m - n) * k = (m * k) - (n * k)" |
2469 |
for k m n :: nat |
|
62365 | 2470 |
by (fact left_diff_distrib') |
2471 |
||
63588 | 2472 |
lemma diff_mult_distrib2: "k * (m - n) = (k * m) - (k * n)" |
2473 |
for k m n :: nat |
|
62365 | 2474 |
by (fact right_diff_distrib') |
2475 |
||
71588
f3fe59e61f3d
put back Nat.le_diff_conv2 because AUTO2 doesn't work with Groups.le_diff_conv2
paulson <lp15@cam.ac.uk>
parents:
71585
diff
changeset
|
2476 |
(*Used in AUTO2 and Groups.le_diff_conv2 (with variables renamed) doesn't work for some reason*) |
f3fe59e61f3d
put back Nat.le_diff_conv2 because AUTO2 doesn't work with Groups.le_diff_conv2
paulson <lp15@cam.ac.uk>
parents:
71585
diff
changeset
|
2477 |
lemma le_diff_conv2: "k \<le> j \<Longrightarrow> (i \<le> j - k) = (i + k \<le> j)" |
f3fe59e61f3d
put back Nat.le_diff_conv2 because AUTO2 doesn't work with Groups.le_diff_conv2
paulson <lp15@cam.ac.uk>
parents:
71585
diff
changeset
|
2478 |
for i j k :: nat |
f3fe59e61f3d
put back Nat.le_diff_conv2 because AUTO2 doesn't work with Groups.le_diff_conv2
paulson <lp15@cam.ac.uk>
parents:
71585
diff
changeset
|
2479 |
by (fact le_diff_conv2) |
f3fe59e61f3d
put back Nat.le_diff_conv2 because AUTO2 doesn't work with Groups.le_diff_conv2
paulson <lp15@cam.ac.uk>
parents:
71585
diff
changeset
|
2480 |
|
63588 | 2481 |
lemma diff_self_eq_0 [simp]: "m - m = 0" |
2482 |
for m :: nat |
|
62365 | 2483 |
by (fact diff_cancel) |
2484 |
||
63588 | 2485 |
lemma diff_diff_left [simp]: "i - j - k = i - (j + k)" |
2486 |
for i j k :: nat |
|
62365 | 2487 |
by (fact diff_diff_add) |
2488 |
||
63588 | 2489 |
lemma diff_commute: "i - j - k = i - k - j" |
2490 |
for i j k :: nat |
|
62365 | 2491 |
by (fact diff_right_commute) |
2492 |
||
63588 | 2493 |
lemma diff_add_inverse: "(n + m) - n = m" |
2494 |
for m n :: nat |
|
62365 | 2495 |
by (fact add_diff_cancel_left') |
2496 |
||
63588 | 2497 |
lemma diff_add_inverse2: "(m + n) - n = m" |
2498 |
for m n :: nat |
|
62365 | 2499 |
by (fact add_diff_cancel_right') |
2500 |
||
63588 | 2501 |
lemma diff_cancel: "(k + m) - (k + n) = m - n" |
2502 |
for k m n :: nat |
|
62365 | 2503 |
by (fact add_diff_cancel_left) |
2504 |
||
63588 | 2505 |
lemma diff_cancel2: "(m + k) - (n + k) = m - n" |
2506 |
for k m n :: nat |
|
62365 | 2507 |
by (fact add_diff_cancel_right) |
2508 |
||
63588 | 2509 |
lemma diff_add_0: "n - (n + m) = 0" |
2510 |
for m n :: nat |
|
62365 | 2511 |
by (fact diff_add_zero) |
2512 |
||
63588 | 2513 |
lemma add_mult_distrib2: "k * (m + n) = (k * m) + (k * n)" |
2514 |
for k m n :: nat |
|
62365 | 2515 |
by (fact distrib_left) |
2516 |
||
2517 |
lemmas nat_distrib = |
|
2518 |
add_mult_distrib distrib_left diff_mult_distrib diff_mult_distrib2 |
|
2519 |
||
44817 | 2520 |
|
60758 | 2521 |
subsection \<open>Size of a datatype value\<close> |
25193 | 2522 |
|
29608 | 2523 |
class size = |
61799 | 2524 |
fixes size :: "'a \<Rightarrow> nat" \<comment> \<open>see further theory \<open>Wellfounded\<close>\<close> |
23852 | 2525 |
|
58377
c6f93b8d2d8e
moved old 'size' generator together with 'old_datatype'
blanchet
parents:
58306
diff
changeset
|
2526 |
instantiation nat :: size |
c6f93b8d2d8e
moved old 'size' generator together with 'old_datatype'
blanchet
parents:
58306
diff
changeset
|
2527 |
begin |
c6f93b8d2d8e
moved old 'size' generator together with 'old_datatype'
blanchet
parents:
58306
diff
changeset
|
2528 |
|
63110 | 2529 |
definition size_nat where [simp, code]: "size (n::nat) = n" |
58377
c6f93b8d2d8e
moved old 'size' generator together with 'old_datatype'
blanchet
parents:
58306
diff
changeset
|
2530 |
|
c6f93b8d2d8e
moved old 'size' generator together with 'old_datatype'
blanchet
parents:
58306
diff
changeset
|
2531 |
instance .. |
c6f93b8d2d8e
moved old 'size' generator together with 'old_datatype'
blanchet
parents:
58306
diff
changeset
|
2532 |
|
c6f93b8d2d8e
moved old 'size' generator together with 'old_datatype'
blanchet
parents:
58306
diff
changeset
|
2533 |
end |
c6f93b8d2d8e
moved old 'size' generator together with 'old_datatype'
blanchet
parents:
58306
diff
changeset
|
2534 |
|
67332 | 2535 |
lemmas size_nat = size_nat_def |
2536 |
||
71836
c095d3143047
New HOL simproc 'datatype_no_proper_subterm'
Manuel Eberl <eberlm@in.tum.de>
parents:
71588
diff
changeset
|
2537 |
lemma size_neq_size_imp_neq: "size x \<noteq> size y \<Longrightarrow> x \<noteq> y" |
c095d3143047
New HOL simproc 'datatype_no_proper_subterm'
Manuel Eberl <eberlm@in.tum.de>
parents:
71588
diff
changeset
|
2538 |
by (erule contrapos_nn) (rule arg_cong) |
c095d3143047
New HOL simproc 'datatype_no_proper_subterm'
Manuel Eberl <eberlm@in.tum.de>
parents:
71588
diff
changeset
|
2539 |
|
58377
c6f93b8d2d8e
moved old 'size' generator together with 'old_datatype'
blanchet
parents:
58306
diff
changeset
|
2540 |
|
60758 | 2541 |
subsection \<open>Code module namespace\<close> |
33364 | 2542 |
|
52435
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents:
52289
diff
changeset
|
2543 |
code_identifier |
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents:
52289
diff
changeset
|
2544 |
code_module Nat \<rightharpoonup> (SML) Arith and (OCaml) Arith and (Haskell) Arith |
33364 | 2545 |
|
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46351
diff
changeset
|
2546 |
hide_const (open) of_nat_aux |
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46351
diff
changeset
|
2547 |
|
25193 | 2548 |
end |