src/HOL/Library/Extended_Nat.thy
author haftmann
Fri Mar 22 19:18:08 2019 +0000 (3 months ago)
changeset 69946 494934c30f38
parent 69861 62e47f06d22c
permissions -rw-r--r--
improved code equations taken over from AFP
hoelzl@43919
     1
(*  Title:      HOL/Library/Extended_Nat.thy
haftmann@27110
     2
    Author:     David von Oheimb, TU Muenchen;  Florian Haftmann, TU Muenchen
nipkow@41853
     3
    Contributions: David Trachtenherz, TU Muenchen
oheimb@11351
     4
*)
oheimb@11351
     5
wenzelm@60500
     6
section \<open>Extended natural numbers (i.e. with infinity)\<close>
oheimb@11351
     7
hoelzl@43919
     8
theory Extended_Nat
hoelzl@60636
     9
imports Main Countable Order_Continuity
nipkow@15131
    10
begin
oheimb@11351
    11
hoelzl@43921
    12
class infinity =
wenzelm@61384
    13
  fixes infinity :: "'a"  ("\<infinity>")
hoelzl@43921
    14
hoelzl@62378
    15
context
hoelzl@62378
    16
  fixes f :: "nat \<Rightarrow> 'a::{canonically_ordered_monoid_add, linorder_topology, complete_linorder}"
hoelzl@62378
    17
begin
hoelzl@62378
    18
hoelzl@62378
    19
lemma sums_SUP[simp, intro]: "f sums (SUP n. \<Sum>i<n. f i)"
nipkow@64267
    20
  unfolding sums_def by (intro LIMSEQ_SUP monoI sum_mono2 zero_le) auto
hoelzl@62378
    21
hoelzl@62378
    22
lemma suminf_eq_SUP: "suminf f = (SUP n. \<Sum>i<n. f i)"
hoelzl@62378
    23
  using sums_SUP by (rule sums_unique[symmetric])
hoelzl@62378
    24
hoelzl@62378
    25
end
hoelzl@62378
    26
wenzelm@60500
    27
subsection \<open>Type definition\<close>
oheimb@11351
    28
wenzelm@60500
    29
text \<open>
wenzelm@11355
    30
  We extend the standard natural numbers by a special value indicating
haftmann@27110
    31
  infinity.
wenzelm@60500
    32
\<close>
oheimb@11351
    33
wenzelm@49834
    34
typedef enat = "UNIV :: nat option set" ..
hoelzl@54415
    35
wenzelm@69593
    36
text \<open>TODO: introduce enat as coinductive datatype, enat is just \<^const>\<open>of_nat\<close>\<close>
hoelzl@54415
    37
hoelzl@43924
    38
definition enat :: "nat \<Rightarrow> enat" where
hoelzl@43924
    39
  "enat n = Abs_enat (Some n)"
hoelzl@62374
    40
hoelzl@43921
    41
instantiation enat :: infinity
hoelzl@43921
    42
begin
wenzelm@60679
    43
wenzelm@60679
    44
definition "\<infinity> = Abs_enat None"
wenzelm@60679
    45
instance ..
wenzelm@60679
    46
hoelzl@43921
    47
end
hoelzl@54415
    48
hoelzl@54415
    49
instance enat :: countable
hoelzl@54415
    50
proof
hoelzl@54415
    51
  show "\<exists>to_nat::enat \<Rightarrow> nat. inj to_nat"
hoelzl@54415
    52
    by (rule exI[of _ "to_nat \<circ> Rep_enat"]) (simp add: inj_on_def Rep_enat_inject)
hoelzl@54415
    53
qed
hoelzl@62374
    54
blanchet@58306
    55
old_rep_datatype enat "\<infinity> :: enat"
hoelzl@43921
    56
proof -
hoelzl@43924
    57
  fix P i assume "\<And>j. P (enat j)" "P \<infinity>"
hoelzl@43921
    58
  then show "P i"
hoelzl@43921
    59
  proof induct
hoelzl@43921
    60
    case (Abs_enat y) then show ?case
hoelzl@43921
    61
      by (cases y rule: option.exhaust)
hoelzl@43924
    62
         (auto simp: enat_def infinity_enat_def)
hoelzl@43921
    63
  qed
hoelzl@43924
    64
qed (auto simp add: enat_def infinity_enat_def Abs_enat_inject)
wenzelm@19736
    65
hoelzl@43924
    66
declare [[coercion "enat::nat\<Rightarrow>enat"]]
wenzelm@19736
    67
noschinl@45934
    68
lemmas enat2_cases = enat.exhaust[case_product enat.exhaust]
noschinl@45934
    69
lemmas enat3_cases = enat.exhaust[case_product enat.exhaust enat.exhaust]
noschinl@45934
    70
hoelzl@54416
    71
lemma not_infinity_eq [iff]: "(x \<noteq> \<infinity>) = (\<exists>i. x = enat i)"
huffman@44019
    72
  by (cases x) auto
nipkow@31084
    73
hoelzl@54416
    74
lemma not_enat_eq [iff]: "(\<forall>y. x \<noteq> enat y) = (x = \<infinity>)"
huffman@44019
    75
  by (cases x) auto
nipkow@31077
    76
hoelzl@62376
    77
lemma enat_ex_split: "(\<exists>c::enat. P c) \<longleftrightarrow> P \<infinity> \<or> (\<exists>c::nat. P c)"
hoelzl@62376
    78
  by (metis enat.exhaust)
hoelzl@62376
    79
hoelzl@43924
    80
primrec the_enat :: "enat \<Rightarrow> nat"
huffman@44019
    81
  where "the_enat (enat n) = n"
nipkow@41855
    82
huffman@47108
    83
wenzelm@60500
    84
subsection \<open>Constructors and numbers\<close>
haftmann@27110
    85
hoelzl@62378
    86
instantiation enat :: zero_neq_one
haftmann@25594
    87
begin
haftmann@25594
    88
haftmann@25594
    89
definition
hoelzl@43924
    90
  "0 = enat 0"
haftmann@25594
    91
haftmann@25594
    92
definition
huffman@47108
    93
  "1 = enat 1"
oheimb@11351
    94
hoelzl@62378
    95
instance
hoelzl@62378
    96
  proof qed (simp add: zero_enat_def one_enat_def)
haftmann@25594
    97
haftmann@25594
    98
end
haftmann@25594
    99
huffman@44019
   100
