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