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