definition eSuc :: "enat \<Rightarrow> enat" where
huffman@44019
   101
  "eSuc i = (case i of enat n \<Rightarrow> enat (Suc n) | \<infinity> \<Rightarrow> \<infinity>)"
oheimb@11351
   102
huffman@47108
   103
lemma enat_0 [code_post]: "enat 0 = 0"
hoelzl@43919
   104
  by (simp add: zero_enat_def)
haftmann@27110
   105
huffman@47108
   106
lemma enat_1 [code_post]: "enat 1 = 1"
hoelzl@43919
   107
  by (simp add: one_enat_def)
haftmann@27110
   108
hoelzl@54416
   109
lemma enat_0_iff: "enat x = 0 \<longleftrightarrow> x = 0" "0 = enat x \<longleftrightarrow> x = 0"
hoelzl@54416
   110
  by (auto simp add: zero_enat_def)
hoelzl@54416
   111
hoelzl@54416
   112
lemma enat_1_iff: "enat x = 1 \<longleftrightarrow> x = 1" "1 = enat x \<longleftrightarrow> x = 1"
hoelzl@54416
   113
  by (auto simp add: one_enat_def)
hoelzl@54416
   114
huffman@44019
   115
lemma one_eSuc: "1 = eSuc 0"
huffman@44019
   116
  by (simp add: zero_enat_def one_enat_def eSuc_def)
oheimb@11351
   117
huffman@44019
   118
lemma infinity_ne_i0 [simp]: "(\<infinity>::enat) \<noteq> 0"
hoelzl@43919
   119
  by (simp add: zero_enat_def)
oheimb@11351
   120
huffman@44019
   121
lemma i0_ne_infinity [simp]: "0 \<noteq> (\<infinity>::enat)"
hoelzl@43919
   122
  by (simp add: zero_enat_def)
haftmann@27110
   123
hoelzl@62378
   124
lemma zero_one_enat_neq:
wenzelm@61076
   125
  "\<not> 0 = (1::enat)"
wenzelm@61076
   126
  "\<not> 1 = (0::enat)"
hoelzl@43919
   127
  unfolding zero_enat_def one_enat_def by simp_all
oheimb@11351
   128
huffman@44019
   129
lemma infinity_ne_i1 [simp]: "(\<infinity>::enat) \<noteq> 1"
hoelzl@43919
   130
  by (simp add: one_enat_def)
haftmann@27110
   131
huffman@44019
   132
lemma i1_ne_infinity [simp]: "1 \<noteq> (\<infinity>::enat)"
hoelzl@43919
   133
  by (simp add: one_enat_def)
haftmann@27110
   134
huffman@44019
   135
lemma eSuc_enat: "eSuc (enat n) = enat (Suc n)"
huffman@44019
   136
  by (simp add: eSuc_def)
haftmann@27110
   137
huffman@44019
   138
lemma eSuc_infinity [simp]: "eSuc \<infinity> = \<infinity>"
huffman@44019
   139
  by (simp add: eSuc_def)
oheimb@11351
   140
huffman@44019
   141
lemma eSuc_ne_0 [simp]: "eSuc n \<noteq> 0"
huffman@44019
   142
  by (simp add: eSuc_def zero_enat_def split: enat.splits)
haftmann@27110
   143
huffman@44019
   144
lemma zero_ne_eSuc [simp]: "0 \<noteq> eSuc n"
huffman@44019
   145
  by (rule eSuc_ne_0 [symmetric])
oheimb@11351
   146
huffman@44019
   147
lemma eSuc_inject [simp]: "eSuc m = eSuc n \<longleftrightarrow> m = n"
huffman@44019
   148
  by (simp add: eSuc_def split: enat.splits)
haftmann@27110
   149
hoelzl@59000
   150
lemma eSuc_enat_iff: "eSuc x = enat y \<longleftrightarrow> (\<exists>n. y = Suc n \<and> x = enat n)"
hoelzl@59000
   151
  by (cases y) (auto simp: enat_0 eSuc_enat[symmetric])
hoelzl@59000
   152
hoelzl@59000
   153
lemma enat_eSuc_iff: "enat y = eSuc x \<longleftrightarrow> (\<exists>n. y = Suc n \<and> enat n = x)"
hoelzl@59000
   154
  by (cases y) (auto simp: enat_0 eSuc_enat[symmetric])
hoelzl@59000
   155
wenzelm@60500
   156
subsection \<open>Addition\<close>
haftmann@27110
   157
hoelzl@43919
   158
instantiation enat :: comm_monoid_add
haftmann@27110
   159
begin
haftmann@27110
   160
blanchet@38167
   161
definition [nitpick_simp]:
hoelzl@43924
   162
  "m + n = (case m of \<infinity> \<Rightarrow> \<infinity> | enat m \<Rightarrow> (case n of \<infinity> \<Rightarrow> \<infinity> | enat n \<Rightarrow> enat (m + n)))"
oheimb@11351
   163
hoelzl@43919
   164
lemma plus_enat_simps [simp, code]:
hoelzl@43921
   165
  fixes q :: enat
hoelzl@43924
   166
  shows "enat m + enat n = enat (m + n)"
hoelzl@43921
   167
    and "\<infinity> + q = \<infinity>"
hoelzl@43921
   168
    and "q + \<infinity> = \<infinity>"
hoelzl@43919
   169
  by (simp_all add: plus_enat_def split: enat.splits)
haftmann@27110
   170
wenzelm@60679
   171
instance
wenzelm@60679
   172
proof
hoelzl@43919
   173
  fix n m q :: enat
haftmann@27110
   174
  show "n + m + q = n + (m + q)"
noschinl@45934
   175
    by (cases n m q rule: enat3_cases) auto
haftmann@27110
   176
  show "n + m = m + n"
noschinl@45934
   177
    by (cases n m rule: enat2_cases) auto
haftmann@27110
   178
  show "0 + n = n"
hoelzl@43919
   179
    by (cases n) (simp_all add: zero_enat_def)
huffman@26089
   180
qed
huffman@26089
   181
haftmann@27110
   182
end
oheimb@11351
   183
huffman@44019
   184
lemma eSuc_plus_1:
huffman@44019
   185
  "eSuc n = n + 1"
huffman@44019
   186
  by (cases n) (simp_all add: eSuc_enat one_enat_def)
hoelzl@62374
   187
huffman@44019
   188
lemma plus_1_eSuc:
huffman@44019
   189
  "1 + q = eSuc q"
