src/HOL/Library/Extended_Nat.thy
author wenzelm
Fri, 21 Mar 2025 22:26:18 +0100
changeset 82317 231b6d8231c6
parent 81816 bee084ecd18c
permissions -rw-r--r--
more uniform Proof_Display.print_results for theory and proof output --- avoid loss of information seen in src/Doc/JEdit/document/output-and-state.png (the first bad changeset is f8c412a45af8, see also 53b59fa42696);
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
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 59582
diff changeset
     6
section \<open>Extended natural numbers (i.e. with infinity)\<close>
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
60636
ee18efe9b246 add named theorems order_continuous_intros; lfp/gfp_funpow; bounded variant for lfp/gfp transfer
hoelzl
parents: 60500
diff changeset
     9
imports Main Countable Order_Continuity
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 =
80914
d97fdabd9e2b standardize mixfix annotations via "isabelle update -a -u mixfix_cartouches" --- to simplify systematic editing;
wenzelm
parents: 78099
diff changeset
    13
  fixes infinity :: "'a"  (\<open>\<infinity>\<close>)
43921
e8511be08ddd Introduce infinity type class
hoelzl
parents: 43919
diff changeset
    14
62378
85ed00c1fe7c generalize more theorems to support enat and ennreal
hoelzl
parents: 62376
diff changeset
    15
context
85ed00c1fe7c generalize more theorems to support enat and ennreal
hoelzl
parents: 62376
diff changeset
    16
  fixes f :: "nat \<Rightarrow> 'a::{canonically_ordered_monoid_add, linorder_topology, complete_linorder}"
85ed00c1fe7c generalize more theorems to support enat and ennreal
hoelzl
parents: 62376
diff changeset
    17
begin
85ed00c1fe7c generalize more theorems to support enat and ennreal
hoelzl
parents: 62376
diff changeset
    18
85ed00c1fe7c generalize more theorems to support enat and ennreal
hoelzl
parents: 62376
diff changeset
    19
lemma sums_SUP[simp, intro]: "f sums (SUP n. \<Sum>i<n. f i)"
64267
b9a1486e79be setsum -> sum
nipkow
parents: 62378
diff changeset
    20
  unfolding sums_def by (intro LIMSEQ_SUP monoI sum_mono2 zero_le) auto
62378
85ed00c1fe7c generalize more theorems to support enat and ennreal
hoelzl
parents: 62376
diff changeset
    21
85ed00c1fe7c generalize more theorems to support enat and ennreal
hoelzl
parents: 62376
diff changeset
    22
lemma suminf_eq_SUP: "suminf f = (SUP n. \<Sum>i<n. f i)"
85ed00c1fe7c generalize more theorems to support enat and ennreal
hoelzl
parents: 62376
diff changeset
    23
  using sums_SUP by (rule sums_unique[symmetric])
85ed00c1fe7c generalize more theorems to support enat and ennreal
hoelzl
parents: 62376
diff changeset
    24
85ed00c1fe7c generalize more theorems to support enat and ennreal
hoelzl
parents: 62376
diff changeset
    25
end
85ed00c1fe7c generalize more theorems to support enat and ennreal
hoelzl
parents: 62376
diff changeset
    26
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 59582
diff changeset
    27
subsection \<open>Type definition\<close>
11351
c5c403d30c77 added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff changeset
    28
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 59582
diff changeset
    29
text \<open>
11355
wenzelm
parents: 11351
diff changeset
    30
  We extend the standard natural numbers by a special value indicating
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
    31
  infinity.
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 59582
diff changeset
    32
\<close>
11351
c5c403d30c77 added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff changeset
    33
49834
b27bbb021df1 discontinued obsolete typedef (open) syntax;
wenzelm
parents: 47108
diff changeset
    34
typedef enat = "UNIV :: nat option set" ..
54415
eaf25431d4c4 enat is countable
hoelzl
parents: 52729
diff changeset
    35
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 68406
diff changeset
    36
text \<open>TODO: introduce enat as coinductive datatype, enat is just \<^const>\<open>of_nat\<close>\<close>
54415
eaf25431d4c4 enat is countable
hoelzl
parents: 52729
diff changeset
    37
43924
1165fe965da8 rename Fin to enat
hoelzl
parents: 43923
diff changeset
    38
definition enat :: "nat \<Rightarrow> enat" where
1165fe965da8 rename Fin to enat
hoelzl
parents: 43923
diff changeset
    39
  "enat n = Abs_enat (Some n)"
62374
cb27a55d868a remove lattice syntax from countable complete lattice
hoelzl
parents: 61631
diff changeset
    40
43921
e8511be08ddd Introduce infinity type class
hoelzl
parents: 43919
diff changeset
    41
instantiation enat :: infinity
e8511be08ddd Introduce infinity type class
hoelzl
parents: 43919
diff changeset
    42
begin
60679
ade12ef2773c tuned proofs;
wenzelm
parents: 60636
diff changeset
    43
ade12ef2773c tuned proofs;
wenzelm
parents: 60636
diff changeset
    44
definition "\<infinity> = Abs_enat None"
ade12ef2773c tuned proofs;
wenzelm
parents: 60636
diff changeset
    45
instance ..
ade12ef2773c tuned proofs;
wenzelm
parents: 60636
diff changeset
    46
43921
e8511be08ddd Introduce infinity type class
hoelzl
parents: 43919
diff changeset
    47
end
54415
eaf25431d4c4 enat is countable
hoelzl
parents: 52729
diff changeset
    48
eaf25431d4c4 enat is countable
hoelzl
parents: 52729
diff changeset
    49
instance enat :: countable
eaf25431d4c4 enat is countable
hoelzl
parents: 52729
diff changeset
    50
proof
eaf25431d4c4 enat is countable
hoelzl
parents: 52729
diff changeset
    51
  show "\<exists>to_nat::enat \<Rightarrow> nat. inj to_nat"
eaf25431d4c4 enat is countable
hoelzl
parents: 52729
diff changeset
    52
    by (rule exI[of _ "to_nat \<circ> Rep_enat"]) (simp add: inj_on_def Rep_enat_inject)
eaf25431d4c4 enat is countable
hoelzl
parents: 52729
diff changeset
    53
qed
62374
cb27a55d868a remove lattice syntax from countable complete lattice
hoelzl
parents: 61631
diff changeset
    54
58306
117ba6cbe414 renamed 'rep_datatype' to 'old_rep_datatype' (HOL)
blanchet
parents: 57514
diff changeset
    55
old_rep_datatype enat "\<infinity> :: enat"
43921
e8511be08ddd Introduce infinity type class
hoelzl
parents: 43919
diff changeset
    56
proof -
43924
1165fe965da8 rename Fin to enat
hoelzl
parents: 43923
diff changeset
    57
  fix P i assume "\<And>j. P (enat j)" "P \<infinity>"
43921
e8511be08ddd Introduce infinity type class
hoelzl
parents: 43919
diff changeset
    58
  then show "P i"
e8511be08ddd Introduce infinity type class
hoelzl
parents: 43919
diff changeset
    59
  proof induct
e8511be08ddd Introduce infinity type class
hoelzl
parents: 43919
diff changeset
    60
    case (Abs_enat y) then show ?case
e8511be08ddd Introduce infinity type class
hoelzl
parents: 43919
diff changeset
    61
      by (cases y rule: option.exhaust)
43924
1165fe965da8 rename Fin to enat
hoelzl
parents: 43923
diff changeset
    62
         (auto simp: enat_def infinity_enat_def)
43921
e8511be08ddd Introduce infinity type class
hoelzl
parents: 43919
diff changeset
    63
  qed
43924
1165fe965da8 rename Fin to enat
hoelzl
parents: 43923
diff changeset
    64
qed (auto simp add: enat_def infinity_enat_def Abs_enat_inject)
19736
wenzelm
parents: 15140
diff changeset
    65
43924
1165fe965da8 rename Fin to enat
hoelzl
parents: 43923
diff changeset
    66
declare [[coercion "enat::nat\<Rightarrow>enat"]]
19736
wenzelm
parents: 15140
diff changeset
    67
45934
9321cd2572fe add simp rules for enat and ereal
noschinl
parents: 45775
diff changeset
    68
lemmas enat2_cases = enat.exhaust[case_product enat.exhaust]
9321cd2572fe add simp rules for enat and ereal
noschinl
parents: 45775
diff changeset
    69
lemmas enat3_cases = enat.exhaust[case_product enat.exhaust enat.exhaust]
9321cd2572fe add simp rules for enat and ereal
noschinl
parents: 45775
diff changeset
    70
54416
7fb88ed6ff3c better support for enat and ereal conversions
hoelzl
parents: 54415
diff changeset
    71
lemma not_infinity_eq [iff]: "(x \<noteq> \<infinity>) = (\<exists>i. x = enat i)"
44019
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
    72
  by (cases x) auto
31084
f4db921165ce fixed HOLCF proofs
nipkow
parents: 31077
diff changeset
    73
54416
7fb88ed6ff3c better support for enat and ereal conversions
hoelzl
parents: 54415
diff changeset
    74
lemma not_enat_eq [iff]: "(\<forall>y. x \<noteq> enat y) = (x = \<infinity>)"
44019
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
    75
  by (cases x) auto
31077
28dd6fd3d184 more lemmas
nipkow
parents: 30663
diff changeset
    76
62376
85f38d5f8807 Rename ordered_comm_monoid_add to ordered_cancel_comm_monoid_add. Introduce ordreed_comm_monoid_add, canonically_ordered_comm_monoid and dioid. Setup nat, entat and ennreal as dioids.
hoelzl
parents: 62374
diff changeset
    77
