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