huffman@44019
   190
  "q + 1 = eSuc q"
haftmann@57514
   191
  by (simp_all add: eSuc_plus_1 ac_simps)
nipkow@41853
   192
huffman@44019
   193
lemma iadd_Suc: "eSuc m + n = eSuc (m + n)"
haftmann@57514
   194
  by (simp_all add: eSuc_plus_1 ac_simps)
oheimb@11351
   195
huffman@44019
   196
lemma iadd_Suc_right: "m + eSuc n = eSuc (m + n)"
haftmann@57512
   197
  by (simp only: add.commute[of m] iadd_Suc)
nipkow@41853
   198
wenzelm@60500
   199
subsection \<open>Multiplication\<close>
huffman@29014
   200
hoelzl@62378
   201
instantiation enat :: "{comm_semiring_1, semiring_no_zero_divisors}"
huffman@29014
   202
begin
huffman@29014
   203
hoelzl@43919
   204
definition times_enat_def [nitpick_simp]:
hoelzl@43924
   205
  "m * n = (case m of \<infinity> \<Rightarrow> if n = 0 then 0 else \<infinity> | enat m \<Rightarrow>
hoelzl@43924
   206
    (case n of \<infinity> \<Rightarrow> if m = 0 then 0 else \<infinity> | enat n \<Rightarrow> enat (m * n)))"
huffman@29014
   207
hoelzl@43919
   208
lemma times_enat_simps [simp, code]:
hoelzl@43924
   209
  "enat m * enat n = enat (m * n)"
hoelzl@43921
   210
  "\<infinity> * \<infinity> = (\<infinity>::enat)"
hoelzl@43924
   211
  "\<infinity> * enat n = (if n = 0 then 0 else \<infinity>)"
hoelzl@43924
   212
  "enat m * \<infinity> = (if m = 0 then 0 else \<infinity>)"
hoelzl@43919
   213
  unfolding times_enat_def zero_enat_def
hoelzl@43919
   214
  by (simp_all split: enat.split)
huffman@29014
   215
wenzelm@60679
   216
instance
wenzelm@60679
   217
proof
hoelzl@43919
   218
  fix a b c :: enat
huffman@29014
   219
  show "(a * b) * c = a * (b * c)"
hoelzl@43919
   220
    unfolding times_enat_def zero_enat_def
hoelzl@43919
   221
    by (simp split: enat.split)
hoelzl@62378
   222
  show comm: "a * b = b * a"
hoelzl@43919
   223
    unfolding times_enat_def zero_enat_def
hoelzl@43919
   224
    by (simp split: enat.split)
huffman@29014
   225
  show "1 * a = a"
hoelzl@43919
   226
    unfolding times_enat_def zero_enat_def one_enat_def
hoelzl@43919
   227
    by (simp split: enat.split)
hoelzl@62378
   228
  show distr: "(a + b) * c = a * c + b * c"
hoelzl@43919
   229
    unfolding times_enat_def zero_enat_def
webertj@49962
   230
    by (simp split: enat.split add: distrib_right)
huffman@29014
   231
  show "0 * a = 0"
hoelzl@43919
   232
    unfolding times_enat_def zero_enat_def
hoelzl@43919
   233
    by (simp split: enat.split)
huffman@29014
   234
  show "a * 0 = 0"
hoelzl@43919
   235
    unfolding times_enat_def zero_enat_def
hoelzl@43919
   236
    by (simp split: enat.split)
hoelzl@62378
   237
  show "a * (b + c) = a * b + a * c"
hoelzl@62378
   238
    by (cases a b c rule: enat3_cases) (auto simp: times_enat_def zero_enat_def distrib_left)
hoelzl@62378
   239
  show "a \<noteq> 0 \<Longrightarrow> b \<noteq> 0 \<Longrightarrow> a * b \<noteq> 0"
hoelzl@62378
   240
    by (cases a b rule: enat2_cases) (auto simp: times_enat_def zero_enat_def)
huffman@29014
   241
qed
huffman@29014
   242
huffman@29014
   243
end
huffman@29014
   244
huffman@44019
   245
lemma mult_eSuc: "eSuc m * n = n + m * n"
huffman@44019
   246
  unfolding eSuc_plus_1 by (simp add: algebra_simps)
huffman@29014
   247
huffman@44019
   248
lemma mult_eSuc_right: "m * eSuc n = m + m * n"
huffman@44019
   249
  unfolding eSuc_plus_1 by (simp add: algebra_simps)
huffman@29014
   250
hoelzl@43924
   251
lemma of_nat_eq_enat: "of_nat n = enat n"
huffman@29023
   252
  apply (induct n)
hoelzl@43924
   253
  apply (simp add: enat_0)
huffman@44019
   254
  apply (simp add: plus_1_eSuc eSuc_enat)
huffman@29023
   255
  done
huffman@29023
   256
wenzelm@60679
   257
instance enat :: semiring_char_0
wenzelm@60679
   258
proof
hoelzl@43924
   259
  have "inj enat" by (rule injI) simp
hoelzl@43924
   260
  then show "inj (\<lambda>n. of_nat n :: enat)" by (simp add: of_nat_eq_enat)
haftmann@38621
   261
qed
huffman@29023
   262
huffman@44019
   263
lemma imult_is_infinity: "((a::enat) * b = \<infinity>) = (a = \<infinity> \<and> b \<noteq> 0 \<or> b = \<infinity> \<and> a \<noteq> 0)"
huffman@44019
   264
  by (auto simp add: times_enat_def zero_enat_def split: enat.split)
nipkow@41853
   265
wenzelm@60500
   266
subsection \<open>Numerals\<close>
huffman@47108
   267
huffman@47108
   268
lemma numeral_eq_enat:
huffman@47108
   269
  "numeral k = enat (numeral k)"
huffman@47108
   270
  using of_nat_eq_enat [of "numeral k"] by simp
huffman@47108
   271
huffman@47108
   272
lemma enat_numeral [code_abbrev]:
huffman@47108
   273
  "enat (numeral k) = numeral k"
huffman@47108
   274
  using numeral_eq_enat ..
huffman@47108
   275
huffman@47108
   276
lemma infinity_ne_numeral [simp]: "(\<infinity>::enat) \<noteq> numeral k"
huffman@47108
   277
  by (simp add: numeral_eq_enat)
huffman@47108
   278
huffman@47108
   279
