# Theory Nat_Infinity

Up to index of Isabelle/HOLCF/ex

theory Nat_Infinity
imports Main
begin

    (*  Title:      HOL/Library/Nat_Infinity.thy
        ID:         $Id: Nat_Infinity.thy,v 1.11 2004/08/18 09:10:01 nipkow Exp $
        Author:     David von Oheimb, TU Muenchen
    *)

    header {* Natural numbers with infinity *}

    theory Nat_Infinity
    imports Main
    begin

    subsection "Definitions"

    text {*
      We extend the standard natural numbers by a special value indicating
      infinity.  This includes extending the ordering relations @{term "op
      <"} and @{term "op ≤"}.
    *}

    datatype inat = Fin nat | Infty

    instance inat :: "{ord, zero}" ..

    consts
      iSuc :: "inat => inat"

    syntax (xsymbols)
      Infty :: inat    ("∞")

    syntax (HTML output)
      Infty :: inat    ("∞")

    defs
      Zero_inat_def: "0 == Fin 0"
      iSuc_def: "iSuc i == case i of Fin n  => Fin (Suc n) | ∞ => ∞"
      iless_def: "m < n ==
        case m of Fin m1 => (case n of Fin n1 => m1 < n1 | ∞ => True)
        | ∞  => False"
      ile_def: "(m::inat) ≤ n == ¬ (n < m)"

    lemmas inat_defs = Zero_inat_def iSuc_def iless_def ile_def
    lemmas inat_splits = inat.split inat.split_asm

    text {*
      Below is a not quite complete set of theorems.  Use the method
      @{text "(simp add: inat_defs split:inat_splits, arith?)"} to prove
      new theorems or solve arithmetic subgoals involving @{typ inat} on
      the fly.
    *}

    subsection "Constructors"

    lemma Fin_0: "Fin 0 = 0"
      by (simp add: inat_defs split:inat_splits, arith?)

    lemma Infty_ne_i0 [simp]: "∞ ≠ 0"
      by (simp add: inat_defs split:inat_splits, arith?)

    lemma i0_ne_Infty [simp]: "0 ≠ ∞"
      by (simp add: inat_defs split:inat_splits, arith?)

    lemma iSuc_Fin [simp]: "iSuc (Fin n) = Fin (Suc n)"
      by (simp add: inat_defs split:inat_splits, arith?)

    lemma iSuc_Infty [simp]: "iSuc ∞ = ∞"
      by (simp add: inat_defs split:inat_splits, arith?)

    lemma iSuc_ne_0 [simp]: "iSuc n ≠ 0"
      by (simp add: inat_defs split:inat_splits, arith?)

    lemma iSuc_inject [simp]: "(iSuc x = iSuc y) = (x = y)"
      by (simp add: inat_defs split:inat_splits, arith?)

    subsection "Ordering relations"

    lemma Infty_ilessE [elim!]: "∞ < Fin m ==> R"
      by (simp add: inat_defs split:inat_splits, arith?)

    lemma iless_linear: "m < n ∨ m = n ∨ n < (m::inat)"
      by (simp add: inat_defs split:inat_splits, arith?)

    lemma iless_not_refl [simp]: "¬ n < (n::inat)"
      by (simp add: inat_defs split:inat_splits, arith?)

    lemma iless_trans: "i < j ==> j < k ==> i < (k::inat)"
      by (simp add: inat_defs split:inat_splits, arith?)

    lemma iless_not_sym: "n < m ==> ¬ m < (n::inat)"
      by (simp add: inat_defs split:inat_splits, arith?)

    lemma Fin_iless_mono [simp]: "(Fin n < Fin m) = (n < m)"
      by (simp add: inat_defs split:inat_splits, arith?)

    lemma Fin_iless_Infty [simp]: "Fin n < ∞"
      by (simp add: inat_defs split:inat_splits, arith?)

    lemma Infty_eq [simp]: "(n < ∞) = (n ≠ ∞)"
      by (simp add: inat_defs split:inat_splits, arith?)

    lemma i0_eq [simp]: "((0::inat) < n) = (n ≠ 0)"
      by (simp add: inat_defs split:inat_splits, arith?)

    lemma i0_iless_iSuc [simp]: "0 < iSuc n"
      by (simp add: inat_defs split:inat_splits, arith?)

    lemma not_ilessi0 [simp]: "¬ n < (0::inat)"
      by (simp add: inat_defs split:inat_splits, arith?)

    lemma Fin_iless: "n < Fin m ==> ∃k. n = Fin k"
      by (simp add: inat_defs split:inat_splits, arith?)

    lemma iSuc_mono [simp]: "(iSuc n < iSuc m) = (n < m)"
      by (simp add: inat_defs split:inat_splits, arith?)

    (* ----------------------------------------------------------------------- *)

    lemma ile_def2: "(m ≤ n) = (m < n ∨ m = (n::inat))"
      by (simp add: inat_defs split:inat_splits, arith?)

    lemma ile_refl [simp]: "n ≤ (n::inat)"
      by (simp add: inat_defs split:inat_splits, arith?)

    lemma ile_trans: "i ≤ j ==> j ≤ k ==> i ≤ (k::inat)"
      by (simp add: inat_defs split:inat_splits, arith?)

    lemma ile_iless_trans: "i ≤ j ==> j < k ==> i < (k::inat)"
      by (simp add: inat_defs split:inat_splits, arith?)

    lemma iless_ile_trans: "i < j ==> j ≤ k ==> i < (k::inat)"
      by (simp add: inat_defs split:inat_splits, arith?)

    lemma Infty_ub [simp]: "n ≤ ∞"
      by (simp add: inat_defs split:inat_splits, arith?)

    lemma i0_lb [simp]: "(0::inat) ≤ n"
      by (simp add: inat_defs split:inat_splits, arith?)

    lemma Infty_ileE [elim!]: "∞ ≤ Fin m ==> R"
      by (simp add: inat_defs split:inat_splits, arith?)

    lemma Fin_ile_mono [simp]: "(Fin n ≤ Fin m) = (n ≤ m)"
      by (simp add: inat_defs split:inat_splits, arith?)

    lemma ilessI1: "n ≤ m ==> n ≠ m ==> n < (m::inat)"
      by (simp add: inat_defs split:inat_splits, arith?)

    lemma ileI1: "m < n ==> iSuc m ≤ n"
      by (simp add: inat_defs split:inat_splits, arith?)

    lemma Suc_ile_eq: "(Fin (Suc m) ≤ n) = (Fin m < n)"
      by (simp add: inat_defs split:inat_splits, arith?)

    lemma iSuc_ile_mono [simp]: "(iSuc n ≤ iSuc m) = (n ≤ m)"
      by (simp add: inat_defs split:inat_splits, arith?)

    lemma iless_Suc_eq [simp]: "(Fin m < iSuc n) = (Fin m ≤ n)"
      by (simp add: inat_defs split:inat_splits, arith?)

    lemma not_iSuc_ilei0 [simp]: "¬ iSuc n ≤ 0"
      by (simp add: inat_defs split:inat_splits, arith?)

    lemma ile_iSuc [simp]: "n ≤ iSuc n"
      by (simp add: inat_defs split:inat_splits, arith?)

    lemma Fin_ile: "n ≤ Fin m ==> ∃k. n = Fin k"
      by (simp add: inat_defs split:inat_splits, arith?)

    lemma chain_incr: "∀i. ∃j. Y i < Y j ==> ∃j. Fin k < Y j"
      apply (induct_tac k)
       apply (simp (no_asm) only: Fin_0)
       apply (fast intro: ile_iless_trans i0_lb)
      apply (erule exE)
      apply (drule spec)
      apply (erule exE)
      apply (drule ileI1)
      apply (rule iSuc_Fin [THEN subst])
      apply (rule exI)
      apply (erule (1) ile_iless_trans)
      done

    end

### Definitions

lemmas inat_defs:

      0 == Fin 0

      iSuc i == case i of Fin n => Fin (Suc n) | ∞ => ∞

      m < n ==
      case m of Fin m1 => case n of Fin n1 => m1 < n1 | ∞ => True | ∞ => False

      m ≤ n == ¬ n < m

lemmas inat_defs:

      0 == Fin 0

      iSuc i == case i of Fin n => Fin (Suc n) | ∞ => ∞

      m < n ==
      case m of Fin m1 => case n of Fin n1 => m1 < n1 | ∞ => True | ∞ => False

      m ≤ n == ¬ n < m

lemmas inat_splits:

      P (inat_case f1.0 f2.0 x) =
      ((∀nat. x = Fin nat --> P (f1.0 nat)) ∧ (x = ∞ --> P f2.0))

      P (inat_case f1.0 f2.0 x) =
      (¬ ((∃nat. x = Fin nat ∧ ¬ P (f1.0 nat)) ∨ x = ∞ ∧ ¬ P f2.0))

lemmas inat_splits:

      P (inat_case f1.0 f2.0 x) =
      ((∀nat. x = Fin nat --> P (f1.0 nat)) ∧ (x = ∞ --> P f2.0))

      P (inat_case f1.0 f2.0 x) =
      (¬ ((∃nat. x = Fin nat ∧ ¬ P (f1.0 nat)) ∨ x = ∞ ∧ ¬ P f2.0))

### Constructors

lemma Fin_0:

      Fin 0 = 0

lemma Infty_ne_i0:

      ∞ ≠ 0

lemma i0_ne_Infty:

      0 ≠ ∞

lemma iSuc_Fin:

      iSuc (Fin n) = Fin (Suc n)

lemma iSuc_Infty:

      iSuc ∞ = ∞

lemma iSuc_ne_0:

      iSuc n ≠ 0

lemma iSuc_inject:

      (iSuc x = iSuc y) = (x = y)

### Ordering relations

lemma Infty_ilessE:

      ∞ < Fin m ==> R

lemma iless_linear:

      m < n ∨ m = n ∨ n < m

lemma iless_not_refl:

      ¬ n < n

lemma iless_trans:

      [| i < j; j < k |] ==> i < k

lemma iless_not_sym:

      n < m ==> ¬ m < n

lemma Fin_iless_mono:

      (Fin n < Fin m) = (n < m)

lemma Fin_iless_Infty:

      Fin n < ∞

lemma Infty_eq:

      (n < ∞) = (n ≠ ∞)

lemma i0_eq:

      (0 < n) = (n ≠ 0)

lemma i0_iless_iSuc:

      0 < iSuc n

lemma not_ilessi0:

      ¬ n < 0

lemma Fin_iless:

      n < Fin m ==> ∃k. n = Fin k

lemma iSuc_mono:

      (iSuc n < iSuc m) = (n < m)

lemma ile_def2:

      (m ≤ n) = (m < n ∨ m = n)

lemma ile_refl:

      n ≤ n

lemma ile_trans:

      [| i ≤ j; j ≤ k |] ==> i ≤ k

lemma ile_iless_trans:

      [| i ≤ j; j < k |] ==> i < k

lemma iless_ile_trans:

      [| i < j; j ≤ k |] ==> i < k

lemma Infty_ub:

      n ≤ ∞

lemma i0_lb:

      0 ≤ n

lemma Infty_ileE:

      ∞ ≤ Fin m ==> R

lemma Fin_ile_mono:

      (Fin n ≤ Fin m) = (n ≤ m)

lemma ilessI1:

      [| n ≤ m; n ≠ m |] ==> n < m

lemma ileI1:

      m < n ==> iSuc m ≤ n

lemma Suc_ile_eq:

      (Fin (Suc m) ≤ n) = (Fin m < n)

lemma iSuc_ile_mono:

      (iSuc n ≤ iSuc m) = (n ≤ m)

lemma iless_Suc_eq:

      (Fin m < iSuc n) = (Fin m ≤ n)

lemma not_iSuc_ilei0:

      ¬ iSuc n ≤ 0

lemma ile_iSuc:

      n ≤ iSuc n

lemma Fin_ile:

      n ≤ Fin m ==> ∃k. n = Fin k

lemma chain_incr:

      ∀i. ∃j. Y i < Y j ==> ∃j. Fin k < Y j