src/HOL/Library/Extended_Nat.thy
author hoelzl
Tue, 19 Jul 2011 14:37:49 +0200
changeset 43922 c6f35921056e
parent 43921 e8511be08ddd
child 43923 ab93d0190a5d
permissions -rw-r--r--
add nat => enat coercion
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
     1
(*  Title:      HOL/Library/Extended_Nat.thy
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
     2
    Author:     David von Oheimb, TU Muenchen;  Florian Haftmann, TU Muenchen
41853
258a489c24b2 Added material by David Trachtenherz
nipkow
parents: 38621
diff changeset
     3
    Contributions: David Trachtenherz, TU Muenchen
11351
c5c403d30c77 added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff changeset
     4
*)
c5c403d30c77 added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff changeset
     5
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
     6
header {* Extended natural numbers (i.e. with infinity) *}
11351
c5c403d30c77 added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff changeset
     7
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
     8
theory Extended_Nat
30663
0b6aff7451b2 Main is (Complex_Main) base entry point in library theories
haftmann
parents: 29668
diff changeset
     9
imports Main
15131
c69542757a4d New theory header syntax.
nipkow
parents: 14981
diff changeset
    10
begin
11351
c5c403d30c77 added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff changeset
    11
43921
e8511be08ddd Introduce infinity type class
hoelzl
parents: 43919
diff changeset
    12
class infinity =
e8511be08ddd Introduce infinity type class
hoelzl
parents: 43919
diff changeset
    13
  fixes infinity :: "'a"
e8511be08ddd Introduce infinity type class
hoelzl
parents: 43919
diff changeset
    14
e8511be08ddd Introduce infinity type class
hoelzl
parents: 43919
diff changeset
    15
notation (xsymbols)
e8511be08ddd Introduce infinity type class
hoelzl
parents: 43919
diff changeset
    16
  infinity  ("\<infinity>")
e8511be08ddd Introduce infinity type class
hoelzl
parents: 43919
diff changeset
    17
e8511be08ddd Introduce infinity type class
hoelzl
parents: 43919
diff changeset
    18
notation (HTML output)
e8511be08ddd Introduce infinity type class
hoelzl
parents: 43919
diff changeset
    19
  infinity  ("\<infinity>")
e8511be08ddd Introduce infinity type class
hoelzl
parents: 43919
diff changeset
    20
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
    21
subsection {* Type definition *}
11351
c5c403d30c77 added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff changeset
    22
c5c403d30c77 added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff changeset
    23
text {*
11355
wenzelm
parents: 11351
diff changeset
    24
  We extend the standard natural numbers by a special value indicating
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
    25
  infinity.
11351
c5c403d30c77 added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff changeset
    26
*}
c5c403d30c77 added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff changeset
    27
43921
e8511be08ddd Introduce infinity type class
hoelzl
parents: 43919
diff changeset
    28
typedef (open) enat = "UNIV :: nat option set" ..
e8511be08ddd Introduce infinity type class
hoelzl
parents: 43919
diff changeset
    29
 
e8511be08ddd Introduce infinity type class
hoelzl
parents: 43919
diff changeset
    30
definition Fin :: "nat \<Rightarrow> enat" where
e8511be08ddd Introduce infinity type class
hoelzl
parents: 43919
diff changeset
    31
  "Fin n = Abs_enat (Some n)"
e8511be08ddd Introduce infinity type class
hoelzl
parents: 43919
diff changeset
    32
 
e8511be08ddd Introduce infinity type class
hoelzl
parents: 43919
diff changeset
    33
instantiation enat :: infinity
e8511be08ddd Introduce infinity type class
hoelzl
parents: 43919
diff changeset
    34
begin
e8511be08ddd Introduce infinity type class
hoelzl
parents: 43919
diff changeset
    35
  definition "\<infinity> = Abs_enat None"
e8511be08ddd Introduce infinity type class
hoelzl
parents: 43919
diff changeset
    36
  instance proof qed
e8511be08ddd Introduce infinity type class
hoelzl
parents: 43919
diff changeset
    37
end
e8511be08ddd Introduce infinity type class
hoelzl
parents: 43919
diff changeset
    38
 
e8511be08ddd Introduce infinity type class
hoelzl
parents: 43919
diff changeset
    39
rep_datatype Fin "\<infinity> :: enat"
e8511be08ddd Introduce infinity type class
hoelzl
parents: 43919
diff changeset
    40
proof -
e8511be08ddd Introduce infinity type class
hoelzl
parents: 43919
diff changeset
    41
  fix P i assume "\<And>j. P (Fin j)" "P \<infinity>"
e8511be08ddd Introduce infinity type class
hoelzl
parents: 43919
diff changeset
    42
  then show "P i"
e8511be08ddd Introduce infinity type class
hoelzl
parents: 43919
diff changeset
    43
  proof induct
e8511be08ddd Introduce infinity type class
hoelzl
parents: 43919
diff changeset
    44
    case (Abs_enat y) then show ?case
e8511be08ddd Introduce infinity type class
hoelzl
parents: 43919
diff changeset
    45
      by (cases y rule: option.exhaust)
e8511be08ddd Introduce infinity type class
hoelzl
parents: 43919
diff changeset
    46
         (auto simp: Fin_def infinity_enat_def)
e8511be08ddd Introduce infinity type class
hoelzl
parents: 43919
diff changeset
    47
  qed
e8511be08ddd Introduce infinity type class
hoelzl
parents: 43919
diff changeset
    48
qed (auto simp add: Fin_def infinity_enat_def Abs_enat_inject)
19736
wenzelm
parents: 15140
diff changeset
    49
43922
c6f35921056e add nat => enat coercion
hoelzl
parents: 43921
diff changeset
    50
declare [[coercion_enabled]]
c6f35921056e add nat => enat coercion
hoelzl
parents: 43921
diff changeset
    51
declare [[coercion "Fin::nat\<Rightarrow>enat"]]
19736
wenzelm
parents: 15140
diff changeset
    52
43921
e8511be08ddd Introduce infinity type class
hoelzl
parents: 43919
diff changeset
    53
lemma not_Infty_eq[iff]: "(x \<noteq> \<infinity>) = (EX i. x = Fin i)"
31084
f4db921165ce fixed HOLCF proofs
nipkow
parents: 31077
diff changeset
    54
by (cases x) auto
f4db921165ce fixed HOLCF proofs
nipkow
parents: 31077
diff changeset
    55
43921
e8511be08ddd Introduce infinity type class
hoelzl
parents: 43919
diff changeset
    56
lemma not_Fin_eq [iff]: "(ALL y. x ~= Fin y) = (x = \<infinity>)"
31077
28dd6fd3d184 more lemmas
nipkow
parents: 30663
diff changeset
    57
by (cases x) auto
28dd6fd3d184 more lemmas
nipkow
parents: 30663
diff changeset
    58
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
    59
primrec the_Fin :: "enat \<Rightarrow> nat"
41855
c3b6e69da386 added a few lemmas by Andreas Lochbihler
nipkow
parents: 41853
diff changeset
    60
