src/HOL/Library/Extended_Nat.thy
author wenzelm
Thu, 16 Feb 2012 22:53:24 +0100
changeset 46507 1b24c24017dd
parent 45934 9321cd2572fe
child 47108 2a1953f0d20d
permissions -rw-r--r--
tuned proofs;
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
 
43924
1165fe965da8 rename Fin to enat
hoelzl
parents: 43923
diff changeset
    30
definition enat :: "nat \<Rightarrow> enat" where
1165fe965da8 rename Fin to enat
hoelzl
parents: 43923
diff changeset
    31
  "enat n = Abs_enat (Some n)"
43921
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
 
43924
1165fe965da8 rename Fin to enat
hoelzl
parents: 43923
diff changeset
    39
rep_datatype enat "\<infinity> :: enat"
43921
e8511be08ddd Introduce infinity type class
hoelzl
parents: 43919
diff changeset
    40
proof -
43924
1165fe965da8 rename Fin to enat
hoelzl
parents: 43923
diff changeset
    41
  fix P i assume "\<And>j. P (enat j)" "P \<infinity>"
43921
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)
43924
1165fe965da8 rename Fin to enat
hoelzl
parents: 43923
diff changeset
    46
         (auto simp: enat_def infinity_enat_def)
43921
e8511be08ddd Introduce infinity type class
hoelzl
parents: 43919
diff changeset
    47
  qed
43924
1165fe965da8 rename Fin to enat
hoelzl
parents: 43923
diff changeset
    48
qed (auto simp add: enat_def infinity_enat_def Abs_enat_inject)
19736
wenzelm
parents: 15140
diff changeset
    49
43924
1165fe965da8 rename Fin to enat
hoelzl
parents: 43923
diff changeset
    50
declare [[coercion "enat::nat\<Rightarrow>enat"]]
19736
wenzelm
parents: 15140
diff changeset
    51
45934
9321cd2572fe add simp rules for enat and ereal
noschinl
parents: 45775
diff changeset
    52
lemmas enat2_cases = enat.exhaust[case_product enat.exhaust]
9321cd2572fe add simp rules for enat and ereal
noschinl
parents: 45775
diff changeset
    53
lemmas enat3_cases = enat.exhaust[case_product enat.exhaust enat.exhaust]
9321cd2572fe add simp rules for enat and ereal
noschinl
parents: 45775
diff changeset
    54
44019
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
    55
lemma not_infinity_eq [iff]: "(x \<noteq> \<infinity>) = (EX i. x = enat i)"
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
    56
  by (cases x) auto
31084
f4db921165ce fixed HOLCF proofs
nipkow
parents: 31077
diff changeset
    57
43924
1165fe965da8 rename Fin to enat
hoelzl
parents: 43923
diff changeset
    58
lemma not_enat_eq [iff]: "(ALL y. x ~= enat y) = (x = \<infinity>)"
44019
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
    59
  by (cases x) auto
31077
28dd6fd3d184 more lemmas
nipkow
parents: 30663
diff changeset
    60
43924
1165fe965da8 rename Fin to enat
hoelzl
parents: 43923
diff changeset
    61
primrec the_enat :: "enat \<Rightarrow> nat"
44019
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
    62
  where "the_enat (enat n) = n"
41855
c3b6e69da386 added a few lemmas by Andreas Lochbihler
nipkow
parents: 41853
diff changeset
    63
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
    64
subsection {* Constructors and numbers *}
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
    65
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
    66
instantiation enat :: "{zero, one, number}"
25594
43c718438f9f switched import from Main to PreList
haftmann
parents: 25134
diff changeset
    67
begin
43c718438f9f switched import from Main to PreList
haftmann
parents: 25134
diff changeset
    68
43c718438f9f switched import from Main to PreList
haftmann
parents: 25134
diff changeset
    69
definition
43924
1165fe965da8 rename Fin to enat
hoelzl
parents: 43923
diff changeset
    70
  "0 = enat 0"
25594
43c718438f9f switched import from Main to PreList
haftmann
parents: 25134
diff changeset
    71
43c718438f9f switched import from Main to PreList
haftmann
parents: 25134
diff changeset
    72
definition
43924
1165fe965da8 rename Fin to enat
hoelzl
parents: 43923
diff changeset
    73
  [code_unfold]: "1 = enat 1"
25594
43c718438f9f switched import from Main to PreList
haftmann
parents: 25134
diff changeset
    74
43c718438f9f switched import from Main to PreList
haftmann
parents: 25134
diff changeset
    75
definition
43924
1165fe965da8 rename Fin to enat
hoelzl
parents: 43923
diff changeset
    76
  [code_unfold, code del]: "number_of k = enat (number_of k)"
11351
c5c403d30c77 added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff changeset
    77
25594
43c718438f9f switched import from Main to PreList
haftmann
parents: 25134
diff changeset
    78
instance ..
43c718438f9f switched import from Main to PreList
haftmann
parents: 25134
diff changeset
    79
43c718438f9f switched import from Main to PreList
haftmann
parents: 25134
diff changeset
    80
end
43c718438f9f switched import from Main to PreList
haftmann
parents: 25134
diff changeset
    81
44019
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
    82
definition eSuc :: "enat \<Rightarrow> enat" where
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
    83
  "eSuc i = (case i of enat n \<Rightarrow> enat (Suc n) | \<infinity> \<Rightarrow> \<infinity>)"
11351
c5c403d30c77 added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff changeset
    84
43924
1165fe965da8 rename Fin to enat
hoelzl
parents: 43923
diff changeset
    85
lemma enat_0: "enat 0 = 0"
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
    86
  by (simp add: zero_enat_def)
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
    87
43924
1165fe965da8 rename Fin to enat
hoelzl
parents: 43923
diff changeset
    88
lemma enat_1: "enat 1 = 1"
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
    89
  by (simp add: one_enat_def)
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
    90
43924
1165fe965da8 rename Fin to enat
hoelzl
parents: 43923
diff changeset
    91
lemma enat_number: "enat (number_of k) = number_of k"
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
    92
  by (simp add: number_of_enat_def)
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
    93
44019
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
    94
lemma one_eSuc: "1 = eSuc 0"
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
    95
  by (simp add: zero_enat_def one_enat_def eSuc_def)
11351
c5c403d30c77 added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff changeset
    96
44019
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
    97
lemma infinity_ne_i0 [simp]: "(\<infinity>::enat) \<noteq> 0"
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
    98
  by (simp add: zero_enat_def)
11351
c5c403d30c77 added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff changeset
    99
44019
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   100
lemma i0_ne_infinity [simp]: "0 \<noteq> (\<infinity>::enat)"
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   101
  by (simp add: zero_enat_def)
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   102
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   103
lemma zero_enat_eq [simp]:
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   104
  "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
   105
  "(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
   106
  unfolding zero_enat_def number_of_enat_def by simp_all
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   107
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   108
lemma one_enat_eq [simp]:
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   109
  "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
   110
  "(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
   111
  unfolding one_enat_def number_of_enat_def by simp_all
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   112
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   113
lemma zero_one_enat_neq [simp]:
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   114
  "\<not> 0 = (1\<Colon>enat)"
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   115
  "\<not> 1 = (0\<Colon>enat)"
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   116
  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
   117
