src/HOL/Nat.thy
author paulson
Tue Oct 23 13:10:19 2007 +0200 (2007-10-23)
changeset 25157 8b80535cd017
parent 25145 d432105e5bd0
child 25162 ad4d5365d9d8
permissions -rw-r--r--
random tidying of proofs
clasohm@923
     1
(*  Title:      HOL/Nat.thy
clasohm@923
     2
    ID:         $Id$
wenzelm@21243
     3
    Author:     Tobias Nipkow and Lawrence C Paulson and Markus Wenzel
clasohm@923
     4
wenzelm@9436
     5
Type "nat" is a linear order, and a datatype; arithmetic operators + -
wenzelm@9436
     6
and * (for div, mod and dvd, see theory Divides).
clasohm@923
     7
*)
clasohm@923
     8
berghofe@13449
     9
header {* Natural numbers *}
berghofe@13449
    10
nipkow@15131
    11
theory Nat
nipkow@15140
    12
imports Wellfounded_Recursion Ring_and_Field
haftmann@23263
    13
uses
haftmann@23263
    14
  "~~/src/Tools/rat.ML"
haftmann@23263
    15
  "~~/src/Provers/Arith/cancel_sums.ML"
haftmann@23263
    16
  ("arith_data.ML")
wenzelm@24091
    17
  "~~/src/Provers/Arith/fast_lin_arith.ML"
wenzelm@24091
    18
  ("Tools/lin_arith.ML")
haftmann@24699
    19
  ("Tools/function_package/size.ML")
nipkow@15131
    20
begin
berghofe@13449
    21
berghofe@13449
    22
subsection {* Type @{text ind} *}
berghofe@13449
    23
berghofe@13449
    24
typedecl ind
berghofe@13449
    25
wenzelm@19573
    26
axiomatization
wenzelm@19573
    27
  Zero_Rep :: ind and
wenzelm@19573
    28
  Suc_Rep :: "ind => ind"
wenzelm@19573
    29
where
berghofe@13449
    30
  -- {* the axiom of infinity in 2 parts *}
wenzelm@19573
    31
  inj_Suc_Rep:          "inj Suc_Rep" and
paulson@14267
    32
  Suc_Rep_not_Zero_Rep: "Suc_Rep x \<noteq> Zero_Rep"
wenzelm@19573
    33
berghofe@13449
    34
berghofe@13449
    35
subsection {* Type nat *}
berghofe@13449
    36
berghofe@13449
    37
text {* Type definition *}
berghofe@13449
    38
berghofe@23740
    39
inductive_set Nat :: "ind set"
berghofe@22262
    40
where
berghofe@23740
    41
    Zero_RepI: "Zero_Rep : Nat"
berghofe@23740
    42
  | Suc_RepI: "i : Nat ==> Suc_Rep i : Nat"
berghofe@13449
    43
berghofe@13449
    44
global
berghofe@13449
    45
berghofe@13449
    46
typedef (open Nat)
berghofe@23740
    47
  nat = Nat
wenzelm@21243
    48
proof
berghofe@23740
    49
  show "Zero_Rep : Nat" by (rule Nat.Zero_RepI)
wenzelm@21243
    50
qed
berghofe@13449
    51
berghofe@13449
    52
consts
berghofe@13449
    53
  Suc :: "nat => nat"
berghofe@13449
    54
berghofe@13449
    55
local
berghofe@13449
    56
haftmann@24995
    57
instance nat :: zero
haftmann@24995
    58
  Zero_nat_def: "0 == Abs_Nat Zero_Rep" ..
haftmann@24995
    59
lemmas [code func del] = Zero_nat_def
haftmann@24995
    60
berghofe@13449
    61
defs
paulson@18648
    62
  Suc_def:      "Suc == (%n. Abs_Nat (Suc_Rep (Rep_Nat n)))"
wenzelm@22718
    63
berghofe@13449
    64
theorem nat_induct: "P 0 ==> (!!n. P n ==> P (Suc n)) ==> P n"
berghofe@13449
    65
  apply (unfold Zero_nat_def Suc_def)
berghofe@13449
    66
  apply (rule Rep_Nat_inverse [THEN subst]) -- {* types force good instantiation *}
berghofe@23740
    67
  apply (erule Rep_Nat [THEN Nat.induct])
berghofe@23740
    68
  apply (iprover elim: Abs_Nat_inverse [THEN subst])
berghofe@13449
    69
  done
berghofe@13449
    70
paulson@14267
    71
lemma Suc_not_Zero [iff]: "Suc m \<noteq> 0"
berghofe@23740
    72
  by (simp add: Zero_nat_def Suc_def Abs_Nat_inject Rep_Nat Suc_RepI Zero_RepI
wenzelm@22718
    73
                Suc_Rep_not_Zero_Rep)
berghofe@13449
    74
paulson@14267
    75
lemma Zero_not_Suc [iff]: "0 \<noteq> Suc m"
berghofe@13449
    76
  by (rule not_sym, rule Suc_not_Zero not_sym)
berghofe@13449
    77
nipkow@16733
    78
lemma inj_Suc[simp]: "inj_on Suc N"
berghofe@23740
    79
  by (simp add: Suc_def inj_on_def Abs_Nat_inject Rep_Nat Suc_RepI
wenzelm@22718
    80
                inj_Suc_Rep [THEN inj_eq] Rep_Nat_inject)
berghofe@13449
    81
berghofe@13449
    82
lemma Suc_Suc_eq [iff]: "(Suc m = Suc n) = (m = n)"
paulson@15413
    83
  by (rule inj_Suc [THEN inj_eq])
berghofe@13449
    84
berghofe@5188
    85
rep_datatype nat
berghofe@13449
    86
  distinct  Suc_not_Zero Zero_not_Suc
berghofe@13449
    87
  inject    Suc_Suc_eq
haftmann@21411
    88
  induction nat_induct
haftmann@21411
    89
haftmann@21411
    90
declare nat.induct [case_names 0 Suc, induct type: nat]
haftmann@21411
    91
declare nat.exhaust [case_names 0 Suc, cases type: nat]
berghofe@13449
    92
wenzelm@21672
    93
lemmas nat_rec_0 = nat.recs(1)
wenzelm@21672
    94
  and nat_rec_Suc = nat.recs(2)
wenzelm@21672
    95
wenzelm@21672
    96
lemmas nat_case_0 = nat.cases(1)
wenzelm@21672
    97
  and nat_case_Suc = nat.cases(2)
wenzelm@21672
    98
haftmann@24995
    99
haftmann@24995
   100
text {* Injectiveness and distinctness lemmas *}
haftmann@24995
   101
haftmann@24995
   102
lemma Suc_neq_Zero: "Suc m = 0 ==> R"
haftmann@24995
   103
  by (rule notE, rule Suc_not_Zero)
haftmann@24995
   104
haftmann@24995
   105
lemma Zero_neq_Suc: "0 = Suc m ==> R"
haftmann@24995
   106
  by (rule Suc_neq_Zero, erule sym)
haftmann@24995
   107
haftmann@24995
   108
lemma Suc_inject: "Suc x = Suc y ==> x = y"
haftmann@24995
   109
  by (rule inj_Suc [THEN injD])
haftmann@24995
   110
haftmann@24995
   111
lemma nat_not_singleton: "(\<forall>x. x = (0::nat)) = False"
haftmann@24995
   112
  by auto
haftmann@24995
   113
paulson@14267
   114
lemma n_not_Suc_n: "n \<noteq> Suc n"
berghofe@13449
   115
  by (induct n) simp_all
berghofe@13449
   116
paulson@14267
   117
lemma Suc_n_not_n: "Suc t \<noteq> t"
berghofe@13449
   118
  by (rule not_sym, rule n_not_Suc_n)
berghofe@13449
   119
haftmann@24995
   120
berghofe@13449
   121
text {* A special form of induction for reasoning
berghofe@13449
   122
  about @{term "m < n"} and @{term "m - n"} *}
berghofe@13449
   123
berghofe@13449
   124
theorem diff_induct: "(!!x. P x 0) ==> (!!y. P 0 (Suc y)) ==>
berghofe@13449
   125
    (!!x y. P x y ==> P (Suc x) (Suc y)) ==> P m n"
paulson@14208
   126
  apply (rule_tac x = m in spec)
paulson@15251
   127
  apply (induct n)
berghofe@13449
   128
  prefer 2
berghofe@13449
   129
  apply (rule allI)
nipkow@17589
   130
  apply (induct_tac x, iprover+)
berghofe@13449
   131
  done
berghofe@13449
   132
haftmann@24995
   133
haftmann@24995
   134
subsection {* Arithmetic operators *}
haftmann@24995
   135
haftmann@24995
   136
instance nat :: "{one, plus, minus, times}"
haftmann@24995
   137
  One_nat_def [simp]: "1 == Suc 0" ..
haftmann@24995
   138
haftmann@24995
   139
primrec
haftmann@24995
   140
  add_0:    "0 + n = n"
haftmann@24995
   141
  add_Suc:  "Suc m + n = Suc (m + n)"
haftmann@24995
   142
haftmann@24995
   143
primrec
haftmann@24995
   144
  diff_0:   "m - 0 = m"
haftmann@24995
   145
  diff_Suc: "m - Suc n = (case m - n of 0 => 0 | Suc k => k)"
haftmann@24995
   146
haftmann@24995
   147
primrec
haftmann@24995
   148
  mult_0:   "0 * n = 0"
haftmann@24995
   149
  mult_Suc: "Suc m * n = n + (m * n)"
haftmann@24995
   150
haftmann@24995
   151
haftmann@24995
   152
subsection {* Orders on @{typ nat} *}
haftmann@24995
   153
haftmann@24995
   154
definition
haftmann@24995
   155
  pred_nat :: "(nat * nat) set" where
haftmann@24995
   156
  "pred_nat = {(m, n). n = Suc m}"
haftmann@24995
   157
haftmann@24995
   158
instance nat :: ord
haftmann@24995
   159
  less_def: "m < n == (m, n) : pred_nat^+"
haftmann@24995
   160
  le_def:   "m \<le> (n::nat) == ~ (n < m)" ..
haftmann@24995
   161
haftmann@24995
   162
lemmas [code func del] = less_def le_def
berghofe@13449
   163
berghofe@13449
   164
lemma wf_pred_nat: "wf pred_nat"
paulson@14208
   165
  apply (unfold wf_def pred_nat_def, clarify)
paulson@14208
   166
  apply (induct_tac x, blast+)
berghofe@13449
   167
  done
berghofe@13449
   168
berghofe@13449
   169
lemma wf_less: "wf {(x, y::nat). x < y}"
berghofe@13449
   170
  apply (unfold less_def)
paulson@14208
   171
  apply (rule wf_pred_nat [THEN wf_trancl, THEN wf_subset], blast)
berghofe@13449
   172
  done
berghofe@13449
   173
berghofe@13449
   174
lemma less_eq: "((m, n) : pred_nat^+) = (m < n)"
berghofe@13449
   175
  apply (unfold less_def)
berghofe@13449
   176
  apply (rule refl)
berghofe@13449
   177
  done
berghofe@13449
   178
berghofe@13449
   179
subsubsection {* Introduction properties *}
berghofe@13449
   180
berghofe@13449
   181
lemma less_trans: "i < j ==> j < k ==> i < (k::nat)"
berghofe@13449
   182
  apply (unfold less_def)
paulson@14208
   183
  apply (rule trans_trancl [THEN transD], assumption+)
berghofe@13449
   184
  done
berghofe@13449
   185
berghofe@13449
   186
lemma lessI [iff]: "n < Suc n"
berghofe@13449
   187
  apply (unfold less_def pred_nat_def)
berghofe@13449
   188
  apply (simp add: r_into_trancl)
berghofe@13449
   189
  done
berghofe@13449
   190
berghofe@13449
   191
lemma less_SucI: "i < j ==> i < Suc j"
paulson@14208
   192
  apply (rule less_trans, assumption)
berghofe@13449
   193
  apply (rule lessI)
berghofe@13449
   194
  done
berghofe@13449
   195
berghofe@13449
   196
lemma zero_less_Suc [iff]: "0 < Suc n"
berghofe@13449
   197
  apply (induct n)
berghofe@13449
   198
  apply (rule lessI)
berghofe@13449
   199
  apply (erule less_trans)
berghofe@13449
   200
  apply (rule lessI)
berghofe@13449
   201
  done
berghofe@13449
   202
berghofe@13449
   203
subsubsection {* Elimination properties *}
berghofe@13449
   204
berghofe@13449
   205
lemma less_not_sym: "n < m ==> ~ m < (n::nat)"
berghofe@13449
   206
  apply (unfold less_def)
berghofe@13449
   207
  apply (blast intro: wf_pred_nat wf_trancl [THEN wf_asym])
berghofe@13449
   208
  done