where "the_Fin (Fin n) = n"
c3b6e69da386 added a few lemmas by Andreas Lochbihler
nipkow
parents: 41853
diff changeset
    61
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
    62
subsection {* Constructors and numbers *}
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
    63
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
    64
instantiation enat :: "{zero, one, number}"
25594
43c718438f9f switched import from Main to PreList
haftmann
parents: 25134
diff changeset
    65
begin
43c718438f9f switched import from Main to PreList
haftmann
parents: 25134
diff changeset
    66
43c718438f9f switched import from Main to PreList
haftmann
parents: 25134
diff changeset
    67
definition
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
    68
  "0 = Fin 0"
25594
43c718438f9f switched import from Main to PreList
haftmann
parents: 25134
diff changeset
    69
43c718438f9f switched import from Main to PreList
haftmann
parents: 25134
diff changeset
    70
definition
32069
6d28bbd33e2c prefer code_inline over code_unfold; use code_unfold_post where appropriate
haftmann
parents: 31998
diff changeset
    71
  [code_unfold]: "1 = Fin 1"
25594
43c718438f9f switched import from Main to PreList
haftmann
parents: 25134
diff changeset
    72
43c718438f9f switched import from Main to PreList
haftmann
parents: 25134
diff changeset
    73
definition
32069
6d28bbd33e2c prefer code_inline over code_unfold; use code_unfold_post where appropriate
haftmann
parents: 31998
diff changeset
    74
  [code_unfold, code del]: "number_of k = Fin (number_of k)"
11351
c5c403d30c77 added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff changeset
    75
25594
43c718438f9f switched import from Main to PreList
haftmann
parents: 25134
diff changeset
    76
instance ..
43c718438f9f switched import from Main to PreList
haftmann
parents: 25134
diff changeset
    77
43c718438f9f switched import from Main to PreList
haftmann
parents: 25134
diff changeset
    78
end
43c718438f9f switched import from Main to PreList
haftmann
parents: 25134
diff changeset
    79
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
    80
definition iSuc :: "enat \<Rightarrow> enat" where
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
    81
  "iSuc i = (case i of Fin n \<Rightarrow> Fin (Suc n) | \<infinity> \<Rightarrow> \<infinity>)"
11351
c5c403d30c77 added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff changeset
    82
c5c403d30c77 added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff changeset
    83
lemma Fin_0: "Fin 0 = 0"
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
    84
  by (simp add: zero_enat_def)
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
    85
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
    86
lemma Fin_1: "Fin 1 = 1"
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
    87
  by (simp add: one_enat_def)
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
    88
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
    89
lemma Fin_number: "Fin (number_of k) = number_of k"
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
    90
  by (simp add: number_of_enat_def)
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
    91
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
    92
lemma one_iSuc: "1 = iSuc 0"
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
    93
  by (simp add: zero_enat_def one_enat_def iSuc_def)
11351
c5c403d30c77 added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff changeset
    94
43921
e8511be08ddd Introduce infinity type class
hoelzl
parents: 43919
diff changeset
    95
lemma Infty_ne_i0 [simp]: "(\<infinity>::enat) \<noteq> 0"
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
    96
  by (simp add: zero_enat_def)
11351
c5c403d30c77 added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff changeset
    97
43921
e8511be08ddd Introduce infinity type class
hoelzl
parents: 43919
diff changeset
    98
lemma i0_ne_Infty [simp]: "0 \<noteq> (\<infinity>::enat)"
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
    99
  by (simp add: zero_enat_def)
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   100
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   101
lemma zero_enat_eq [simp]:
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   102
  "number_of k = (0\<Colon>enat) \<longleftrightarrow> number_of k = (0\<Colon>nat)"
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   103
  "(0\<Colon>enat) = number_of k \<longleftrightarrow> number_of k = (0\<Colon>nat)"
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   104
  unfolding zero_enat_def number_of_enat_def by simp_all
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   105
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   106
lemma one_enat_eq [simp]:
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   107
  "number_of k = (1\<Colon>enat) \<longleftrightarrow> number_of k = (1\<Colon>nat)"
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   108
  "(1\<Colon>enat) = number_of k \<longleftrightarrow> number_of k = (1\<Colon>nat)"
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   109
  unfolding one_enat_def number_of_enat_def by simp_all
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   110
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   111
lemma zero_one_enat_neq [simp]:
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   112
  "\<not> 0 = (1\<Colon>enat)"
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   113
  "\<not> 1 = (0\<Colon>enat)"
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   114
  unfolding zero_enat_def one_enat_def by simp_all
11351
c5c403d30c77 added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff changeset
   115
43921
e8511be08ddd Introduce infinity type class
hoelzl
parents: 43919
diff changeset
   116
lemma Infty_ne_i1 [simp]: "(\<infinity>::enat) \<noteq> 1"
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   117
  by (simp add: one_enat_def)
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   118
43921
e8511be08ddd Introduce infinity type class
hoelzl
parents: 43919
diff changeset
   119
lemma i1_ne_Infty [simp]: "1 \<noteq> (\<infinity>::enat)"
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   120
  by (simp add: one_enat_def)
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   121
43921
e8511be08ddd Introduce infinity type class
hoelzl
parents: 43919
diff changeset
   122
lemma Infty_ne_number [simp]: "(\<infinity>::enat) \<noteq> number_of k"
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   123
  by (simp add: number_of_enat_def)
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   124
43921
e8511be08ddd Introduce infinity type class
hoelzl
parents: 43919
diff changeset
   125
lemma number_ne_Infty [simp]: "number_of k \<noteq> (\<infinity>::enat)"
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   126
  by (simp add: number_of_enat_def)
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   127
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   128
lemma iSuc_Fin: "iSuc (Fin n) = Fin (Suc n)"
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   129
  by (simp add: iSuc_def)
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   130
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   131
lemma iSuc_number_of: "iSuc (number_of k) = Fin (Suc (number_of k))"
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   132
  by (simp add: iSuc_Fin number_of_enat_def)
11351
c5c403d30c77 added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff changeset
   133
c5c403d30c77 added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff changeset
   134
lemma iSuc_Infty [simp]: "iSuc \<infinity> = \<infinity>"
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   135
  by (simp add: iSuc_def)
11351
c5c403d30c77 added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff changeset
   136
c5c403d30c77 added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff changeset
   137
lemma iSuc_ne_0 [simp]: "iSuc n \<noteq> 0"
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   138
  by (simp add: iSuc_def zero_enat_def split: enat.splits)
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   139
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   140
lemma zero_ne_iSuc [simp]: "0 \<noteq> iSuc n"
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   141
  by (rule iSuc_ne_0 [symmetric])
11351
c5c403d30c77 added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff changeset
   142
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   143
lemma iSuc_inject [simp]: "iSuc m = iSuc n \<longleftrightarrow> m = n"
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   144
  by (simp add: iSuc_def split: enat.splits)
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   145
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   146
lemma number_of_enat_inject [simp]:
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   147
  "(number_of k \<Colon> enat) = number_of l \<longleftrightarrow> (number_of k \<Colon> nat) = number_of l"
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   148
  by (simp add: number_of_enat_def)