44019
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   118
lemma infinity_ne_i1 [simp]: "(\<infinity>::enat) \<noteq> 1"
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   119
  by (simp add: one_enat_def)
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   120
44019
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   121
lemma i1_ne_infinity [simp]: "1 \<noteq> (\<infinity>::enat)"
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   122
  by (simp add: one_enat_def)
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   123
44019
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   124
lemma infinity_ne_number [simp]: "(\<infinity>::enat) \<noteq> number_of k"
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   125
  by (simp add: number_of_enat_def)
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   126
44019
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   127
lemma number_ne_infinity [simp]: "number_of k \<noteq> (\<infinity>::enat)"
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   128
  by (simp add: number_of_enat_def)
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   129
44019
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   130
lemma eSuc_enat: "eSuc (enat n) = enat (Suc n)"
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   131
  by (simp add: eSuc_def)
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   132
44019
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   133
lemma eSuc_number_of: "eSuc (number_of k) = enat (Suc (number_of k))"
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   134
  by (simp add: eSuc_enat number_of_enat_def)
11351
c5c403d30c77 added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff changeset
   135
44019
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   136
lemma eSuc_infinity [simp]: "eSuc \<infinity> = \<infinity>"
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   137
  by (simp add: eSuc_def)
11351
c5c403d30c77 added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff changeset
   138
44019
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   139
lemma eSuc_ne_0 [simp]: "eSuc n \<noteq> 0"
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   140
  by (simp add: eSuc_def zero_enat_def split: enat.splits)
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   141
44019
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   142
lemma zero_ne_eSuc [simp]: "0 \<noteq> eSuc n"
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   143
  by (rule eSuc_ne_0 [symmetric])
11351
c5c403d30c77 added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff changeset
   144
44019
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   145
lemma eSuc_inject [simp]: "eSuc m = eSuc n \<longleftrightarrow> m = n"
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   146
  by (simp add: eSuc_def split: enat.splits)
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   147
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   148
lemma number_of_enat_inject [simp]:
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   149
  "(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
   150
  by (simp add: number_of_enat_def)
11351
c5c403d30c77 added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff changeset
   151
c5c403d30c77 added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff changeset
   152
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   153
subsection {* Addition *}
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   154
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   155
instantiation enat :: comm_monoid_add
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   156
begin
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   157
38167
ab528533db92 help Nitpick
blanchet
parents: 37765
diff changeset
   158
definition [nitpick_simp]:
43924
1165fe965da8 rename Fin to enat
hoelzl
parents: 43923
diff changeset
   159
  "m + n = (case m of \<infinity> \<Rightarrow> \<infinity> | enat m \<Rightarrow> (case n of \<infinity> \<Rightarrow> \<infinity> | enat n \<Rightarrow> enat (m + n)))"
11351
c5c403d30c77 added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff changeset
   160
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   161
lemma plus_enat_simps [simp, code]:
43921
e8511be08ddd Introduce infinity type class
hoelzl
parents: 43919
diff changeset
   162
  fixes q :: enat
43924
1165fe965da8 rename Fin to enat
hoelzl
parents: 43923
diff changeset
   163
  shows "enat m + enat n = enat (m + n)"
43921
e8511be08ddd Introduce infinity type class
hoelzl
parents: 43919
diff changeset
   164
    and "\<infinity> + q = \<infinity>"
e8511be08ddd Introduce infinity type class
hoelzl
parents: 43919
diff changeset
   165
    and "q + \<infinity> = \<infinity>"
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   166
  by (simp_all add: plus_enat_def split: enat.splits)
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   167
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   168
instance proof
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   169
  fix n m q :: enat
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   170
  show "n + m + q = n + (m + q)"
45934
9321cd2572fe add simp rules for enat and ereal
noschinl
parents: 45775
diff changeset
   171
    by (cases n m q rule: enat3_cases) auto
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   172
  show "n + m = m + n"
45934
9321cd2572fe add simp rules for enat and ereal
noschinl
parents: 45775
diff changeset
   173
    by (cases n m rule: enat2_cases) auto
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   174
  show "0 + n = n"
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   175
    by (cases n) (simp_all add: zero_enat_def)
26089
373221497340 proved linorder and wellorder class instances
huffman
parents: 25691
diff changeset
   176
qed
373221497340 proved linorder and wellorder class instances
huffman
parents: 25691
diff changeset
   177
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   178
end
11351
c5c403d30c77 added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff changeset
   179
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   180
lemma plus_enat_number [simp]:
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   181
  "(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
   182
    else if l < Int.Pls then number_of k else number_of (k + l))"
43924
1165fe965da8 rename Fin to enat
hoelzl
parents: 43923
diff changeset
   183
  unfolding number_of_enat_def plus_enat_simps nat_arith(1) if_distrib [symmetric, of _ enat] ..
11351
c5c403d30c77 added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff changeset
   184
44019
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   185
lemma eSuc_number [simp]:
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   186
  "eSuc (number_of k) = (if neg (number_of k \<Colon> int) then 1 else number_of (Int.succ k))"
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   187
  unfolding eSuc_number_of
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   188
  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
   189
44019
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   190
lemma eSuc_plus_1:
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   191
  "eSuc n = n + 1"
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   192
  by (cases n) (simp_all add: eSuc_enat one_enat_def)
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   193
  
44019
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   194
lemma plus_1_eSuc:
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   195
  "1 + q = eSuc q"
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   196
  "q + 1 = eSuc q"
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   197
  by (simp_all add: eSuc_plus_1 add_ac)
41853
258a489c24b2 Added material by David Trachtenherz
nipkow
parents: 38621
diff changeset
   198
44019
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   199
lemma iadd_Suc: "eSuc m + n = eSuc (m + n)"
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   200
  by (simp_all add: eSuc_plus_1 add_ac)
11351
c5c403d30c77 added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff changeset
   201
44019
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   202
lemma iadd_Suc_right: "m + eSuc n = eSuc (m + n)"
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   203
  by (simp only: add_commute[of m] iadd_Suc)
41853
258a489c24b2 Added material by David Trachtenherz
nipkow
parents: 38621
diff changeset
   204
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   205
lemma iadd_is_0: "(m + n = (0::enat)) = (m = 0 \<and> n = 0)"
44019
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   206
  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
   207
29014
e515f42d1db7 multiplication for type inat
huffman
parents: 29012
diff changeset
   208
subsection {* Multiplication *}
e515f42d1db7 multiplication for type inat
huffman
parents: 29012
diff changeset
   209
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   210
instantiation enat :: comm_semiring_1
29014
e515f42d1db7 multiplication for type inat
huffman
parents: 29012
diff changeset
   211
begin
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
definition times_enat_def [nitpick_simp]:
43924
1165fe965da8 rename Fin to enat
hoelzl
parents: 43923
diff changeset
   214
  "m * n = (case m of \<infinity> \<Rightarrow> if n = 0 then 0 else \<infinity> | enat m \<Rightarrow>
1165fe965da8 rename Fin to enat
hoelzl
parents: 43923
diff changeset
   215
    (case n of \<infinity> \<Rightarrow> if m = 0 then 0 else \<infinity> | enat n \<Rightarrow> enat (m * n)))"
29014
e515f42d1db7 multiplication for type inat
huffman
parents: 29012
diff changeset
   216
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   217
lemma times_enat_simps [simp, code]:
43924
1165fe965da8 rename Fin to enat
hoelzl
parents: 43923
diff changeset
   218
  "enat m * enat n = enat (m * n)"
43921
e8511be08ddd Introduce infinity type class
hoelzl
parents: 43919
diff changeset
   219
  "\<infinity> * \<infinity> = (\<infinity>::enat)"
43924
1165fe965da8 rename Fin to enat
hoelzl
parents: 43923
diff changeset
   220
  "\<infinity> * enat n = (if n = 0 then 0 else \<infinity>)"