lemma numeral_ne_infinity [simp]: "numeral k \<noteq> (\<infinity>::enat)"
huffman@47108
   280
  by (simp add: numeral_eq_enat)
huffman@47108
   281
huffman@47108
   282
lemma eSuc_numeral [simp]: "eSuc (numeral k) = numeral (k + Num.One)"
huffman@47108
   283
  by (simp only: eSuc_plus_1 numeral_plus_one)
huffman@47108
   284
wenzelm@60500
   285
subsection \<open>Subtraction\<close>
nipkow@41853
   286
hoelzl@43919
   287
instantiation enat :: minus
nipkow@41853
   288
begin
nipkow@41853
   289
hoelzl@43919
   290
definition diff_enat_def:
hoelzl@43924
   291
"a - b = (case a of (enat x) \<Rightarrow> (case b of (enat y) \<Rightarrow> enat (x - y) | \<infinity> \<Rightarrow> 0)
nipkow@41853
   292
          | \<infinity> \<Rightarrow> \<infinity>)"
nipkow@41853
   293
nipkow@41853
   294
instance ..
nipkow@41853
   295
nipkow@41853
   296
end
nipkow@41853
   297
huffman@47108
   298
lemma idiff_enat_enat [simp, code]: "enat a - enat b = enat (a - b)"
huffman@44019
   299
  by (simp add: diff_enat_def)
nipkow@41853
   300
huffman@47108
   301
lemma idiff_infinity [simp, code]: "\<infinity> - n = (\<infinity>::enat)"
huffman@44019
   302
  by (simp add: diff_enat_def)
nipkow@41853
   303
huffman@47108
   304
lemma idiff_infinity_right [simp, code]: "enat a - \<infinity> = 0"
huffman@44019
   305
  by (simp add: diff_enat_def)
nipkow@41853
   306
huffman@44019
   307
lemma idiff_0 [simp]: "(0::enat) - n = 0"
huffman@44019
   308
  by (cases n, simp_all add: zero_enat_def)
nipkow@41853
   309
huffman@44019
   310
lemmas idiff_enat_0 [simp] = idiff_0 [unfolded zero_enat_def]
nipkow@41853
   311
huffman@44019
   312
lemma idiff_0_right [simp]: "(n::enat) - 0 = n"
huffman@44019
   313
  by (cases n) (simp_all add: zero_enat_def)
nipkow@41853
   314
huffman@44019
   315
lemmas idiff_enat_0_right [simp] = idiff_0_right [unfolded zero_enat_def]
nipkow@41853
   316
huffman@44019
   317
lemma idiff_self [simp]: "n \<noteq> \<infinity> \<Longrightarrow> (n::enat) - n = 0"
huffman@44019
   318
  by (auto simp: zero_enat_def)
nipkow@41853
   319
huffman@44019
   320
lemma eSuc_minus_eSuc [simp]: "eSuc n - eSuc m = n - m"
huffman@44019
   321
  by (simp add: eSuc_def split: enat.split)
nipkow@41855
   322
huffman@44019
   323
lemma eSuc_minus_1 [simp]: "eSuc n - 1 = n"
nipkow@68406
   324
  by (simp add: one_enat_def flip: eSuc_enat zero_enat_def)
nipkow@41855
   325
hoelzl@43924
   326
(*lemmas idiff_self_eq_0_enat = idiff_self_eq_0[unfolded zero_enat_def]*)
nipkow@41853
   327
wenzelm@60500
   328
subsection \<open>Ordering\<close>
haftmann@27110
   329
hoelzl@43919
   330
instantiation enat :: linordered_ab_semigroup_add
haftmann@27110
   331
begin
oheimb@11351
   332
blanchet@38167
   333
definition [nitpick_simp]:
hoelzl@43924
   334
  "m \<le> n = (case n of enat n1 \<Rightarrow> (case m of enat m1 \<Rightarrow> m1 \<le> n1 | \<infinity> \<Rightarrow> False)
haftmann@27110
   335
    | \<infinity> \<Rightarrow> True)"
oheimb@11351
   336
blanchet@38167
   337
definition [nitpick_simp]:
hoelzl@43924
   338
  "m < n = (case m of enat m1 \<Rightarrow> (case n of enat n1 \<Rightarrow> m1 < n1 | \<infinity> \<Rightarrow> True)
haftmann@27110
   339
    | \<infinity> \<Rightarrow> False)"
oheimb@11351
   340
hoelzl@43919
   341
lemma enat_ord_simps [simp]:
hoelzl@43924
   342
  "enat m \<le> enat n \<longleftrightarrow> m \<le> n"
hoelzl@43924
   343
  "enat m < enat n \<longleftrightarrow> m < n"
hoelzl@43921
   344
  "q \<le> (\<infinity>::enat)"
hoelzl@43921
   345
  "q < (\<infinity>::enat) \<longleftrightarrow> q \<noteq> \<infinity>"
hoelzl@43921
   346
  "(\<infinity>::enat) \<le> q \<longleftrightarrow> q = \<infinity>"
hoelzl@43921
   347
  "(\<infinity>::enat) < q \<longleftrightarrow> False"
hoelzl@43919
   348
  by (simp_all add: less_eq_enat_def less_enat_def split: enat.splits)
oheimb@11351
   349
huffman@47108
   350
lemma numeral_le_enat_iff[simp]:
huffman@47108
   351
  shows "numeral m \<le> enat n \<longleftrightarrow> numeral m \<le> n"
huffman@47108
   352
by (auto simp: numeral_eq_enat)
noschinl@45934
   353
huffman@47108
   354
lemma numeral_less_enat_iff[simp]:
huffman@47108
   355
  shows "numeral m < enat n \<longleftrightarrow> numeral m < n"
huffman@47108
   356
by (auto simp: numeral_eq_enat)
noschinl@45934
   357
hoelzl@43919
   358
lemma enat_ord_code [code]:
hoelzl@43924
   359
  "enat m \<le> enat n \<longleftrightarrow> m \<le> n"
hoelzl@43924
   360
  "enat m < enat n \<longleftrightarrow> m < n"
hoelzl@43921
   361
  "q \<le> (\<infinity>::enat) \<longleftrightarrow> True"
hoelzl@43924
   362
  "enat m < \<infinity> \<longleftrightarrow> True"
hoelzl@43924
   363
  "\<infinity> \<le> enat n \<longleftrightarrow> False"
hoelzl@43921
   364
  "(\<infinity>::enat) < q \<longleftrightarrow> False"