11351
c5c403d30c77 added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff changeset
   149
c5c403d30c77 added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff changeset
   150
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   151
subsection {* Addition *}
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   152
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   153
instantiation enat :: comm_monoid_add
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   154
begin
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   155
38167
ab528533db92 help Nitpick
blanchet
parents: 37765
diff changeset
   156
definition [nitpick_simp]:
37765
26bdfb7b680b dropped superfluous [code del]s
haftmann
parents: 35028
diff changeset
   157
  "m + n = (case m of \<infinity> \<Rightarrow> \<infinity> | Fin m \<Rightarrow> (case n of \<infinity> \<Rightarrow> \<infinity> | Fin n \<Rightarrow> Fin (m + n)))"
11351
c5c403d30c77 added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff changeset
   158
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   159
lemma plus_enat_simps [simp, code]:
43921
e8511be08ddd Introduce infinity type class
hoelzl
parents: 43919
diff changeset
   160
  fixes q :: enat
e8511be08ddd Introduce infinity type class
hoelzl
parents: 43919
diff changeset
   161
  shows "Fin m + Fin n = Fin (m + n)"
e8511be08ddd Introduce infinity type class
hoelzl
parents: 43919
diff changeset
   162
    and "\<infinity> + q = \<infinity>"
e8511be08ddd Introduce infinity type class
hoelzl
parents: 43919
diff changeset
   163
    and "q + \<infinity> = \<infinity>"
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   164
  by (simp_all add: plus_enat_def split: enat.splits)
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   165
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   166
instance proof
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   167
  fix n m q :: enat
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   168
  show "n + m + q = n + (m + q)"
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   169
    by (cases n, auto, cases m, auto, cases q, auto)
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   170
  show "n + m = m + n"
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   171
    by (cases n, auto, cases m, auto)
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   172
  show "0 + n = n"
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   173
    by (cases n) (simp_all add: zero_enat_def)
26089
373221497340 proved linorder and wellorder class instances
huffman
parents: 25691
diff changeset
   174
qed
373221497340 proved linorder and wellorder class instances
huffman
parents: 25691
diff changeset
   175
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   176
end
11351
c5c403d30c77 added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff changeset
   177
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   178
lemma plus_enat_0 [simp]:
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   179
  "0 + (q\<Colon>enat) = q"
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   180
  "(q\<Colon>enat) + 0 = q"
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   181
  by (simp_all add: plus_enat_def zero_enat_def split: enat.splits)
11351
c5c403d30c77 added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff changeset
   182
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   183
lemma plus_enat_number [simp]:
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   184
  "(number_of k \<Colon> enat) + number_of l = (if k < Int.Pls then number_of l
29012
9140227dc8c5 change lemmas to avoid using neg
huffman
parents: 28562
diff changeset
   185
    else if l < Int.Pls then number_of k else number_of (k + l))"
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   186
  unfolding number_of_enat_def plus_enat_simps nat_arith(1) if_distrib [symmetric, of _ Fin] ..
11351
c5c403d30c77 added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff changeset
   187
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   188
lemma iSuc_number [simp]:
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   189
  "iSuc (number_of k) = (if neg (number_of k \<Colon> int) then 1 else number_of (Int.succ k))"
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   190
  unfolding iSuc_number_of
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   191
  unfolding one_enat_def number_of_enat_def Suc_nat_number_of if_distrib [symmetric] ..
11351
c5c403d30c77 added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff changeset
   192
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   193
lemma iSuc_plus_1:
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   194
  "iSuc n = n + 1"
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   195
  by (cases n) (simp_all add: iSuc_Fin one_enat_def)
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   196
  
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   197
lemma plus_1_iSuc:
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   198
  "1 + q = iSuc q"
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   199
  "q + 1 = iSuc q"
41853
258a489c24b2 Added material by David Trachtenherz
nipkow
parents: 38621
diff changeset
   200
by (simp_all add: iSuc_plus_1 add_ac)
258a489c24b2 Added material by David Trachtenherz
nipkow
parents: 38621
diff changeset
   201
258a489c24b2 Added material by David Trachtenherz
nipkow
parents: 38621
diff changeset
   202
lemma iadd_Suc: "iSuc m + n = iSuc (m + n)"
258a489c24b2 Added material by David Trachtenherz
nipkow
parents: 38621
diff changeset
   203
by (simp_all add: iSuc_plus_1 add_ac)
11351
c5c403d30c77 added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff changeset
   204
41853
258a489c24b2 Added material by David Trachtenherz
nipkow
parents: 38621
diff changeset
   205
lemma iadd_Suc_right: "m + iSuc n = iSuc (m + n)"
258a489c24b2 Added material by David Trachtenherz
nipkow
parents: 38621
diff changeset
   206
by (simp only: add_commute[of m] iadd_Suc)
258a489c24b2 Added material by David Trachtenherz
nipkow
parents: 38621
diff changeset
   207
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   208
lemma iadd_is_0: "(m + n = (0::enat)) = (m = 0 \<and> n = 0)"
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   209
by (cases m, cases n, simp_all add: zero_enat_def)
11351
c5c403d30c77 added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff changeset
   210
29014
e515f42d1db7 multiplication for type inat
huffman
parents: 29012
diff changeset
   211
subsection {* Multiplication *}
e515f42d1db7 multiplication for type inat
huffman
parents: 29012
diff changeset
   212
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   213
instantiation enat :: comm_semiring_1
29014
e515f42d1db7 multiplication for type inat
huffman
parents: 29012
diff changeset
   214
begin
e515f42d1db7 multiplication for type inat
huffman
parents: 29012
diff changeset
   215
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   216
definition times_enat_def [nitpick_simp]:
29014
e515f42d1db7 multiplication for type inat
huffman
parents: 29012
diff changeset
   217
  "m * n = (case m of \<infinity> \<Rightarrow> if n = 0 then 0 else \<infinity> | Fin m \<Rightarrow>
e515f42d1db7 multiplication for type inat
huffman
parents: 29012
diff changeset
   218
    (case n of \<infinity> \<Rightarrow> if m = 0 then 0 else \<infinity> | Fin n \<Rightarrow> Fin (m * n)))"
e515f42d1db7 multiplication for type inat
huffman
parents: 29012
diff changeset
   219
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   220
lemma times_enat_simps [simp, code]:
29014
e515f42d1db7 multiplication for type inat
huffman
parents: 29012
diff changeset
   221
  "Fin m * Fin n = Fin (m * n)"
43921
e8511be08ddd Introduce infinity type class
hoelzl
parents: 43919
diff changeset
   222
  "\<infinity> * \<infinity> = (\<infinity>::enat)"
29014
e515f42d1db7 multiplication for type inat
huffman
parents: 29012
diff changeset
   223
  "\<infinity> * Fin n = (if n = 0 then 0 else \<infinity>)"
e515f42d1db7 multiplication for type inat
huffman
parents: 29012
diff changeset
   224
  "Fin m * \<infinity> = (if m = 0 then 0 else \<infinity>)"
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   225
  unfolding times_enat_def zero_enat_def
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   226
  by (simp_all split: enat.split)
