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