haftmann@27110
   365
  by simp_all
oheimb@11351
   366
wenzelm@60679
   367
instance
wenzelm@60679
   368
  by standard (auto simp add: less_eq_enat_def less_enat_def plus_enat_def split: enat.splits)
oheimb@11351
   369
haftmann@27110
   370
end
haftmann@27110
   371
hoelzl@62376
   372
instance enat :: dioid
hoelzl@62376
   373
proof
hoelzl@62376
   374
  fix a b :: enat show "(a \<le> b) = (\<exists>c. b = a + c)"
hoelzl@62376
   375
    by (cases a b rule: enat2_cases) (auto simp: le_iff_add enat_ex_split)
hoelzl@62376
   376
qed
hoelzl@62376
   377
hoelzl@62378
   378
instance enat :: "{linordered_nonzero_semiring, strict_ordered_comm_monoid_add}"
huffman@29014
   379
proof
hoelzl@43919
   380
  fix a b c :: enat
hoelzl@62378
   381
  show "a \<le> b \<Longrightarrow> 0 \<le> c \<Longrightarrow>c * a \<le> c * b"
hoelzl@43919
   382
    unfolding times_enat_def less_eq_enat_def zero_enat_def
hoelzl@43919
   383
    by (simp split: enat.splits)
hoelzl@62378
   384
  show "a < b \<Longrightarrow> c < d \<Longrightarrow> a + c < b + d" for a b c d :: enat
hoelzl@62378
   385
    by (cases a b c d rule: enat2_cases[case_product enat2_cases]) auto
lp15@67689
   386
  show "a < b \<Longrightarrow> a + 1 < b + 1"
lp15@67689
   387
    by (metis add_right_mono eSuc_minus_1 eSuc_plus_1 less_le)
hoelzl@62378
   388
qed (simp add: zero_enat_def one_enat_def)
huffman@29014
   389
huffman@47108
   390
(* BH: These equations are already proven generally for any type in
huffman@47108
   391
class linordered_semidom. However, enat is not in that class because
huffman@47108
   392
it does not have the cancellation property. Would it be worthwhile to
huffman@47108
   393
a generalize linordered_semidom to a new class that includes enat? *)
huffman@47108
   394
nipkow@69800
   395
lemma add_diff_assoc_enat: "z \<le> y \<Longrightarrow> x + (y - z) = x + y - (z::enat)"
nipkow@69800
   396
by(cases x)(auto simp add: diff_enat_def split: enat.split)
nipkow@69800
   397
hoelzl@43919
   398
lemma enat_ord_number [simp]:
wenzelm@61076
   399
  "(numeral m :: enat) \<le> numeral n \<longleftrightarrow> (numeral m :: nat) \<le> numeral n"
wenzelm@61076
   400
  "(numeral m :: enat) < numeral n \<longleftrightarrow> (numeral m :: nat) < numeral n"
huffman@47108
   401
  by (simp_all add: numeral_eq_enat)
oheimb@11351
   402
huffman@44019
   403
lemma infinity_ileE [elim!]: "\<infinity> \<le> enat m \<Longrightarrow> R"
huffman@44019
   404
  by (simp add: zero_enat_def less_eq_enat_def split: enat.splits)
huffman@44019
   405
huffman@44019
   406
lemma infinity_ilessE [elim!]: "\<infinity> < enat m \<Longrightarrow> R"
haftmann@27110
   407
  by simp
oheimb@11351
   408
huffman@44019
   409
lemma eSuc_ile_mono [simp]: "eSuc n \<le> eSuc m \<longleftrightarrow> n \<le> m"
huffman@44019
   410
  by (simp add: eSuc_def less_eq_enat_def split: enat.splits)
hoelzl@62374
   411
huffman@44019
   412
lemma eSuc_mono [simp]: "eSuc n < eSuc m \<longleftrightarrow> n < m"
huffman@44019
   413
  by (simp add: eSuc_def less_enat_def split: enat.splits)
oheimb@11351
   414
huffman@44019
   415
lemma ile_eSuc [simp]: "n \<le> eSuc n"
huffman@44019
   416
  by (simp add: eSuc_def less_eq_enat_def split: enat.splits)
oheimb@11351
   417
huffman@44019
   418
lemma not_eSuc_ilei0 [simp]: "\<not> eSuc n \<le> 0"
huffman@44019
   419
  by (simp add: zero_enat_def eSuc_def less_eq_enat_def split: enat.splits)
haftmann@27110
   420
huffman@44019
   421
lemma i0_iless_eSuc [simp]: "0 < eSuc n"
huffman@44019
   422
  by (simp add: zero_enat_def eSuc_def less_enat_def split: enat.splits)
haftmann@27110
   423
huffman@44019
   424
lemma iless_eSuc0[simp]: "(n < eSuc 0) = (n = 0)"
huffman@44019
   425
  by (simp add: zero_enat_def eSuc_def less_enat_def split: enat.split)
nipkow@41853
   426
huffman@44019
   427
lemma ileI1: "m < n \<Longrightarrow> eSuc m \<le> n"
huffman@44019
   428
  by (simp add: eSuc_def less_eq_enat_def less_enat_def split: enat.splits)
haftmann@27110
   429
hoelzl@43924
   430
lemma Suc_ile_eq: "enat (Suc m) \<le> n \<longleftrightarrow> enat m < n"
haftmann@27110
   431
  by (cases n) auto
haftmann@27110
   432
huffman@44019
   433
lemma iless_Suc_eq [simp]: "enat m < eSuc n \<longleftrightarrow> enat m \<le> n"
huffman@44019
   434
  by (auto simp add: eSuc_def less_enat_def split: enat.splits)
oheimb@11351
   435
huffman@44019
   436
lemma imult_infinity: "(0::enat) < n \<Longrightarrow> \<infinity> * n = \<infinity>"
huffman@44019
   437
  by (simp add: zero_enat_def less_enat_def split: enat.splits)
nipkow@41853
   438
huffman@44019
   439
lemma imult_infinity_right: "(0::enat) < n \<Longrightarrow> n * \<infinity> = \<infinity>"
huffman@44019
   440
  by (simp add: zero_enat_def less_enat_def split: enat.splits)
nipkow@41853
   441
hoelzl@43919
   442
lemma enat_0_less_mult_iff: "(0 < (m::enat) * n) = (0 < m \<and> 0 < n)"
hoelzl@62378
   443
  by (simp only: zero_less_iff_neq_zero mult_eq_0_iff, simp)