29014
e515f42d1db7 multiplication for type inat
huffman
parents: 29012
diff changeset
   227
e515f42d1db7 multiplication for type inat
huffman
parents: 29012
diff changeset
   228
instance proof
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   229
  fix a b c :: enat
29014
e515f42d1db7 multiplication for type inat
huffman
parents: 29012
diff changeset
   230
  show "(a * b) * c = a * (b * c)"
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   231
    unfolding times_enat_def zero_enat_def
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   232
    by (simp split: enat.split)
29014
e515f42d1db7 multiplication for type inat
huffman
parents: 29012
diff changeset
   233
  show "a * b = b * a"
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   234
    unfolding times_enat_def zero_enat_def
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   235
    by (simp split: enat.split)
29014
e515f42d1db7 multiplication for type inat
huffman
parents: 29012
diff changeset
   236
  show "1 * a = a"
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   237
    unfolding times_enat_def zero_enat_def one_enat_def
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   238
    by (simp split: enat.split)
29014
e515f42d1db7 multiplication for type inat
huffman
parents: 29012
diff changeset
   239
  show "(a + b) * c = a * c + b * c"
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   240
    unfolding times_enat_def zero_enat_def
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   241
    by (simp split: enat.split add: left_distrib)
29014
e515f42d1db7 multiplication for type inat
huffman
parents: 29012
diff changeset
   242
  show "0 * a = 0"
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   243
    unfolding times_enat_def zero_enat_def
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   244
    by (simp split: enat.split)
29014
e515f42d1db7 multiplication for type inat
huffman
parents: 29012
diff changeset
   245
  show "a * 0 = 0"
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   246
    unfolding times_enat_def zero_enat_def
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   247
    by (simp split: enat.split)
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   248
  show "(0::enat) \<noteq> 1"
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   249
    unfolding zero_enat_def one_enat_def
29014
e515f42d1db7 multiplication for type inat
huffman
parents: 29012
diff changeset
   250
    by simp
e515f42d1db7 multiplication for type inat
huffman
parents: 29012
diff changeset
   251
qed
e515f42d1db7 multiplication for type inat
huffman
parents: 29012
diff changeset
   252
e515f42d1db7 multiplication for type inat
huffman
parents: 29012
diff changeset
   253
end
e515f42d1db7 multiplication for type inat
huffman
parents: 29012
diff changeset
   254
e515f42d1db7 multiplication for type inat
huffman
parents: 29012
diff changeset
   255
lemma mult_iSuc: "iSuc m * n = n + m * n"
29667
53103fc8ffa3 Replaced group_ and ring_simps by algebra_simps;
nipkow
parents: 29337
diff changeset
   256
  unfolding iSuc_plus_1 by (simp add: algebra_simps)
29014
e515f42d1db7 multiplication for type inat
huffman
parents: 29012
diff changeset
   257
e515f42d1db7 multiplication for type inat
huffman
parents: 29012
diff changeset
   258
lemma mult_iSuc_right: "m * iSuc n = m + m * n"
29667
53103fc8ffa3 Replaced group_ and ring_simps by algebra_simps;
nipkow
parents: 29337
diff changeset
   259
  unfolding iSuc_plus_1 by (simp add: algebra_simps)
29014
e515f42d1db7 multiplication for type inat
huffman
parents: 29012
diff changeset
   260
29023
ef3adebc6d98 instance inat :: semiring_char_0
huffman
parents: 29014
diff changeset
   261
lemma of_nat_eq_Fin: "of_nat n = Fin n"
ef3adebc6d98 instance inat :: semiring_char_0
huffman
parents: 29014
diff changeset
   262
  apply (induct n)
ef3adebc6d98 instance inat :: semiring_char_0
huffman
parents: 29014
diff changeset
   263
  apply (simp add: Fin_0)
ef3adebc6d98 instance inat :: semiring_char_0
huffman
parents: 29014
diff changeset
   264
  apply (simp add: plus_1_iSuc iSuc_Fin)
ef3adebc6d98 instance inat :: semiring_char_0
huffman
parents: 29014
diff changeset
   265
  done
ef3adebc6d98 instance inat :: semiring_char_0
huffman
parents: 29014
diff changeset
   266
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   267
instance enat :: number_semiring
43532
d32d72ea3215 instance inat :: number_semiring
huffman
parents: 42993
diff changeset
   268
proof
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   269
  fix n show "number_of (int n) = (of_nat n :: enat)"
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   270
    unfolding number_of_enat_def number_of_int of_nat_id of_nat_eq_Fin ..
43532
d32d72ea3215 instance inat :: number_semiring
huffman
parents: 42993
diff changeset
   271
qed
d32d72ea3215 instance inat :: number_semiring
huffman
parents: 42993
diff changeset
   272
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   273
instance enat :: semiring_char_0 proof
38621
d6cb7e625d75 more concise characterization of of_nat operation and class semiring_char_0
haftmann
parents: 38167
diff changeset
   274
  have "inj Fin" by (rule injI) simp
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   275
  then show "inj (\<lambda>n. of_nat n :: enat)" by (simp add: of_nat_eq_Fin)
38621
d6cb7e625d75 more concise characterization of of_nat operation and class semiring_char_0
haftmann
parents: 38167
diff changeset
   276
qed
29023
ef3adebc6d98 instance inat :: semiring_char_0
huffman
parents: 29014
diff changeset
   277
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   278
lemma imult_is_0[simp]: "((m::enat) * n = 0) = (m = 0 \<or> n = 0)"
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   279
by(auto simp add: times_enat_def zero_enat_def split: enat.split)
41853
258a489c24b2 Added material by David Trachtenherz
nipkow
parents: 38621
diff changeset
   280
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   281
lemma imult_is_Infty: "((a::enat) * b = \<infinity>) = (a = \<infinity> \<and> b \<noteq> 0 \<or> b = \<infinity> \<and> a \<noteq> 0)"
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   282
by(auto simp add: times_enat_def zero_enat_def split: enat.split)
41853
258a489c24b2 Added material by David Trachtenherz
nipkow
parents: 38621
diff changeset
   283
258a489c24b2 Added material by David Trachtenherz
nipkow
parents: 38621
diff changeset
   284
258a489c24b2 Added material by David Trachtenherz
nipkow
parents: 38621
diff changeset
   285
subsection {* Subtraction *}
258a489c24b2 Added material by David Trachtenherz
nipkow
parents: 38621
diff changeset
   286
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   287
instantiation enat :: minus
41853
258a489c24b2 Added material by David Trachtenherz
nipkow
parents: 38621
diff changeset
   288
begin
258a489c24b2 Added material by David Trachtenherz
nipkow
parents: 38621
diff changeset
   289
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   290
definition diff_enat_def:
41853
258a489c24b2 Added material by David Trachtenherz
nipkow
parents: 38621
diff changeset
   291
"a - b = (case a of (Fin x) \<Rightarrow> (case b of (Fin y) \<Rightarrow> Fin (x - y) | \<infinity> \<Rightarrow> 0)
258a489c24b2 Added material by David Trachtenherz
nipkow
parents: 38621
diff changeset
   292
          | \<infinity> \<Rightarrow> \<infinity>)"
