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