lemma enat_ex_split: "(\<exists>c::enat. P c) \<longleftrightarrow> P \<infinity> \<or> (\<exists>c::nat. P c)"
85f38d5f8807 Rename ordered_comm_monoid_add to ordered_cancel_comm_monoid_add. Introduce ordreed_comm_monoid_add, canonically_ordered_comm_monoid and dioid. Setup nat, entat and ennreal as dioids.
hoelzl
parents: 62374
diff changeset
    78
  by (metis enat.exhaust)
85f38d5f8807 Rename ordered_comm_monoid_add to ordered_cancel_comm_monoid_add. Introduce ordreed_comm_monoid_add, canonically_ordered_comm_monoid and dioid. Setup nat, entat and ennreal as dioids.
hoelzl
parents: 62374
diff changeset
    79
43924
1165fe965da8 rename Fin to enat
hoelzl
parents: 43923
diff changeset
    80
primrec the_enat :: "enat \<Rightarrow> nat"
44019
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
    81
  where "the_enat (enat n) = n"
41855
c3b6e69da386 added a few lemmas by Andreas Lochbihler
nipkow
parents: 41853
diff changeset
    82
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 45934
diff changeset
    83
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 59582
diff changeset
    84
subsection \<open>Constructors and numbers\<close>
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
    85
62378
85ed00c1fe7c generalize more theorems to support enat and ennreal
hoelzl
parents: 62376
diff changeset
    86
instantiation enat :: zero_neq_one
25594
43c718438f9f switched import from Main to PreList
haftmann
parents: 25134
diff changeset
    87
begin
43c718438f9f switched import from Main to PreList
haftmann
parents: 25134
diff changeset
    88
43c718438f9f switched import from Main to PreList
haftmann
parents: 25134
diff changeset
    89
definition
43924
1165fe965da8 rename Fin to enat
hoelzl
parents: 43923
diff changeset
    90
  "0 = enat 0"
25594
43c718438f9f switched import from Main to PreList
haftmann
parents: 25134
diff changeset
    91
43c718438f9f switched import from Main to PreList
haftmann
parents: 25134
diff changeset
    92
definition
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 45934
diff changeset
    93
  "1 = enat 1"
11351
c5c403d30c77 added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff changeset
    94
62378
85ed00c1fe7c generalize more theorems to support enat and ennreal
hoelzl
parents: 62376
diff changeset
    95
instance
85ed00c1fe7c generalize more theorems to support enat and ennreal
hoelzl
parents: 62376
diff changeset
    96
  proof qed (simp add: zero_enat_def one_enat_def)
25594
43c718438f9f switched import from Main to PreList
haftmann
parents: 25134
diff changeset
    97
43c718438f9f switched import from Main to PreList
haftmann
parents: 25134
diff changeset
    98
end
43c718438f9f switched import from Main to PreList
haftmann
parents: 25134
diff changeset
    99
44019
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   100
definition eSuc :: "enat \<Rightarrow> enat" where
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   101
  "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
   102
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 45934
diff changeset
   103
lemma enat_0 [code_post]: "enat 0 = 0"
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   104
  by (simp add: zero_enat_def)
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   105
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 45934
diff changeset
   106
lemma enat_1 [code_post]: "enat 1 = 1"
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   107
  by (simp add: one_enat_def)
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   108
54416
7fb88ed6ff3c better support for enat and ereal conversions
hoelzl
parents: 54415
diff changeset
   109
lemma enat_0_iff: "enat x = 0 \<longleftrightarrow> x = 0" "0 = enat x \<longleftrightarrow> x = 0"
7fb88ed6ff3c better support for enat and ereal conversions
hoelzl
parents: 54415
diff changeset
   110
  by (auto simp add: zero_enat_def)
7fb88ed6ff3c better support for enat and ereal conversions
hoelzl
parents: 54415
diff changeset
   111
7fb88ed6ff3c better support for enat and ereal conversions
hoelzl
parents: 54415
diff changeset
   112
lemma enat_1_iff: "enat x = 1 \<longleftrightarrow> x = 1" "1 = enat x \<longleftrightarrow> x = 1"
7fb88ed6ff3c better support for enat and ereal conversions
hoelzl
parents: 54415
diff changeset
   113
  by (auto simp add: one_enat_def)
7fb88ed6ff3c better support for enat and ereal conversions
hoelzl
parents: 54415
diff changeset
   114
44019
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   115
lemma one_eSuc: "1 = eSuc 0"
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   116
  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
   117
44019
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   118
lemma infinity_ne_i0 [simp]: "(\<infinity>::enat) \<noteq> 0"
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   119
  by (simp add: zero_enat_def)
11351
c5c403d30c77 added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff changeset
   120
44019
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   121
lemma i0_ne_infinity [simp]: "0 \<noteq> (\<infinity>::enat)"
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   122
  by (simp add: zero_enat_def)
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   123
62378
85ed00c1fe7c generalize more theorems to support enat and ennreal
hoelzl
parents: 62376
diff changeset
   124
lemma zero_one_enat_neq:
61076
bdc1e2f0a86a eliminated \<Colon>;
wenzelm
parents: 60679
diff changeset
   125
  "\<not> 0 = (1::enat)"
bdc1e2f0a86a eliminated \<Colon>;
wenzelm
parents: 60679
diff changeset
   126
  "\<not> 1 = (0::enat)"
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   127
  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
   128
44019
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   129
lemma infinity_ne_i1 [simp]: "(\<infinity>::enat) \<noteq> 1"
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   130
  by (simp add: one_enat_def)
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   131
44019
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   132
lemma i1_ne_infinity [simp]: "1 \<noteq> (\<infinity>::enat)"
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   133
  by (simp add: one_enat_def)
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   134
44019
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   135
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
   136
  by (simp add: eSuc_def)
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   137
44019
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   138
lemma eSuc_infinity [simp]: "eSuc \<infinity> = \<infinity>"
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   139
  by (simp add: eSuc_def)
11351
c5c403d30c77 added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff changeset
   140
44019
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   141
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
   142
  by (simp add: eSuc_def zero_enat_def split: enat.splits)
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   143
44019
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   144
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
   145
  by (rule eSuc_ne_0 [symmetric])
11351
c5c403d30c77 added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff changeset
   146
44019
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   147
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
   148
  by (simp add: eSuc_def split: enat.splits)
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   149
59000
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58881
diff changeset
   150
lemma eSuc_enat_iff: "eSuc x = enat y \<longleftrightarrow> (\<exists>n. y = Suc n \<and> x = enat n)"
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58881
diff changeset
   151
  by (cases y) (auto simp: enat_0 eSuc_enat[symmetric])
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58881
diff changeset
   152
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58881
diff changeset
   153
lemma enat_eSuc_iff: "enat y = eSuc x \<longleftrightarrow> (\<exists>n. y = Suc n \<and> enat n = x)"
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58881
diff changeset
   154
  by (cases y) (auto simp: enat_0 eSuc_enat[symmetric])
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58881
diff changeset
   155
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 59582
diff changeset
   156
subsection \<open>Addition\<close>
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   157
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   158
instantiation enat :: comm_monoid_add
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   159
begin
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   160
38167
ab528533db92 help Nitpick
blanchet
parents: 37765
diff changeset
   161
definition [nitpick_simp]:
43924
1165fe965da8 rename Fin to enat
hoelzl
parents: 43923
diff changeset
   162
  "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
   163
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   164
lemma plus_enat_simps [simp, code]:
43921
e8511be08ddd Introduce infinity type class
hoelzl
parents: 43919
diff changeset
   165
  fixes q :: enat
43924
1165fe965da8 rename Fin to enat
hoelzl
parents: 43923
diff changeset
   166
  shows "enat m + enat n = enat (m + n)"
43921
e8511be08ddd Introduce infinity type class
hoelzl
parents: 43919
diff changeset
   167
    and "\<infinity> + q = \<infinity>"
e8511be08ddd Introduce infinity type class
hoelzl
parents: 43919
diff changeset
   168
    and "q + \<infinity> = \<infinity>"
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   169
  by (simp_all add: plus_enat_def split: enat.splits)
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   170
60679
ade12ef2773c tuned proofs;
wenzelm
parents: 60636
diff changeset
   171
instance
ade12ef2773c tuned proofs;
wenzelm
parents: 60636
diff changeset
   172
proof
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   173
  fix n m q :: enat
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   174
  show "n + m + q = n + (m + q)"
45934
9321cd2572fe add simp rules for enat and ereal
noschinl
parents: 45775
diff changeset
   175
    by (cases n m q rule: enat3_cases) auto
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   176
  show "n + m = m + n"
45934
9321cd2572fe add simp rules for enat and ereal
noschinl
parents: 45775
diff changeset
   177
    by (cases n m rule: enat2_cases) auto
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   178
  show "0 + n = n"
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   179
    by (cases n) (simp_all add: zero_enat_def)
26089
373221497340 proved linorder and wellorder class instances
huffman
parents: 25691
diff changeset
   180
qed
373221497340 proved linorder and wellorder class instances
huffman
parents: 25691
diff changeset
   181
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   182
end
11351
c5c403d30c77 added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff changeset
   183
44019
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   184
lemma eSuc_plus_1:
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   185
  "eSuc n = n + 1"
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   186
  by (cases n) (simp_all add: eSuc_enat one_enat_def)
62374
cb27a55d868a remove lattice syntax from countable complete lattice
hoelzl
parents: 61631
diff changeset
   187