258a489c24b2 Added material by David Trachtenherz
nipkow
parents: 38621
diff changeset
   293
258a489c24b2 Added material by David Trachtenherz
nipkow
parents: 38621
diff changeset
   294
instance ..
258a489c24b2 Added material by David Trachtenherz
nipkow
parents: 38621
diff changeset
   295
258a489c24b2 Added material by David Trachtenherz
nipkow
parents: 38621
diff changeset
   296
end
258a489c24b2 Added material by David Trachtenherz
nipkow
parents: 38621
diff changeset
   297
258a489c24b2 Added material by David Trachtenherz
nipkow
parents: 38621
diff changeset
   298
lemma idiff_Fin_Fin[simp,code]: "Fin a - Fin b = Fin (a - b)"
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   299
by(simp add: diff_enat_def)
41853
258a489c24b2 Added material by David Trachtenherz
nipkow
parents: 38621
diff changeset
   300
43921
e8511be08ddd Introduce infinity type class
hoelzl
parents: 43919
diff changeset
   301
lemma idiff_Infty[simp,code]: "\<infinity> - n = (\<infinity>::enat)"
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   302
by(simp add: diff_enat_def)
41853
258a489c24b2 Added material by David Trachtenherz
nipkow
parents: 38621
diff changeset
   303
258a489c24b2 Added material by David Trachtenherz
nipkow
parents: 38621
diff changeset
   304
lemma idiff_Infty_right[simp,code]: "Fin a - \<infinity> = 0"
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   305
by(simp add: diff_enat_def)
41853
258a489c24b2 Added material by David Trachtenherz
nipkow
parents: 38621
diff changeset
   306
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   307
lemma idiff_0[simp]: "(0::enat) - n = 0"
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   308
by (cases n, simp_all add: zero_enat_def)
41853
258a489c24b2 Added material by David Trachtenherz
nipkow
parents: 38621
diff changeset
   309
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   310
lemmas idiff_Fin_0[simp] = idiff_0[unfolded zero_enat_def]
41853
258a489c24b2 Added material by David Trachtenherz
nipkow
parents: 38621
diff changeset
   311
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   312
lemma idiff_0_right[simp]: "(n::enat) - 0 = n"
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   313
by (cases n) (simp_all add: zero_enat_def)
41853
258a489c24b2 Added material by David Trachtenherz
nipkow
parents: 38621
diff changeset
   314
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   315
lemmas idiff_Fin_0_right[simp] = idiff_0_right[unfolded zero_enat_def]
41853
258a489c24b2 Added material by David Trachtenherz
nipkow
parents: 38621
diff changeset
   316
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   317
lemma idiff_self[simp]: "n \<noteq> \<infinity> \<Longrightarrow> (n::enat) - n = 0"
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   318
by(auto simp: zero_enat_def)
41853
258a489c24b2 Added material by David Trachtenherz
nipkow
parents: 38621
diff changeset
   319
41855
c3b6e69da386 added a few lemmas by Andreas Lochbihler
nipkow
parents: 41853
diff changeset
   320
lemma iSuc_minus_iSuc [simp]: "iSuc n - iSuc m = n - m"
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   321
by(simp add: iSuc_def split: enat.split)
41855
c3b6e69da386 added a few lemmas by Andreas Lochbihler
nipkow
parents: 41853
diff changeset
   322
c3b6e69da386 added a few lemmas by Andreas Lochbihler
nipkow
parents: 41853
diff changeset
   323
lemma iSuc_minus_1 [simp]: "iSuc n - 1 = n"
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   324
by(simp add: one_enat_def iSuc_Fin[symmetric] zero_enat_def[symmetric])
41855
c3b6e69da386 added a few lemmas by Andreas Lochbihler
nipkow
parents: 41853
diff changeset
   325
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   326
(*lemmas idiff_self_eq_0_Fin = idiff_self_eq_0[unfolded zero_enat_def]*)
41853
258a489c24b2 Added material by David Trachtenherz
nipkow
parents: 38621
diff changeset
   327
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   328
subsection {* Ordering *}
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   329
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   330
instantiation enat :: linordered_ab_semigroup_add
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   331
begin
11351
c5c403d30c77 added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff changeset
   332
38167
ab528533db92 help Nitpick
blanchet
parents: 37765
diff changeset
   333
definition [nitpick_simp]:
37765
26bdfb7b680b dropped superfluous [code del]s
haftmann
parents: 35028
diff changeset
   334
  "m \<le> n = (case n of Fin n1 \<Rightarrow> (case m of Fin m1 \<Rightarrow> m1 \<le> n1 | \<infinity> \<Rightarrow> False)
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   335
    | \<infinity> \<Rightarrow> True)"
11351
c5c403d30c77 added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff changeset
   336
38167
ab528533db92 help Nitpick
blanchet
parents: 37765
diff changeset
   337
definition [nitpick_simp]:
37765
26bdfb7b680b dropped superfluous [code del]s
haftmann
parents: 35028
diff changeset
   338
  "m < n = (case m of Fin m1 \<Rightarrow> (case n of Fin n1 \<Rightarrow> m1 < n1 | \<infinity> \<Rightarrow> True)
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   339
    | \<infinity> \<Rightarrow> False)"
11351
c5c403d30c77 added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff changeset
   340
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   341
lemma enat_ord_simps [simp]:
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   342
  "Fin m \<le> Fin n \<longleftrightarrow> m \<le> n"
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   343
  "Fin m < Fin n \<longleftrightarrow> m < n"
43921
e8511be08ddd Introduce infinity type class
hoelzl
parents: 43919
diff changeset
   344
  "q \<le> (\<infinity>::enat)"
e8511be08ddd Introduce infinity type class
hoelzl
parents: 43919
diff changeset
   345
  "q < (\<infinity>::enat) \<longleftrightarrow> q \<noteq> \<infinity>"
e8511be08ddd Introduce infinity type class
hoelzl
parents: 43919
diff changeset
   346
  "(\<infinity>::enat) \<le> q \<longleftrightarrow> q = \<infinity>"
e8511be08ddd Introduce infinity type class
hoelzl
parents: 43919
diff changeset
   347
  "(\<infinity>::enat) < q \<longleftrightarrow> False"
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   348
  by (simp_all add: less_eq_enat_def less_enat_def split: enat.splits)
11351
c5c403d30c77 added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff changeset
   349
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   350
lemma enat_ord_code [code]:
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   351
  "Fin m \<le> Fin n \<longleftrightarrow> m \<le> n"
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   352
  "Fin m < Fin n \<longleftrightarrow> m < n"
43921
e8511be08ddd Introduce infinity type class
hoelzl
parents: 43919
diff changeset
   353
  "q \<le> (\<infinity>::enat) \<longleftrightarrow> True"
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   354
  "Fin m < \<infinity> \<longleftrightarrow> True"
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   355
  "\<infinity> \<le> Fin n \<longleftrightarrow> False"
43921
e8511be08ddd Introduce infinity type class
hoelzl
parents: 43919
diff changeset
   356
  "(\<infinity>::enat) < q \<longleftrightarrow> False"
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   357
  by simp_all