berghofe@13449
   209
berghofe@13449
   210
lemma less_asym:
berghofe@13449
   211
  assumes h1: "(n::nat) < m" and h2: "~ P ==> m < n" shows P
berghofe@13449
   212
  apply (rule contrapos_np)
berghofe@13449
   213
  apply (rule less_not_sym)
berghofe@13449
   214
  apply (rule h1)
berghofe@13449
   215
  apply (erule h2)
berghofe@13449
   216
  done
berghofe@13449
   217
berghofe@13449
   218
lemma less_not_refl: "~ n < (n::nat)"
berghofe@13449
   219
  apply (unfold less_def)
berghofe@13449
   220
  apply (rule wf_pred_nat [THEN wf_trancl, THEN wf_not_refl])
berghofe@13449
   221
  done
berghofe@13449
   222
berghofe@13449
   223
lemma less_irrefl [elim!]: "(n::nat) < n ==> R"
berghofe@13449
   224
  by (rule notE, rule less_not_refl)
berghofe@13449
   225
paulson@14267
   226
lemma less_not_refl2: "n < m ==> m \<noteq> (n::nat)" by blast
berghofe@13449
   227
paulson@14267
   228
lemma less_not_refl3: "(s::nat) < t ==> s \<noteq> t"
berghofe@13449
   229
  by (rule not_sym, rule less_not_refl2)
berghofe@13449
   230
berghofe@13449
   231
lemma lessE:
berghofe@13449
   232
  assumes major: "i < k"
berghofe@13449
   233
  and p1: "k = Suc i ==> P" and p2: "!!j. i < j ==> k = Suc j ==> P"
berghofe@13449
   234
  shows P
paulson@14208
   235
  apply (rule major [unfolded less_def pred_nat_def, THEN tranclE], simp_all)
berghofe@13449
   236
  apply (erule p1)
berghofe@13449
   237
  apply (rule p2)
paulson@14208
   238
  apply (simp add: less_def pred_nat_def, assumption)
berghofe@13449
   239
  done
berghofe@13449
   240
berghofe@13449
   241
lemma not_less0 [iff]: "~ n < (0::nat)"
berghofe@13449
   242
  by (blast elim: lessE)
berghofe@13449
   243
berghofe@13449
   244
lemma less_zeroE: "(n::nat) < 0 ==> R"
berghofe@13449
   245
  by (rule notE, rule not_less0)
berghofe@13449
   246
berghofe@13449
   247
lemma less_SucE: assumes major: "m < Suc n"
berghofe@13449
   248
  and less: "m < n ==> P" and eq: "m = n ==> P" shows P
berghofe@13449
   249
  apply (rule major [THEN lessE])
paulson@14208
   250
  apply (rule eq, blast)
paulson@14208
   251
  apply (rule less, blast)
berghofe@13449
   252
  done
berghofe@13449
   253
berghofe@13449
   254
lemma less_Suc_eq: "(m < Suc n) = (m < n | m = n)"
berghofe@13449
   255
  by (blast elim!: less_SucE intro: less_trans)
berghofe@13449
   256
paulson@24286
   257
lemma less_one [iff,noatp]: "(n < (1::nat)) = (n = 0)"
berghofe@13449
   258
  by (simp add: less_Suc_eq)
berghofe@13449
   259
berghofe@13449
   260
lemma less_Suc0 [iff]: "(n < Suc 0) = (n = 0)"
berghofe@13449
   261
  by (simp add: less_Suc_eq)
berghofe@13449
   262
berghofe@13449
   263
lemma Suc_mono: "m < n ==> Suc m < Suc n"
berghofe@13449
   264
  by (induct n) (fast elim: less_trans lessE)+
berghofe@13449
   265
berghofe@13449
   266
text {* "Less than" is a linear ordering *}
berghofe@13449
   267
lemma less_linear: "m < n | m = n | n < (m::nat)"
paulson@15251
   268
  apply (induct m)
paulson@15251
   269
  apply (induct n)
berghofe@13449
   270
  apply (rule refl [THEN disjI1, THEN disjI2])
berghofe@13449
   271
  apply (rule zero_less_Suc [THEN disjI1])
berghofe@13449
   272
  apply (blast intro: Suc_mono less_SucI elim: lessE)
berghofe@13449
   273
  done
berghofe@13449
   274
nipkow@14302
   275
text {* "Less than" is antisymmetric, sort of *}
nipkow@14302
   276
lemma less_antisym: "\<lbrakk> \<not> n < m; n < Suc m \<rbrakk> \<Longrightarrow> m = n"
wenzelm@22718
   277
  apply(simp only:less_Suc_eq)
wenzelm@22718
   278
  apply blast
wenzelm@22718
   279
  done
nipkow@14302
   280
paulson@14267
   281
lemma nat_neq_iff: "((m::nat) \<noteq> n) = (m < n | n < m)"
berghofe@13449
   282
  using less_linear by blast
berghofe@13449
   283
berghofe@13449
   284
lemma nat_less_cases: assumes major: "(m::nat) < n ==> P n m"
berghofe@13449
   285
  and eqCase: "m = n ==> P n m" and lessCase: "n<m ==> P n m"
berghofe@13449
   286
  shows "P n m"
berghofe@13449
   287
  apply (rule less_linear [THEN disjE])
berghofe@13449
   288
  apply (erule_tac [2] disjE)
berghofe@13449
   289
  apply (erule lessCase)
berghofe@13449
   290
  apply (erule sym [THEN eqCase])
berghofe@13449
   291
  apply (erule major)
berghofe@13449
   292
  done
berghofe@13449
   293
berghofe@13449
   294
berghofe@13449
   295
subsubsection {* Inductive (?) properties *}
berghofe@13449
   296
paulson@14267
   297
lemma Suc_lessI: "m < n ==> Suc m \<noteq> n ==> Suc m < n"
berghofe@13449
   298
  apply (simp add: nat_neq_iff)
berghofe@13449
   299
  apply (blast elim!: less_irrefl less_SucE elim: less_asym)
berghofe@13449
   300
  done
berghofe@13449
   301
berghofe@13449
   302
lemma Suc_lessD: "Suc m < n ==> m < n"
berghofe@13449
   303
  apply (induct n)
berghofe@13449
   304
  apply (fast intro!: lessI [THEN less_SucI] elim: less_trans lessE)+
berghofe@13449
   305
  done
berghofe@13449
   306
berghofe@13449
   307
lemma Suc_lessE: assumes major: "Suc i < k"
berghofe@13449
   308
  and minor: "!!j. i < j ==> k = Suc j ==> P" shows P
berghofe@13449
   309
  apply (rule major [THEN lessE])
berghofe@13449
   310
  apply (erule lessI [THEN minor])
paulson@14208
   311
  apply (erule Suc_lessD [THEN minor], assumption)
berghofe@13449
   312
  done
berghofe@13449
   313
berghofe@13449
   314
lemma Suc_less_SucD: "Suc m < Suc n ==> m < n"
berghofe@13449
   315
  by (blast elim: lessE dest: Suc_lessD)
wenzelm@4104
   316
berghofe@16635
   317
lemma Suc_less_eq [iff, code]: "(Suc m < Suc n) = (m < n)"
berghofe@13449
   318
  apply (rule iffI)
berghofe@13449
   319
  apply (erule Suc_less_SucD)
berghofe@13449
   320
  apply (erule Suc_mono)
berghofe@13449
   321
  done
berghofe@13449
   322
berghofe@13449
   323
lemma less_trans_Suc:
berghofe@13449
   324
  assumes le: "i < j" shows "j < k ==> Suc i < k"
paulson@14208
   325
  apply (induct k, simp_all)
berghofe@13449
   326
  apply (insert le)
berghofe@13449
   327
  apply (simp add: less_Suc_eq)
berghofe@13449
   328
  apply (blast dest: Suc_lessD)
berghofe@13449
   329
  done
berghofe@13449
   330
berghofe@16635
   331
lemma [code]: "((n::nat) < 0) = False" by simp
berghofe@16635
   332
lemma [code]: "(0 < Suc n) = True" by simp
berghofe@16635
   333
berghofe@13449
   334
text {* Can be used with @{text less_Suc_eq} to get @{term "n = m | n < m"} *}
berghofe@13449
   335
lemma not_less_eq: "(~ m < n) = (n < Suc m)"
wenzelm@22718
   336
  by (induct m n rule: diff_induct) simp_all
berghofe@13449
   337
berghofe@13449
   338
text {* Complete induction, aka course-of-values induction *}
berghofe@13449
   339
lemma nat_less_induct:
paulson@14267
   340
  assumes prem: "!!n. \<forall>m::nat. m < n --> P m ==> P n" shows "P n"
wenzelm@22718
   341
  apply (induct n rule: wf_induct [OF wf_pred_nat [THEN wf_trancl]])
berghofe@13449
   342
  apply (rule prem)
paulson@14208
   343
  apply (unfold less_def, assumption)
berghofe@13449
   344
  done
berghofe@13449
   345
paulson@14131
   346
lemmas less_induct = nat_less_induct [rule_format, case_names less]
paulson@14131
   347
wenzelm@21243
   348
haftmann@24995
   349
text {* Properties of "less than or equal" *}
berghofe@13449
   350
berghofe@13449
   351
text {* Was @{text le_eq_less_Suc}, but this orientation is more useful *}
paulson@14267
   352
lemma less_Suc_eq_le: "(m < Suc n) = (m \<le> n)"
wenzelm@22718
   353
  unfolding le_def by (rule not_less_eq [symmetric])
berghofe@13449
   354
paulson@14267
   355
lemma le_imp_less_Suc: "m \<le> n ==> m < Suc n"
berghofe@13449
   356
  by (rule less_Suc_eq_le [THEN iffD2])
berghofe@13449
   357
paulson@14267
   358
lemma le0 [iff]: "(0::nat) \<le> n"
wenzelm@22718
   359
  unfolding le_def by (rule not_less0)
berghofe@13449
   360
paulson@14267
   361
lemma Suc_n_not_le_n: "~ Suc n \<le> n"
berghofe@13449
   362
  by (simp add: le_def)
berghofe@13449
   363
paulson@14267
   364
lemma le_0_eq [iff]: "((i::nat) \<le> 0) = (i = 0)"
berghofe@13449
   365
  by (induct i) (simp_all add: le_def)
berghofe@13449
   366
paulson@14267
   367
lemma le_Suc_eq: "(m \<le> Suc n) = (m \<le> n | m = Suc n)"
berghofe@13449
   368
  by (simp del: less_Suc_eq_le add: less_Suc_eq_le [symmetric] less_Suc_eq)
berghofe@13449
   369
paulson@14267
   370
lemma le_SucE: "m \<le> Suc n ==> (m \<le> n ==> R) ==> (m = Suc n ==> R) ==> R"
nipkow@17589
   371
  by (drule le_Suc_eq [THEN iffD1], iprover+)
berghofe@13449
   372
paulson@14267
   373
lemma Suc_leI: "m < n ==> Suc(m) \<le> n"
berghofe@13449
   374
  apply (simp add: le_def less_Suc_eq)
berghofe@13449
   375
  apply (blast elim!: less_irrefl less_asym)
berghofe@13449
   376
  done -- {* formerly called lessD *}
berghofe@13449
   377
paulson@14267
   378
lemma Suc_leD: "Suc(m) \<le> n ==> m \<le> n"
berghofe@13449
   379
  by (simp add: le_def less_Suc_eq)
berghofe@13449
   380
berghofe@13449
   381
text {* Stronger version of @{text Suc_leD} *}
paulson@14267
   382
lemma Suc_le_lessD: "Suc m \<le> n ==> m < n"
berghofe@13449
   383
  apply (simp add: le_def less_Suc_eq)
berghofe@13449
   384
  using less_linear
berghofe@13449
   385
  apply blast
berghofe@13449
   386
  done
berghofe@13449
   387
paulson@14267
   388
lemma Suc_le_eq: "(Suc m \<le> n) = (m < n)"
berghofe@13449
   389
  by (blast intro: Suc_leI Suc_le_lessD)
berghofe@13449
   390
paulson@14267
   391
lemma le_SucI: "m \<le> n ==> m \<le> Suc n"
berghofe@13449
   392
  by (unfold le_def) (blast dest: Suc_lessD)
berghofe@13449
   393
paulson@14267
   394
lemma less_imp_le: "m < n ==> m \<le> (n::nat)"
berghofe@13449
   395
  by (unfold le_def) (blast elim: less_asym)
berghofe@13449
   396
paulson@14267
   397
text {* For instance, @{text "(Suc m < Suc n) = (Suc m \<le> n) = (m < n)"} *}
berghofe@13449
   398
lemmas le_simps = less_imp_le less_Suc_eq_le Suc_le_eq
berghofe@13449
   399
berghofe@13449
   400
