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