11351
c5c403d30c77 added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff changeset
   358
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   359
instance by default
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   360
  (auto simp add: less_eq_enat_def less_enat_def plus_enat_def split: enat.splits)
11351
c5c403d30c77 added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff changeset
   361
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   362
end
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   363
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   364
instance enat :: ordered_comm_semiring
29014
e515f42d1db7 multiplication for type inat
huffman
parents: 29012
diff changeset
   365
proof
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   366
  fix a b c :: enat
29014
e515f42d1db7 multiplication for type inat
huffman
parents: 29012
diff changeset
   367
  assume "a \<le> b" and "0 \<le> c"
e515f42d1db7 multiplication for type inat
huffman
parents: 29012
diff changeset
   368
  thus "c * a \<le> c * b"
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   369
    unfolding times_enat_def less_eq_enat_def zero_enat_def
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   370
    by (simp split: enat.splits)
29014
e515f42d1db7 multiplication for type inat
huffman
parents: 29012
diff changeset
   371
qed
e515f42d1db7 multiplication for type inat
huffman
parents: 29012
diff changeset
   372
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   373
lemma enat_ord_number [simp]:
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   374
  "(number_of m \<Colon> enat) \<le> number_of n \<longleftrightarrow> (number_of m \<Colon> nat) \<le> number_of n"
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   375
  "(number_of m \<Colon> enat) < number_of n \<longleftrightarrow> (number_of m \<Colon> nat) < number_of n"
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   376
  by (simp_all add: number_of_enat_def)
11351
c5c403d30c77 added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff changeset
   377
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   378
lemma i0_lb [simp]: "(0\<Colon>enat) \<le> n"
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   379
  by (simp add: zero_enat_def less_eq_enat_def split: enat.splits)
11351
c5c403d30c77 added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff changeset
   380
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   381
lemma ile0_eq [simp]: "n \<le> (0\<Colon>enat) \<longleftrightarrow> n = 0"
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   382
by (simp add: zero_enat_def less_eq_enat_def split: enat.splits)
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   383
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   384
lemma Infty_ileE [elim!]: "\<infinity> \<le> Fin m \<Longrightarrow> R"
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   385
  by (simp add: zero_enat_def less_eq_enat_def split: enat.splits)
11351
c5c403d30c77 added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff changeset
   386
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   387
lemma Infty_ilessE [elim!]: "\<infinity> < Fin m \<Longrightarrow> R"
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   388
  by simp
11351
c5c403d30c77 added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff changeset
   389
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   390
lemma not_iless0 [simp]: "\<not> n < (0\<Colon>enat)"
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   391
  by (simp add: zero_enat_def less_enat_def split: enat.splits)
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   392
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   393
lemma i0_less [simp]: "(0\<Colon>enat) < n \<longleftrightarrow> n \<noteq> 0"
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   394
by (simp add: zero_enat_def less_enat_def split: enat.splits)
11351
c5c403d30c77 added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff changeset
   395
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   396
lemma iSuc_ile_mono [simp]: "iSuc n \<le> iSuc m \<longleftrightarrow> n \<le> m"
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   397
  by (simp add: iSuc_def less_eq_enat_def split: enat.splits)
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   398
 
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   399
lemma iSuc_mono [simp]: "iSuc n < iSuc m \<longleftrightarrow> n < m"
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   400
  by (simp add: iSuc_def less_enat_def split: enat.splits)
11351
c5c403d30c77 added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff changeset
   401
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   402
lemma ile_iSuc [simp]: "n \<le> iSuc n"
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   403
  by (simp add: iSuc_def less_eq_enat_def split: enat.splits)
11351
c5c403d30c77 added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff changeset
   404
11355
wenzelm
parents: 11351
diff changeset
   405
lemma not_iSuc_ilei0 [simp]: "\<not> iSuc n \<le> 0"
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   406
  by (simp add: zero_enat_def iSuc_def less_eq_enat_def split: enat.splits)
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   407
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   408
lemma i0_iless_iSuc [simp]: "0 < iSuc n"
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   409
  by (simp add: zero_enat_def iSuc_def less_enat_def split: enat.splits)
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   410
41853
258a489c24b2 Added material by David Trachtenherz
nipkow
parents: 38621
diff changeset
   411
lemma iless_iSuc0[simp]: "(n < iSuc 0) = (n = 0)"
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   412
by (simp add: zero_enat_def iSuc_def less_enat_def split: enat.split)
41853
258a489c24b2 Added material by David Trachtenherz
nipkow
parents: 38621
diff changeset
   413
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   414
lemma ileI1: "m < n \<Longrightarrow> iSuc m \<le> n"
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   415
  by (simp add: iSuc_def less_eq_enat_def less_enat_def split: enat.splits)
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   416
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   417
lemma Suc_ile_eq: "Fin (Suc m) \<le> n \<longleftrightarrow> Fin m < n"
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   418
  by (cases n) auto
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   419
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   420
lemma iless_Suc_eq [simp]: "Fin m < iSuc n \<longleftrightarrow> Fin m \<le> n"
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   421
  by (auto simp add: iSuc_def less_enat_def split: enat.splits)
11351
c5c403d30c77 added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff changeset
   422
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   423
lemma imult_Infty: "(0::enat) < n \<Longrightarrow> \<infinity> * n = \<infinity>"
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   424
by (simp add: zero_enat_def less_enat_def split: enat.splits)
41853
258a489c24b2 Added material by David Trachtenherz
nipkow
parents: 38621
diff changeset
   425
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   426
lemma imult_Infty_right: "(0::enat) < n \<Longrightarrow> n * \<infinity> = \<infinity>"
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   427
by (simp add: zero_enat_def less_enat_def split: enat.splits)
41853
258a489c24b2 Added material by David Trachtenherz
nipkow
parents: 38621
diff changeset
   428
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   429
lemma enat_0_less_mult_iff: "(0 < (m::enat) * n) = (0 < m \<and> 0 < n)"
41853
258a489c24b2 Added material by David Trachtenherz
nipkow
parents: 38621
diff changeset
   430
by (simp only: i0_less imult_is_0, simp)
258a489c24b2 Added material by David Trachtenherz
nipkow
parents: 38621
diff changeset
   431
258a489c24b2 Added material by David Trachtenherz
nipkow
parents: 38621
diff changeset
   432
lemma mono_iSuc: "mono iSuc"
258a489c24b2 Added material by David Trachtenherz
nipkow
parents: 38621
diff changeset
   433
by(simp add: mono_def)
258a489c24b2 Added material by David Trachtenherz
nipkow
parents: 38621
diff changeset
   434
258a489c24b2 Added material by David Trachtenherz
nipkow
parents: 38621
diff changeset
   435
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   436
lemma min_enat_simps [simp]:
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   437
  "min (Fin m) (Fin n) = Fin (min m n)"
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   438
  "min q 0 = 0"
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   439
  "min 0 q = 0"
43921
e8511be08ddd Introduce infinity type class
hoelzl
parents: 43919
diff changeset
   440
  "min q (\<infinity>::enat) = q"