paulson@14267
   401
text {* Equivalence of @{term "m \<le> n"} and @{term "m < n | m = n"} *}
berghofe@13449
   402
paulson@14267
   403
lemma le_imp_less_or_eq: "m \<le> n ==> m < n | m = (n::nat)"
wenzelm@22718
   404
  unfolding le_def
berghofe@13449
   405
  using less_linear
wenzelm@22718
   406
  by (blast elim: less_irrefl less_asym)
berghofe@13449
   407
paulson@14267
   408
lemma less_or_eq_imp_le: "m < n | m = n ==> m \<le> (n::nat)"
wenzelm@22718
   409
  unfolding le_def
berghofe@13449
   410
  using less_linear
wenzelm@22718
   411
  by (blast elim!: less_irrefl elim: less_asym)
berghofe@13449
   412
paulson@14267
   413
lemma le_eq_less_or_eq: "(m \<le> (n::nat)) = (m < n | m=n)"
nipkow@17589
   414
  by (iprover intro: less_or_eq_imp_le le_imp_less_or_eq)
berghofe@13449
   415
wenzelm@22718
   416
text {* Useful with @{text blast}. *}
paulson@14267
   417
lemma eq_imp_le: "(m::nat) = n ==> m \<le> n"
wenzelm@22718
   418
  by (rule less_or_eq_imp_le) (rule disjI2)
berghofe@13449
   419
paulson@14267
   420
lemma le_refl: "n \<le> (n::nat)"
berghofe@13449
   421
  by (simp add: le_eq_less_or_eq)
berghofe@13449
   422
paulson@14267
   423
lemma le_less_trans: "[| i \<le> j; j < k |] ==> i < (k::nat)"
berghofe@13449
   424
  by (blast dest!: le_imp_less_or_eq intro: less_trans)
berghofe@13449
   425
paulson@14267
   426
lemma less_le_trans: "[| i < j; j \<le> k |] ==> i < (k::nat)"
berghofe@13449
   427
  by (blast dest!: le_imp_less_or_eq intro: less_trans)
berghofe@13449
   428
paulson@14267
   429
lemma le_trans: "[| i \<le> j; j \<le> k |] ==> i \<le> (k::nat)"
berghofe@13449
   430
  by (blast dest!: le_imp_less_or_eq intro: less_or_eq_imp_le less_trans)
berghofe@13449
   431
paulson@14267
   432
lemma le_anti_sym: "[| m \<le> n; n \<le> m |] ==> m = (n::nat)"
berghofe@13449
   433
  by (blast dest!: le_imp_less_or_eq elim!: less_irrefl elim: less_asym)
berghofe@13449
   434
paulson@14267
   435
lemma Suc_le_mono [iff]: "(Suc n \<le> Suc m) = (n \<le> m)"
berghofe@13449
   436
  by (simp add: le_simps)
berghofe@13449
   437
berghofe@13449
   438
text {* Axiom @{text order_less_le} of class @{text order}: *}
paulson@14267
   439
lemma nat_less_le: "((m::nat) < n) = (m \<le> n & m \<noteq> n)"
berghofe@13449
   440
  by (simp add: le_def nat_neq_iff) (blast elim!: less_asym)
berghofe@13449
   441
paulson@14267
   442
lemma le_neq_implies_less: "(m::nat) \<le> n ==> m \<noteq> n ==> m < n"
berghofe@13449
   443
  by (rule iffD2, rule nat_less_le, rule conjI)
berghofe@13449
   444
berghofe@13449
   445
text {* Axiom @{text linorder_linear} of class @{text linorder}: *}
paulson@14267
   446
lemma nat_le_linear: "(m::nat) \<le> n | n \<le> m"
berghofe@13449
   447
  apply (simp add: le_eq_less_or_eq)
wenzelm@22718
   448
  using less_linear by blast
berghofe@13449
   449
haftmann@24995
   450
text {* Type @{typ nat} is a wellfounded linear order *}
paulson@14341
   451
haftmann@22318
   452
instance nat :: wellorder
wenzelm@14691
   453
  by intro_classes
wenzelm@14691
   454
    (assumption |
wenzelm@14691
   455
      rule le_refl le_trans le_anti_sym nat_less_le nat_le_linear wf_less)+
paulson@14341
   456
wenzelm@22718
   457