1165fe965da8 rename Fin to enat
hoelzl
parents: 43923
diff changeset
   221
  "enat m * \<infinity> = (if m = 0 then 0 else \<infinity>)"
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   222
  unfolding times_enat_def zero_enat_def
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   223
  by (simp_all split: enat.split)
29014
e515f42d1db7 multiplication for type inat
huffman
parents: 29012
diff changeset
   224
e515f42d1db7 multiplication for type inat
huffman
parents: 29012
diff changeset
   225
instance proof
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   226
  fix a b c :: enat
29014
e515f42d1db7 multiplication for type inat
huffman
parents: 29012
diff changeset
   227
  show "(a * b) * c = a * (b * c)"
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   228
    unfolding times_enat_def zero_enat_def
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   229
    by (simp split: enat.split)
29014
e515f42d1db7 multiplication for type inat
huffman
parents: 29012
diff changeset
   230
  show "a * b = b * a"
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 "1 * a = a"
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   234
    unfolding times_enat_def zero_enat_def one_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 "(a + b) * c = a * c + b * c"
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   237
    unfolding times_enat_def zero_enat_def
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   238
    by (simp split: enat.split add: left_distrib)
29014
e515f42d1db7 multiplication for type inat
huffman
parents: 29012
diff changeset
   239
  show "0 * a = 0"
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)
29014
e515f42d1db7 multiplication for type inat
huffman
parents: 29012
diff changeset
   242
  show "a * 0 = 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)
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   245
  show "(0::enat) \<noteq> 1"
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   246
    unfolding zero_enat_def one_enat_def
29014
e515f42d1db7 multiplication for type inat
huffman
parents: 29012
diff changeset
   247
    by simp
e515f42d1db7 multiplication for type inat
huffman
parents: 29012
diff changeset
   248
qed
e515f42d1db7 multiplication for type inat
huffman
parents: 29012
diff changeset
   249
e515f42d1db7 multiplication for type inat
huffman
parents: 29012
diff changeset
   250
end
e515f42d1db7 multiplication for type inat
huffman
parents: 29012
diff changeset
   251
44019
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   252
lemma mult_eSuc: "eSuc m * n = n + m * n"
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   253
  unfolding eSuc_plus_1 by (simp add: algebra_simps)
29014
e515f42d1db7 multiplication for type inat
huffman
parents: 29012
diff changeset
   254
44019
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   255
lemma mult_eSuc_right: "m * eSuc n = m + m * n"
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   256
  unfolding eSuc_plus_1 by (simp add: algebra_simps)
29014
e515f42d1db7 multiplication for type inat
huffman
parents: 29012
diff changeset
   257
43924
1165fe965da8 rename Fin to enat
hoelzl
parents: 43923
diff changeset
   258
lemma of_nat_eq_enat: "of_nat n = enat n"
29023
ef3adebc6d98 instance inat :: semiring_char_0
huffman
parents: 29014
diff changeset
   259
  apply (induct n)
43924
1165fe965da8 rename Fin to enat
hoelzl
parents: 43923
diff changeset
   260
  apply (simp add: enat_0)
44019
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   261
  apply (simp add: plus_1_eSuc eSuc_enat)
29023
ef3adebc6d98 instance inat :: semiring_char_0
huffman
parents: 29014
diff changeset
   262
  done
ef3adebc6d98 instance inat :: semiring_char_0
huffman
parents: 29014
diff changeset
   263
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   264
instance enat :: number_semiring
43532
d32d72ea3215 instance inat :: number_semiring
huffman
parents: 42993
diff changeset
   265
proof
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   266
  fix n show "number_of (int n) = (of_nat n :: enat)"
43924
1165fe965da8 rename Fin to enat
hoelzl
parents: 43923
diff changeset
   267
    unfolding number_of_enat_def number_of_int of_nat_id of_nat_eq_enat ..
43532
d32d72ea3215 instance inat :: number_semiring
huffman
parents: 42993
diff changeset
   268
qed
d32d72ea3215 instance inat :: number_semiring
huffman
parents: 42993
diff changeset
   269
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   270
instance enat :: semiring_char_0 proof
43924
1165fe965da8 rename Fin to enat
hoelzl
parents: 43923
diff changeset
   271
  have "inj enat" by (rule injI) simp
1165fe965da8 rename Fin to enat
hoelzl
parents: 43923
diff changeset
   272
  then show "inj (\<lambda>n. of_nat n :: enat)" by (simp add: of_nat_eq_enat)
38621
d6cb7e625d75 more concise characterization of of_nat operation and class semiring_char_0
haftmann
parents: 38167
diff changeset
   273
qed
29023
ef3adebc6d98 instance inat :: semiring_char_0
huffman
parents: 29014
diff changeset
   274
44019
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   275
lemma imult_is_0 [simp]: "((m::enat) * n = 0) = (m = 0 \<or> n = 0)"
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   276
  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
   277
44019
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   278
lemma imult_is_infinity: "((a::enat) * b = \<infinity>) = (a = \<infinity> \<and> b \<noteq> 0 \<or> b = \<infinity> \<and> a \<noteq> 0)"
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
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
258a489c24b2 Added material by David Trachtenherz
nipkow
parents: 38621
diff changeset
   281
258a489c24b2 Added material by David Trachtenherz
nipkow
parents: 38621
diff changeset
   282
subsection {* Subtraction *}
258a489c24b2 Added material by David Trachtenherz
nipkow
parents: 38621
diff changeset
   283
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   284
instantiation enat :: minus
41853
258a489c24b2 Added material by David Trachtenherz
nipkow
parents: 38621
diff changeset
   285
begin
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
definition diff_enat_def:
43924
1165fe965da8 rename Fin to enat
hoelzl
parents: 43923
diff changeset
   288
"a - b = (case a of (enat x) \<Rightarrow> (case b of (enat y) \<Rightarrow> enat (x - y) | \<infinity> \<Rightarrow> 0)
41853
258a489c24b2 Added material by David Trachtenherz
nipkow
parents: 38621
diff changeset
   289
          | \<infinity> \<Rightarrow> \<infinity>)"
258a489c24b2 Added material by David Trachtenherz
nipkow
parents: 38621
diff changeset
   290
258a489c24b2 Added material by David Trachtenherz
nipkow
parents: 38621
diff changeset
   291
instance ..
258a489c24b2 Added material by David Trachtenherz
nipkow
parents: 38621
diff changeset
   292
258a489c24b2 Added material by David Trachtenherz
nipkow
parents: 38621
diff changeset
   293
end
258a489c24b2 Added material by David Trachtenherz
nipkow
parents: 38621
diff changeset
   294
44019
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   295
lemma idiff_enat_enat [simp,code]: "enat a - enat b = enat (a - b)"
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   296
  by (simp add: diff_enat_def)
41853
258a489c24b2 Added material by David Trachtenherz
nipkow
parents: 38621
diff changeset
   297
44019
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   298
lemma idiff_infinity [simp,code]: "\<infinity> - n = (\<infinity>::enat)"
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   299
  by (simp add: diff_enat_def)
41853
258a489c24b2 Added material by David Trachtenherz
nipkow
parents: 38621
diff changeset
   300
44019
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   301
lemma idiff_infinity_right [simp,code]: "enat a - \<infinity> = 0"
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   302
  by (simp add: diff_enat_def)
41853
258a489c24b2 Added material by David Trachtenherz
nipkow
parents: 38621
diff changeset
   303
44019
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   304
lemma idiff_0 [simp]: "(0::enat) - n = 0"
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   305
  by (cases n, simp_all add: zero_enat_def)