44019
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   188
lemma plus_1_eSuc:
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   189
  "1 + q = eSuc q"
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   190
  "q + 1 = eSuc q"
57514
bdc2c6b40bf2 prefer ac_simps collections over separate name bindings for add and mult
haftmann
parents: 57512
diff changeset
   191
  by (simp_all add: eSuc_plus_1 ac_simps)
41853
258a489c24b2 Added material by David Trachtenherz
nipkow
parents: 38621
diff changeset
   192
44019
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   193
lemma iadd_Suc: "eSuc m + n = eSuc (m + n)"
81816
bee084ecd18c More tidying of old proofs
paulson <lp15@cam.ac.uk>
parents: 81332
diff changeset
   194
  by (simp add: eSuc_plus_1 ac_simps)
11351
c5c403d30c77 added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff changeset
   195
44019
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   196
lemma iadd_Suc_right: "m + eSuc n = eSuc (m + n)"
81816
bee084ecd18c More tidying of old proofs
paulson <lp15@cam.ac.uk>
parents: 81332
diff changeset
   197
  by (metis add.commute iadd_Suc)
41853
258a489c24b2 Added material by David Trachtenherz
nipkow
parents: 38621
diff changeset
   198
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 59582
diff changeset
   199
subsection \<open>Multiplication\<close>
29014
e515f42d1db7 multiplication for type inat
huffman
parents: 29012
diff changeset
   200
62378
85ed00c1fe7c generalize more theorems to support enat and ennreal
hoelzl
parents: 62376
diff changeset
   201
instantiation enat :: "{comm_semiring_1, semiring_no_zero_divisors}"
29014
e515f42d1db7 multiplication for type inat
huffman
parents: 29012
diff changeset
   202
begin
e515f42d1db7 multiplication for type inat
huffman
parents: 29012
diff changeset
   203
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   204
definition times_enat_def [nitpick_simp]:
43924
1165fe965da8 rename Fin to enat
hoelzl
parents: 43923
diff changeset
   205
  "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
   206
    (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
   207
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   208
lemma times_enat_simps [simp, code]:
43924
1165fe965da8 rename Fin to enat
hoelzl
parents: 43923
diff changeset
   209
  "enat m * enat n = enat (m * n)"
43921
e8511be08ddd Introduce infinity type class
hoelzl
parents: 43919
diff changeset
   210
  "\<infinity> * \<infinity> = (\<infinity>::enat)"
43924
1165fe965da8 rename Fin to enat
hoelzl
parents: 43923
diff changeset
   211
  "\<infinity> * enat n = (if n = 0 then 0 else \<infinity>)"
1165fe965da8 rename Fin to enat
hoelzl
parents: 43923
diff changeset
   212
  "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
   213
  unfolding times_enat_def zero_enat_def
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   214
  by (simp_all split: enat.split)
29014
e515f42d1db7 multiplication for type inat
huffman
parents: 29012
diff changeset
   215
60679
ade12ef2773c tuned proofs;
wenzelm
parents: 60636
diff changeset
   216
instance
ade12ef2773c tuned proofs;
wenzelm
parents: 60636
diff changeset
   217
proof
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   218
  fix a b c :: enat
62378
85ed00c1fe7c generalize more theorems to support enat and ennreal
hoelzl
parents: 62376
diff changeset
   219
  show distr: "(a + b) * c = a * c + b * c"
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   220
    unfolding times_enat_def zero_enat_def
49962
a8cc904a6820 Renamed {left,right}_distrib to distrib_{right,left}.
webertj
parents: 49834
diff changeset
   221
    by (simp split: enat.split add: distrib_right)
62378
85ed00c1fe7c generalize more theorems to support enat and ennreal
hoelzl
parents: 62376
diff changeset
   222
  show "a * (b + c) = a * b + a * c"
85ed00c1fe7c generalize more theorems to support enat and ennreal
hoelzl
parents: 62376
diff changeset
   223
    by (cases a b c rule: enat3_cases) (auto simp: times_enat_def zero_enat_def distrib_left)
81816
bee084ecd18c More tidying of old proofs
paulson <lp15@cam.ac.uk>
parents: 81332
diff changeset
   224
qed (auto simp: times_enat_def zero_enat_def one_enat_def split: enat.split)
29014
e515f42d1db7 multiplication for type inat
huffman
parents: 29012
diff changeset
   225
e515f42d1db7 multiplication for type inat
huffman
parents: 29012
diff changeset
   226
end
e515f42d1db7 multiplication for type inat
huffman
parents: 29012
diff changeset
   227
44019
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   228
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
   229
  unfolding eSuc_plus_1 by (simp add: algebra_simps)
29014
e515f42d1db7 multiplication for type inat
huffman
parents: 29012
diff changeset
   230
44019
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   231
lemma mult_eSuc_right: "m * eSuc n = m + m * n"
81816
bee084ecd18c More tidying of old proofs
paulson <lp15@cam.ac.uk>
parents: 81332
diff changeset
   232
  by (metis mult.commute mult_eSuc)
29014
e515f42d1db7 multiplication for type inat
huffman
parents: 29012
diff changeset
   233
43924
1165fe965da8 rename Fin to enat
hoelzl
parents: 43923
diff changeset
   234
lemma of_nat_eq_enat: "of_nat n = enat n"
81816
bee084ecd18c More tidying of old proofs
paulson <lp15@cam.ac.uk>
parents: 81332
diff changeset
   235
  by (induct n) (auto simp: enat_0 plus_1_eSuc eSuc_enat)
29023
ef3adebc6d98 instance inat :: semiring_char_0
huffman
parents: 29014
diff changeset
   236
60679
ade12ef2773c tuned proofs;
wenzelm
parents: 60636
diff changeset
   237
instance enat :: semiring_char_0
ade12ef2773c tuned proofs;
wenzelm
parents: 60636
diff changeset
   238
proof
43924
1165fe965da8 rename Fin to enat
hoelzl
parents: 43923
diff changeset
   239
  have "inj enat" by (rule injI) simp
1165fe965da8 rename Fin to enat
hoelzl
parents: 43923
diff changeset
   240
  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
   241
qed
29023
ef3adebc6d98 instance inat :: semiring_char_0
huffman
parents: 29014
diff changeset
   242
44019
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   243
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
   244
  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
   245
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 59582
diff changeset
   246
subsection \<open>Numerals\<close>
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 45934
diff changeset
   247
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 45934
diff changeset
   248
lemma numeral_eq_enat:
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 45934
diff changeset
   249
  "numeral k = enat (numeral k)"
81816
bee084ecd18c More tidying of old proofs
paulson <lp15@cam.ac.uk>
parents: 81332
diff changeset
   250
  by (metis of_nat_eq_enat of_nat_numeral)
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 45934
diff changeset
   251
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 45934
diff changeset
   252
lemma enat_numeral [code_abbrev]:
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 45934
diff changeset
   253
  "enat (numeral k) = numeral k"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 45934
diff changeset
   254
  using numeral_eq_enat ..
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 45934
diff changeset
   255
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 45934
diff changeset
   256
lemma infinity_ne_numeral [simp]: "(\<infinity>::enat) \<noteq> numeral k"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 45934
diff changeset
   257
  by (simp add: numeral_eq_enat)
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 45934
diff changeset
   258
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 45934
diff changeset
   259
lemma numeral_ne_infinity [simp]: "numeral k \<noteq> (\<infinity>::enat)"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 45934
diff changeset
   260
  by (simp add: numeral_eq_enat)
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 45934
diff changeset
   261
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 45934
diff changeset
   262
lemma eSuc_numeral [simp]: "eSuc (numeral k) = numeral (k + Num.One)"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 45934
diff changeset
   263
  by (simp only: eSuc_plus_1 numeral_plus_one)
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 45934
diff changeset
   264
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 59582
diff changeset
   265
subsection \<open>Subtraction\<close>
41853
258a489c24b2 Added material by David Trachtenherz
nipkow
parents: 38621
diff changeset
   266
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   267
instantiation enat :: minus
41853
258a489c24b2 Added material by David Trachtenherz
nipkow
parents: 38621
diff changeset
   268
begin
258a489c24b2 Added material by David Trachtenherz
nipkow
parents: 38621
diff changeset
   269
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   270
definition diff_enat_def:
43924
1165fe965da8 rename Fin to enat
hoelzl
parents: 43923
diff changeset
   271
"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
   272
          | \<infinity> \<Rightarrow> \<infinity>)"
258a489c24b2 Added material by David Trachtenherz
nipkow
parents: 38621
diff changeset
   273
258a489c24b2 Added material by David Trachtenherz
nipkow
parents: 38621
diff changeset
   274
instance ..
258a489c24b2 Added material by David Trachtenherz
nipkow
parents: 38621
diff changeset
   275
258a489c24b2 Added material by David Trachtenherz
nipkow
parents: 38621
diff changeset
   276
end
258a489c24b2 Added material by David Trachtenherz
nipkow
parents: 38621
diff changeset
   277
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 45934
diff changeset
   278
lemma idiff_enat_enat [simp, code]: "enat a - enat b = enat (a - b)"
44019
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   279
  by (simp add: diff_enat_def)
41853
258a489c24b2 Added material by David Trachtenherz
nipkow
parents: 38621
diff changeset
   280
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 45934
diff changeset
   281
lemma idiff_infinity [simp, code]: "\<infinity> - n = (\<infinity>::enat)"
44019
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   282
  by (simp add: diff_enat_def)
41853
258a489c24b2 Added material by David Trachtenherz
nipkow
parents: 38621
diff changeset
   283
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 45934
diff changeset
   284