nipkow@41853
   444
huffman@44019
   445
lemma mono_eSuc: "mono eSuc"
huffman@44019
   446
  by (simp add: mono_def)
nipkow@41853
   447
hoelzl@43919
   448
lemma min_enat_simps [simp]:
hoelzl@43924
   449
  "min (enat m) (enat n) = enat (min m n)"
haftmann@27110
   450
  "min q 0 = 0"
haftmann@27110
   451
  "min 0 q = 0"
hoelzl@43921
   452
  "min q (\<infinity>::enat) = q"
hoelzl@43921
   453
  "min (\<infinity>::enat) q = q"
haftmann@27110
   454
  by (auto simp add: min_def)
oheimb@11351
   455
hoelzl@43919
   456
lemma max_enat_simps [simp]:
hoelzl@43924
   457
  "max (enat m) (enat n) = enat (max m n)"
haftmann@27110
   458
  "max q 0 = q"
haftmann@27110
   459
  "max 0 q = q"
hoelzl@43921
   460
  "max q \<infinity> = (\<infinity>::enat)"
hoelzl@43921
   461
  "max \<infinity> q = (\<infinity>::enat)"
haftmann@27110
   462
  by (simp_all add: max_def)
haftmann@27110
   463
hoelzl@43924
   464
lemma enat_ile: "n \<le> enat m \<Longrightarrow> \<exists>k. n = enat k"
haftmann@27110
   465
  by (cases n) simp_all
haftmann@27110
   466
hoelzl@43924
   467
lemma enat_iless: "n < enat m \<Longrightarrow> \<exists>k. n = enat k"
haftmann@27110
   468
  by (cases n) simp_all
oheimb@11351
   469
Andreas@61631
   470
lemma iadd_le_enat_iff:
Andreas@61631
   471
  "x + y \<le> enat n \<longleftrightarrow> (\<exists>y' x'. x = enat x' \<and> y = enat y' \<and> x' + y' \<le> n)"
Andreas@61631
   472
by(cases x y rule: enat.exhaust[case_product enat.exhaust]) simp_all
Andreas@61631
   473
hoelzl@62378
   474
lemma chain_incr: "\<forall>i. \<exists>j. Y i < Y j \<Longrightarrow> \<exists>j. enat k < Y j"
nipkow@25134
   475
apply (induct_tac k)
hoelzl@43924
   476
 apply (simp (no_asm) only: enat_0)
hoelzl@62378
   477
 apply (fast intro: le_less_trans [OF zero_le])
nipkow@25134
   478
apply (erule exE)
nipkow@25134
   479
apply (drule spec)
nipkow@25134
   480
apply (erule exE)
nipkow@25134
   481
apply (drule ileI1)
huffman@44019
   482
apply (rule eSuc_enat [THEN subst])
nipkow@25134
   483
apply (rule exI)
haftmann@27110
   484
apply (erule (1) le_less_trans)
nipkow@25134
   485
done
oheimb@11351
   486
hoelzl@60636
   487
lemma eSuc_max: "eSuc (max x y) = max (eSuc x) (eSuc y)"
hoelzl@60636
   488
  by (simp add: eSuc_def split: enat.split)
hoelzl@60636
   489
hoelzl@62374
   490
lemma eSuc_Max:
hoelzl@60636
   491
  assumes "finite A" "A \<noteq> {}"
hoelzl@60636
   492
  shows "eSuc (Max A) = Max (eSuc ` A)"
hoelzl@60636
   493
using assms proof induction
hoelzl@60636
   494
  case (insert x A)
hoelzl@60636
   495
  thus ?case by(cases "A = {}")(simp_all add: eSuc_max)
hoelzl@60636
   496
qed simp
hoelzl@60636
   497
haftmann@52729
   498
instantiation enat :: "{order_bot, order_top}"
haftmann@29337
   499
begin
haftmann@29337
   500
wenzelm@60679
   501
definition bot_enat :: enat where "bot_enat = 0"
wenzelm@60679
   502
definition top_enat :: enat where "top_enat = \<infinity>"
haftmann@29337
   503
wenzelm@60679
   504
instance
wenzelm@60679
   505
  by standard (simp_all add: bot_enat_def top_enat_def)
haftmann@29337
   506
haftmann@29337
   507
end
haftmann@29337
   508
hoelzl@43924
   509
lemma finite_enat_bounded:
hoelzl@43924
   510
  assumes le_fin: "\<And>y. y \<in> A \<Longrightarrow> y \<le> enat n"
noschinl@42993
   511
  shows "finite A"
noschinl@42993
   512
proof (rule finite_subset)
hoelzl@43924
   513
  show "finite (enat ` {..n})" by blast
nipkow@44890
   514
  have "A \<subseteq> {..enat n}" using le_fin by fastforce
hoelzl@43924
   515
  also have "\<dots> \<subseteq> enat ` {..n}"
wenzelm@60679
   516
    apply (rule subsetI)
wenzelm@60679
   517
    subgoal for x by (cases x) auto
wenzelm@60679
   518
    done
hoelzl@43924
   519
  finally show "A \<subseteq> enat ` {..n}" .
noschinl@42993
   520
qed
noschinl@42993
   521
huffman@26089
   522
wenzelm@60500
   523
subsection \<open>Cancellation simprocs\<close>
huffman@45775
   524
nipkow@69803
   525
lemma add_diff_cancel_enat[simp]: "x \<noteq> \<infinity> \<Longrightarrow> x + y - x = (y::enat)"
nipkow@69803
   526
by (metis add.commute add.right_neutral add_diff_assoc_enat idiff_self order_refl)
nipkow@69803
   527
huffman@45775
   528
lemma enat_add_left_cancel: "a + b = a + c \<longleftrightarrow> a = (\<infinity>::enat) \<or> b = c"
huffman@45775
   529
  unfolding plus_enat_def by (simp split: enat.split)
huffman@45775
   530
huffman@45775
   531
lemma enat_add_left_cancel_le: "a + b \<le> a + c \<longleftrightarrow> a = (\<infinity>::enat) \<or> b \<le> c"
huffman@45775
   532
  unfolding plus_enat_def by (simp split: enat.split)
huffman@45775
   533
huffman@45775
   534
lemma enat_add_left_cancel_less: "a + b < a + c \<longleftrightarrow> a \<noteq> (\<infinity>::enat) \<and> b < c"
huffman@45775
   535
  unfolding plus_enat_def by (simp split: enat.split)