41853
258a489c24b2 Added material by David Trachtenherz
nipkow
parents: 38621
diff changeset
   306
44019
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   307
lemmas idiff_enat_0 [simp] = idiff_0 [unfolded zero_enat_def]
41853
258a489c24b2 Added material by David Trachtenherz
nipkow
parents: 38621
diff changeset
   308
44019
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   309
lemma idiff_0_right [simp]: "(n::enat) - 0 = n"
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   310
  by (cases n) (simp_all add: zero_enat_def)
41853
258a489c24b2 Added material by David Trachtenherz
nipkow
parents: 38621
diff changeset
   311
44019
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   312
lemmas idiff_enat_0_right [simp] = idiff_0_right [unfolded zero_enat_def]
41853
258a489c24b2 Added material by David Trachtenherz
nipkow
parents: 38621
diff changeset
   313
44019
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   314
lemma idiff_self [simp]: "n \<noteq> \<infinity> \<Longrightarrow> (n::enat) - n = 0"
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   315
  by (auto simp: zero_enat_def)
41853
258a489c24b2 Added material by David Trachtenherz
nipkow
parents: 38621
diff changeset
   316
44019
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   317
lemma eSuc_minus_eSuc [simp]: "eSuc n - eSuc m = n - m"
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   318
  by (simp add: eSuc_def split: enat.split)
41855
c3b6e69da386 added a few lemmas by Andreas Lochbihler
nipkow
parents: 41853
diff changeset
   319
44019
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   320
lemma eSuc_minus_1 [simp]: "eSuc n - 1 = n"
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   321
  by (simp add: one_enat_def eSuc_enat[symmetric] zero_enat_def[symmetric])
41855
c3b6e69da386 added a few lemmas by Andreas Lochbihler
nipkow
parents: 41853
diff changeset
   322
43924
1165fe965da8 rename Fin to enat
hoelzl
parents: 43923
diff changeset
   323
(*lemmas idiff_self_eq_0_enat = idiff_self_eq_0[unfolded zero_enat_def]*)
41853
258a489c24b2 Added material by David Trachtenherz
nipkow
parents: 38621
diff changeset
   324
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   325
subsection {* Ordering *}
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   326
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   327
instantiation enat :: linordered_ab_semigroup_add
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   328
begin
11351
c5c403d30c77 added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff changeset
   329
38167
ab528533db92 help Nitpick
blanchet
parents: 37765
diff changeset
   330
definition [nitpick_simp]:
43924
1165fe965da8 rename Fin to enat
hoelzl
parents: 43923
diff changeset
   331
  "m \<le> n = (case n of enat n1 \<Rightarrow> (case m of enat m1 \<Rightarrow> m1 \<le> n1 | \<infinity> \<Rightarrow> False)
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   332
    | \<infinity> \<Rightarrow> True)"
11351
c5c403d30c77 added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff changeset
   333
38167
ab528533db92 help Nitpick
blanchet
parents: 37765
diff changeset
   334
definition [nitpick_simp]:
43924
1165fe965da8 rename Fin to enat
hoelzl
parents: 43923
diff changeset
   335
  "m < n = (case m of enat m1 \<Rightarrow> (case n of enat n1 \<Rightarrow> m1 < n1 | \<infinity> \<Rightarrow> True)
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   336
    | \<infinity> \<Rightarrow> False)"
11351
c5c403d30c77 added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff changeset
   337
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   338
lemma enat_ord_simps [simp]:
43924
1165fe965da8 rename Fin to enat
hoelzl
parents: 43923
diff changeset
   339
  "enat m \<le> enat n \<longleftrightarrow> m \<le> n"
1165fe965da8 rename Fin to enat
hoelzl
parents: 43923
diff changeset
   340
  "enat m < enat n \<longleftrightarrow> m < n"
43921
e8511be08ddd Introduce infinity type class
hoelzl
parents: 43919
diff changeset
   341
  "q \<le> (\<infinity>::enat)"
e8511be08ddd Introduce infinity type class
hoelzl
parents: 43919
diff changeset
   342
  "q < (\<infinity>::enat) \<longleftrightarrow> q \<noteq> \<infinity>"
e8511be08ddd Introduce infinity type class
hoelzl
parents: 43919
diff changeset
   343
  "(\<infinity>::enat) \<le> q \<longleftrightarrow> q = \<infinity>"
e8511be08ddd Introduce infinity type class
hoelzl
parents: 43919
diff changeset
   344
  "(\<infinity>::enat) < q \<longleftrightarrow> False"
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   345
  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
   346
45934
9321cd2572fe add simp rules for enat and ereal
noschinl
parents: 45775
diff changeset
   347
lemma number_of_le_enat_iff[simp]:
9321cd2572fe add simp rules for enat and ereal
noschinl
parents: 45775
diff changeset
   348
  shows "number_of m \<le> enat n \<longleftrightarrow> number_of m \<le> n"
9321cd2572fe add simp rules for enat and ereal
noschinl
parents: 45775
diff changeset
   349
by (auto simp: number_of_enat_def)
9321cd2572fe add simp rules for enat and ereal
noschinl
parents: 45775
diff changeset
   350
9321cd2572fe add simp rules for enat and ereal
noschinl
parents: 45775
diff changeset
   351
lemma number_of_less_enat_iff[simp]:
9321cd2572fe add simp rules for enat and ereal
noschinl
parents: 45775
diff changeset
   352
  shows "number_of m < enat n \<longleftrightarrow> number_of m < n"
9321cd2572fe add simp rules for enat and ereal
noschinl
parents: 45775
diff changeset
   353
by (auto simp: number_of_enat_def)
9321cd2572fe add simp rules for enat and ereal
noschinl
parents: 45775
diff changeset
   354
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   355
lemma enat_ord_code [code]:
43924
1165fe965da8 rename Fin to enat
hoelzl
parents: 43923
diff changeset
   356
  "enat m \<le> enat n \<longleftrightarrow> m \<le> n"
1165fe965da8 rename Fin to enat
hoelzl
parents: 43923
diff changeset
   357
  "enat m < enat n \<longleftrightarrow> m < n"
43921
e8511be08ddd Introduce infinity type class
hoelzl
parents: 43919
diff changeset
   358
  "q \<le> (\<infinity>::enat) \<longleftrightarrow> True"
43924
1165fe965da8 rename Fin to enat
hoelzl
parents: 43923
diff changeset
   359
  "enat m < \<infinity> \<longleftrightarrow> True"
1165fe965da8 rename Fin to enat
hoelzl
parents: 43923
diff changeset
   360
  "\<infinity> \<le> enat n \<longleftrightarrow> False"
43921
e8511be08ddd Introduce infinity type class
hoelzl
parents: 43919
diff changeset
   361
  "(\<infinity>::enat) < q \<longleftrightarrow> False"
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   362
  by simp_all
