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