huffman@45775
   536
nipkow@69801
   537
lemma plus_eq_infty_iff_enat: "(m::enat) + n = \<infinity> \<longleftrightarrow> m=\<infinity> \<or> n=\<infinity>"
nipkow@69800
   538
using enat_add_left_cancel by fastforce
nipkow@69800
   539
wenzelm@60500
   540
ML \<open>
huffman@45775
   541
structure Cancel_Enat_Common =
huffman@45775
   542
struct
huffman@45775
   543
  (* copied from src/HOL/Tools/nat_numeral_simprocs.ML *)
huffman@45775
   544
  fun find_first_t _    _ []         = raise TERM("find_first_t", [])
huffman@45775
   545
    | find_first_t past u (t::terms) =
huffman@45775
   546
          if u aconv t then (rev past @ terms)
huffman@45775
   547
          else find_first_t (t::past) u terms
huffman@45775
   548
wenzelm@69593
   549
  fun dest_summing (Const (\<^const_name>\<open>Groups.plus\<close>, _) $ t $ u, ts) =
huffman@51366
   550
        dest_summing (t, dest_summing (u, ts))
huffman@51366
   551
    | dest_summing (t, ts) = t :: ts
huffman@51366
   552
huffman@45775
   553
  val mk_sum = Arith_Data.long_mk_sum
huffman@51366
   554
  fun dest_sum t = dest_summing (t, [])
huffman@45775
   555
  val find_first = find_first_t []
huffman@45775
   556
  val trans_tac = Numeral_Simprocs.trans_tac
wenzelm@51717
   557
  val norm_ss =
wenzelm@69593
   558
    simpset_of (put_simpset HOL_basic_ss \<^context>
haftmann@57514
   559
      addsimps @{thms ac_simps add_0_left add_0_right})
wenzelm@51717
   560
  fun norm_tac ctxt = ALLGOALS (simp_tac (put_simpset norm_ss ctxt))
wenzelm@51717
   561
  fun simplify_meta_eq ctxt cancel_th th =
wenzelm@51717
   562
    Arith_Data.simplify_meta_eq [] ctxt
huffman@45775
   563
      ([th, cancel_th] MRS trans)
huffman@45775
   564
  fun mk_eq (a, b) = HOLogic.mk_Trueprop (HOLogic.mk_eq (a, b))
huffman@45775
   565
end
huffman@45775
   566
huffman@45775
   567
structure Eq_Enat_Cancel = ExtractCommonTermFun
huffman@45775
   568
(open Cancel_Enat_Common
huffman@45775
   569
  val mk_bal = HOLogic.mk_eq
wenzelm@69593
   570
  val dest_bal = HOLogic.dest_bin \<^const_name>\<open>HOL.eq\<close> \<^typ>\<open>enat\<close>
huffman@45775
   571
  fun simp_conv _ _ = SOME @{thm enat_add_left_cancel}
huffman@45775
   572
)
huffman@45775
   573
huffman@45775
   574
structure Le_Enat_Cancel = ExtractCommonTermFun
huffman@45775
   575
(open Cancel_Enat_Common
wenzelm@69593
   576
  val mk_bal = HOLogic.mk_binrel \<^const_name>\<open>Orderings.less_eq\<close>
wenzelm@69593
   577
  val dest_bal = HOLogic.dest_bin \<^const_name>\<open>Orderings.less_eq\<close> \<^typ>\<open>enat\<close>
huffman@45775
   578
  fun simp_conv _ _ = SOME @{thm enat_add_left_cancel_le}
huffman@45775
   579
)
huffman@45775
   580
huffman@45775
   581
structure Less_Enat_Cancel = ExtractCommonTermFun
huffman@45775
   582
(open Cancel_Enat_Common
wenzelm@69593
   583
  val mk_bal = HOLogic.mk_binrel \<^const_name>\<open>Orderings.less\<close>
wenzelm@69593
   584
  val dest_bal = HOLogic.dest_bin \<^const_name>\<open>Orderings.less\<close> \<^typ>\<open>enat\<close>
huffman@45775
   585
  fun simp_conv _ _ = SOME @{thm enat_add_left_cancel_less}
huffman@45775
   586
)
wenzelm@60500
   587
\<close>
huffman@45775
   588
huffman@45775
   589
simproc_setup enat_eq_cancel
huffman@45775
   590
  ("(l::enat) + m = n" | "(l::enat) = m + n") =
wenzelm@60500
   591
  \<open>fn phi => fn ctxt => fn ct => Eq_Enat_Cancel.proc ctxt (Thm.term_of ct)\<close>
huffman@45775
   592
huffman@45775
   593
simproc_setup enat_le_cancel
huffman@45775
   594
  ("(l::enat) + m \<le> n" | "(l::enat) \<le> m + n") =
wenzelm@60500
   595
  \<open>fn phi => fn ctxt => fn ct => Le_Enat_Cancel.proc ctxt (Thm.term_of ct)\<close>
huffman@45775
   596
huffman@45775
   597
simproc_setup enat_less_cancel
huffman@45775
   598
  ("(l::enat) + m < n" | "(l::enat) < m + n") =
wenzelm@60500
   599
  \<open>fn phi => fn ctxt => fn ct => Less_Enat_Cancel.proc ctxt (Thm.term_of ct)\<close>
huffman@45775
   600
wenzelm@60500
   601
text \<open>TODO: add regression tests for these simprocs\<close>
huffman@45775
   602
wenzelm@60500
   603
text \<open>TODO: add simprocs for combining and cancelling numerals\<close>
huffman@45775
   604
wenzelm@60500
   605
subsection \<open>Well-ordering\<close>
huffman@26089
   606
hoelzl@43924
   607
lemma less_enatE:
hoelzl@43924
   608
  "[| n < enat m; !!k. n = enat k ==> k < m ==> P |] ==> P"
huffman@26089
   609
by (induct n) auto
huffman@26089
   610
huffman@44019
   611
lemma less_infinityE:
hoelzl@43924
   612
  "[| n < \<infinity>; !!k. n = enat k ==> P |] ==> P"
huffman@26089
   613
by (induct n) auto
huffman@26089
   614
hoelzl@43919
   615
lemma enat_less_induct:
wenzelm@67091
   616
  assumes prem: "\<And>n. \<forall>m::enat. m < n \<longrightarrow> P m \<Longrightarrow> P n" shows "P n"