e8511be08ddd Introduce infinity type class
hoelzl
parents: 43919
diff changeset
   441
  "min (\<infinity>::enat) q = q"
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   442
  by (auto simp add: min_def)
11351
c5c403d30c77 added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff changeset
   443
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   444
lemma max_enat_simps [simp]:
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   445
  "max (Fin m) (Fin n) = Fin (max m n)"
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   446
  "max q 0 = q"
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   447
  "max 0 q = q"
43921
e8511be08ddd Introduce infinity type class
hoelzl
parents: 43919
diff changeset
   448
  "max q \<infinity> = (\<infinity>::enat)"
e8511be08ddd Introduce infinity type class
hoelzl
parents: 43919
diff changeset
   449
  "max \<infinity> q = (\<infinity>::enat)"
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   450
  by (simp_all add: max_def)
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   451
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   452
lemma Fin_ile: "n \<le> Fin m \<Longrightarrow> \<exists>k. n = Fin k"
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   453
  by (cases n) simp_all
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   454
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   455
lemma Fin_iless: "n < Fin m \<Longrightarrow> \<exists>k. n = Fin k"
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   456
  by (cases n) simp_all
11351
c5c403d30c77 added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff changeset
   457
c5c403d30c77 added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff changeset
   458
lemma chain_incr: "\<forall>i. \<exists>j. Y i < Y j ==> \<exists>j. Fin k < Y j"
25134
3d4953e88449 Eliminated most of the neq0_conv occurrences. As a result, many
nipkow
parents: 25112
diff changeset
   459
apply (induct_tac k)
3d4953e88449 Eliminated most of the neq0_conv occurrences. As a result, many
nipkow
parents: 25112
diff changeset
   460
 apply (simp (no_asm) only: Fin_0)
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   461
 apply (fast intro: le_less_trans [OF i0_lb])
25134
3d4953e88449 Eliminated most of the neq0_conv occurrences. As a result, many
nipkow
parents: 25112
diff changeset
   462
apply (erule exE)
3d4953e88449 Eliminated most of the neq0_conv occurrences. As a result, many
nipkow
parents: 25112
diff changeset
   463
apply (drule spec)
3d4953e88449 Eliminated most of the neq0_conv occurrences. As a result, many
nipkow
parents: 25112
diff changeset
   464
apply (erule exE)
3d4953e88449 Eliminated most of the neq0_conv occurrences. As a result, many
nipkow
parents: 25112
diff changeset
   465
apply (drule ileI1)
3d4953e88449 Eliminated most of the neq0_conv occurrences. As a result, many
nipkow
parents: 25112
diff changeset
   466
apply (rule iSuc_Fin [THEN subst])
3d4953e88449 Eliminated most of the neq0_conv occurrences. As a result, many
nipkow
parents: 25112
diff changeset
   467
apply (rule exI)
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   468
apply (erule (1) le_less_trans)
25134
3d4953e88449 Eliminated most of the neq0_conv occurrences. As a result, many
nipkow
parents: 25112
diff changeset
   469
done
11351
c5c403d30c77 added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff changeset
   470
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   471
instantiation enat :: "{bot, top}"
29337
450805a4a91f added instance for bot, top
haftmann
parents: 29023
diff changeset
   472
begin
450805a4a91f added instance for bot, top
haftmann
parents: 29023
diff changeset
   473
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   474
definition bot_enat :: enat where
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   475
  "bot_enat = 0"
29337
450805a4a91f added instance for bot, top
haftmann
parents: 29023
diff changeset
   476
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   477
definition top_enat :: enat where
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   478
  "top_enat = \<infinity>"
29337
450805a4a91f added instance for bot, top
haftmann
parents: 29023
diff changeset
   479
450805a4a91f added instance for bot, top
haftmann
parents: 29023
diff changeset
   480
instance proof
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   481
qed (simp_all add: bot_enat_def top_enat_def)
29337
450805a4a91f added instance for bot, top
haftmann
parents: 29023
diff changeset
   482
450805a4a91f added instance for bot, top
haftmann
parents: 29023
diff changeset
   483
end
450805a4a91f added instance for bot, top
haftmann
parents: 29023
diff changeset
   484
42993
da014b00d7a4 instance inat for complete_lattice
noschinl
parents: 41855
diff changeset
   485
lemma finite_Fin_bounded:
da014b00d7a4 instance inat for complete_lattice
noschinl
parents: 41855
diff changeset
   486
  assumes le_fin: "\<And>y. y \<in> A \<Longrightarrow> y \<le> Fin n"
da014b00d7a4 instance inat for complete_lattice
noschinl
parents: 41855
diff changeset
   487
  shows "finite A"
da014b00d7a4 instance inat for complete_lattice
noschinl
parents: 41855
diff changeset
   488
proof (rule finite_subset)
da014b00d7a4 instance inat for complete_lattice
noschinl
parents: 41855
diff changeset
   489
  show "finite (Fin ` {..n})" by blast
da014b00d7a4 instance inat for complete_lattice
noschinl
parents: 41855
diff changeset
   490
da014b00d7a4 instance inat for complete_lattice
noschinl
parents: 41855
diff changeset
   491
  have "A \<subseteq> {..Fin n}" using le_fin by fastsimp
da014b00d7a4 instance inat for complete_lattice
noschinl
parents: 41855
diff changeset
   492
  also have "\<dots> \<subseteq> Fin ` {..n}"
da014b00d7a4 instance inat for complete_lattice
noschinl
parents: 41855
diff changeset
   493
    by (rule subsetI) (case_tac x, auto)
da014b00d7a4 instance inat for complete_lattice
noschinl
parents: 41855
diff changeset
   494
  finally show "A \<subseteq> Fin ` {..n}" .
da014b00d7a4 instance inat for complete_lattice
noschinl
parents: 41855
diff changeset
   495
qed
da014b00d7a4 instance inat for complete_lattice
noschinl
parents: 41855
diff changeset
   496
26089
373221497340 proved linorder and wellorder class instances
huffman
parents: 25691
diff changeset
   497
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   498
subsection {* Well-ordering *}
26089
373221497340 proved linorder and wellorder class instances
huffman
parents: 25691
diff changeset
   499
373221497340 proved linorder and wellorder class instances
huffman
parents: 25691
diff changeset
   500
lemma less_FinE:
373221497340 proved linorder and wellorder class instances
huffman
parents: 25691
diff changeset
   501
  "[| n < Fin m; !!k. n = Fin k ==> k < m ==> P |] ==> P"
373221497340 proved linorder and wellorder class instances
huffman
parents: 25691
diff changeset
   502
by (induct n) auto
373221497340 proved linorder and wellorder class instances
huffman
parents: 25691
diff changeset
   503
373221497340 proved linorder and wellorder class instances
huffman
parents: 25691
diff changeset
   504
lemma less_InftyE:
43921
e8511be08ddd Introduce infinity type class
hoelzl
parents: 43919
diff changeset
   505
  "[| n < \<infinity>; !!k. n = Fin k ==> P |] ==> P"
26089
373221497340 proved linorder and wellorder class instances
huffman
parents: 25691
diff changeset
   506
