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