11351
c5c403d30c77 added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff changeset
   363
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   364
instance by default
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   365
  (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
   366
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   367
end
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   368
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   369
instance enat :: ordered_comm_semiring
29014
e515f42d1db7 multiplication for type inat
huffman
parents: 29012
diff changeset
   370
proof
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   371
  fix a b c :: enat
29014
e515f42d1db7 multiplication for type inat
huffman
parents: 29012
diff changeset
   372
  assume "a \<le> b" and "0 \<le> c"
e515f42d1db7 multiplication for type inat
huffman
parents: 29012
diff changeset
   373
  thus "c * a \<le> c * b"
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   374
    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
   375
    by (simp split: enat.splits)
29014
e515f42d1db7 multiplication for type inat
huffman
parents: 29012
diff changeset
   376
qed
e515f42d1db7 multiplication for type inat
huffman
parents: 29012
diff changeset
   377
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   378
lemma enat_ord_number [simp]:
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   379
  "(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
   380
  "(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
   381
  by (simp_all add: number_of_enat_def)
11351
c5c403d30c77 added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff changeset
   382
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   383
lemma i0_lb [simp]: "(0\<Colon>enat) \<le> n"
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   384
  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
   385
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   386
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
   387
  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
   388
44019
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   389
lemma infinity_ileE [elim!]: "\<infinity> \<le> enat m \<Longrightarrow> R"
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   390
  by (simp add: zero_enat_def less_eq_enat_def split: enat.splits)
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   391
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   392
lemma infinity_ilessE [elim!]: "\<infinity> < enat m \<Longrightarrow> R"
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   393
  by simp
11351
c5c403d30c77 added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff changeset
   394
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   395
lemma not_iless0 [simp]: "\<not> n < (0\<Colon>enat)"
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   396
  by (simp add: zero_enat_def less_enat_def split: enat.splits)
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   397
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   398
lemma i0_less [simp]: "(0\<Colon>enat) < n \<longleftrightarrow> n \<noteq> 0"
44019
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   399
  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
   400
44019
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   401
lemma eSuc_ile_mono [simp]: "eSuc n \<le> eSuc m \<longleftrightarrow> n \<le> m"
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   402
  by (simp add: eSuc_def less_eq_enat_def split: enat.splits)
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   403
 
44019
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   404
lemma eSuc_mono [simp]: "eSuc n < eSuc m \<longleftrightarrow> n < m"
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   405
  by (simp add: eSuc_def less_enat_def split: enat.splits)
11351
c5c403d30c77 added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff changeset
   406
44019
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   407
lemma ile_eSuc [simp]: "n \<le> eSuc n"
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   408
  by (simp add: eSuc_def less_eq_enat_def split: enat.splits)
11351
c5c403d30c77 added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff changeset
   409
44019
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   410
lemma not_eSuc_ilei0 [simp]: "\<not> eSuc n \<le> 0"
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   411
  by (simp add: zero_enat_def eSuc_def less_eq_enat_def split: enat.splits)
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   412
44019
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   413
lemma i0_iless_eSuc [simp]: "0 < eSuc n"
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   414
  by (simp add: zero_enat_def eSuc_def less_enat_def split: enat.splits)
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   415
44019
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   416
lemma iless_eSuc0[simp]: "(n < eSuc 0) = (n = 0)"
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   417
  by (simp add: zero_enat_def eSuc_def less_enat_def split: enat.split)
41853
258a489c24b2 Added material by David Trachtenherz
nipkow
parents: 38621
diff changeset
   418
44019
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   419
lemma ileI1: "m < n \<Longrightarrow> eSuc m \<le> n"
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   420
  by (simp add: eSuc_def less_eq_enat_def less_enat_def split: enat.splits)
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   421
43924
1165fe965da8 rename Fin to enat
hoelzl
parents: 43923
diff changeset
   422
lemma Suc_ile_eq: "enat (Suc m) \<le> n \<longleftrightarrow> enat m < n"
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   423
  by (cases n) auto
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   424
44019
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   425
lemma iless_Suc_eq [simp]: "enat m < eSuc n \<longleftrightarrow> enat m \<le> n"
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   426
  by (auto simp add: eSuc_def less_enat_def split: enat.splits)
11351
c5c403d30c77 added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff changeset
   427
44019
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   428
lemma imult_infinity: "(0::enat) < n \<Longrightarrow> \<infinity> * n = \<infinity>"
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   429
  by (simp add: zero_enat_def less_enat_def split: enat.splits)
41853
258a489c24b2 Added material by David Trachtenherz
nipkow
parents: 38621
diff changeset
   430
44019
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   431
lemma imult_infinity_right: "(0::enat) < n \<Longrightarrow> n * \<infinity> = \<infinity>"
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   432
  by (simp add: zero_enat_def less_enat_def split: enat.splits)
41853
258a489c24b2 Added material by David Trachtenherz
nipkow
parents: 38621
diff changeset
   433
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   434
lemma enat_0_less_mult_iff: "(0 < (m::enat) * n) = (0 < m \<and> 0 < n)"
44019
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   435
  by (simp only: i0_less imult_is_0, simp)
41853
258a489c24b2 Added material by David Trachtenherz
nipkow
parents: 38621
diff changeset
   436
44019
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   437
lemma mono_eSuc: "mono eSuc"
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   438
  by (simp add: mono_def)
41853
258a489c24b2 Added material by David Trachtenherz
nipkow
parents: 38621
diff changeset
   439
258a489c24b2 Added material by David Trachtenherz
nipkow
parents: 38621
diff changeset
   440
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   441
lemma min_enat_simps [simp]:
43924
1165fe965da8 rename Fin to enat
hoelzl
parents: 43923
diff changeset
   442
  "min (enat m) (enat n) = enat (min m n)"
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   443
  "min q 0 = 0"
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   444
  "min 0 q = 0"
43921
e8511be08ddd Introduce infinity type class
hoelzl
parents: 43919
diff changeset
   445
  "min q (\<infinity>::enat) = q"
e8511be08ddd Introduce infinity type class
hoelzl
parents: 43919
diff changeset
   446
  "min (\<infinity>::enat) q = q"
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   447
  by (auto simp add: min_def)
11351
c5c403d30c77 added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff changeset
   448
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   449
lemma max_enat_simps [simp]:
43924
1165fe965da8 rename Fin to enat
hoelzl
parents: 43923
diff changeset
   450
  "max (enat m) (enat n) = enat (max m n)"
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   451
  "max q 0 = q"
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   452
  "max 0 q = q"
43921
e8511be08ddd Introduce infinity type class
hoelzl
parents: 43919
diff changeset
   453
  "max q \<infinity> = (\<infinity>::enat)"
e8511be08ddd Introduce infinity type class
hoelzl
parents: 43919
diff changeset
   454
  "max \<infinity> q = (\<infinity>::enat)"
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   455
  by (simp_all add: max_def)
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   456
43924
1165fe965da8 rename Fin to enat
hoelzl
parents: 43923
diff changeset
   457
lemma enat_ile: "n \<le> enat m \<Longrightarrow> \<exists>k. n = enat k"
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   458
  by (cases n) simp_all
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   459
43924
1165fe965da8 rename Fin to enat
hoelzl
parents: 43923
diff changeset
   460
lemma enat_iless: "n < enat m \<Longrightarrow> \<exists>k. n = enat k"
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   461
  by (cases n) simp_all
11351
c5c403d30c77 added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff changeset
   462
43924
1165fe965da8 rename Fin to enat
hoelzl
parents: 43923
diff changeset
   463
lemma chain_incr: "\<forall>i. \<exists>j. Y i < Y j ==> \<exists>j. enat k < Y j"
25134
3d4953e88449 Eliminated most of the neq0_conv occurrences. As a result, many
nipkow
parents: 25112
diff changeset
   464
apply (induct_tac k)
43924
1165fe965da8 rename Fin to enat
hoelzl
parents: 43923
diff changeset
   465
 apply (simp (no_asm) only: enat_0)
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   466
 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
   467
apply (erule exE)
3d4953e88449 Eliminated most of the neq0_conv occurrences. As a result, many
nipkow
parents: 25112
diff changeset
   468
apply (drule spec)
3d4953e88449 Eliminated most of the neq0_conv occurrences. As a result, many
nipkow
parents: 25112
diff changeset
   469
apply (erule exE)
3d4953e88449 Eliminated most of the neq0_conv occurrences. As a result, many
nipkow
parents: 25112
diff changeset
   470
apply (drule ileI1)
44019
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   471
apply (rule eSuc_enat [THEN subst])
25134
3d4953e88449 Eliminated most of the neq0_conv occurrences. As a result, many
nipkow
parents: 25112
diff changeset
   472
apply (rule exI)
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   473
apply (erule (1) le_less_trans)
25134
3d4953e88449 Eliminated most of the neq0_conv occurrences. As a result, many
nipkow
parents: 25112
diff changeset
   474
done
11351
c5c403d30c77 added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff changeset
   475
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   476
instantiation enat :: "{bot, top}"
29337
450805a4a91f added instance for bot, top
haftmann
parents: 29023
diff changeset
   477
begin
450805a4a91f added instance for bot, top
haftmann
parents: 29023
diff changeset
   478
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   479
definition bot_enat :: enat where
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   480
  "bot_enat = 0"
29337
450805a4a91f added instance for bot, top
haftmann
parents: 29023
diff changeset
   481
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   482
definition top_enat :: enat where
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   483
  "top_enat = \<infinity>"
29337
450805a4a91f added instance for bot, top
haftmann
parents: 29023
diff changeset
   484
450805a4a91f added instance for bot, top
haftmann
parents: 29023
diff changeset
   485
instance proof
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   486
qed (simp_all add: bot_enat_def top_enat_def)
29337
450805a4a91f added instance for bot, top
haftmann
parents: 29023
diff changeset
   487
450805a4a91f added instance for bot, top
haftmann
parents: 29023
diff changeset
   488
end
450805a4a91f added instance for bot, top
haftmann
parents: 29023
diff changeset
   489
43924
1165fe965da8 rename Fin to enat
hoelzl
parents: 43923
diff changeset
   490
lemma finite_enat_bounded:
1165fe965da8 rename Fin to enat
hoelzl
parents: 43923
diff changeset
   491
  assumes le_fin: "\<And>y. y \<in> A \<Longrightarrow> y \<le> enat n"
42993
da014b00d7a4 instance inat for complete_lattice
noschinl
parents: 41855
diff changeset
   492
  shows "finite A"
da014b00d7a4 instance inat for complete_lattice
noschinl
parents: 41855
diff changeset
   493
proof (rule finite_subset)
43924
1165fe965da8 rename Fin to enat
hoelzl
parents: 43923
diff changeset
   494
  show "finite (enat ` {..n})" by blast
42993
da014b00d7a4 instance inat for complete_lattice
noschinl
parents: 41855
diff changeset
   495
44890
22f665a2e91c new fastforce replacing fastsimp - less confusing name
nipkow
parents: 44019
diff changeset
   496
  have "A \<subseteq> {..enat n}" using le_fin by fastforce
43924
1165fe965da8 rename Fin to enat
hoelzl
parents: 43923
diff changeset
   497
  also have "\<dots> \<subseteq> enat ` {..n}"
42993
da014b00d7a4 instance inat for complete_lattice
noschinl
parents: 41855
diff changeset
   498
    by (rule subsetI) (case_tac x, auto)
43924
1165fe965da8 rename Fin to enat
hoelzl
parents: 43923
diff changeset
   499
  finally show "A \<subseteq> enat ` {..n}" .
42993
da014b00d7a4 instance inat for complete_lattice
noschinl
parents: 41855
diff changeset
   500
qed
da014b00d7a4 instance inat for complete_lattice
noschinl
parents: 41855
diff changeset
   501
26089
373221497340 proved linorder and wellorder class instances
huffman
parents: 25691
diff changeset
   502
45775
6c340de26a0d add cancellation simprocs for type enat
huffman
parents: 45539
diff changeset
   503
subsection {* Cancellation simprocs *}
6c340de26a0d add cancellation simprocs for type enat
huffman
parents: 45539
diff changeset
   504
6c340de26a0d add cancellation simprocs for type enat
huffman
parents: 45539
diff changeset
   505
lemma enat_add_left_cancel: "a + b = a + c \<longleftrightarrow> a = (\<infinity>::enat) \<or> b = c"
6c340de26a0d add cancellation simprocs for type enat
huffman
parents: 45539
diff changeset
   506
  unfolding plus_enat_def by (simp split: enat.split)
6c340de26a0d add cancellation simprocs for type enat
huffman
parents: 45539
diff changeset
   507
6c340de26a0d add cancellation simprocs for type enat
huffman
parents: 45539
diff changeset
   508
lemma enat_add_left_cancel_le: "a + b \<le> a + c \<longleftrightarrow> a = (\<infinity>::enat) \<or> b \<le> c"
6c340de26a0d add cancellation simprocs for type enat
huffman
parents: 45539
diff changeset
   509
  unfolding plus_enat_def by (simp split: enat.split)
6c340de26a0d add cancellation simprocs for type enat
huffman
parents: 45539
diff changeset
   510
6c340de26a0d add cancellation simprocs for type enat
huffman
parents: 45539
diff changeset
   511
lemma enat_add_left_cancel_less: "a + b < a + c \<longleftrightarrow> a \<noteq> (\<infinity>::enat) \<and> b < c"
6c340de26a0d add cancellation simprocs for type enat
huffman
parents: 45539
diff changeset
   512
  unfolding plus_enat_def by (simp split: enat.split)
6c340de26a0d add cancellation simprocs for type enat
huffman
parents: 45539
diff changeset
   513
6c340de26a0d add cancellation simprocs for type enat
huffman
parents: 45539
diff changeset
   514
ML {*
6c340de26a0d add cancellation simprocs for type enat
huffman
parents: 45539
diff changeset
   515
structure Cancel_Enat_Common =
6c340de26a0d add cancellation simprocs for type enat
huffman
parents: 45539
diff changeset
   516
struct
6c340de26a0d add cancellation simprocs for type enat
huffman
parents: 45539
diff changeset
   517
  (* copied from src/HOL/Tools/nat_numeral_simprocs.ML *)
6c340de26a0d add cancellation simprocs for type enat
huffman
parents: 45539
diff changeset
   518
  fun find_first_t _    _ []         = raise TERM("find_first_t", [])
6c340de26a0d add cancellation simprocs for type enat
huffman
parents: 45539
diff changeset
   519
    | find_first_t past u (t::terms) =
6c340de26a0d add cancellation simprocs for type enat
huffman
parents: 45539
diff changeset
   520
          if u aconv t then (rev past @ terms)
6c340de26a0d add cancellation simprocs for type enat
huffman
parents: 45539
diff changeset
   521
          else find_first_t (t::past) u terms
6c340de26a0d add cancellation simprocs for type enat
huffman
parents: 45539
diff changeset
   522
6c340de26a0d add cancellation simprocs for type enat
huffman
parents: 45539
diff changeset
   523
  val mk_sum = Arith_Data.long_mk_sum
6c340de26a0d add cancellation simprocs for type enat
huffman
parents: 45539
diff changeset
   524
  val dest_sum = Arith_Data.dest_sum
6c340de26a0d add cancellation simprocs for type enat
huffman
parents: 45539
diff changeset
   525
  val find_first = find_first_t []
6c340de26a0d add cancellation simprocs for type enat
huffman
parents: 45539
diff changeset
   526
  val trans_tac = Numeral_Simprocs.trans_tac
6c340de26a0d add cancellation simprocs for type enat
huffman
parents: 45539
diff changeset
   527
  val norm_ss = HOL_basic_ss addsimps
6c340de26a0d add cancellation simprocs for type enat
huffman
parents: 45539
diff changeset
   528
    @{thms add_ac semiring_numeral_0_eq_0 add_0_left add_0_right}
6c340de26a0d add cancellation simprocs for type enat
huffman
parents: 45539
diff changeset
   529
  fun norm_tac ss = ALLGOALS (simp_tac (Simplifier.inherit_context ss norm_ss))
6c340de26a0d add cancellation simprocs for type enat
huffman
parents: 45539
diff changeset
   530
  fun simplify_meta_eq ss cancel_th th =
6c340de26a0d add cancellation simprocs for type enat
huffman
parents: 45539
diff changeset
   531
    Arith_Data.simplify_meta_eq @{thms semiring_numeral_0_eq_0} ss
6c340de26a0d add cancellation simprocs for type enat
huffman
parents: 45539
diff changeset
   532
      ([th, cancel_th] MRS trans)
6c340de26a0d add cancellation simprocs for type enat
huffman
parents: 45539
diff changeset
   533
  fun mk_eq (a, b) = HOLogic.mk_Trueprop (HOLogic.mk_eq (a, b))
6c340de26a0d add cancellation simprocs for type enat
huffman
parents: 45539
diff changeset
   534
end
6c340de26a0d add cancellation simprocs for type enat
huffman
parents: 45539
diff changeset
   535
6c340de26a0d add cancellation simprocs for type enat
huffman
parents: 45539
diff changeset
   536
structure Eq_Enat_Cancel = ExtractCommonTermFun
6c340de26a0d add cancellation simprocs for type enat
huffman
parents: 45539
diff changeset
   537
(open Cancel_Enat_Common
6c340de26a0d add cancellation simprocs for type enat
huffman
parents: 45539
diff changeset
   538
  val mk_bal = HOLogic.mk_eq
6c340de26a0d add cancellation simprocs for type enat
huffman
parents: 45539
diff changeset
   539
  val dest_bal = HOLogic.dest_bin @{const_name HOL.eq} @{typ enat}
6c340de26a0d add cancellation simprocs for type enat
huffman
parents: 45539
diff changeset
   540
  fun simp_conv _ _ = SOME @{thm enat_add_left_cancel}
6c340de26a0d add cancellation simprocs for type enat
huffman
parents: 45539
diff changeset
   541
)
6c340de26a0d add cancellation simprocs for type enat
huffman
parents: 45539
diff changeset
   542
6c340de26a0d add cancellation simprocs for type enat
huffman
parents: 45539
diff changeset
   543
structure Le_Enat_Cancel = ExtractCommonTermFun
6c340de26a0d add cancellation simprocs for type enat
huffman
parents: 45539
diff changeset
   544
(open Cancel_Enat_Common
6c340de26a0d add cancellation simprocs for type enat
huffman
parents: 45539
diff changeset
   545
  val mk_bal = HOLogic.mk_binrel @{const_name Orderings.less_eq}
6c340de26a0d add cancellation simprocs for type enat
huffman
parents: 45539
diff changeset
   546
  val dest_bal = HOLogic.dest_bin @{const_name Orderings.less_eq} @{typ enat}
6c340de26a0d add cancellation simprocs for type enat
huffman
parents: 45539
diff changeset
   547
  fun simp_conv _ _ = SOME @{thm enat_add_left_cancel_le}
6c340de26a0d add cancellation simprocs for type enat
huffman
parents: 45539
diff changeset
   548
)
6c340de26a0d add cancellation simprocs for type enat
huffman
parents: 45539
diff changeset
   549
6c340de26a0d add cancellation simprocs for type enat
huffman
parents: 45539
diff changeset
   550
structure Less_Enat_Cancel = ExtractCommonTermFun
6c340de26a0d add cancellation simprocs for type enat
huffman
parents: 45539
diff changeset
   551
(open Cancel_Enat_Common
6c340de26a0d add cancellation simprocs for type enat
huffman
parents: 45539
diff changeset
   552
  val mk_bal = HOLogic.mk_binrel @{const_name Orderings.less}
6c340de26a0d add cancellation simprocs for type enat
huffman
parents: 45539
diff changeset
   553
  val dest_bal = HOLogic.dest_bin @{const_name Orderings.less} @{typ enat}
6c340de26a0d add cancellation simprocs for type enat
huffman
parents: 45539
diff changeset
   554
  fun simp_conv _ _ = SOME @{thm enat_add_left_cancel_less}
6c340de26a0d add cancellation simprocs for type enat
huffman
parents: 45539
diff changeset
   555
)
6c340de26a0d add cancellation simprocs for type enat
huffman
parents: 45539
diff changeset
   556
*}
6c340de26a0d add cancellation simprocs for type enat
huffman
parents: 45539
diff changeset
   557
6c340de26a0d add cancellation simprocs for type enat
huffman
parents: 45539
diff changeset
   558
simproc_setup enat_eq_cancel
6c340de26a0d add cancellation simprocs for type enat
huffman
parents: 45539
diff changeset
   559
  ("(l::enat) + m = n" | "(l::enat) = m + n") =
6c340de26a0d add cancellation simprocs for type enat
huffman
parents: 45539
diff changeset
   560
  {* fn phi => fn ss => fn ct => Eq_Enat_Cancel.proc ss (term_of ct) *}
6c340de26a0d add cancellation simprocs for type enat
huffman
parents: 45539
diff changeset
   561
6c340de26a0d add cancellation simprocs for type enat
huffman
parents: 45539
diff changeset
   562
simproc_setup enat_le_cancel
6c340de26a0d add cancellation simprocs for type enat
huffman
parents: 45539
diff changeset
   563
  ("(l::enat) + m \<le> n" | "(l::enat) \<le> m + n") =
6c340de26a0d add cancellation simprocs for type enat
huffman
parents: 45539
diff changeset
   564
  {* fn phi => fn ss => fn ct => Le_Enat_Cancel.proc ss (term_of ct) *}
6c340de26a0d add cancellation simprocs for type enat
huffman
parents: 45539
diff changeset
   565
6c340de26a0d add cancellation simprocs for type enat
huffman
parents: 45539
diff changeset
   566
simproc_setup enat_less_cancel
6c340de26a0d add cancellation simprocs for type enat
huffman
parents: 45539
diff changeset
   567
  ("(l::enat) + m < n" | "(l::enat) < m + n") =
6c340de26a0d add cancellation simprocs for type enat
huffman
parents: 45539
diff changeset
   568
  {* fn phi => fn ss => fn ct => Less_Enat_Cancel.proc ss (term_of ct) *}
6c340de26a0d add cancellation simprocs for type enat
huffman
parents: 45539
diff changeset
   569
6c340de26a0d add cancellation simprocs for type enat
huffman
parents: 45539
diff changeset
   570
text {* TODO: add regression tests for these simprocs *}
6c340de26a0d add cancellation simprocs for type enat
huffman
parents: 45539
diff changeset
   571
6c340de26a0d add cancellation simprocs for type enat
huffman
parents: 45539
diff changeset
   572
text {* TODO: add simprocs for combining and cancelling numerals *}
6c340de26a0d add cancellation simprocs for type enat
huffman
parents: 45539
diff changeset
   573
6c340de26a0d add cancellation simprocs for type enat
huffman
parents: 45539
diff changeset
   574
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   575
subsection {* Well-ordering *}
26089
373221497340 proved linorder and wellorder class instances
huffman
parents: 25691
diff changeset
   576
43924
1165fe965da8 rename Fin to enat
hoelzl
parents: 43923
diff changeset
   577
lemma less_enatE:
1165fe965da8 rename Fin to enat
hoelzl
parents: 43923
diff changeset
   578
  "[| n < enat m; !!k. n = enat k ==> k < m ==> P |] ==> P"
26089
373221497340 proved linorder and wellorder class instances
huffman
parents: 25691
diff changeset
   579
by (induct n) auto
373221497340 proved linorder and wellorder class instances
huffman
parents: 25691
diff changeset
   580
44019
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   581
lemma less_infinityE:
43924
1165fe965da8 rename Fin to enat
hoelzl
parents: 43923
diff changeset
   582
  "[| n < \<infinity>; !!k. n = enat k ==> P |] ==> P"
26089
373221497340 proved linorder and wellorder class instances
huffman
parents: 25691
diff changeset
   583
by (induct n) auto
373221497340 proved linorder and wellorder class instances
huffman
parents: 25691
diff changeset
   584
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   585
lemma enat_less_induct:
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   586
  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
   587
proof -
43924
1165fe965da8 rename Fin to enat
hoelzl
parents: 43923
diff changeset
   588
  have P_enat: "!!k. P (enat k)"
26089
373221497340 proved linorder and wellorder class instances
huffman
parents: 25691
diff changeset
   589
    apply (rule nat_less_induct)
373221497340 proved linorder and wellorder class instances
huffman
parents: 25691
diff changeset
   590
    apply (rule prem, clarify)
43924
1165fe965da8 rename Fin to enat
hoelzl
parents: 43923
diff changeset
   591
    apply (erule less_enatE, simp)
26089
373221497340 proved linorder and wellorder class instances
huffman
parents: 25691
diff changeset
   592
    done
373221497340 proved linorder and wellorder class instances
huffman
parents: 25691
diff changeset
   593
  show ?thesis
373221497340 proved linorder and wellorder class instances
huffman
parents: 25691
diff changeset
   594
  proof (induct n)
373221497340 proved linorder and wellorder class instances
huffman
parents: 25691
diff changeset
   595
    fix nat
43924
1165fe965da8 rename Fin to enat
hoelzl
parents: 43923
diff changeset
   596
    show "P (enat nat)" by (rule P_enat)
26089
373221497340 proved linorder and wellorder class instances
huffman
parents: 25691
diff changeset
   597
  next
43921
e8511be08ddd Introduce infinity type class
hoelzl
parents: 43919
diff changeset
   598
    show "P \<infinity>"
26089
373221497340 proved linorder and wellorder class instances
huffman
parents: 25691
diff changeset
   599
      apply (rule prem, clarify)
44019
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   600
      apply (erule less_infinityE)
43924
1165fe965da8 rename Fin to enat
hoelzl
parents: 43923
diff changeset
   601
      apply (simp add: P_enat)
26089
373221497340 proved linorder and wellorder class instances
huffman
parents: 25691
diff changeset
   602
      done
373221497340 proved linorder and wellorder class instances
huffman
parents: 25691
diff changeset
   603
  qed
373221497340 proved linorder and wellorder class instances
huffman
parents: 25691
diff changeset
   604
qed
373221497340 proved linorder and wellorder class instances
huffman
parents: 25691
diff changeset
   605
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   606
instance enat :: wellorder
26089
373221497340 proved linorder and wellorder class instances
huffman
parents: 25691
diff changeset
   607
proof
27823
52971512d1a2 moved class wellorder to theory Orderings
haftmann
parents: 27487
diff changeset
   608
  fix P and n
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   609
  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
   610
  show "P n" by (blast intro: enat_less_induct hyp)
26089
373221497340 proved linorder and wellorder class instances
huffman
parents: 25691
diff changeset
   611
qed
373221497340 proved linorder and wellorder class instances
huffman
parents: 25691
diff changeset
   612
42993
da014b00d7a4 instance inat for complete_lattice
noschinl
parents: 41855
diff changeset
   613
subsection {* Complete Lattice *}
da014b00d7a4 instance inat for complete_lattice
noschinl
parents: 41855
diff changeset
   614
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   615
instantiation enat :: complete_lattice
42993
da014b00d7a4 instance inat for complete_lattice
noschinl
parents: 41855
diff changeset
   616
begin
da014b00d7a4 instance inat for complete_lattice
noschinl
parents: 41855
diff changeset
   617
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   618
definition inf_enat :: "enat \<Rightarrow> enat \<Rightarrow> enat" where
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   619
  "inf_enat \<equiv> min"
42993
da014b00d7a4 instance inat for complete_lattice
noschinl
parents: 41855
diff changeset
   620
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   621
definition sup_enat :: "enat \<Rightarrow> enat \<Rightarrow> enat" where
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   622
  "sup_enat \<equiv> max"
42993
da014b00d7a4 instance inat for complete_lattice
noschinl
parents: 41855
diff changeset
   623
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   624
definition Inf_enat :: "enat set \<Rightarrow> enat" where
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   625
  "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
   626
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   627
definition Sup_enat :: "enat set \<Rightarrow> enat" where
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   628
  "Sup_enat A \<equiv> if A = {} then 0
42993
da014b00d7a4 instance inat for complete_lattice
noschinl
parents: 41855
diff changeset
   629
    else if finite A then Max A
da014b00d7a4 instance inat for complete_lattice
noschinl
parents: 41855
diff changeset
   630
                     else \<infinity>"
da014b00d7a4 instance inat for complete_lattice
noschinl
parents: 41855
diff changeset
   631
instance proof
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   632
  fix x :: "enat" and A :: "enat set"
42993
da014b00d7a4 instance inat for complete_lattice
noschinl
parents: 41855
diff changeset
   633
  { 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
   634
      unfolding Inf_enat_def by (auto intro: Least_le) }
42993
da014b00d7a4 instance inat for complete_lattice
noschinl
parents: 41855
diff changeset
   635
  { 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
   636
      unfolding Inf_enat_def
42993
da014b00d7a4 instance inat for complete_lattice
noschinl
parents: 41855
diff changeset
   637
      by (cases "A = {}") (auto intro: LeastI2_ex) }
da014b00d7a4 instance inat for complete_lattice
noschinl
parents: 41855
diff changeset
   638
  { 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
   639
      unfolding Sup_enat_def by (cases "finite A") auto }
42993
da014b00d7a4 instance inat for complete_lattice
noschinl
parents: 41855
diff changeset
   640
  { assume "\<And>y. y \<in> A \<Longrightarrow> y \<le> x" then show "Sup A \<le> x"
43924
1165fe965da8 rename Fin to enat
hoelzl
parents: 43923
diff changeset
   641
      unfolding Sup_enat_def using finite_enat_bounded by auto }
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   642
qed (simp_all add: inf_enat_def sup_enat_def)
42993
da014b00d7a4 instance inat for complete_lattice
noschinl
parents: 41855
diff changeset
   643
end
da014b00d7a4 instance inat for complete_lattice
noschinl
parents: 41855
diff changeset
   644
43978
da7d04d4023c enat is a complete_linorder instance
hoelzl
parents: 43924
diff changeset
   645
instance enat :: complete_linorder ..
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   646
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   647
subsection {* Traditional theorem names *}
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   648
44019
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   649
lemmas enat_defs = zero_enat_def one_enat_def number_of_enat_def eSuc_def
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   650
  plus_enat_def less_eq_enat_def less_enat_def
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   651
11351
c5c403d30c77 added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff changeset
   652
end