huffman@26089
   617
proof -
wenzelm@67091
   618
  have P_enat: "\<And>k. P (enat k)"
huffman@26089
   619
    apply (rule nat_less_induct)
huffman@26089
   620
    apply (rule prem, clarify)
hoelzl@43924
   621
    apply (erule less_enatE, simp)
huffman@26089
   622
    done
huffman@26089
   623
  show ?thesis
huffman@26089
   624
  proof (induct n)
huffman@26089
   625
    fix nat
hoelzl@43924
   626
    show "P (enat nat)" by (rule P_enat)
huffman@26089
   627
  next
hoelzl@43921
   628
    show "P \<infinity>"
huffman@26089
   629
      apply (rule prem, clarify)
huffman@44019
   630
      apply (erule less_infinityE)
hoelzl@43924
   631
      apply (simp add: P_enat)
huffman@26089
   632
      done
huffman@26089
   633
  qed
huffman@26089
   634
qed
huffman@26089
   635
hoelzl@43919
   636
instance enat :: wellorder
huffman@26089
   637
proof
haftmann@27823
   638
  fix P and n
wenzelm@61076
   639
  assume hyp: "(\<And>n::enat. (\<And>m::enat. m < n \<Longrightarrow> P m) \<Longrightarrow> P n)"
hoelzl@43919
   640
  show "P n" by (blast intro: enat_less_induct hyp)
huffman@26089
   641
qed
huffman@26089
   642
wenzelm@60500
   643
subsection \<open>Complete Lattice\<close>
noschinl@42993
   644
hoelzl@43919
   645
instantiation enat :: complete_lattice
noschinl@42993
   646
begin
noschinl@42993
   647
hoelzl@43919
   648
definition inf_enat :: "enat \<Rightarrow> enat \<Rightarrow> enat" where
wenzelm@56777
   649
  "inf_enat = min"
noschinl@42993
   650
hoelzl@43919
   651
definition sup_enat :: "enat \<Rightarrow> enat \<Rightarrow> enat" where
wenzelm@56777
   652
  "sup_enat = max"
noschinl@42993
   653
hoelzl@43919
   654
definition Inf_enat :: "enat set \<Rightarrow> enat" where
wenzelm@56777
   655
  "Inf_enat A = (if A = {} then \<infinity> else (LEAST x. x \<in> A))"
noschinl@42993
   656
hoelzl@43919
   657
definition Sup_enat :: "enat set \<Rightarrow> enat" where
wenzelm@56777
   658
  "Sup_enat A = (if A = {} then 0 else if finite A then Max A else \<infinity>)"
wenzelm@56777
   659
instance
wenzelm@56777
   660
proof
hoelzl@43919
   661
  fix x :: "enat" and A :: "enat set"
noschinl@42993
   662
  { assume "x \<in> A" then show "Inf A \<le> x"
hoelzl@43919
   663
      unfolding Inf_enat_def by (auto intro: Least_le) }
noschinl@42993
   664
  { assume "\<And>y. y \<in> A \<Longrightarrow> x \<le> y" then show "x \<le> Inf A"
hoelzl@43919
   665
      unfolding Inf_enat_def
noschinl@42993
   666
      by (cases "A = {}") (auto intro: LeastI2_ex) }
noschinl@42993
   667
  { assume "x \<in> A" then show "x \<le> Sup A"
hoelzl@43919
   668
      unfolding Sup_enat_def by (cases "finite A") auto }
noschinl@42993
   669
  { assume "\<And>y. y \<in> A \<Longrightarrow> y \<le> x" then show "Sup A \<le> x"
hoelzl@43924
   670
      unfolding Sup_enat_def using finite_enat_bounded by auto }
haftmann@52729
   671
qed (simp_all add:
haftmann@52729
   672
 inf_enat_def sup_enat_def bot_enat_def top_enat_def Inf_enat_def Sup_enat_def)
noschinl@42993
   673
end
noschinl@42993
   674
hoelzl@43978
   675
instance enat :: complete_linorder ..
haftmann@27110
   676
hoelzl@60636
   677
lemma eSuc_Sup: "A \<noteq> {} \<Longrightarrow> eSuc (Sup A) = Sup (eSuc ` A)"
hoelzl@60636
   678
  by(auto simp add: Sup_enat_def eSuc_Max inj_on_def dest: finite_imageD)
hoelzl@60636
   679
hoelzl@60636
   680
lemma sup_continuous_eSuc: "sup_continuous f \<Longrightarrow> sup_continuous (\<lambda>x. eSuc (f x))"
haftmann@69861
   681
  using eSuc_Sup [of "_ ` UNIV"] by (auto simp: sup_continuous_def image_comp)
haftmann@69861
   682
hoelzl@60636
   683
wenzelm@60500
   684
subsection \<open>Traditional theorem names\<close>
haftmann@27110
   685
huffman@47108
   686
lemmas enat_defs = zero_enat_def one_enat_def eSuc_def
hoelzl@43919
   687
  plus_enat_def less_eq_enat_def less_enat_def
haftmann@27110
   688
hoelzl@62378
   689
lemma iadd_is_0: "(m + n = (0::enat)) = (m = 0 \<and> n = 0)"
hoelzl@62378
   690
  by (rule add_eq_0_iff_both_eq_0)
hoelzl@62378
   691
hoelzl@62378
   692
lemma i0_lb : "(0::enat) \<le> n"
hoelzl@62378
   693
  by (rule zero_le)
hoelzl@62378
   694
hoelzl@62378
   695
lemma ile0_eq: "n \<le> (0::enat) \<longleftrightarrow> n = 0"
hoelzl@62378
   696
  by (rule le_zero_eq)
hoelzl@62378
   697
hoelzl@62378
   698
lemma not_iless0: "\<not> n < (0::enat)"
hoelzl@62378
   699
  by (rule not_less_zero)
hoelzl@62378
   700
hoelzl@62378
   701
lemma i0_less[simp]: "(0::enat) < n \<longleftrightarrow> n \<noteq> 0"
hoelzl@62378
   702
  by (rule zero_less_iff_neq_zero)
hoelzl@62378
   703
hoelzl@62378
   704
lemma imult_is_0: "((m::enat) * n = 0) = (m = 0 \<or> n = 0)"
hoelzl@62378
   705
  by (rule mult_eq_0_iff)
hoelzl@62378
   706
oheimb@11351
   707
end