lemma idiff_infinity_right [simp, code]: "enat a - \<infinity> = 0"
44019
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   285
  by (simp add: diff_enat_def)
41853
258a489c24b2 Added material by David Trachtenherz
nipkow
parents: 38621
diff changeset
   286
44019
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   287
lemma idiff_0 [simp]: "(0::enat) - n = 0"
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   288
  by (cases n, simp_all add: zero_enat_def)
41853
258a489c24b2 Added material by David Trachtenherz
nipkow
parents: 38621
diff changeset
   289
44019
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   290
lemmas idiff_enat_0 [simp] = idiff_0 [unfolded zero_enat_def]
41853
258a489c24b2 Added material by David Trachtenherz
nipkow
parents: 38621
diff changeset
   291
44019
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   292
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
   293
  by (cases n) (simp_all add: zero_enat_def)
41853
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
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
   296
44019
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   297
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
   298
  by (auto simp: zero_enat_def)
41853
258a489c24b2 Added material by David Trachtenherz
nipkow
parents: 38621
diff changeset
   299
44019
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   300
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
   301
  by (simp add: eSuc_def split: enat.split)
41855
c3b6e69da386 added a few lemmas by Andreas Lochbihler
nipkow
parents: 41853
diff changeset
   302
44019
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   303
lemma eSuc_minus_1 [simp]: "eSuc n - 1 = n"
68406
6beb45f6cf67 utilize 'flip'
nipkow
parents: 67689
diff changeset
   304
  by (simp add: one_enat_def flip: eSuc_enat zero_enat_def)
41855
c3b6e69da386 added a few lemmas by Andreas Lochbihler
nipkow
parents: 41853
diff changeset
   305
43924
1165fe965da8 rename Fin to enat
hoelzl
parents: 43923
diff changeset
   306
(*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
   307
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 59582
diff changeset
   308
subsection \<open>Ordering\<close>
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   309
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   310
instantiation enat :: linordered_ab_semigroup_add
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   311
begin
11351
c5c403d30c77 added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff changeset
   312
38167
ab528533db92 help Nitpick
blanchet
parents: 37765
diff changeset
   313
definition [nitpick_simp]:
43924
1165fe965da8 rename Fin to enat
hoelzl
parents: 43923
diff changeset
   314
  "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
   315
    | \<infinity> \<Rightarrow> True)"
11351
c5c403d30c77 added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff changeset
   316
38167
ab528533db92 help Nitpick
blanchet
parents: 37765
diff changeset
   317
definition [nitpick_simp]:
43924
1165fe965da8 rename Fin to enat
hoelzl
parents: 43923
diff changeset
   318
  "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
   319
    | \<infinity> \<Rightarrow> False)"
11351
c5c403d30c77 added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff changeset
   320
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   321
lemma enat_ord_simps [simp]:
43924
1165fe965da8 rename Fin to enat
hoelzl
parents: 43923
diff changeset
   322
  "enat m \<le> enat n \<longleftrightarrow> m \<le> n"
1165fe965da8 rename Fin to enat
hoelzl
parents: 43923
diff changeset
   323
  "enat m < enat n \<longleftrightarrow> m < n"
43921
e8511be08ddd Introduce infinity type class
hoelzl
parents: 43919
diff changeset
   324
  "q \<le> (\<infinity>::enat)"
e8511be08ddd Introduce infinity type class
hoelzl
parents: 43919
diff changeset
   325
  "q < (\<infinity>::enat) \<longleftrightarrow> q \<noteq> \<infinity>"
e8511be08ddd Introduce infinity type class
hoelzl
parents: 43919
diff changeset
   326
  "(\<infinity>::enat) \<le> q \<longleftrightarrow> q = \<infinity>"
e8511be08ddd Introduce infinity type class
hoelzl
parents: 43919
diff changeset
   327
  "(\<infinity>::enat) < q \<longleftrightarrow> False"
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   328
  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
   329
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 45934
diff changeset
   330
lemma numeral_le_enat_iff[simp]:
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 45934
diff changeset
   331
  shows "numeral m \<le> enat n \<longleftrightarrow> numeral m \<le> n"
81816
bee084ecd18c More tidying of old proofs
paulson <lp15@cam.ac.uk>
parents: 81332
diff changeset
   332
  by (auto simp: numeral_eq_enat)
45934
9321cd2572fe add simp rules for enat and ereal
noschinl
parents: 45775
diff changeset
   333
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 45934
diff changeset
   334
lemma numeral_less_enat_iff[simp]:
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 45934
diff changeset
   335
  shows "numeral m < enat n \<longleftrightarrow> numeral m < n"
81816
bee084ecd18c More tidying of old proofs
paulson <lp15@cam.ac.uk>
parents: 81332
diff changeset
   336
  by (auto simp: numeral_eq_enat)
45934
9321cd2572fe add simp rules for enat and ereal
noschinl
parents: 45775
diff changeset
   337
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   338
lemma enat_ord_code [code]:
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) \<longleftrightarrow> True"
43924
1165fe965da8 rename Fin to enat
hoelzl
parents: 43923
diff changeset
   342
  "enat m < \<infinity> \<longleftrightarrow> True"
1165fe965da8 rename Fin to enat
hoelzl
parents: 43923
diff changeset
   343
  "\<infinity> \<le> enat n \<longleftrightarrow> False"
43921
e8511be08ddd Introduce infinity type class
hoelzl
parents: 43919
diff changeset
   344
  "(\<infinity>::enat) < q \<longleftrightarrow> False"
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   345
  by simp_all
11351
c5c403d30c77 added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff changeset
   346
60679
ade12ef2773c tuned proofs;
wenzelm
parents: 60636
diff changeset
   347