lemmas linorder_neqE_nat = linorder_neqE [where 'a = nat]
nipkow@15921
   458
berghofe@13449
   459
lemma not_less_less_Suc_eq: "~ n < m ==> (n < Suc m) = (n = m)"
berghofe@13449
   460
  by (blast elim!: less_SucE)
berghofe@13449
   461
berghofe@13449
   462
text {*
berghofe@13449
   463
  Rewrite @{term "n < Suc m"} to @{term "n = m"}
paulson@14267
   464
  if @{term "~ n < m"} or @{term "m \<le> n"} hold.
berghofe@13449
   465
  Not suitable as default simprules because they often lead to looping
berghofe@13449
   466
*}
paulson@14267
   467
lemma le_less_Suc_eq: "m \<le> n ==> (n < Suc m) = (n = m)"
berghofe@13449
   468
  by (rule not_less_less_Suc_eq, rule leD)
berghofe@13449
   469
berghofe@13449
   470
lemmas not_less_simps = not_less_less_Suc_eq le_less_Suc_eq
berghofe@13449
   471
berghofe@13449
   472
berghofe@13449
   473
text {*
wenzelm@22718
   474
  Re-orientation of the equations @{text "0 = x"} and @{text "1 = x"}.
wenzelm@22718
   475
  No longer added as simprules (they loop)
berghofe@13449
   476
  but via @{text reorient_simproc} in Bin
berghofe@13449
   477
*}
berghofe@13449
   478
berghofe@13449
   479
text {* Polymorphic, not just for @{typ nat} *}
berghofe@13449
   480
lemma zero_reorient: "(0 = x) = (x = 0)"
berghofe@13449
   481
  by auto
berghofe@13449
   482
berghofe@13449
   483
lemma one_reorient: "(1 = x) = (x = 1)"
berghofe@13449
   484
  by auto
berghofe@13449
   485
wenzelm@22718
   486
text {* These two rules ease the use of primitive recursion.
paulson@14341
   487
NOTE USE OF @{text "=="} *}
berghofe@13449
   488
lemma def_nat_rec_0: "(!!n. f n == nat_rec c h n) ==> f 0 = c"
berghofe@13449
   489
  by simp
berghofe@13449
   490
berghofe@13449
   491
lemma def_nat_rec_Suc: "(!!n. f n == nat_rec c h n) ==> f (Suc n) = h n (f n)"
berghofe@13449
   492
  by simp
berghofe@13449
   493
paulson@14267
   494
lemma not0_implies_Suc: "n \<noteq> 0 ==> \<exists>m. n = Suc m"
wenzelm@22718
   495
  by (cases n) simp_all
berghofe@13449
   496
wenzelm@22718
   497
lemma gr_implies_not0: fixes n :: nat shows "m<n ==> n \<noteq> 0"
wenzelm@22718
   498
  by (cases n) simp_all
berghofe@13449
   499
chaieb@25111
   500
lemma neq0_conv: fixes n :: nat shows "(n \<noteq> 0) = (0 < n)"
wenzelm@22718
   501
  by (cases n) simp_all
berghofe@13449
   502
nipkow@25140
   503
lemmas gr0_conv = neq0_conv[symmetric]
nipkow@25140
   504
berghofe@13449
   505
text {* This theorem is useful with @{text blast} *}
berghofe@13449
   506
lemma gr0I: "((n::nat) = 0 ==> False) ==> 0 < n"
nipkow@17589
   507
  by (rule iffD1, rule neq0_conv, iprover)
berghofe@13449
   508
paulson@14267
   509
lemma gr0_conv_Suc: "(0 < n) = (\<exists>m. n = Suc m)"
berghofe@13449
   510
  by (fast intro: not0_implies_Suc)
berghofe@13449
   511
paulson@24286
   512
lemma not_gr0 [iff,noatp]: "!!n::nat. (~ (0 < n)) = (n = 0)"
nipkow@25134
   513
using neq0_conv by blast
berghofe@13449
   514
paulson@14267
   515
lemma Suc_le_D: "(Suc n \<le> m') ==> (? m. m' = Suc m)"
berghofe@13449
   516
  by (induct m') simp_all
berghofe@13449
   517
berghofe@13449
   518
text {* Useful in certain inductive arguments *}
paulson@14267
   519
lemma less_Suc_eq_0_disj: "(m < Suc n) = (m = 0 | (\<exists>j. m = Suc j & j < n))"
wenzelm@22718
   520
  by (cases m) simp_all
berghofe@13449
   521
paulson@14341
   522
lemma nat_induct2: "[|P 0; P (Suc 0); !!k. P k ==> P (Suc (Suc k))|] ==> P n"
berghofe@13449
   523
  apply (rule nat_less_induct)
berghofe@13449
   524
  apply (case_tac n)
berghofe@13449
   525
  apply (case_tac [2] nat)
berghofe@13449
   526
  apply (blast intro: less_trans)+
berghofe@13449
   527
  done
berghofe@13449
   528
wenzelm@21243
   529
paulson@15341
   530
subsection {* @{text LEAST} theorems for type @{typ nat}*}
berghofe@13449
   531
paulson@14267
   532
lemma Least_Suc:
paulson@14267
   533
     "[| P n; ~ P 0 |] ==> (LEAST n. P n) = Suc (LEAST m. P(Suc m))"
paulson@14208
   534
  apply (case_tac "n", auto)
berghofe@13449
   535
  apply (frule LeastI)
berghofe@13449
   536
  apply (drule_tac P = "%x. P (Suc x) " in LeastI)
paulson@14267
   537
  apply (subgoal_tac " (LEAST x. P x) \<le> Suc (LEAST x. P (Suc x))")
berghofe@13449
   538
  apply (erule_tac [2] Least_le)
paulson@14208
   539
  apply (case_tac "LEAST x. P x", auto)
berghofe@13449
   540
  apply (drule_tac P = "%x. P (Suc x) " in Least_le)
berghofe@13449
   541
  apply (blast intro: order_antisym)
berghofe@13449
   542
  done
berghofe@13449
   543
paulson@14267
   544
lemma Least_Suc2:
paulson@14267
   545
     "[|P n; Q m; ~P 0; !k. P (Suc k) = Q k|] ==> Least P = Suc (Least Q)"
paulson@14267
   546
  by (erule (1) Least_Suc [THEN ssubst], simp)
berghofe@13449
   547
berghofe@13449
   548
berghofe@13449
   549
subsection {* @{term min} and @{term max} *}
berghofe@13449
   550
haftmann@25076
   551
lemma mono_Suc: "mono Suc"
haftmann@25076
   552
  by (rule monoI) simp
haftmann@25076
   553
berghofe@13449
   554
lemma min_0L [simp]: "min 0 n = (0::nat)"
berghofe@13449
   555
  by (rule min_leastL) simp
berghofe@13449
   556
berghofe@13449
   557
lemma min_0R [simp]: "min n 0 = (0::nat)"
berghofe@13449
   558
  by (rule min_leastR) simp
berghofe@13449
   559
berghofe@13449
   560
lemma min_Suc_Suc [simp]: "min (Suc m) (Suc n) = Suc (min m n)"
haftmann@25076
   561
  by (simp add: mono_Suc min_of_mono)
berghofe@13449
   562
paulson@22191
   563
lemma min_Suc1:
paulson@22191
   564
   "min (Suc n) m = (case m of 0 => 0 | Suc m' => Suc(min n m'))"
wenzelm@22718
   565
  by (simp split: nat.split)
paulson@22191
   566
paulson@22191
   567
lemma min_Suc2:
paulson@22191
   568
   "min m (Suc n) = (case m of 0 => 0 | Suc m' => Suc(min m' n))"
paulson@22191
   569
  by (simp split: nat.split)
paulson@22191
   570
berghofe@13449
   571
lemma max_0L [simp]: "max 0 n = (n::nat)"
berghofe@13449
   572
  by (rule max_leastL) simp
berghofe@13449
   573
berghofe@13449
   574
lemma max_0R [simp]: "max n 0 = (n::nat)"
berghofe@13449
   575
  by (rule max_leastR) simp
berghofe@13449
   576
berghofe@13449
   577
lemma max_Suc_Suc [simp]: "max (Suc m) (Suc n) = Suc(max m n)"
haftmann@25076
   578
  by (simp add: mono_Suc max_of_mono)
berghofe@13449
   579
paulson@22191
   580
lemma max_Suc1:
paulson@22191
   581
   "max (Suc n) m = (case m of 0 => Suc n | Suc m' => Suc(max n m'))"
wenzelm@22718
   582
  by (simp split: nat.split)
paulson@22191
   583
paulson@22191
   584
lemma max_Suc2:
paulson@22191
   585
   "max m (Suc n) = (case m of 0 => Suc n | Suc m' => Suc(max m' n))"
paulson@22191
   586
  by (simp split: nat.split)
paulson@22191
   587
berghofe@13449
   588
berghofe@13449
   589
subsection {* Basic rewrite rules for the arithmetic operators *}
berghofe@13449
   590
berghofe@13449
   591
text {* Difference *}
berghofe@13449
   592
berghofe@14193
   593
lemma diff_0_eq_0 [simp, code]: "0 - n = (0::nat)"
paulson@15251
   594
  by (induct n) simp_all
berghofe@13449
   595
berghofe@14193
   596
lemma diff_Suc_Suc [simp, code]: "Suc(m) - Suc(n) = m - n"
paulson@15251
   597
  by (induct n) simp_all
berghofe@13449
   598
berghofe@13449
   599
berghofe@13449
   600
text {*
berghofe@13449
   601
  Could be (and is, below) generalized in various ways
berghofe@13449
   602
  However, none of the generalizations are currently in the simpset,
berghofe@13449
   603
  and I dread to think what happens if I put them in
berghofe@13449
   604
*}
nipkow@25134
   605
lemma Suc_pred [simp]: "0 \<noteq> n ==> Suc (n - Suc 0) = n"
nipkow@25134
   606
by (simp split add: nat.split)
berghofe@13449
   607
berghofe@14193
   608
declare diff_Suc [simp del, code del]
berghofe@13449
   609
berghofe@13449
   610
berghofe@13449
   611
subsection {* Addition *}
berghofe@13449
   612
berghofe@13449
   613
lemma add_0_right [simp]: "m + 0 = (m::nat)"
berghofe@13449
   614
  by (induct m) simp_all
berghofe@13449
   615
berghofe@13449
   616
lemma add_Suc_right [simp]: "m + Suc n = Suc (m + n)"
berghofe@13449
   617
  by (induct m) simp_all
berghofe@13449
   618
haftmann@19890
   619
lemma add_Suc_shift [code]: "Suc m + n = m + Suc n"
haftmann@19890
   620
  by simp
berghofe@14193
   621
berghofe@13449
   622
berghofe@13449
   623
text {* Associative law for addition *}
paulson@14267
   624
lemma nat_add_assoc: "(m + n) + k = m + ((n + k)::nat)"
berghofe@13449
   625
  by (induct m) simp_all
berghofe@13449
   626
berghofe@13449
   627
text {* Commutative law for addition *}
paulson@14267
   628
lemma nat_add_commute: "m + n = n + (m::nat)"
berghofe@13449
   629
  by (induct m) simp_all
berghofe@13449
   630
paulson@14267
   631
lemma nat_add_left_commute: "x + (y + z) = y + ((x + z)::nat)"
berghofe@13449
   632
  apply (rule mk_left_commute [of "op +"])
paulson@14267
   633
  apply (rule nat_add_assoc)
paulson@14267
   634
  apply (rule nat_add_commute)
berghofe@13449
   635
  done
berghofe@13449
   636
paulson@14331
   637
lemma nat_add_left_cancel [simp]: "(k + m = k + n) = (m = (n::nat))"
berghofe@13449
   638
  by (induct k) simp_all
berghofe@13449
   639
paulson@14331
   640
lemma nat_add_right_cancel [simp]: "(m + k = n + k) = (m=(n::nat))"
berghofe@13449
   641
  by (induct k) simp_all
berghofe@13449
   642
paulson@14331
   643
lemma nat_add_left_cancel_le [simp]: "(k + m \<le> k + n) = (m\<le>(n::nat))"
berghofe@13449
   644
  by (induct k) simp_all
berghofe@13449
   645
paulson@14331
   646
lemma nat_add_left_cancel_less [simp]: "(k + m < k + n) = (m<(n::nat))"
berghofe@13449
   647
  by (induct k) simp_all
berghofe@13449
   648
berghofe@13449
   649
text {* Reasoning about @{text "m + 0 = 0"}, etc. *}
berghofe@13449
   650
wenzelm@22718
   651
lemma add_is_0 [iff]: fixes m :: nat shows "(m + n = 0) = (m = 0 & n = 0)"
wenzelm@22718
   652
  by (cases m) simp_all
berghofe@13449
   653
berghofe@13449
   654
lemma add_is_1: "(m+n= Suc 0) = (m= Suc 0 & n=0 | m=0 & n= Suc 0)"
wenzelm@22718
   655
  by (cases m) simp_all
berghofe@13449
   656
berghofe@13449
   657
lemma one_is_add: "(Suc 0 = m + n) = (m = Suc 0 & n = 0 | m = 0 & n = Suc 0)"
berghofe@13449
   658
  by (rule trans, rule eq_commute, rule add_is_1)
berghofe@13449
   659
nipkow@25140
   660
lemma add_gr_0 [iff]: "!!m::nat. (m + n > 0) = (m\<noteq>0 | n\<noteq>0)"
nipkow@25140
   661
by (simp add:gr0_conv)
berghofe@13449
   662
berghofe@13449
   663
lemma add_eq_self_zero: "!!m::nat. m + n = m ==> n = 0"
berghofe@13449
   664
  apply (drule add_0_right [THEN ssubst])
paulson@14267
   665
  apply (simp add: nat_add_assoc del: add_0_right)
berghofe@13449
   666
  done
berghofe@13449
   667
nipkow@16733
   668
lemma inj_on_add_nat[simp]: "inj_on (%n::nat. n+k) N"
wenzelm@22718
   669
  apply (induct k)
wenzelm@22718
   670
   apply simp
wenzelm@22718
   671
  apply(drule comp_inj_on[OF _ inj_Suc])
wenzelm@22718
   672
  apply (simp add:o_def)
wenzelm@22718
   673
  done
nipkow@16733
   674
nipkow@16733
   675
paulson@14267
   676
subsection {* Multiplication *}
paulson@14267
   677
paulson@14267
   678
text {* right annihilation in product *}
paulson@14267
   679
lemma mult_0_right [simp]: "(m::nat) * 0 = 0"
paulson@14267
   680
  by (induct m) simp_all
paulson@14267
   681
paulson@14267
   682
text {* right successor law for multiplication *}
paulson@14267
   683
lemma mult_Suc_right [simp]: "m * Suc n = m + (m * n)"
paulson@14267
   684
  by (induct m) (simp_all add: nat_add_left_commute)
paulson@14267
   685
paulson@14267
   686
text {* Commutative law for multiplication *}
paulson@14267
   687
lemma nat_mult_commute: "m * n = n * (m::nat)"
paulson@14267
   688
  by (induct m) simp_all
paulson@14267
   689
paulson@14267
   690
text {* addition distributes over multiplication *}
paulson@14267
   691
lemma add_mult_distrib: "(m + n) * k = (m * k) + ((n * k)::nat)"
paulson@14267
   692
  by (induct m) (simp_all add: nat_add_assoc nat_add_left_commute)
paulson@14267
   693
paulson@14267
   694
lemma add_mult_distrib2: "k * (m + n) = (k * m) + ((k * n)::nat)"
paulson@14267
   695
  by (induct m) (simp_all add: nat_add_assoc)
paulson@14267
   696
paulson@14267
   697
text {* Associative law for multiplication *}
paulson@14267
   698
lemma nat_mult_assoc: "(m * n) * k = m * ((n * k)::nat)"
paulson@14267
   699
  by (induct m) (simp_all add: add_mult_distrib)
paulson@14267
   700
paulson@14267
   701
nipkow@14740
   702
text{*The naturals form a @{text comm_semiring_1_cancel}*}
obua@14738
   703
instance nat :: comm_semiring_1_cancel
paulson@14267
   704
proof
paulson@14267
   705
  fix i j k :: nat
paulson@14267
   706
  show "(i + j) + k = i + (j + k)" by (rule nat_add_assoc)
paulson@14267
   707
  show "i + j = j + i" by (rule nat_add_commute)
paulson@14267
   708
  show "0 + i = i" by simp
paulson@14267
   709
  show "(i * j) * k = i * (j * k)" by (rule nat_mult_assoc)
paulson@14267
   710
  show "i * j = j * i" by (rule nat_mult_commute)
paulson@14267
   711
  show "1 * i = i" by simp
paulson@14267
   712
  show "(i + j) * k = i * k + j * k" by (simp add: add_mult_distrib)
paulson@14267
   713
  show "0 \<noteq> (1::nat)" by simp
paulson@14341
   714
  assume "k+i = k+j" thus "i=j" by simp
paulson@14341
   715
qed
paulson@14341
   716
paulson@14341
   717
lemma mult_is_0 [simp]: "((m::nat) * n = 0) = (m=0 | n=0)"
paulson@15251
   718
  apply (induct m)
wenzelm@22718
   719
   apply (induct_tac [2] n)
wenzelm@22718
   720
    apply simp_all
paulson@14341
   721
  done
paulson@14341
   722
wenzelm@21243
   723
paulson@14341
   724
subsection {* Monotonicity of Addition *}
paulson@14341
   725
paulson@14341
   726
text {* strict, in 1st argument *}
paulson@14341
   727
lemma add_less_mono1: "i < j ==> i + k < j + (k::nat)"
paulson@14341
   728
  by (induct k) simp_all
paulson@14341
   729
paulson@14341
   730
text {* strict, in both arguments *}
paulson@14341
   731
lemma add_less_mono: "[|i < j; k < l|] ==> i + k < j + (l::nat)"
paulson@14341
   732
  apply (rule add_less_mono1 [THEN less_trans], assumption+)
paulson@15251
   733
  apply (induct j, simp_all)
paulson@14341
   734
  done
paulson@14341
   735
paulson@14341
   736
text {* Deleted @{text less_natE}; use @{text "less_imp_Suc_add RS exE"} *}
paulson@14341
   737
lemma less_imp_Suc_add: "m < n ==> (\<exists>k. n = Suc (m + k))"
paulson@14341
   738
  apply (induct n)
paulson@14341
   739
  apply (simp_all add: order_le_less)
wenzelm@22718
   740
  apply (blast elim!: less_SucE
paulson@14341
   741
               intro!: add_0_right [symmetric] add_Suc_right [symmetric])
paulson@14341
   742
  done
paulson@14341
   743
paulson@14341
   744
text {* strict, in 1st argument; proof is by induction on @{text "k > 0"} *}
nipkow@25134
   745
lemma mult_less_mono2: "(i::nat) < j ==> 0<k ==> k * i < k * j"
nipkow@25134
   746
apply(auto simp: gr0_conv_Suc)
nipkow@25134
   747
apply (induct_tac m)
nipkow@25134
   748
apply (simp_all add: add_less_mono)
nipkow@25134
   749
done
paulson@14341
   750
paulson@14341
   751
nipkow@14740
   752
text{*The naturals form an ordered @{text comm_semiring_1_cancel}*}
obua@14738
   753
instance nat :: ordered_semidom
paulson@14341
   754
proof
paulson@14341
   755
  fix i j k :: nat
paulson@14348
   756
  show "0 < (1::nat)" by simp
paulson@14267
   757
  show "i \<le> j ==> k + i \<le> k + j" by simp
paulson@14267
   758
  show "i < j ==> 0 < k ==> k * i < k * j" by (simp add: mult_less_mono2)
paulson@14267
   759
qed
paulson@14267
   760
paulson@14267
   761
lemma nat_mult_1: "(1::nat) * n = n"
paulson@14267
   762
  by simp
paulson@14267
   763
paulson@14267
   764
lemma nat_mult_1_right: "n * (1::nat) = n"
paulson@14267
   765
  by simp
paulson@14267
   766
paulson@14267
   767
paulson@14267
   768
subsection {* Additional theorems about "less than" *}
paulson@14267
   769
paulson@19870
   770
text{*An induction rule for estabilishing binary relations*}
wenzelm@22718
   771
lemma less_Suc_induct:
paulson@19870
   772
  assumes less:  "i < j"
paulson@19870
   773
     and  step:  "!!i. P i (Suc i)"
paulson@19870
   774
     and  trans: "!!i j k. P i j ==> P j k ==> P i k"
paulson@19870
   775
  shows "P i j"
paulson@19870
   776
proof -
wenzelm@22718
   777
  from less obtain k where j: "j = Suc(i+k)" by (auto dest: less_imp_Suc_add)
wenzelm@22718
   778
  have "P i (Suc (i + k))"
paulson@19870
   779
  proof (induct k)
wenzelm@22718
   780
    case 0
wenzelm@22718
   781
    show ?case by (simp add: step)
paulson@19870
   782
  next
paulson@19870
   783
    case (Suc k)
wenzelm@22718
   784
    thus ?case by (auto intro: assms)
paulson@19870
   785
  qed
wenzelm@22718
   786
  thus "P i j" by (simp add: j)
paulson@19870
   787
qed
paulson@19870
   788
nipkow@24438
   789
text {* The method of infinite descent, frequently used in number theory.
nipkow@24438
   790
Provided by Roelof Oosterhuis.
nipkow@24438
   791
$P(n)$ is true for all $n\in\mathbb{N}$ if
nipkow@24438
   792
\begin{itemize}
nipkow@24438
   793
  \item case ``0'': given $n=0$ prove $P(n)$,
nipkow@24438
   794
  \item case ``smaller'': given $n>0$ and $\neg P(n)$ prove there exists
nipkow@24438
   795
        a smaller integer $m$ such that $\neg P(m)$.
nipkow@24438
   796
\end{itemize} *}
nipkow@24438
   797
nipkow@24523
   798
lemma infinite_descent0[case_names 0 smaller]: 
nipkow@24438
   799
  "\<lbrakk> P 0; !!n. n>0 \<Longrightarrow> \<not> P n \<Longrightarrow> (\<exists>m::nat. m < n \<and> \<not>P m) \<rbrakk> \<Longrightarrow> P n"
nipkow@24438
   800
by (induct n rule: less_induct, case_tac "n>0", auto)
nipkow@24438
   801
nipkow@24523
   802
text{* A compact version without explicit base case: *}
nipkow@24523
   803
lemma infinite_descent:
nipkow@24523
   804
  "\<lbrakk> !!n::nat. \<not> P n \<Longrightarrow>  \<exists>m<n. \<not>  P m \<rbrakk> \<Longrightarrow>  P n"
nipkow@24523
   805
by (induct n rule: less_induct, auto)
nipkow@24523
   806
nipkow@24438
   807
nipkow@24438
   808
text {* Infinite descent using a mapping to $\mathbb{N}$:
nipkow@24438
   809
$P(x)$ is true for all $x\in D$ if there exists a $V: D \to \mathbb{N}$ and
nipkow@24438
   810
\begin{itemize}
nipkow@24438
   811
\item case ``0'': given $V(x)=0$ prove $P(x)$,
nipkow@24438
   812
\item case ``smaller'': given $V(x)>0$ and $\neg P(x)$ prove there exists a $y \in D$ such that $V(y)<V(x)$ and $~\neg P(y)$.
nipkow@24438
   813
\end{itemize}
nipkow@24438
   814
NB: the proof also shows how to use the previous lemma. *}
nipkow@24523
   815
corollary infinite_descent0_measure[case_names 0 smaller]:
nipkow@24523
   816
assumes 0: "!!x. V x = (0::nat) \<Longrightarrow> P x"
nipkow@24523
   817
and     1: "!!x. V x > 0 \<Longrightarrow> \<not>P x \<Longrightarrow> (\<exists>y. V y < V x \<and> \<not>P y)"
nipkow@24438
   818
shows "P x"
nipkow@24438
   819
proof -
nipkow@24438
   820
  obtain n where "n = V x" by auto
nipkow@24523
   821
  moreover have "!!x. V x = n \<Longrightarrow> P x"
nipkow@24523
   822
  proof (induct n rule: infinite_descent0)
nipkow@24438
   823
    case 0 -- "i.e. $V(x) = 0$"
nipkow@24438
   824
    with 0 show "P x" by auto
nipkow@24438
   825
  next -- "now $n>0$ and $P(x)$ does not hold for some $x$ with $V(x)=n$"
nipkow@24438
   826
    case (smaller n)
nipkow@24438
   827
    then obtain x where vxn: "V x = n " and "V x > 0 \<and> \<not> P x" by auto
nipkow@24438
   828
    with 1 obtain y where "V y < V x \<and> \<not> P y" by auto
nipkow@24438
   829
    with vxn obtain m where "m = V y \<and> m<n \<and> \<not> P y" by auto
nipkow@24438
   830
    thus ?case by auto
nipkow@24438
   831
  qed
nipkow@24438
   832
  ultimately show "P x" by auto
nipkow@24438
   833
qed
paulson@19870
   834
nipkow@24523
   835
text{* Again, without explicit base case: *}
nipkow@24523
   836
lemma infinite_descent_measure:
nipkow@24523
   837
assumes "!!x. \<not> P x \<Longrightarrow> \<exists>y. (V::'a\<Rightarrow>nat) y < V x \<and> \<not> P y" shows "P x"
nipkow@24523
   838
proof -
nipkow@24523
   839
  from assms obtain n where "n = V x" by auto
nipkow@24523
   840
  moreover have "!!x. V x = n \<Longrightarrow> P x"
nipkow@24523
   841
  proof (induct n rule: infinite_descent, auto)
nipkow@24523
   842
    fix x assume "\<not> P x"
nipkow@24523
   843
    with assms show "\<exists>m < V x. \<exists>y. V y = m \<and> \<not> P y" by auto
nipkow@24523
   844
  qed
nipkow@24523
   845
  ultimately show "P x" by auto
nipkow@24523
   846
qed
nipkow@24523
   847
nipkow@24523
   848
nipkow@24523
   849
paulson@14267
   850
text {* A [clumsy] way of lifting @{text "<"}
paulson@14267
   851
  monotonicity to @{text "\<le>"} monotonicity *}
paulson@14267
   852
lemma less_mono_imp_le_mono:
nipkow@24438
   853
  "\<lbrakk> !!i j::nat. i < j \<Longrightarrow> f i < f j; i \<le> j \<rbrakk> \<Longrightarrow> f i \<le> ((f j)::nat)"
nipkow@24438
   854
by (simp add: order_le_less) (blast)
nipkow@24438
   855
paulson@14267
   856
paulson@14267
   857
text {* non-strict, in 1st argument *}
paulson@14267
   858
lemma add_le_mono1: "i \<le> j ==> i + k \<le> j + (k::nat)"
nipkow@24438
   859
by (rule add_right_mono)
paulson@14267
   860
paulson@14267
   861
text {* non-strict, in both arguments *}
paulson@14267
   862
lemma add_le_mono: "[| i \<le> j;  k \<le> l |] ==> i + k \<le> j + (l::nat)"
nipkow@24438
   863
by (rule add_mono)
paulson@14267
   864
paulson@14267
   865
lemma le_add2: "n \<le> ((m + n)::nat)"
nipkow@24438
   866
by (insert add_right_mono [of 0 m n], simp)
berghofe@13449
   867
paulson@14267
   868
lemma le_add1: "n \<le> ((n + m)::nat)"
nipkow@24438
   869
by (simp add: add_commute, rule le_add2)
berghofe@13449
   870
berghofe@13449
   871
lemma less_add_Suc1: "i < Suc (i + m)"
nipkow@24438
   872
by (rule le_less_trans, rule le_add1, rule lessI)
berghofe@13449
   873
berghofe@13449
   874
lemma less_add_Suc2: "i < Suc (m + i)"
nipkow@24438
   875
by (rule le_less_trans, rule le_add2, rule lessI)
berghofe@13449
   876
paulson@14267
   877
lemma less_iff_Suc_add: "(m < n) = (\<exists>k. n = Suc (m + k))"
nipkow@24438
   878
by (iprover intro!: less_add_Suc1 less_imp_Suc_add)
berghofe@13449
   879
paulson@14267
   880
lemma trans_le_add1: "(i::nat) \<le> j ==> i \<le> j + m"
nipkow@24438
   881
by (rule le_trans, assumption, rule le_add1)
berghofe@13449
   882
paulson@14267
   883
lemma trans_le_add2: "(i::nat) \<le> j ==> i \<le> m + j"
nipkow@24438
   884
by (rule le_trans, assumption, rule le_add2)
berghofe@13449
   885
berghofe@13449
   886
lemma trans_less_add1: "(i::nat) < j ==> i < j + m"
nipkow@24438
   887
by (rule less_le_trans, assumption, rule le_add1)
berghofe@13449
   888
berghofe@13449
   889
lemma trans_less_add2: "(i::nat) < j ==> i < m + j"
nipkow@24438
   890
by (rule less_le_trans, assumption, rule le_add2)
berghofe@13449
   891
berghofe@13449
   892
lemma add_lessD1: "i + j < (k::nat) ==> i < k"
nipkow@24438
   893
apply (rule le_less_trans [of _ "i+j"])
nipkow@24438
   894
apply (simp_all add: le_add1)
nipkow@24438
   895
done
berghofe@13449
   896
berghofe@13449
   897
lemma not_add_less1 [iff]: "~ (i + j < (i::nat))"
nipkow@24438
   898
apply (rule notI)
nipkow@24438
   899
apply (erule add_lessD1 [THEN less_irrefl])
nipkow@24438
   900
done
berghofe@13449
   901
berghofe@13449
   902
lemma not_add_less2 [iff]: "~ (j + i < (i::nat))"
nipkow@24438
   903
by (simp add: add_commute not_add_less1)
berghofe@13449
   904
paulson@14267
   905
lemma add_leD1: "m + k \<le> n ==> m \<le> (n::nat)"
nipkow@24438
   906
apply (rule order_trans [of _ "m+k"])
nipkow@24438
   907
apply (simp_all add: le_add1)
nipkow@24438
   908
done
berghofe@13449
   909
paulson@14267
   910
lemma add_leD2: "m + k \<le> n ==> k \<le> (n::nat)"
nipkow@24438
   911
apply (simp add: add_commute)
nipkow@24438
   912
apply (erule add_leD1)
nipkow@24438
   913
done
berghofe@13449
   914
paulson@14267
   915
lemma add_leE: "(m::nat) + k \<le> n ==> (m \<le> n ==> k \<le> n ==> R) ==> R"
nipkow@24438
   916
by (blast dest: add_leD1 add_leD2)
berghofe@13449
   917
berghofe@13449
   918
text {* needs @{text "!!k"} for @{text add_ac} to work *}
berghofe@13449
   919
lemma less_add_eq_less: "!!k::nat. k < l ==> m + l = k + n ==> m < n"
nipkow@24438
   920
by (force simp del: add_Suc_right
berghofe@13449
   921
    simp add: less_iff_Suc_add add_Suc_right [symmetric] add_ac)
berghofe@13449
   922
berghofe@13449
   923
berghofe@13449
   924
subsection {* Difference *}
berghofe@13449
   925
berghofe@13449
   926
lemma diff_self_eq_0 [simp]: "(m::nat) - m = 0"
nipkow@24438
   927
by (induct m) simp_all
berghofe@13449
   928
berghofe@13449
   929
text {* Addition is the inverse of subtraction:
paulson@14267
   930
  if @{term "n \<le> m"} then @{term "n + (m - n) = m"}. *}
berghofe@13449
   931
lemma add_diff_inverse: "~  m < n ==> n + (m - n) = (m::nat)"
nipkow@24438
   932
by (induct m n rule: diff_induct) simp_all
berghofe@13449
   933
paulson@14267
   934
lemma le_add_diff_inverse [simp]: "n \<le> m ==> n + (m - n) = (m::nat)"
nipkow@24438
   935
by (simp add: add_diff_inverse linorder_not_less)
berghofe@13449
   936
paulson@14267
   937
lemma le_add_diff_inverse2 [simp]: "n \<le> m ==> (m - n) + n = (m::nat)"
nipkow@24438
   938
by (simp add: le_add_diff_inverse add_commute)
berghofe@13449
   939
berghofe@13449
   940
berghofe@13449
   941
subsection {* More results about difference *}
berghofe@13449
   942
paulson@14267
   943
lemma Suc_diff_le: "n \<le> m ==> Suc m - n = Suc (m - n)"
nipkow@24438
   944
by (induct m n rule: diff_induct) simp_all
berghofe@13449
   945
berghofe@13449
   946
lemma diff_less_Suc: "m - n < Suc m"
nipkow@24438
   947
apply (induct m n rule: diff_induct)
nipkow@24438
   948
apply (erule_tac [3] less_SucE)
nipkow@24438
   949
apply (simp_all add: less_Suc_eq)
nipkow@24438
   950
done
berghofe@13449
   951
paulson@14267
   952
lemma diff_le_self [simp]: "m - n \<le> (m::nat)"
nipkow@24438
   953
by (induct m n rule: diff_induct) (simp_all add: le_SucI)
berghofe@13449
   954
berghofe@13449
   955
lemma less_imp_diff_less: "(j::nat) < k ==> j - n < k"
nipkow@24438
   956
by (rule le_less_trans, rule diff_le_self)
berghofe@13449
   957
berghofe@13449
   958
lemma diff_diff_left: "(i::nat) - j - k = i - (j + k)"
nipkow@24438
   959
by (induct i j rule: diff_induct) simp_all
berghofe@13449
   960
berghofe@13449
   961
lemma Suc_diff_diff [simp]: "(Suc m - n) - Suc k = m - n - k"
nipkow@24438
   962
by (simp add: diff_diff_left)
berghofe@13449
   963
berghofe@13449
   964
lemma diff_Suc_less [simp]: "0<n ==> n - Suc i < n"
nipkow@24438
   965
by (cases n) (auto simp add: le_simps)
berghofe@13449
   966
berghofe@13449
   967
text {* This and the next few suggested by Florian Kammueller *}
berghofe@13449
   968
lemma diff_commute: "(i::nat) - j - k = i - k - j"
nipkow@24438
   969
by (simp add: diff_diff_left add_commute)
berghofe@13449
   970
paulson@14267
   971
lemma diff_add_assoc: "k \<le> (j::nat) ==> (i + j) - k = i + (j - k)"
nipkow@24438
   972
by (induct j k rule: diff_induct) simp_all
berghofe@13449
   973
paulson@14267
   974
lemma diff_add_assoc2: "k \<le> (j::nat) ==> (j + i) - k = (j - k) + i"
nipkow@24438
   975
by (simp add: add_commute diff_add_assoc)
berghofe@13449
   976
berghofe@13449
   977
lemma diff_add_inverse: "(n + m) - n = (m::nat)"
nipkow@24438
   978
by (induct n) simp_all
berghofe@13449
   979
berghofe@13449
   980
lemma diff_add_inverse2: "(m + n) - n = (m::nat)"
nipkow@24438
   981
by (simp add: diff_add_assoc)
berghofe@13449
   982
paulson@14267
   983
lemma le_imp_diff_is_add: "i \<le> (j::nat) ==> (j - i = k) = (j = k + i)"
nipkow@24438
   984
by (auto simp add: diff_add_inverse2)
berghofe@13449
   985
paulson@14267
   986
lemma diff_is_0_eq [simp]: "((m::nat) - n = 0) = (m \<le> n)"
nipkow@24438
   987
by (induct m n rule: diff_induct) simp_all
berghofe@13449
   988
paulson@14267
   989
lemma diff_is_0_eq' [simp]: "m \<le> n ==> (m::nat) - n = 0"
nipkow@24438
   990
by (rule iffD2, rule diff_is_0_eq)
berghofe@13449
   991
berghofe@13449
   992
lemma zero_less_diff [simp]: "(0 < n - (m::nat)) = (m < n)"
nipkow@24438
   993
by (induct m n rule: diff_induct) simp_all
berghofe@13449
   994
wenzelm@22718
   995
lemma less_imp_add_positive:
wenzelm@22718
   996
  assumes "i < j"
wenzelm@22718
   997
  shows "\<exists>k::nat. 0 < k & i + k = j"
wenzelm@22718
   998
proof
wenzelm@22718
   999
  from assms show "0 < j - i & i + (j - i) = j"
huffman@23476
  1000
    by (simp add: order_less_imp_le)
wenzelm@22718
  1001
qed
wenzelm@9436
  1002
berghofe@13449
  1003
lemma diff_cancel: "(k + m) - (k + n) = m - (n::nat)"
nipkow@24438
  1004
by (induct k) simp_all
berghofe@13449
  1005
berghofe@13449
  1006
lemma diff_cancel2: "(m + k) - (n + k) = m - (n::nat)"
nipkow@24438
  1007
by (simp add: diff_cancel add_commute)
berghofe@13449
  1008
berghofe@13449
  1009
lemma diff_add_0: "n - (n + m) = (0::nat)"
nipkow@24438
  1010
by (induct n) simp_all
berghofe@13449
  1011
berghofe@13449
  1012
berghofe@13449
  1013
text {* Difference distributes over multiplication *}
berghofe@13449
  1014
berghofe@13449
  1015
lemma diff_mult_distrib: "((m::nat) - n) * k = (m * k) - (n * k)"
nipkow@24438
  1016
by (induct m n rule: diff_induct) (simp_all add: diff_cancel)
berghofe@13449
  1017
berghofe@13449
  1018
lemma diff_mult_distrib2: "k * ((m::nat) - n) = (k * m) - (k * n)"
nipkow@24438
  1019
by (simp add: diff_mult_distrib mult_commute [of k])
berghofe@13449
  1020
  -- {* NOT added as rewrites, since sometimes they are used from right-to-left *}
berghofe@13449
  1021
berghofe@13449
  1022
lemmas nat_distrib =
berghofe@13449
  1023
  add_mult_distrib add_mult_distrib2 diff_mult_distrib diff_mult_distrib2
berghofe@13449
  1024
berghofe@13449
  1025
berghofe@13449
  1026
subsection {* Monotonicity of Multiplication *}
berghofe@13449
  1027
paulson@14267
  1028
lemma mult_le_mono1: "i \<le> (j::nat) ==> i * k \<le> j * k"
nipkow@24438
  1029
by (simp add: mult_right_mono)
berghofe@13449
  1030
paulson@14267
  1031
lemma mult_le_mono2: "i \<le> (j::nat) ==> k * i \<le> k * j"
nipkow@24438
  1032
by (simp add: mult_left_mono)
berghofe@13449
  1033
paulson@14267
  1034
text {* @{text "\<le>"} monotonicity, BOTH arguments *}
paulson@14267
  1035
lemma mult_le_mono: "i \<le> (j::nat) ==> k \<le> l ==> i * k \<le> j * l"
nipkow@24438
  1036
by (simp add: mult_mono)
berghofe@13449
  1037
berghofe@13449
  1038
lemma mult_less_mono1: "(i::nat) < j ==> 0 < k ==> i * k < j * k"
nipkow@24438
  1039
by (simp add: mult_strict_right_mono)
berghofe@13449
  1040
paulson@14266
  1041
text{*Differs from the standard @{text zero_less_mult_iff} in that
paulson@14266
  1042
      there are no negative numbers.*}
paulson@14266
  1043
lemma nat_0_less_mult_iff [simp]: "(0 < (m::nat) * n) = (0 < m & 0 < n)"
berghofe@13449
  1044
  apply (induct m)
wenzelm@22718
  1045
   apply simp
wenzelm@22718
  1046
  apply (case_tac n)
wenzelm@22718
  1047
   apply simp_all
berghofe@13449
  1048
  done
berghofe@13449
  1049
paulson@14267
  1050
lemma one_le_mult_iff [simp]: "(Suc 0 \<le> m * n) = (1 \<le> m & 1 \<le> n)"
berghofe@13449
  1051
  apply (induct m)
wenzelm@22718
  1052
   apply simp
wenzelm@22718
  1053
  apply (case_tac n)
wenzelm@22718
  1054
   apply simp_all
berghofe@13449
  1055
  done
berghofe@13449
  1056
berghofe@13449
  1057
lemma mult_eq_1_iff [simp]: "(m * n = Suc 0) = (m = 1 & n = 1)"
wenzelm@22718
  1058
  apply (induct m)
wenzelm@22718
  1059
   apply simp
wenzelm@22718
  1060
  apply (induct n)
wenzelm@22718
  1061
   apply auto
berghofe@13449
  1062
  done
berghofe@13449
  1063
paulson@24286
  1064
lemma one_eq_mult_iff [simp,noatp]: "(Suc 0 = m * n) = (m = 1 & n = 1)"
berghofe@13449
  1065
  apply (rule trans)
paulson@14208
  1066
  apply (rule_tac [2] mult_eq_1_iff, fastsimp)
berghofe@13449
  1067
  done
berghofe@13449
  1068
paulson@14341
  1069
lemma mult_less_cancel2 [simp]: "((m::nat) * k < n * k) = (0 < k & m < n)"
berghofe@13449
  1070
  apply (safe intro!: mult_less_mono1)
paulson@14208
  1071
  apply (case_tac k, auto)
berghofe@13449
  1072
  apply (simp del: le_0_eq add: linorder_not_le [symmetric])
berghofe@13449
  1073
  apply (blast intro: mult_le_mono1)
berghofe@13449
  1074
  done
berghofe@13449
  1075
berghofe@13449
  1076
lemma mult_less_cancel1 [simp]: "(k * (m::nat) < k * n) = (0 < k & m < n)"
nipkow@24438
  1077
by (simp add: mult_commute [of k])
berghofe@13449
  1078
paulson@14267
  1079
lemma mult_le_cancel1 [simp]: "(k * (m::nat) \<le> k * n) = (0 < k --> m \<le> n)"
nipkow@24438
  1080
by (simp add: linorder_not_less [symmetric], auto)
berghofe@13449
  1081
paulson@14267
  1082
lemma mult_le_cancel2 [simp]: "((m::nat) * k \<le> n * k) = (0 < k --> m \<le> n)"
nipkow@24438
  1083
by (simp add: linorder_not_less [symmetric], auto)
berghofe@13449
  1084
paulson@14341
  1085
lemma mult_cancel2 [simp]: "(m * k = n * k) = (m = n | (k = (0::nat)))"
nipkow@25134
  1086
apply (cut_tac less_linear, safe, auto simp add: neq0_conv)
nipkow@25134
  1087
apply (drule mult_less_mono1, assumption, simp)+
nipkow@25134
  1088
done
berghofe@13449
  1089
berghofe@13449
  1090
lemma mult_cancel1 [simp]: "(k * m = k * n) = (m = n | (k = (0::nat)))"
nipkow@24438
  1091
by (simp add: mult_commute [of k])
berghofe@13449
  1092
berghofe@13449
  1093
lemma Suc_mult_less_cancel1: "(Suc k * m < Suc k * n) = (m < n)"
nipkow@24438
  1094
by (subst mult_less_cancel1) simp
berghofe@13449
  1095
paulson@14267
  1096
lemma Suc_mult_le_cancel1: "(Suc k * m \<le> Suc k * n) = (m \<le> n)"
nipkow@24438
  1097
by (subst mult_le_cancel1) simp
berghofe@13449
  1098
berghofe@13449
  1099
lemma Suc_mult_cancel1: "(Suc k * m = Suc k * n) = (m = n)"
nipkow@24438
  1100
by (subst mult_cancel1) simp
berghofe@13449
  1101
berghofe@13449
  1102
text {* Lemma for @{text gcd} *}
berghofe@13449
  1103
lemma mult_eq_self_implies_10: "(m::nat) = m * n ==> n = 1 | m = 0"
berghofe@13449
  1104
  apply (drule sym)
berghofe@13449
  1105
  apply (rule disjCI)
berghofe@13449
  1106
  apply (rule nat_less_cases, erule_tac [2] _)
paulson@25157
  1107
   apply (drule_tac [2] mult_less_mono2)
paulson@25157
  1108
    apply (auto simp add: neq0_conv)
berghofe@13449
  1109
  done
wenzelm@9436
  1110
haftmann@20588
  1111
haftmann@24995
  1112
subsection {* size of a datatype value *}
haftmann@24995
  1113
haftmann@24995
  1114
class size = type +
haftmann@24995
  1115
  fixes size :: "'a \<Rightarrow> nat"
haftmann@24995
  1116
haftmann@24995
  1117
use "Tools/function_package/size.ML"
haftmann@24995
  1118
haftmann@24995
  1119
setup Size.setup
haftmann@24995
  1120
haftmann@24995
  1121
lemma nat_size [simp, code func]: "size (n\<Colon>nat) = n"
haftmann@24995
  1122
  by (induct n) simp_all
haftmann@24995
  1123
haftmann@24995
  1124
lemma size_bool [code func]:
haftmann@24995
  1125
  "size (b\<Colon>bool) = 0" by (cases b) auto
haftmann@24995
  1126
haftmann@24995
  1127
declare "*.size" [noatp]
haftmann@24995
  1128
haftmann@24995
  1129
haftmann@18702
  1130
subsection {* Code generator setup *}
haftmann@18702
  1131
haftmann@20588
  1132
instance nat :: eq ..
haftmann@20588
  1133
haftmann@20588
  1134
lemma [code func]:
haftmann@25145
  1135
  "(0\<Colon>nat) = 0 \<longleftrightarrow> True"
haftmann@25145
  1136
  "Suc n = Suc m \<longleftrightarrow> n = m"
haftmann@25145
  1137
  "Suc n = 0 \<longleftrightarrow> False"
haftmann@25145
  1138
  "0 = Suc m \<longleftrightarrow> False"
haftmann@25145
  1139
  by auto
haftmann@20588
  1140
haftmann@20588
  1141
lemma [code func]:
haftmann@25145
  1142
  "(0\<Colon>nat) \<le> m \<longleftrightarrow> True"
haftmann@25145
  1143
  "Suc (n\<Colon>nat) \<le> m \<longleftrightarrow> n < m"
haftmann@25145
  1144
  "(n\<Colon>nat) < 0 \<longleftrightarrow> False"
haftmann@25145
  1145
  "(n\<Colon>nat) < Suc m \<longleftrightarrow> n \<le> m"
haftmann@22348
  1146
  using Suc_le_eq less_Suc_eq_le by simp_all
haftmann@20588
  1147
wenzelm@21243
  1148
haftmann@24196
  1149
subsection{*Embedding of the Naturals into any
haftmann@24196
  1150
  @{text semiring_1}: @{term of_nat}*}
haftmann@24196
  1151
haftmann@24196
  1152
context semiring_1
haftmann@24196
  1153
begin
haftmann@24196
  1154
haftmann@24196
  1155
definition
haftmann@25062
  1156
  of_nat_def: "of_nat = nat_rec 0 (\<lambda>_. (op +) 1)"
haftmann@24196
  1157
haftmann@24196
  1158
end
haftmann@24196
  1159
wenzelm@21243
  1160
subsection {* Further Arithmetic Facts Concerning the Natural Numbers *}
wenzelm@21243
  1161
haftmann@22845
  1162
lemma subst_equals:
haftmann@22845
  1163
  assumes 1: "t = s" and 2: "u = t"
haftmann@22845
  1164
  shows "u = s"
haftmann@22845
  1165
  using 2 1 by (rule trans)
haftmann@22845
  1166
haftmann@24196
  1167
wenzelm@21243
  1168
use "arith_data.ML"
wenzelm@24091
  1169
declaration {* K arith_data_setup *}
wenzelm@24091
  1170
wenzelm@24091
  1171
use "Tools/lin_arith.ML"
wenzelm@24091
  1172
declaration {* K LinArith.setup *}
wenzelm@24091
  1173
wenzelm@21243
  1174
wenzelm@21243
  1175
text{*The following proofs may rely on the arithmetic proof procedures.*}
wenzelm@21243
  1176
wenzelm@21243
  1177
lemma le_iff_add: "(m::nat) \<le> n = (\<exists>k. n = m + k)"
nipkow@24438
  1178
by (auto simp: le_eq_less_or_eq dest: less_imp_Suc_add)
wenzelm@21243
  1179
wenzelm@21243
  1180
lemma pred_nat_trancl_eq_le: "((m, n) : pred_nat^*) = (m \<le> n)"
nipkow@24438
  1181
by (simp add: less_eq reflcl_trancl [symmetric] del: reflcl_trancl, arith)
wenzelm@21243
  1182
wenzelm@21243
  1183
lemma nat_diff_split:
wenzelm@22718
  1184
  "P(a - b::nat) = ((a<b --> P 0) & (ALL d. a = b + d --> P d))"
wenzelm@21243
  1185
    -- {* elimination of @{text -} on @{text nat} *}
nipkow@24438
  1186
by (cases "a<b" rule: case_split) (auto simp add: diff_is_0_eq [THEN iffD2])
wenzelm@21243
  1187
wenzelm@21243
  1188
lemma nat_diff_split_asm:
wenzelm@21243
  1189
    "P(a - b::nat) = (~ (a < b & ~ P 0 | (EX d. a = b + d & ~ P d)))"
wenzelm@21243
  1190
    -- {* elimination of @{text -} on @{text nat} in assumptions *}
nipkow@24438
  1191
by (simp split: nat_diff_split)
wenzelm@21243
  1192
wenzelm@21243
  1193
lemmas [arith_split] = nat_diff_split split_min split_max
wenzelm@21243
  1194
wenzelm@21243
  1195
wenzelm@21243
  1196
lemma le_square: "m \<le> m * (m::nat)"
nipkow@24438
  1197
by (induct m) auto
wenzelm@21243
  1198
wenzelm@21243
  1199
lemma le_cube: "(m::nat) \<le> m * (m * m)"
nipkow@24438
  1200
by (induct m) auto
wenzelm@21243
  1201
wenzelm@21243
  1202
wenzelm@21243
  1203
text{*Subtraction laws, mostly by Clemens Ballarin*}
wenzelm@21243
  1204
wenzelm@21243
  1205
lemma diff_less_mono: "[| a < (b::nat); c \<le> a |] ==> a-c < b-c"
nipkow@24438
  1206
by arith
wenzelm@21243
  1207
wenzelm@21243
  1208
lemma less_diff_conv: "(i < j-k) = (i+k < (j::nat))"
nipkow@24438
  1209
by arith
wenzelm@21243
  1210
wenzelm@21243
  1211
lemma le_diff_conv: "(j-k \<le> (i::nat)) = (j \<le> i+k)"
nipkow@24438
  1212
by arith
wenzelm@21243
  1213
wenzelm@21243
  1214
lemma le_diff_conv2: "k \<le> j ==> (i \<le> j-k) = (i+k \<le> (j::nat))"
nipkow@24438
  1215
by arith
wenzelm@21243
  1216
wenzelm@21243
  1217
lemma diff_diff_cancel [simp]: "i \<le> (n::nat) ==> n - (n - i) = i"
nipkow@24438
  1218
by arith
wenzelm@21243
  1219
wenzelm@21243
  1220
lemma le_add_diff: "k \<le> (n::nat) ==> m \<le> n + m - k"
nipkow@24438
  1221
by arith
wenzelm@21243
  1222
wenzelm@21243
  1223
(*Replaces the previous diff_less and le_diff_less, which had the stronger
wenzelm@21243
  1224
  second premise n\<le>m*)
wenzelm@21243
  1225
lemma diff_less[simp]: "!!m::nat. [| 0<n; 0<m |] ==> m - n < m"
nipkow@24438
  1226
by arith
wenzelm@21243
  1227
wenzelm@21243
  1228
wenzelm@21243
  1229
(** Simplification of relational expressions involving subtraction **)
wenzelm@21243
  1230
wenzelm@21243
  1231
lemma diff_diff_eq: "[| k \<le> m;  k \<le> (n::nat) |] ==> ((m-k) - (n-k)) = (m-n)"
nipkow@24438
  1232
by (simp split add: nat_diff_split)
wenzelm@21243
  1233
wenzelm@21243
  1234
lemma eq_diff_iff: "[| k \<le> m;  k \<le> (n::nat) |] ==> (m-k = n-k) = (m=n)"
nipkow@24438
  1235
by (auto split add: nat_diff_split)
wenzelm@21243
  1236
wenzelm@21243
  1237
lemma less_diff_iff: "[| k \<le> m;  k \<le> (n::nat) |] ==> (m-k < n-k) = (m<n)"
nipkow@24438
  1238
by (auto split add: nat_diff_split)
wenzelm@21243
  1239
wenzelm@21243
  1240
lemma le_diff_iff: "[| k \<le> m;  k \<le> (n::nat) |] ==> (m-k \<le> n-k) = (m\<le>n)"
nipkow@24438
  1241
by (auto split add: nat_diff_split)
wenzelm@21243
  1242
wenzelm@21243
  1243
wenzelm@21243
  1244
text{*(Anti)Monotonicity of subtraction -- by Stephan Merz*}
wenzelm@21243
  1245
wenzelm@21243
  1246
(* Monotonicity of subtraction in first argument *)
wenzelm@21243
  1247
lemma diff_le_mono: "m \<le> (n::nat) ==> (m-l) \<le> (n-l)"
nipkow@24438
  1248
by (simp split add: nat_diff_split)
wenzelm@21243
  1249
wenzelm@21243
  1250
lemma diff_le_mono2: "m \<le> (n::nat) ==> (l-n) \<le> (l-m)"
nipkow@24438
  1251
by (simp split add: nat_diff_split)
wenzelm@21243
  1252
wenzelm@21243
  1253
lemma diff_less_mono2: "[| m < (n::nat); m<l |] ==> (l-n) < (l-m)"
nipkow@24438
  1254
by (simp split add: nat_diff_split)
wenzelm@21243
  1255
wenzelm@21243
  1256
lemma diffs0_imp_equal: "!!m::nat. [| m-n = 0; n-m = 0 |] ==>  m=n"
nipkow@24438
  1257
by (simp split add: nat_diff_split)
wenzelm@21243
  1258
wenzelm@21243
  1259
text{*Lemmas for ex/Factorization*}
wenzelm@21243
  1260
wenzelm@21243
  1261
lemma one_less_mult: "[| Suc 0 < n; Suc 0 < m |] ==> Suc 0 < m*n"
nipkow@24438
  1262
by (cases m) auto
wenzelm@21243
  1263
wenzelm@21243
  1264
lemma n_less_m_mult_n: "[| Suc 0 < n; Suc 0 < m |] ==> n<m*n"
nipkow@24438
  1265
by (cases m) auto
wenzelm@21243
  1266
wenzelm@21243
  1267
lemma n_less_n_mult_m: "[| Suc 0 < n; Suc 0 < m |] ==> n<n*m"
nipkow@24438
  1268
by (cases m) auto
wenzelm@21243
  1269
krauss@23001
  1270
text {* Specialized induction principles that work "backwards": *}
krauss@23001
  1271
krauss@23001
  1272
lemma inc_induct[consumes 1, case_names base step]:
krauss@23001
  1273
  assumes less: "i <= j"
krauss@23001
  1274
  assumes base: "P j"
krauss@23001
  1275
  assumes step: "!!i. [| i < j; P (Suc i) |] ==> P i"
krauss@23001
  1276
  shows "P i"
krauss@23001
  1277
  using less
krauss@23001
  1278
proof (induct d=="j - i" arbitrary: i)
krauss@23001
  1279
  case (0 i)
krauss@23001
  1280
  hence "i = j" by simp
krauss@23001
  1281
  with base show ?case by simp
krauss@23001
  1282
next
krauss@23001
  1283
  case (Suc d i)
krauss@23001
  1284
  hence "i < j" "P (Suc i)"
krauss@23001
  1285
    by simp_all
krauss@23001
  1286
  thus "P i" by (rule step)
krauss@23001
  1287
qed
krauss@23001
  1288
krauss@23001
  1289
lemma strict_inc_induct[consumes 1, case_names base step]:
krauss@23001
  1290
  assumes less: "i < j"
krauss@23001
  1291
  assumes base: "!!i. j = Suc i ==> P i"
krauss@23001
  1292
  assumes step: "!!i. [| i < j; P (Suc i) |] ==> P i"
krauss@23001
  1293
  shows "P i"
krauss@23001
  1294
  using less
krauss@23001
  1295
proof (induct d=="j - i - 1" arbitrary: i)
krauss@23001
  1296
  case (0 i)
krauss@23001
  1297
  with `i < j` have "j = Suc i" by simp
krauss@23001
  1298
  with base show ?case by simp
krauss@23001
  1299
next
krauss@23001
  1300
  case (Suc d i)
krauss@23001
  1301
  hence "i < j" "P (Suc i)"
krauss@23001
  1302
    by simp_all
krauss@23001
  1303
  thus "P i" by (rule step)
krauss@23001
  1304
qed
krauss@23001
  1305
krauss@23001
  1306
lemma zero_induct_lemma: "P k ==> (!!n. P (Suc n) ==> P n) ==> P (k - i)"
krauss@23001
  1307
  using inc_induct[of "k - i" k P, simplified] by blast
krauss@23001
  1308
krauss@23001
  1309
lemma zero_induct: "P k ==> (!!n. P (Suc n) ==> P n) ==> P 0"
krauss@23001
  1310
  using inc_induct[of 0 k P] by blast
wenzelm@21243
  1311
wenzelm@21243
  1312
text{*Rewriting to pull differences out*}
wenzelm@21243
  1313
wenzelm@21243
  1314
lemma diff_diff_right [simp]: "k\<le>j --> i - (j - k) = i + (k::nat) - j"
nipkow@24438
  1315
by arith
wenzelm@21243
  1316
wenzelm@21243
  1317
lemma diff_Suc_diff_eq1 [simp]: "k \<le> j ==> m - Suc (j - k) = m + k - Suc j"
nipkow@24438
  1318
by arith
wenzelm@21243
  1319
wenzelm@21243
  1320
lemma diff_Suc_diff_eq2 [simp]: "k \<le> j ==> Suc (j - k) - m = Suc j - (k + m)"
nipkow@24438
  1321
by arith
wenzelm@21243
  1322
wenzelm@21243
  1323
(*The others are
wenzelm@21243
  1324
      i - j - k = i - (j + k),
wenzelm@21243
  1325
      k \<le> j ==> j - k + i = j + i - k,
wenzelm@21243
  1326
      k \<le> j ==> i + (j - k) = i + j - k *)
wenzelm@21243
  1327
lemmas add_diff_assoc = diff_add_assoc [symmetric]
wenzelm@21243
  1328
lemmas add_diff_assoc2 = diff_add_assoc2[symmetric]
wenzelm@21243
  1329
declare diff_diff_left [simp]  add_diff_assoc [simp]  add_diff_assoc2[simp]
wenzelm@21243
  1330
wenzelm@21243
  1331
text{*At present we prove no analogue of @{text not_less_Least} or @{text
wenzelm@21243
  1332
Least_Suc}, since there appears to be no need.*}
wenzelm@21243
  1333
wenzelm@22718
  1334
wenzelm@22718
  1335
subsection{*Embedding of the Naturals into any
huffman@23276
  1336
  @{text semiring_1}: @{term of_nat}*}
wenzelm@21243
  1337
haftmann@24196
  1338
context semiring_1
haftmann@24196
  1339
begin
wenzelm@21243
  1340
haftmann@24196
  1341
lemma of_nat_simps [simp, code]:
haftmann@25062
  1342
  shows of_nat_0:   "of_nat 0 = 0"
haftmann@25062
  1343
    and of_nat_Suc: "of_nat (Suc m) = 1 + of_nat m"
haftmann@24196
  1344
  unfolding of_nat_def by simp_all
haftmann@24196
  1345
haftmann@24196
  1346
end
wenzelm@21243
  1347
haftmann@22920
  1348
lemma of_nat_id [simp]: "(of_nat n \<Colon> nat) = n"
nipkow@24438
  1349
by (induct n) auto
haftmann@22920
  1350
wenzelm@21243
  1351
lemma of_nat_1 [simp]: "of_nat 1 = 1"
nipkow@24438
  1352
by simp
wenzelm@21243
  1353
haftmann@24196
  1354
lemma of_nat_add [simp]: "of_nat (m + n) = of_nat m + of_nat n"
nipkow@24438
  1355
by (induct m) (simp_all add: add_ac)
wenzelm@21243
  1356
huffman@23431
  1357
lemma of_nat_mult: "of_nat (m*n) = of_nat m * of_nat n"
nipkow@24438
  1358
by (induct m) (simp_all add: add_ac left_distrib)
wenzelm@21243
  1359
wenzelm@21243
  1360
lemma zero_le_imp_of_nat: "0 \<le> (of_nat m::'a::ordered_semidom)"
wenzelm@22718
  1361
  apply (induct m, simp_all)
wenzelm@22718
  1362
  apply (erule order_trans)
huffman@23431
  1363
  apply (rule ord_le_eq_trans [OF _ add_commute])
wenzelm@22718
  1364
  apply (rule less_add_one [THEN order_less_imp_le])
wenzelm@22718
  1365
  done
wenzelm@21243
  1366
wenzelm@21243
  1367
lemma less_imp_of_nat_less:
wenzelm@22718
  1368
    "m < n ==> of_nat m < (of_nat n::'a::ordered_semidom)"
wenzelm@22718
  1369
  apply (induct m n rule: diff_induct, simp_all)
huffman@23431
  1370
  apply (insert add_less_le_mono [OF zero_less_one zero_le_imp_of_nat], force)
wenzelm@22718
  1371
  done
wenzelm@21243
  1372
wenzelm@21243
  1373
lemma of_nat_less_imp_less:
wenzelm@22718
  1374
    "of_nat m < (of_nat n::'a::ordered_semidom) ==> m < n"
wenzelm@22718
  1375
  apply (induct m n rule: diff_induct, simp_all)
wenzelm@22718
  1376
  apply (insert zero_le_imp_of_nat)
wenzelm@22718
  1377
  apply (force simp add: linorder_not_less [symmetric])
wenzelm@22718
  1378
  done
wenzelm@21243
  1379
wenzelm@21243
  1380
lemma of_nat_less_iff [simp]:
wenzelm@22718
  1381
    "(of_nat m < (of_nat n::'a::ordered_semidom)) = (m<n)"
nipkow@24438
  1382
by (blast intro: of_nat_less_imp_less less_imp_of_nat_less)
wenzelm@21243
  1383
wenzelm@21243
  1384
text{*Special cases where either operand is zero*}
wenzelm@22718
  1385
wenzelm@22718
  1386
lemma of_nat_0_less_iff [simp]: "((0::'a::ordered_semidom) < of_nat n) = (0 < n)"
nipkow@24438
  1387
by (rule of_nat_less_iff [of 0, simplified])
wenzelm@22718
  1388
wenzelm@22718
  1389
lemma of_nat_less_0_iff [simp]: "\<not> of_nat m < (0::'a::ordered_semidom)"
nipkow@24438
  1390
by (rule of_nat_less_iff [of _ 0, simplified])
wenzelm@21243
  1391
wenzelm@21243
  1392
lemma of_nat_le_iff [simp]:
wenzelm@22718
  1393
    "(of_nat m \<le> (of_nat n::'a::ordered_semidom)) = (m \<le> n)"
nipkow@24438
  1394
by (simp add: linorder_not_less [symmetric])
wenzelm@21243
  1395
wenzelm@21243
  1396
text{*Special cases where either operand is zero*}
wenzelm@22718
  1397
lemma of_nat_0_le_iff [simp]: "(0::'a::ordered_semidom) \<le> of_nat n"
nipkow@24438
  1398
by (rule of_nat_le_iff [of 0, simplified])
paulson@24286
  1399
lemma of_nat_le_0_iff [simp,noatp]: "(of_nat m \<le> (0::'a::ordered_semidom)) = (m = 0)"
nipkow@24438
  1400
by (rule of_nat_le_iff [of _ 0, simplified])
wenzelm@21243
  1401
huffman@23282
  1402
text{*Class for unital semirings with characteristic zero.
huffman@23282
  1403
 Includes non-ordered rings like the complex numbers.*}
haftmann@24196
  1404
haftmann@24196
  1405
class semiring_char_0 = semiring_1 +
haftmann@24196
  1406
  assumes of_nat_eq_iff [simp]:
haftmann@25062
  1407
    "of_nat m = of_nat n \<longleftrightarrow> m = n"
huffman@23282
  1408
huffman@23282
  1409
text{*Every @{text ordered_semidom} has characteristic zero.*}
huffman@23282
  1410
instance ordered_semidom < semiring_char_0
huffman@23282
  1411
by intro_classes (simp add: order_eq_iff)
wenzelm@21243
  1412
wenzelm@21243
  1413
text{*Special cases where either operand is zero*}
paulson@24286
  1414
lemma of_nat_0_eq_iff [simp,noatp]: "((0::'a::semiring_char_0) = of_nat n) = (0 = n)"
nipkow@24438
  1415
by (rule of_nat_eq_iff [of 0, simplified])
paulson@24286
  1416
lemma of_nat_eq_0_iff [simp,noatp]: "(of_nat m = (0::'a::semiring_char_0)) = (m = 0)"
nipkow@24438
  1417
by (rule of_nat_eq_iff [of _ 0, simplified])
wenzelm@21243
  1418
huffman@23347
  1419
lemma inj_of_nat: "inj (of_nat :: nat \<Rightarrow> 'a::semiring_char_0)"
nipkow@24438
  1420
by (simp add: inj_on_def)
huffman@23347
  1421
huffman@23438
  1422
lemma of_nat_diff:
wenzelm@22718
  1423
    "n \<le> m ==> of_nat (m - n) = of_nat m - (of_nat n :: 'a::ring_1)"
nipkow@24438
  1424
by (simp del: of_nat_add
wenzelm@22718
  1425
    add: compare_rls of_nat_add [symmetric] split add: nat_diff_split)
wenzelm@21243
  1426
haftmann@24196
  1427
lemma abs_of_nat [simp]: "\<bar>of_nat n::'a::ordered_idom\<bar> = of_nat n"
nipkow@24438
  1428
by (rule of_nat_0_le_iff [THEN abs_of_nonneg])
haftmann@24196
  1429
haftmann@23852
  1430
haftmann@23852
  1431
subsection {*The Set of Natural Numbers*}
haftmann@23852
  1432
haftmann@23852
  1433
definition
haftmann@23852
  1434
  Nats  :: "'a::semiring_1 set"
haftmann@23852
  1435
where
haftmann@23852
  1436
  "Nats = range of_nat"
haftmann@23852
  1437
haftmann@23852
  1438
notation (xsymbols)
haftmann@23852
  1439
  Nats  ("\<nat>")
haftmann@23852
  1440
haftmann@23852
  1441
lemma of_nat_in_Nats [simp]: "of_nat n \<in> Nats"
nipkow@24438
  1442
by (simp add: Nats_def)
haftmann@23852
  1443
haftmann@23852
  1444
lemma Nats_0 [simp]: "0 \<in> Nats"
haftmann@23852
  1445
apply (simp add: Nats_def)
haftmann@23852
  1446
apply (rule range_eqI)
haftmann@23852
  1447
apply (rule of_nat_0 [symmetric])
haftmann@23852
  1448
done
haftmann@23852
  1449
haftmann@23852
  1450
lemma Nats_1 [simp]: "1 \<in> Nats"
haftmann@23852
  1451
apply (simp add: Nats_def)
haftmann@23852
  1452
apply (rule range_eqI)
haftmann@23852
  1453
apply (rule of_nat_1 [symmetric])
haftmann@23852
  1454
done
haftmann@23852
  1455
haftmann@23852
  1456
lemma Nats_add [simp]: "[|a \<in> Nats; b \<in> Nats|] ==> a+b \<in> Nats"
haftmann@23852
  1457
apply (auto simp add: Nats_def)
haftmann@23852
  1458
apply (rule range_eqI)
haftmann@23852
  1459
apply (rule of_nat_add [symmetric])
haftmann@23852
  1460
done
haftmann@23852
  1461
haftmann@23852
  1462
lemma Nats_mult [simp]: "[|a \<in> Nats; b \<in> Nats|] ==> a*b \<in> Nats"
haftmann@23852
  1463
apply (auto simp add: Nats_def)
haftmann@23852
  1464
apply (rule range_eqI)
haftmann@23852
  1465
apply (rule of_nat_mult [symmetric])
haftmann@23852
  1466
done
haftmann@23852
  1467
haftmann@23852
  1468
lemma of_nat_eq_id [simp]: "of_nat = (id :: nat => nat)"
nipkow@24438
  1469
by (auto simp add: expand_fun_eq)
haftmann@23852
  1470
haftmann@23852
  1471
haftmann@24995
  1472
text {* the lattice order on @{typ nat} *}
haftmann@24995
  1473
haftmann@22483
  1474
instance nat :: distrib_lattice
haftmann@22483
  1475
  "inf \<equiv> min"
haftmann@22483
  1476
  "sup \<equiv> max"
haftmann@24995
  1477
  by intro_classes
haftmann@24995
  1478
    (simp_all add: inf_nat_def sup_nat_def)
haftmann@24699
  1479
krauss@22157
  1480
haftmann@24196
  1481
subsection {* legacy bindings *}
haftmann@24196
  1482
haftmann@24196
  1483
ML
haftmann@24196
  1484
{*
haftmann@24196
  1485
val pred_nat_trancl_eq_le = thm "pred_nat_trancl_eq_le";
haftmann@24196
  1486
val nat_diff_split = thm "nat_diff_split";
haftmann@24196
  1487
val nat_diff_split_asm = thm "nat_diff_split_asm";
haftmann@24196
  1488
val le_square = thm "le_square";
haftmann@24196
  1489
val le_cube = thm "le_cube";
haftmann@24196
  1490
val diff_less_mono = thm "diff_less_mono";
haftmann@24196
  1491
val less_diff_conv = thm "less_diff_conv";
haftmann@24196
  1492
val le_diff_conv = thm "le_diff_conv";
haftmann@24196
  1493
val le_diff_conv2 = thm "le_diff_conv2";
haftmann@24196
  1494
val diff_diff_cancel = thm "diff_diff_cancel";
haftmann@24196
  1495
val le_add_diff = thm "le_add_diff";
haftmann@24196
  1496
val diff_less = thm "diff_less";
haftmann@24196
  1497
val diff_diff_eq = thm "diff_diff_eq";
haftmann@24196
  1498
val eq_diff_iff = thm "eq_diff_iff";
haftmann@24196
  1499
val less_diff_iff = thm "less_diff_iff";
haftmann@24196
  1500
val le_diff_iff = thm "le_diff_iff";
haftmann@24196
  1501
val diff_le_mono = thm "diff_le_mono";
haftmann@24196
  1502
val diff_le_mono2 = thm "diff_le_mono2";
haftmann@24196
  1503
val diff_less_mono2 = thm "diff_less_mono2";
haftmann@24196
  1504
val diffs0_imp_equal = thm "diffs0_imp_equal";
haftmann@24196
  1505
val one_less_mult = thm "one_less_mult";
haftmann@24196
  1506
val n_less_m_mult_n = thm "n_less_m_mult_n";
haftmann@24196
  1507
val n_less_n_mult_m = thm "n_less_n_mult_m";
haftmann@24196
  1508
val diff_diff_right = thm "diff_diff_right";
haftmann@24196
  1509
val diff_Suc_diff_eq1 = thm "diff_Suc_diff_eq1";
haftmann@24196
  1510
val diff_Suc_diff_eq2 = thm "diff_Suc_diff_eq2";
haftmann@24196
  1511
*}
haftmann@24196
  1512
clasohm@923
  1513
end