by (induct n) auto
373221497340 proved linorder and wellorder class instances
huffman
parents: 25691
diff changeset
   507
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   508
lemma enat_less_induct:
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   509
  assumes prem: "!!n. \<forall>m::enat. m < n --> P m ==> P n" shows "P n"
26089
373221497340 proved linorder and wellorder class instances
huffman
parents: 25691
diff changeset
   510
proof -
373221497340 proved linorder and wellorder class instances
huffman
parents: 25691
diff changeset
   511
  have P_Fin: "!!k. P (Fin k)"
373221497340 proved linorder and wellorder class instances
huffman
parents: 25691
diff changeset
   512
    apply (rule nat_less_induct)
373221497340 proved linorder and wellorder class instances
huffman
parents: 25691
diff changeset
   513
    apply (rule prem, clarify)
373221497340 proved linorder and wellorder class instances
huffman
parents: 25691
diff changeset
   514
    apply (erule less_FinE, simp)
373221497340 proved linorder and wellorder class instances
huffman
parents: 25691
diff changeset
   515
    done
373221497340 proved linorder and wellorder class instances
huffman
parents: 25691
diff changeset
   516
  show ?thesis
373221497340 proved linorder and wellorder class instances
huffman
parents: 25691
diff changeset
   517
  proof (induct n)
373221497340 proved linorder and wellorder class instances
huffman
parents: 25691
diff changeset
   518
    fix nat
373221497340 proved linorder and wellorder class instances
huffman
parents: 25691
diff changeset
   519
    show "P (Fin nat)" by (rule P_Fin)
373221497340 proved linorder and wellorder class instances
huffman
parents: 25691
diff changeset
   520
  next
43921
e8511be08ddd Introduce infinity type class
hoelzl
parents: 43919
diff changeset
   521
    show "P \<infinity>"
26089
373221497340 proved linorder and wellorder class instances
huffman
parents: 25691
diff changeset
   522
      apply (rule prem, clarify)
373221497340 proved linorder and wellorder class instances
huffman
parents: 25691
diff changeset
   523
      apply (erule less_InftyE)
373221497340 proved linorder and wellorder class instances
huffman
parents: 25691
diff changeset
   524
      apply (simp add: P_Fin)
373221497340 proved linorder and wellorder class instances
huffman
parents: 25691
diff changeset
   525
      done
373221497340 proved linorder and wellorder class instances
huffman
parents: 25691
diff changeset
   526
  qed
373221497340 proved linorder and wellorder class instances
huffman
parents: 25691
diff changeset
   527
qed
373221497340 proved linorder and wellorder class instances
huffman
parents: 25691
diff changeset
   528
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   529
instance enat :: wellorder
26089
373221497340 proved linorder and wellorder class instances
huffman
parents: 25691
diff changeset
   530
proof
27823
52971512d1a2 moved class wellorder to theory Orderings
haftmann
parents: 27487
diff changeset
   531
  fix P and n
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   532
  assume hyp: "(\<And>n\<Colon>enat. (\<And>m\<Colon>enat. m < n \<Longrightarrow> P m) \<Longrightarrow> P n)"
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   533
  show "P n" by (blast intro: enat_less_induct hyp)
26089
373221497340 proved linorder and wellorder class instances
huffman
parents: 25691
diff changeset
   534
qed
373221497340 proved linorder and wellorder class instances
huffman
parents: 25691
diff changeset
   535
42993
da014b00d7a4 instance inat for complete_lattice
noschinl
parents: 41855
diff changeset
   536
subsection {* Complete Lattice *}
da014b00d7a4 instance inat for complete_lattice
noschinl
parents: 41855
diff changeset
   537
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   538
instantiation enat :: complete_lattice
42993
da014b00d7a4 instance inat for complete_lattice
noschinl
parents: 41855
diff changeset
   539
begin
da014b00d7a4 instance inat for complete_lattice
noschinl
parents: 41855
diff changeset
   540
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   541
definition inf_enat :: "enat \<Rightarrow> enat \<Rightarrow> enat" where
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   542
  "inf_enat \<equiv> min"
42993
da014b00d7a4 instance inat for complete_lattice
noschinl
parents: 41855
diff changeset
   543
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   544
definition sup_enat :: "enat \<Rightarrow> enat \<Rightarrow> enat" where
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   545
  "sup_enat \<equiv> max"
42993
da014b00d7a4 instance inat for complete_lattice
noschinl
parents: 41855
diff changeset
   546
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   547
definition Inf_enat :: "enat set \<Rightarrow> enat" where
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   548
  "Inf_enat A \<equiv> if A = {} then \<infinity> else (LEAST x. x \<in> A)"
42993
da014b00d7a4 instance inat for complete_lattice
noschinl
parents: 41855
diff changeset
   549
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   550
definition Sup_enat :: "enat set \<Rightarrow> enat" where
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   551
  "Sup_enat A \<equiv> if A = {} then 0
42993
da014b00d7a4 instance inat for complete_lattice
noschinl
parents: 41855
diff changeset
   552
    else if finite A then Max A
da014b00d7a4 instance inat for complete_lattice
noschinl
parents: 41855
diff changeset
   553
                     else \<infinity>"
da014b00d7a4 instance inat for complete_lattice
noschinl
parents: 41855
diff changeset
   554
instance proof
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   555
  fix x :: "enat" and A :: "enat set"
42993
da014b00d7a4 instance inat for complete_lattice
noschinl
parents: 41855
diff changeset
   556
  { assume "x \<in> A" then show "Inf A \<le> x"
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   557
      unfolding Inf_enat_def by (auto intro: Least_le) }
42993
da014b00d7a4 instance inat for complete_lattice
noschinl
parents: 41855
diff changeset
   558
  { assume "\<And>y. y \<in> A \<Longrightarrow> x \<le> y" then show "x \<le> Inf A"
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   559
      unfolding Inf_enat_def
42993
da014b00d7a4 instance inat for complete_lattice
noschinl
parents: 41855
diff changeset
   560
      by (cases "A = {}") (auto intro: LeastI2_ex) }
da014b00d7a4 instance inat for complete_lattice
noschinl
parents: 41855
diff changeset
   561
  { assume "x \<in> A" then show "x \<le> Sup A"
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   562
      unfolding Sup_enat_def by (cases "finite A") auto }
42993
da014b00d7a4 instance inat for complete_lattice
noschinl
parents: 41855
diff changeset
   563
  { assume "\<And>y. y \<in> A \<Longrightarrow> y \<le> x" then show "Sup A \<le> x"
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   564
      unfolding Sup_enat_def using finite_Fin_bounded by auto }
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   565
qed (simp_all add: inf_enat_def sup_enat_def)
42993
da014b00d7a4 instance inat for complete_lattice
noschinl
parents: 41855
diff changeset
   566
end
da014b00d7a4 instance inat for complete_lattice
noschinl
parents: 41855
diff changeset
   567
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   568
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   569
subsection {* Traditional theorem names *}
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   570
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   571
lemmas enat_defs = zero_enat_def one_enat_def number_of_enat_def iSuc_def
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   572
  plus_enat_def less_eq_enat_def less_enat_def
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   573
11351
c5c403d30c77 added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff changeset
   574
end