instance
ade12ef2773c tuned proofs;
wenzelm
parents: 60636
diff changeset
   348
  by standard (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
   349
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   350
end
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   351
62376
85f38d5f8807 Rename ordered_comm_monoid_add to ordered_cancel_comm_monoid_add. Introduce ordreed_comm_monoid_add, canonically_ordered_comm_monoid and dioid. Setup nat, entat and ennreal as dioids.
hoelzl
parents: 62374
diff changeset
   352
instance enat :: dioid
85f38d5f8807 Rename ordered_comm_monoid_add to ordered_cancel_comm_monoid_add. Introduce ordreed_comm_monoid_add, canonically_ordered_comm_monoid and dioid. Setup nat, entat and ennreal as dioids.
hoelzl
parents: 62374
diff changeset
   353
proof
85f38d5f8807 Rename ordered_comm_monoid_add to ordered_cancel_comm_monoid_add. Introduce ordreed_comm_monoid_add, canonically_ordered_comm_monoid and dioid. Setup nat, entat and ennreal as dioids.
hoelzl
parents: 62374
diff changeset
   354
  fix a b :: enat show "(a \<le> b) = (\<exists>c. b = a + c)"
85f38d5f8807 Rename ordered_comm_monoid_add to ordered_cancel_comm_monoid_add. Introduce ordreed_comm_monoid_add, canonically_ordered_comm_monoid and dioid. Setup nat, entat and ennreal as dioids.
hoelzl
parents: 62374
diff changeset
   355
    by (cases a b rule: enat2_cases) (auto simp: le_iff_add enat_ex_split)
85f38d5f8807 Rename ordered_comm_monoid_add to ordered_cancel_comm_monoid_add. Introduce ordreed_comm_monoid_add, canonically_ordered_comm_monoid and dioid. Setup nat, entat and ennreal as dioids.
hoelzl
parents: 62374
diff changeset
   356
qed
85f38d5f8807 Rename ordered_comm_monoid_add to ordered_cancel_comm_monoid_add. Introduce ordreed_comm_monoid_add, canonically_ordered_comm_monoid and dioid. Setup nat, entat and ennreal as dioids.
hoelzl
parents: 62374
diff changeset
   357
62378
85ed00c1fe7c generalize more theorems to support enat and ennreal
hoelzl
parents: 62376
diff changeset
   358
instance enat :: "{linordered_nonzero_semiring, strict_ordered_comm_monoid_add}"
29014
e515f42d1db7 multiplication for type inat
huffman
parents: 29012
diff changeset
   359
proof
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   360
  fix a b c :: enat
62378
85ed00c1fe7c generalize more theorems to support enat and ennreal
hoelzl
parents: 62376
diff changeset
   361
  show "a \<le> b \<Longrightarrow> 0 \<le> c \<Longrightarrow>c * a \<le> c * b"
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   362
    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
   363
    by (simp split: enat.splits)
62378
85ed00c1fe7c generalize more theorems to support enat and ennreal
hoelzl
parents: 62376
diff changeset
   364
  show "a < b \<Longrightarrow> c < d \<Longrightarrow> a + c < b + d" for a b c d :: enat
85ed00c1fe7c generalize more theorems to support enat and ennreal
hoelzl
parents: 62376
diff changeset
   365
    by (cases a b c d rule: enat2_cases[case_product enat2_cases]) auto
67689
2c38ffd6ec71 type class linordered_nonzero_semiring has new axiom to guarantee characteristic 0
paulson <lp15@cam.ac.uk>
parents: 67091
diff changeset
   366
  show "a < b \<Longrightarrow> a + 1 < b + 1"
2c38ffd6ec71 type class linordered_nonzero_semiring has new axiom to guarantee characteristic 0
paulson <lp15@cam.ac.uk>
parents: 67091
diff changeset
   367
    by (metis add_right_mono eSuc_minus_1 eSuc_plus_1 less_le)
62378
85ed00c1fe7c generalize more theorems to support enat and ennreal
hoelzl
parents: 62376
diff changeset
   368
qed (simp add: zero_enat_def one_enat_def)
29014
e515f42d1db7 multiplication for type inat
huffman
parents: 29012
diff changeset
   369
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 45934
diff changeset
   370
(* BH: These equations are already proven generally for any type in
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 45934
diff changeset
   371
class linordered_semidom. However, enat is not in that class because
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 45934
diff changeset
   372
it does not have the cancellation property. Would it be worthwhile to
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 45934
diff changeset
   373
a generalize linordered_semidom to a new class that includes enat? *)
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 45934
diff changeset
   374
69800
74c1a0643010 added lemmas
nipkow
parents: 69593
diff changeset
   375
lemma add_diff_assoc_enat: "z \<le> y \<Longrightarrow> x + (y - z) = x + y - (z::enat)"
74c1a0643010 added lemmas
nipkow
parents: 69593
diff changeset
   376
by(cases x)(auto simp add: diff_enat_def split: enat.split)
74c1a0643010 added lemmas
nipkow
parents: 69593
diff changeset
   377
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   378
lemma enat_ord_number [simp]:
61076
bdc1e2f0a86a eliminated \<Colon>;
wenzelm
parents: 60679
diff changeset
   379
  "(numeral m :: enat) \<le> numeral n \<longleftrightarrow> (numeral m :: nat) \<le> numeral n"
bdc1e2f0a86a eliminated \<Colon>;
wenzelm
parents: 60679
diff changeset
   380
  "(numeral m :: enat) < numeral n \<longleftrightarrow> (numeral m :: nat) < numeral n"
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 45934
diff changeset
   381
  by (simp_all add: numeral_eq_enat)
11351
c5c403d30c77 added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff changeset
   382
44019
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   383
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
   384
  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
   385
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   386
lemma infinity_ilessE [elim!]: "\<infinity> < enat m \<Longrightarrow> R"
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   387
  by simp
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 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
   390
  by (simp add: eSuc_def less_eq_enat_def split: enat.splits)
62374
cb27a55d868a remove lattice syntax from countable complete lattice
hoelzl
parents: 61631
diff changeset
   391
44019
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   392
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
   393
  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
   394
44019
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   395
lemma ile_eSuc [simp]: "n \<le> eSuc n"
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   396
  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
   397
44019
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   398
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
   399
  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
   400
44019
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   401
lemma i0_iless_eSuc [simp]: "0 < eSuc n"
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   402
  by (simp add: zero_enat_def eSuc_def less_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 iless_eSuc0[simp]: "(n < eSuc 0) = (n = 0)"
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   405
  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
   406
44019
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   407
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
   408
  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
   409
43924
1165fe965da8 rename Fin to enat
hoelzl
parents: 43923
diff changeset
   410
lemma Suc_ile_eq: "enat (Suc m) \<le> n \<longleftrightarrow> enat m < n"
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   411
  by (cases n) auto
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 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
   414
  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
   415
44019
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   416
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
   417
  by (simp add: zero_enat_def less_enat_def split: enat.splits)
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 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
   420
  by (simp add: zero_enat_def less_enat_def split: enat.splits)
41853
258a489c24b2 Added material by David Trachtenherz
nipkow
parents: 38621
diff changeset
   421
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   422
lemma enat_0_less_mult_iff: "(0 < (m::enat) * n) = (0 < m \<and> 0 < n)"
62378
85ed00c1fe7c generalize more theorems to support enat and ennreal
hoelzl
parents: 62376
diff changeset
   423
  by (simp only: zero_less_iff_neq_zero mult_eq_0_iff, simp)
41853
258a489c24b2 Added material by David Trachtenherz
nipkow
parents: 38621
diff changeset
   424
44019
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   425
lemma mono_eSuc: "mono eSuc"
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   426
  by (simp add: mono_def)
41853
258a489c24b2 Added material by David Trachtenherz
nipkow
parents: 38621
diff changeset
   427
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   428
lemma min_enat_simps [simp]:
43924
1165fe965da8 rename Fin to enat
hoelzl
parents: 43923
diff changeset
   429
  "min (enat m) (enat n) = enat (min m n)"
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   430
  "min q 0 = 0"
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   431
  "min 0 q = 0"
43921
e8511be08ddd Introduce infinity type class
hoelzl
parents: 43919
diff changeset
   432
  "min q (\<infinity>::enat) = q"
e8511be08ddd Introduce infinity type class
hoelzl
parents: 43919
diff changeset
   433
  "min (\<infinity>::enat) q = q"
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   434
  by (auto simp add: min_def)
11351
c5c403d30c77 added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff changeset
   435
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   436
lemma max_enat_simps [simp]:
43924
1165fe965da8 rename Fin to enat
hoelzl
parents: 43923
diff changeset
   437
  "max (enat m) (enat n) = enat (max m n)"
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   438
  "max q 0 = q"
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   439
  "max 0 q = q"
43921
e8511be08ddd Introduce infinity type class
hoelzl
parents: 43919
diff changeset
   440
  "max q \<infinity> = (\<infinity>::enat)"
e8511be08ddd Introduce infinity type class
hoelzl
parents: 43919
diff changeset
   441
  "max \<infinity> q = (\<infinity>::enat)"
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   442
  by (simp_all add: max_def)
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   443
43924
1165fe965da8 rename Fin to enat
hoelzl
parents: 43923
diff changeset
   444
lemma enat_ile: "n \<le> enat m \<Longrightarrow> \<exists>k. n = enat k"
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   445
  by (cases n) simp_all
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   446
43924
1165fe965da8 rename Fin to enat
hoelzl
parents: 43923
diff changeset
   447
lemma enat_iless: "n < enat m \<Longrightarrow> \<exists>k. n = enat k"
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   448
  by (cases n) simp_all
11351
c5c403d30c77 added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff changeset
   449
61631
4f7ef088c4ed add lemmas for extended nats and reals
Andreas Lochbihler
parents: 61384
diff changeset
   450
lemma iadd_le_enat_iff:
4f7ef088c4ed add lemmas for extended nats and reals
Andreas Lochbihler
parents: 61384
diff changeset
   451
  "x + y \<le> enat n \<longleftrightarrow> (\<exists>y' x'. x = enat x' \<and> y = enat y' \<and> x' + y' \<le> n)"
4f7ef088c4ed add lemmas for extended nats and reals
Andreas Lochbihler
parents: 61384
diff changeset
   452
by(cases x y rule: enat.exhaust[case_product enat.exhaust]) simp_all
4f7ef088c4ed add lemmas for extended nats and reals
Andreas Lochbihler
parents: 61384
diff changeset
   453
62378
85ed00c1fe7c generalize more theorems to support enat and ennreal
hoelzl
parents: 62376
diff changeset
   454
lemma chain_incr: "\<forall>i. \<exists>j. Y i < Y j \<Longrightarrow> \<exists>j. enat k < Y j"
81816
bee084ecd18c More tidying of old proofs
paulson <lp15@cam.ac.uk>
parents: 81332
diff changeset
   455
proof (induction k)
bee084ecd18c More tidying of old proofs
paulson <lp15@cam.ac.uk>
parents: 81332
diff changeset
   456
  case 0
bee084ecd18c More tidying of old proofs
paulson <lp15@cam.ac.uk>
parents: 81332
diff changeset
   457
  then show ?case
bee084ecd18c More tidying of old proofs
paulson <lp15@cam.ac.uk>
parents: 81332
diff changeset
   458
    using enat_0 zero_less_iff_neq_zero by fastforce 
bee084ecd18c More tidying of old proofs
paulson <lp15@cam.ac.uk>
parents: 81332
diff changeset
   459
next
bee084ecd18c More tidying of old proofs
paulson <lp15@cam.ac.uk>
parents: 81332
diff changeset
   460
  case (Suc k)
bee084ecd18c More tidying of old proofs
paulson <lp15@cam.ac.uk>
parents: 81332
diff changeset
   461
  then show ?case
bee084ecd18c More tidying of old proofs
paulson <lp15@cam.ac.uk>
parents: 81332
diff changeset
   462
    by (meson Suc_ile_eq order_le_less_trans)
bee084ecd18c More tidying of old proofs
paulson <lp15@cam.ac.uk>
parents: 81332
diff changeset
   463
qed
11351
c5c403d30c77 added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff changeset
   464
60636
ee18efe9b246 add named theorems order_continuous_intros; lfp/gfp_funpow; bounded variant for lfp/gfp transfer
hoelzl
parents: 60500
diff changeset
   465
lemma eSuc_max: "eSuc (max x y) = max (eSuc x) (eSuc y)"
ee18efe9b246 add named theorems order_continuous_intros; lfp/gfp_funpow; bounded variant for lfp/gfp transfer
hoelzl
parents: 60500
diff changeset
   466
  by (simp add: eSuc_def split: enat.split)
ee18efe9b246 add named theorems order_continuous_intros; lfp/gfp_funpow; bounded variant for lfp/gfp transfer
hoelzl
parents: 60500
diff changeset
   467
62374
cb27a55d868a remove lattice syntax from countable complete lattice
hoelzl
parents: 61631
diff changeset
   468
lemma eSuc_Max:
60636
ee18efe9b246 add named theorems order_continuous_intros; lfp/gfp_funpow; bounded variant for lfp/gfp transfer
hoelzl
parents: 60500
diff changeset
   469
  assumes "finite A" "A \<noteq> {}"
ee18efe9b246 add named theorems order_continuous_intros; lfp/gfp_funpow; bounded variant for lfp/gfp transfer
hoelzl
parents: 60500
diff changeset
   470
  shows "eSuc (Max A) = Max (eSuc ` A)"
81816
bee084ecd18c More tidying of old proofs
paulson <lp15@cam.ac.uk>
parents: 81332
diff changeset
   471
  by (simp add: assms mono_Max_commute mono_eSuc)
60636
ee18efe9b246 add named theorems order_continuous_intros; lfp/gfp_funpow; bounded variant for lfp/gfp transfer
hoelzl
parents: 60500
diff changeset
   472
52729
412c9e0381a1 factored syntactic type classes for bot and top (by Alessandro Coglio)
haftmann
parents: 51717
diff changeset
   473
instantiation enat :: "{order_bot, order_top}"
29337
450805a4a91f added instance for bot, top
haftmann
parents: 29023
diff changeset
   474
begin
450805a4a91f added instance for bot, top
haftmann
parents: 29023
diff changeset
   475
60679
ade12ef2773c tuned proofs;
wenzelm
parents: 60636
diff changeset
   476
definition bot_enat :: enat where "bot_enat = 0"
ade12ef2773c tuned proofs;
wenzelm
parents: 60636
diff changeset
   477
definition top_enat :: enat where "top_enat = \<infinity>"
29337
450805a4a91f added instance for bot, top
haftmann
parents: 29023
diff changeset
   478
60679
ade12ef2773c tuned proofs;
wenzelm
parents: 60636
diff changeset
   479
instance
ade12ef2773c tuned proofs;
wenzelm
parents: 60636
diff changeset
   480
  by standard (simp_all add: bot_enat_def top_enat_def)
29337
450805a4a91f added instance for bot, top
haftmann
parents: 29023
diff changeset
   481
450805a4a91f added instance for bot, top
haftmann
parents: 29023
diff changeset
   482
end
450805a4a91f added instance for bot, top
haftmann
parents: 29023
diff changeset
   483
43924
1165fe965da8 rename Fin to enat
hoelzl
parents: 43923
diff changeset
   484
lemma finite_enat_bounded:
1165fe965da8 rename Fin to enat
hoelzl
parents: 43923
diff changeset
   485
  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
   486
  shows "finite A"
da014b00d7a4 instance inat for complete_lattice
noschinl
parents: 41855
diff changeset
   487
proof (rule finite_subset)
43924
1165fe965da8 rename Fin to enat
hoelzl
parents: 43923
diff changeset
   488
  show "finite (enat ` {..n})" by blast
81816
bee084ecd18c More tidying of old proofs
paulson <lp15@cam.ac.uk>
parents: 81332
diff changeset
   489
  have "A \<subseteq> enat ` {..n}"
bee084ecd18c More tidying of old proofs
paulson <lp15@cam.ac.uk>
parents: 81332
diff changeset
   490
    using enat_ile le_fin by fastforce
bee084ecd18c More tidying of old proofs
paulson <lp15@cam.ac.uk>
parents: 81332
diff changeset
   491
  then show "A \<subseteq> enat ` {..n}" .
42993
da014b00d7a4 instance inat for complete_lattice
noschinl
parents: 41855
diff changeset
   492
qed
da014b00d7a4 instance inat for complete_lattice
noschinl
parents: 41855
diff changeset
   493
26089
373221497340 proved linorder and wellorder class instances
huffman
parents: 25691
diff changeset
   494
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 59582
diff changeset
   495
subsection \<open>Cancellation simprocs\<close>
45775
6c340de26a0d add cancellation simprocs for type enat
huffman
parents: 45539
diff changeset
   496
69803
a24865b6262f added lemma
nipkow
parents: 69801
diff changeset
   497
lemma add_diff_cancel_enat[simp]: "x \<noteq> \<infinity> \<Longrightarrow> x + y - x = (y::enat)"
81816
bee084ecd18c More tidying of old proofs
paulson <lp15@cam.ac.uk>
parents: 81332
diff changeset
   498
  by (metis add.commute add.right_neutral add_diff_assoc_enat idiff_self order_refl)
69803
a24865b6262f added lemma
nipkow
parents: 69801
diff changeset
   499
45775
6c340de26a0d add cancellation simprocs for type enat
huffman
parents: 45539
diff changeset
   500
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
   501
  unfolding plus_enat_def by (simp split: enat.split)
6c340de26a0d add cancellation simprocs for type enat
huffman
parents: 45539
diff changeset
   502
6c340de26a0d add cancellation simprocs for type enat
huffman
parents: 45539
diff changeset
   503
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
   504
  unfolding plus_enat_def by (simp split: enat.split)
6c340de26a0d add cancellation simprocs for type enat
huffman
parents: 45539
diff changeset
   505
6c340de26a0d add cancellation simprocs for type enat
huffman
parents: 45539
diff changeset
   506
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
   507
  unfolding plus_enat_def by (simp split: enat.split)
6c340de26a0d add cancellation simprocs for type enat
huffman
parents: 45539
diff changeset
   508
69801
a99a0f5474c5 too agressive
nipkow
parents: 69800
diff changeset
   509
lemma plus_eq_infty_iff_enat: "(m::enat) + n = \<infinity> \<longleftrightarrow> m=\<infinity> \<or> n=\<infinity>"
81816
bee084ecd18c More tidying of old proofs
paulson <lp15@cam.ac.uk>
parents: 81332
diff changeset
   510
  using enat_add_left_cancel by fastforce
69800
74c1a0643010 added lemmas
nipkow
parents: 69593
diff changeset
   511
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 59582
diff changeset
   512
ML \<open>
45775
6c340de26a0d add cancellation simprocs for type enat
huffman
parents: 45539
diff changeset
   513
structure Cancel_Enat_Common =
6c340de26a0d add cancellation simprocs for type enat
huffman
parents: 45539
diff changeset
   514
struct
6c340de26a0d add cancellation simprocs for type enat
huffman
parents: 45539
diff changeset
   515
  (* copied from src/HOL/Tools/nat_numeral_simprocs.ML *)
6c340de26a0d add cancellation simprocs for type enat
huffman
parents: 45539
diff changeset
   516
  fun find_first_t _    _ []         = raise TERM("find_first_t", [])
6c340de26a0d add cancellation simprocs for type enat
huffman
parents: 45539
diff changeset
   517
    | find_first_t past u (t::terms) =
6c340de26a0d add cancellation simprocs for type enat
huffman
parents: 45539
diff changeset
   518
          if u aconv t then (rev past @ terms)
6c340de26a0d add cancellation simprocs for type enat
huffman
parents: 45539
diff changeset
   519
          else find_first_t (t::past) u terms
6c340de26a0d add cancellation simprocs for type enat
huffman
parents: 45539
diff changeset
   520
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 68406
diff changeset
   521
  fun dest_summing (Const (\<^const_name>\<open>Groups.plus\<close>, _) $ t $ u, ts) =
51366
abdcf1a7cabf avoid using Arith_Data.dest_sum in extended-nat simprocs (it treats 'x - y' as 'x + - y', which is not valid for enat)
huffman
parents: 51301
diff changeset
   522
        dest_summing (t, dest_summing (u, ts))
abdcf1a7cabf avoid using Arith_Data.dest_sum in extended-nat simprocs (it treats 'x - y' as 'x + - y', which is not valid for enat)
huffman
parents: 51301
diff changeset
   523
    | dest_summing (t, ts) = t :: ts
abdcf1a7cabf avoid using Arith_Data.dest_sum in extended-nat simprocs (it treats 'x - y' as 'x + - y', which is not valid for enat)
huffman
parents: 51301
diff changeset
   524
45775
6c340de26a0d add cancellation simprocs for type enat
huffman
parents: 45539
diff changeset
   525
  val mk_sum = Arith_Data.long_mk_sum
51366
abdcf1a7cabf avoid using Arith_Data.dest_sum in extended-nat simprocs (it treats 'x - y' as 'x + - y', which is not valid for enat)
huffman
parents: 51301
diff changeset
   526
  fun dest_sum t = dest_summing (t, [])
45775
6c340de26a0d add cancellation simprocs for type enat
huffman
parents: 45539
diff changeset
   527
  val find_first = find_first_t []
6c340de26a0d add cancellation simprocs for type enat
huffman
parents: 45539
diff changeset
   528
  val trans_tac = Numeral_Simprocs.trans_tac
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 51366
diff changeset
   529
  val norm_ss =
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 68406
diff changeset
   530
    simpset_of (put_simpset HOL_basic_ss \<^context>
57514
bdc2c6b40bf2 prefer ac_simps collections over separate name bindings for add and mult
haftmann
parents: 57512
diff changeset
   531
      addsimps @{thms ac_simps add_0_left add_0_right})
51717
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 51366
diff changeset
   532
  fun norm_tac ctxt = ALLGOALS (simp_tac (put_simpset norm_ss ctxt))
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 51366
diff changeset
   533
  fun simplify_meta_eq ctxt cancel_th th =
9e7d1c139569 simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents: 51366
diff changeset
   534
    Arith_Data.simplify_meta_eq [] ctxt
45775
6c340de26a0d add cancellation simprocs for type enat
huffman
parents: 45539
diff changeset
   535
      ([th, cancel_th] MRS trans)
6c340de26a0d add cancellation simprocs for type enat
huffman
parents: 45539
diff changeset
   536
  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
   537
end
6c340de26a0d add cancellation simprocs for type enat
huffman
parents: 45539
diff changeset
   538
6c340de26a0d add cancellation simprocs for type enat
huffman
parents: 45539
diff changeset
   539
structure Eq_Enat_Cancel = ExtractCommonTermFun
6c340de26a0d add cancellation simprocs for type enat
huffman
parents: 45539
diff changeset
   540
(open Cancel_Enat_Common
6c340de26a0d add cancellation simprocs for type enat
huffman
parents: 45539
diff changeset
   541
  val mk_bal = HOLogic.mk_eq
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 68406
diff changeset
   542
  val dest_bal = HOLogic.dest_bin \<^const_name>\<open>HOL.eq\<close> \<^typ>\<open>enat\<close>
45775
6c340de26a0d add cancellation simprocs for type enat
huffman
parents: 45539
diff changeset
   543
  fun simp_conv _ _ = SOME @{thm enat_add_left_cancel}
6c340de26a0d add cancellation simprocs for type enat
huffman
parents: 45539
diff changeset
   544
)
6c340de26a0d add cancellation simprocs for type enat
huffman
parents: 45539
diff changeset
   545
6c340de26a0d add cancellation simprocs for type enat
huffman
parents: 45539
diff changeset
   546
structure Le_Enat_Cancel = ExtractCommonTermFun
6c340de26a0d add cancellation simprocs for type enat
huffman
parents: 45539
diff changeset
   547
(open Cancel_Enat_Common
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 68406
diff changeset
   548
  val mk_bal = HOLogic.mk_binrel \<^const_name>\<open>Orderings.less_eq\<close>
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 68406
diff changeset
   549
  val dest_bal = HOLogic.dest_bin \<^const_name>\<open>Orderings.less_eq\<close> \<^typ>\<open>enat\<close>
45775
6c340de26a0d add cancellation simprocs for type enat
huffman
parents: 45539
diff changeset
   550
  fun simp_conv _ _ = SOME @{thm enat_add_left_cancel_le}
6c340de26a0d add cancellation simprocs for type enat
huffman
parents: 45539
diff changeset
   551
)
6c340de26a0d add cancellation simprocs for type enat
huffman
parents: 45539
diff changeset
   552
6c340de26a0d add cancellation simprocs for type enat
huffman
parents: 45539
diff changeset
   553
structure Less_Enat_Cancel = ExtractCommonTermFun
6c340de26a0d add cancellation simprocs for type enat
huffman
parents: 45539
diff changeset
   554
(open Cancel_Enat_Common
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 68406
diff changeset
   555
  val mk_bal = HOLogic.mk_binrel \<^const_name>\<open>Orderings.less\<close>
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 68406
diff changeset
   556
  val dest_bal = HOLogic.dest_bin \<^const_name>\<open>Orderings.less\<close> \<^typ>\<open>enat\<close>
45775
6c340de26a0d add cancellation simprocs for type enat
huffman
parents: 45539
diff changeset
   557
  fun simp_conv _ _ = SOME @{thm enat_add_left_cancel_less}
6c340de26a0d add cancellation simprocs for type enat
huffman
parents: 45539
diff changeset
   558
)
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 59582
diff changeset
   559
\<close>
45775
6c340de26a0d add cancellation simprocs for type enat
huffman
parents: 45539
diff changeset
   560
6c340de26a0d add cancellation simprocs for type enat
huffman
parents: 45539
diff changeset
   561
simproc_setup enat_eq_cancel
6c340de26a0d add cancellation simprocs for type enat
huffman
parents: 45539
diff changeset
   562
  ("(l::enat) + m = n" | "(l::enat) = m + n") =
78099
4d9349989d94 more uniform simproc_setup: avoid vacuous abstraction over morphism, which sometimes captures context values in its functional closure;
wenzelm
parents: 69861
diff changeset
   563
  \<open>K (fn ctxt => fn ct => Eq_Enat_Cancel.proc ctxt (Thm.term_of ct))\<close>
45775
6c340de26a0d add cancellation simprocs for type enat
huffman
parents: 45539
diff changeset
   564
6c340de26a0d add cancellation simprocs for type enat
huffman
parents: 45539
diff changeset
   565
simproc_setup enat_le_cancel
6c340de26a0d add cancellation simprocs for type enat
huffman
parents: 45539
diff changeset
   566
  ("(l::enat) + m \<le> n" | "(l::enat) \<le> m + n") =
78099
4d9349989d94 more uniform simproc_setup: avoid vacuous abstraction over morphism, which sometimes captures context values in its functional closure;
wenzelm
parents: 69861
diff changeset
   567
  \<open>K (fn ctxt => fn ct => Le_Enat_Cancel.proc ctxt (Thm.term_of ct))\<close>
45775
6c340de26a0d add cancellation simprocs for type enat
huffman
parents: 45539
diff changeset
   568
6c340de26a0d add cancellation simprocs for type enat
huffman
parents: 45539
diff changeset
   569
simproc_setup enat_less_cancel
6c340de26a0d add cancellation simprocs for type enat
huffman
parents: 45539
diff changeset
   570
  ("(l::enat) + m < n" | "(l::enat) < m + n") =
78099
4d9349989d94 more uniform simproc_setup: avoid vacuous abstraction over morphism, which sometimes captures context values in its functional closure;
wenzelm
parents: 69861
diff changeset
   571
  \<open>K (fn ctxt => fn ct => Less_Enat_Cancel.proc ctxt (Thm.term_of ct))\<close>
45775
6c340de26a0d add cancellation simprocs for type enat
huffman
parents: 45539
diff changeset
   572
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 59582
diff changeset
   573
text \<open>TODO: add regression tests for these simprocs\<close>
45775
6c340de26a0d add cancellation simprocs for type enat
huffman
parents: 45539
diff changeset
   574
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 59582
diff changeset
   575
text \<open>TODO: add simprocs for combining and cancelling numerals\<close>
45775
6c340de26a0d add cancellation simprocs for type enat
huffman
parents: 45539
diff changeset
   576
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 59582
diff changeset
   577
subsection \<open>Well-ordering\<close>
26089
373221497340 proved linorder and wellorder class instances
huffman
parents: 25691
diff changeset
   578
43924
1165fe965da8 rename Fin to enat
hoelzl
parents: 43923
diff changeset
   579
lemma less_enatE:
81816
bee084ecd18c More tidying of old proofs
paulson <lp15@cam.ac.uk>
parents: 81332
diff changeset
   580
  "\<lbrakk>n < enat m; \<And>k. \<lbrakk>n = enat k; k < m\<rbrakk> \<Longrightarrow> P\<rbrakk> \<Longrightarrow> P"
bee084ecd18c More tidying of old proofs
paulson <lp15@cam.ac.uk>
parents: 81332
diff changeset
   581
  using enat_iless enat_ord_simps(2) by blast
26089
373221497340 proved linorder and wellorder class instances
huffman
parents: 25691
diff changeset
   582
44019
ee784502aed5 Extended_Nat.thy: renamed iSuc to eSuc, standardized theorem names
huffman
parents: 43978
diff changeset
   583
lemma less_infinityE:
81816
bee084ecd18c More tidying of old proofs
paulson <lp15@cam.ac.uk>
parents: 81332
diff changeset
   584
  "\<lbrakk>n < \<infinity>; \<And>k. n = enat k \<Longrightarrow> P\<rbrakk> \<Longrightarrow> P"
bee084ecd18c More tidying of old proofs
paulson <lp15@cam.ac.uk>
parents: 81332
diff changeset
   585
  by auto
26089
373221497340 proved linorder and wellorder class instances
huffman
parents: 25691
diff changeset
   586
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   587
lemma enat_less_induct:
81816
bee084ecd18c More tidying of old proofs
paulson <lp15@cam.ac.uk>
parents: 81332
diff changeset
   588
  assumes "\<And>n. \<forall>m::enat. m < n \<longrightarrow> P m \<Longrightarrow> P n" 
bee084ecd18c More tidying of old proofs
paulson <lp15@cam.ac.uk>
parents: 81332
diff changeset
   589
  shows "P n"
26089
373221497340 proved linorder and wellorder class instances
huffman
parents: 25691
diff changeset
   590
proof -
81816
bee084ecd18c More tidying of old proofs
paulson <lp15@cam.ac.uk>
parents: 81332
diff changeset
   591
  have "P (enat k)" for k
bee084ecd18c More tidying of old proofs
paulson <lp15@cam.ac.uk>
parents: 81332
diff changeset
   592
    by (induction k rule: less_induct) (metis less_enatE assms)
bee084ecd18c More tidying of old proofs
paulson <lp15@cam.ac.uk>
parents: 81332
diff changeset
   593
  then show ?thesis
bee084ecd18c More tidying of old proofs
paulson <lp15@cam.ac.uk>
parents: 81332
diff changeset
   594
    by (metis enat.exhaust less_infinityE assms)
26089
373221497340 proved linorder and wellorder class instances
huffman
parents: 25691
diff changeset
   595
qed
373221497340 proved linorder and wellorder class instances
huffman
parents: 25691
diff changeset
   596
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   597
instance enat :: wellorder
26089
373221497340 proved linorder and wellorder class instances
huffman
parents: 25691
diff changeset
   598
proof
27823
52971512d1a2 moved class wellorder to theory Orderings
haftmann
parents: 27487
diff changeset
   599
  fix P and n
61076
bdc1e2f0a86a eliminated \<Colon>;
wenzelm
parents: 60679
diff changeset
   600
  assume hyp: "(\<And>n::enat. (\<And>m::enat. m < n \<Longrightarrow> P m) \<Longrightarrow> P n)"
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   601
  show "P n" by (blast intro: enat_less_induct hyp)
26089
373221497340 proved linorder and wellorder class instances
huffman
parents: 25691
diff changeset
   602
qed
373221497340 proved linorder and wellorder class instances
huffman
parents: 25691
diff changeset
   603
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 59582
diff changeset
   604
subsection \<open>Complete Lattice\<close>
42993
da014b00d7a4 instance inat for complete_lattice
noschinl
parents: 41855
diff changeset
   605
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   606
instantiation enat :: complete_lattice
42993
da014b00d7a4 instance inat for complete_lattice
noschinl
parents: 41855
diff changeset
   607
begin
da014b00d7a4 instance inat for complete_lattice
noschinl
parents: 41855
diff changeset
   608
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   609
definition inf_enat :: "enat \<Rightarrow> enat \<Rightarrow> enat" where
56777
wenzelm
parents: 54419
diff changeset
   610
  "inf_enat = min"
42993
da014b00d7a4 instance inat for complete_lattice
noschinl
parents: 41855
diff changeset
   611
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   612
definition sup_enat :: "enat \<Rightarrow> enat \<Rightarrow> enat" where
56777
wenzelm
parents: 54419
diff changeset
   613
  "sup_enat = max"
42993
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
definition Inf_enat :: "enat set \<Rightarrow> enat" where
56777
wenzelm
parents: 54419
diff changeset
   616
  "Inf_enat A = (if A = {} then \<infinity> else (LEAST x. x \<in> A))"
42993
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 Sup_enat :: "enat set \<Rightarrow> enat" where
56777
wenzelm
parents: 54419
diff changeset
   619
  "Sup_enat A = (if A = {} then 0 else if finite A then Max A else \<infinity>)"
81332
f94b30fa2b6c tuned proofs;
wenzelm
parents: 80914
diff changeset
   620
56777
wenzelm
parents: 54419
diff changeset
   621
instance
wenzelm
parents: 54419
diff changeset
   622
proof
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   623
  fix x :: "enat" and A :: "enat set"
81332
f94b30fa2b6c tuned proofs;
wenzelm
parents: 80914
diff changeset
   624
  show "x \<in> A \<Longrightarrow> Inf A \<le> x"
f94b30fa2b6c tuned proofs;
wenzelm
parents: 80914
diff changeset
   625
    unfolding Inf_enat_def by (auto intro: Least_le)
f94b30fa2b6c tuned proofs;
wenzelm
parents: 80914
diff changeset
   626
  show "(\<And>y. y \<in> A \<Longrightarrow> x \<le> y) \<Longrightarrow> x \<le> Inf A"
f94b30fa2b6c tuned proofs;
wenzelm
parents: 80914
diff changeset
   627
    unfolding Inf_enat_def
f94b30fa2b6c tuned proofs;
wenzelm
parents: 80914
diff changeset
   628
    by (cases "A = {}") (auto intro: LeastI2_ex)
f94b30fa2b6c tuned proofs;
wenzelm
parents: 80914
diff changeset
   629
  show "x \<in> A \<Longrightarrow> x \<le> Sup A"
f94b30fa2b6c tuned proofs;
wenzelm
parents: 80914
diff changeset
   630
    unfolding Sup_enat_def by (cases "finite A") auto
f94b30fa2b6c tuned proofs;
wenzelm
parents: 80914
diff changeset
   631
  show "(\<And>y. y \<in> A \<Longrightarrow> y \<le> x) \<Longrightarrow> Sup A \<le> x"
f94b30fa2b6c tuned proofs;
wenzelm
parents: 80914
diff changeset
   632
    unfolding Sup_enat_def using finite_enat_bounded by auto
f94b30fa2b6c tuned proofs;
wenzelm
parents: 80914
diff changeset
   633
qed (simp_all add: inf_enat_def sup_enat_def bot_enat_def top_enat_def Inf_enat_def Sup_enat_def)
f94b30fa2b6c tuned proofs;
wenzelm
parents: 80914
diff changeset
   634
42993
da014b00d7a4 instance inat for complete_lattice
noschinl
parents: 41855
diff changeset
   635
end
da014b00d7a4 instance inat for complete_lattice
noschinl
parents: 41855
diff changeset
   636
43978
da7d04d4023c enat is a complete_linorder instance
hoelzl
parents: 43924
diff changeset
   637
instance enat :: complete_linorder ..
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   638
60636
ee18efe9b246 add named theorems order_continuous_intros; lfp/gfp_funpow; bounded variant for lfp/gfp transfer
hoelzl
parents: 60500
diff changeset
   639
lemma eSuc_Sup: "A \<noteq> {} \<Longrightarrow> eSuc (Sup A) = Sup (eSuc ` A)"
ee18efe9b246 add named theorems order_continuous_intros; lfp/gfp_funpow; bounded variant for lfp/gfp transfer
hoelzl
parents: 60500
diff changeset
   640
  by(auto simp add: Sup_enat_def eSuc_Max inj_on_def dest: finite_imageD)
ee18efe9b246 add named theorems order_continuous_intros; lfp/gfp_funpow; bounded variant for lfp/gfp transfer
hoelzl
parents: 60500
diff changeset
   641
ee18efe9b246 add named theorems order_continuous_intros; lfp/gfp_funpow; bounded variant for lfp/gfp transfer
hoelzl
parents: 60500
diff changeset
   642
lemma sup_continuous_eSuc: "sup_continuous f \<Longrightarrow> sup_continuous (\<lambda>x. eSuc (f x))"
69861
62e47f06d22c avoid context-sensitive simp rules whose context-free form (image_comp) is not simp by default
haftmann
parents: 69803
diff changeset
   643
  using eSuc_Sup [of "_ ` UNIV"] by (auto simp: sup_continuous_def image_comp)
62e47f06d22c avoid context-sensitive simp rules whose context-free form (image_comp) is not simp by default
haftmann
parents: 69803
diff changeset
   644
60636
ee18efe9b246 add named theorems order_continuous_intros; lfp/gfp_funpow; bounded variant for lfp/gfp transfer
hoelzl
parents: 60500
diff changeset
   645
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 59582
diff changeset
   646
subsection \<open>Traditional theorem names\<close>
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   647
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 45934
diff changeset
   648
lemmas enat_defs = zero_enat_def one_enat_def eSuc_def
43919
a7e4fb1a0502 rename Nat_Infinity (inat) to Extended_Nat (enat)
hoelzl
parents: 43532
diff changeset
   649
  plus_enat_def less_eq_enat_def less_enat_def
27110
194aa674c2a1 refactoring; addition, numerals
haftmann
parents: 26089
diff changeset
   650
62378
85ed00c1fe7c generalize more theorems to support enat and ennreal
hoelzl
parents: 62376
diff changeset
   651
lemma iadd_is_0: "(m + n = (0::enat)) = (m = 0 \<and> n = 0)"
85ed00c1fe7c generalize more theorems to support enat and ennreal
hoelzl
parents: 62376
diff changeset
   652
  by (rule add_eq_0_iff_both_eq_0)
85ed00c1fe7c generalize more theorems to support enat and ennreal
hoelzl
parents: 62376
diff changeset
   653
85ed00c1fe7c generalize more theorems to support enat and ennreal
hoelzl
parents: 62376
diff changeset
   654
lemma i0_lb : "(0::enat) \<le> n"
85ed00c1fe7c generalize more theorems to support enat and ennreal
hoelzl
parents: 62376
diff changeset
   655
  by (rule zero_le)
85ed00c1fe7c generalize more theorems to support enat and ennreal
hoelzl
parents: 62376
diff changeset
   656
85ed00c1fe7c generalize more theorems to support enat and ennreal
hoelzl
parents: 62376
diff changeset
   657
lemma ile0_eq: "n \<le> (0::enat) \<longleftrightarrow> n = 0"
85ed00c1fe7c generalize more theorems to support enat and ennreal
hoelzl
parents: 62376
diff changeset
   658
  by (rule le_zero_eq)
85ed00c1fe7c generalize more theorems to support enat and ennreal
hoelzl
parents: 62376
diff changeset
   659
85ed00c1fe7c generalize more theorems to support enat and ennreal
hoelzl
parents: 62376
diff changeset
   660
lemma not_iless0: "\<not> n < (0::enat)"
85ed00c1fe7c generalize more theorems to support enat and ennreal
hoelzl
parents: 62376
diff changeset
   661
  by (rule not_less_zero)
85ed00c1fe7c generalize more theorems to support enat and ennreal
hoelzl
parents: 62376
diff changeset
   662
85ed00c1fe7c generalize more theorems to support enat and ennreal
hoelzl
parents: 62376
diff changeset
   663
lemma i0_less[simp]: "(0::enat) < n \<longleftrightarrow> n \<noteq> 0"
85ed00c1fe7c generalize more theorems to support enat and ennreal
hoelzl
parents: 62376
diff changeset
   664
  by (rule zero_less_iff_neq_zero)
85ed00c1fe7c generalize more theorems to support enat and ennreal
hoelzl
parents: 62376
diff changeset
   665
85ed00c1fe7c generalize more theorems to support enat and ennreal
hoelzl
parents: 62376
diff changeset
   666
lemma imult_is_0: "((m::enat) * n = 0) = (m = 0 \<or> n = 0)"
85ed00c1fe7c generalize more theorems to support enat and ennreal
hoelzl
parents: 62376
diff changeset
   667
  by (rule mult_eq_0_iff)
85ed00c1fe7c generalize more theorems to support enat and ennreal
hoelzl
parents: 62376
diff changeset
   668
11351
c5c403d30c77 added Library/Nat_Infinity.thy and Library/Continuity.thy
oheimb
parents:
diff changeset
   669
end