Theory Sprod

Up to index of Isabelle/HOLCF

theory Sprod
imports Cprod

(*  Title:      HOLCF/Sprod.thy
    Author:     Franz Regensburger and Brian Huffman
*)

header {* The type of strict products *}

theory Sprod
imports Cprod
begin

defaultsort pcpo

subsection {* Definition of strict product type *}

pcpodef (Sprod)  ('a, 'b) "**" (infixr "**" 20) =
        "{p::'a × 'b. p = ⊥ ∨ (cfst·p ≠ ⊥ ∧ csnd·p ≠ ⊥)}"
by simp_all

instance "**" :: ("{finite_po,pcpo}", "{finite_po,pcpo}") finite_po
by (rule typedef_finite_po [OF type_definition_Sprod])

instance "**" :: ("{chfin,pcpo}", "{chfin,pcpo}") chfin
by (rule typedef_chfin [OF type_definition_Sprod less_Sprod_def])

syntax (xsymbols)
  "**"   :: "[type, type] => type"        ("(_ ⊗/ _)" [21,20] 20)
syntax (HTML output)
  "**"   :: "[type, type] => type"        ("(_ ⊗/ _)" [21,20] 20)

lemma spair_lemma:
  "<strictify·(Λ b. a)·b, strictify·(Λ a. b)·a> ∈ Sprod"
by (simp add: Sprod_def strictify_conv_if)

subsection {* Definitions of constants *}

definition
  sfst :: "('a ** 'b) -> 'a" where
  "sfst = (Λ p. cfst·(Rep_Sprod p))"

definition
  ssnd :: "('a ** 'b) -> 'b" where
  "ssnd = (Λ p. csnd·(Rep_Sprod p))"

definition
  spair :: "'a -> 'b -> ('a ** 'b)" where
  "spair = (Λ a b. Abs_Sprod
             <strictify·(Λ b. a)·b, strictify·(Λ a. b)·a>)"

definition
  ssplit :: "('a -> 'b -> 'c) -> ('a ** 'b) -> 'c" where
  "ssplit = (Λ f. strictify·(Λ p. f·(sfst·p)·(ssnd·p)))"

syntax
  "@stuple" :: "['a, args] => 'a ** 'b"  ("(1'(:_,/ _:'))")
translations
  "(:x, y, z:)" == "(:x, (:y, z:):)"
  "(:x, y:)"    == "CONST spair·x·y"

translations
  "Λ(CONST spair·x·y). t" == "CONST ssplit·(Λ x y. t)"

subsection {* Case analysis *}

lemma Rep_Sprod_spair:
  "Rep_Sprod (:a, b:) = <strictify·(Λ b. a)·b, strictify·(Λ a. b)·a>"
unfolding spair_def
by (simp add: cont_Abs_Sprod Abs_Sprod_inverse spair_lemma)

lemmas Rep_Sprod_simps =
  Rep_Sprod_inject [symmetric] less_Sprod_def
  Rep_Sprod_strict Rep_Sprod_spair

lemma Exh_Sprod:
  "z = ⊥ ∨ (∃a b. z = (:a, b:) ∧ a ≠ ⊥ ∧ b ≠ ⊥)"
apply (insert Rep_Sprod [of z])
apply (simp add: Rep_Sprod_simps eq_cprod)
apply (simp add: Sprod_def)
apply (erule disjE, simp)
apply (simp add: strictify_conv_if)
apply fast
done

lemma sprodE [cases type: **]:
  "[|p = ⊥ ==> Q; !!x y. [|p = (:x, y:); x ≠ ⊥; y ≠ ⊥|] ==> Q|] ==> Q"
by (cut_tac z=p in Exh_Sprod, auto)

lemma sprod_induct [induct type: **]:
  "[|P ⊥; !!x y. [|x ≠ ⊥; y ≠ ⊥|] ==> P (:x, y:)|] ==> P x"
by (cases x, simp_all)

subsection {* Properties of @{term spair} *}

lemma spair_strict1 [simp]: "(:⊥, y:) = ⊥"
by (simp add: Rep_Sprod_simps strictify_conv_if)

lemma spair_strict2 [simp]: "(:x, ⊥:) = ⊥"
by (simp add: Rep_Sprod_simps strictify_conv_if)

lemma spair_strict_iff [simp]: "((:x, y:) = ⊥) = (x = ⊥ ∨ y = ⊥)"
by (simp add: Rep_Sprod_simps strictify_conv_if)

lemma spair_less_iff:
  "((:a, b:) \<sqsubseteq> (:c, d:)) = (a = ⊥ ∨ b = ⊥ ∨ (a \<sqsubseteq> c ∧ b \<sqsubseteq> d))"
by (simp add: Rep_Sprod_simps strictify_conv_if)

lemma spair_eq_iff:
  "((:a, b:) = (:c, d:)) =
    (a = c ∧ b = d ∨ (a = ⊥ ∨ b = ⊥) ∧ (c = ⊥ ∨ d = ⊥))"
by (simp add: Rep_Sprod_simps strictify_conv_if)

lemma spair_strict: "x = ⊥ ∨ y = ⊥ ==> (:x, y:) = ⊥"
by simp

lemma spair_strict_rev: "(:x, y:) ≠ ⊥ ==> x ≠ ⊥ ∧ y ≠ ⊥"
by simp

lemma spair_defined: "[|x ≠ ⊥; y ≠ ⊥|] ==> (:x, y:) ≠ ⊥"
by simp

lemma spair_defined_rev: "(:x, y:) = ⊥ ==> x = ⊥ ∨ y = ⊥"
by simp

lemma spair_eq:
  "[|x ≠ ⊥; y ≠ ⊥|] ==> ((:x, y:) = (:a, b:)) = (x = a ∧ y = b)"
by (simp add: spair_eq_iff)

lemma spair_inject:
  "[|x ≠ ⊥; y ≠ ⊥; (:x, y:) = (:a, b:)|] ==> x = a ∧ y = b"
by (rule spair_eq [THEN iffD1])

lemma inst_sprod_pcpo2: "UU = (:UU,UU:)"
by simp

subsection {* Properties of @{term sfst} and @{term ssnd} *}

lemma sfst_strict [simp]: "sfst·⊥ = ⊥"
by (simp add: sfst_def cont_Rep_Sprod Rep_Sprod_strict)

lemma ssnd_strict [simp]: "ssnd·⊥ = ⊥"
by (simp add: ssnd_def cont_Rep_Sprod Rep_Sprod_strict)

lemma sfst_spair [simp]: "y ≠ ⊥ ==> sfst·(:x, y:) = x"
by (simp add: sfst_def cont_Rep_Sprod Rep_Sprod_spair)

lemma ssnd_spair [simp]: "x ≠ ⊥ ==> ssnd·(:x, y:) = y"
by (simp add: ssnd_def cont_Rep_Sprod Rep_Sprod_spair)

lemma sfst_defined_iff [simp]: "(sfst·p = ⊥) = (p = ⊥)"
by (cases p, simp_all)

lemma ssnd_defined_iff [simp]: "(ssnd·p = ⊥) = (p = ⊥)"
by (cases p, simp_all)

lemma sfst_defined: "p ≠ ⊥ ==> sfst·p ≠ ⊥"
by simp

lemma ssnd_defined: "p ≠ ⊥ ==> ssnd·p ≠ ⊥"
by simp

lemma surjective_pairing_Sprod2: "(:sfst·p, ssnd·p:) = p"
by (cases p, simp_all)

lemma less_sprod: "x \<sqsubseteq> y = (sfst·x \<sqsubseteq> sfst·y ∧ ssnd·x \<sqsubseteq> ssnd·y)"
apply (simp add: less_Sprod_def sfst_def ssnd_def cont_Rep_Sprod)
apply (rule less_cprod)
done

lemma eq_sprod: "(x = y) = (sfst·x = sfst·y ∧ ssnd·x = ssnd·y)"
by (auto simp add: po_eq_conv less_sprod)

lemma spair_less:
  "[|x ≠ ⊥; y ≠ ⊥|] ==> (:x, y:) \<sqsubseteq> (:a, b:) = (x \<sqsubseteq> a ∧ y \<sqsubseteq> b)"
apply (cases "a = ⊥", simp)
apply (cases "b = ⊥", simp)
apply (simp add: less_sprod)
done

lemma sfst_less_iff: "sfst·x \<sqsubseteq> y = x \<sqsubseteq> (:y, ssnd·x:)"
apply (cases "x = ⊥", simp, cases "y = ⊥", simp)
apply (simp add: less_sprod)
done

lemma ssnd_less_iff: "ssnd·x \<sqsubseteq> y = x \<sqsubseteq> (:sfst·x, y:)"
apply (cases "x = ⊥", simp, cases "y = ⊥", simp)
apply (simp add: less_sprod)
done

subsection {* Compactness *}

lemma compact_sfst: "compact x ==> compact (sfst·x)"
by (rule compactI, simp add: sfst_less_iff)

lemma compact_ssnd: "compact x ==> compact (ssnd·x)"
by (rule compactI, simp add: ssnd_less_iff)

lemma compact_spair: "[|compact x; compact y|] ==> compact (:x, y:)"
by (rule compact_Sprod, simp add: Rep_Sprod_spair strictify_conv_if)

lemma compact_spair_iff:
  "compact (:x, y:) = (x = ⊥ ∨ y = ⊥ ∨ (compact x ∧ compact y))"
apply (safe elim!: compact_spair)
apply (drule compact_sfst, simp)
apply (drule compact_ssnd, simp)
apply simp
apply simp
done

subsection {* Properties of @{term ssplit} *}

lemma ssplit1 [simp]: "ssplit·f·⊥ = ⊥"
by (simp add: ssplit_def)

lemma ssplit2 [simp]: "[|x ≠ ⊥; y ≠ ⊥|] ==> ssplit·f·(:x, y:) = f·x·y"
by (simp add: ssplit_def)

lemma ssplit3 [simp]: "ssplit·spair·z = z"
by (cases z, simp_all)

subsection {* Strict product preserves flatness *}

instance "**" :: (flat, flat) flat
proof
  fix x y :: "'a ⊗ 'b"
  assume "x \<sqsubseteq> y" thus "x = ⊥ ∨ x = y"
    apply (induct x, simp)
    apply (induct y, simp)
    apply (simp add: spair_less_iff flat_less_iff)
    done
qed

subsection {* Strict product is a bifinite domain *}

instantiation "**" :: (bifinite, bifinite) bifinite
begin

definition
  approx_sprod_def:
    "approx = (λn. Λ(:x, y:). (:approx n·x, approx n·y:))"

instance proof
  fix i :: nat and x :: "'a ⊗ 'b"
  show "chain (approx :: nat => 'a ⊗ 'b -> 'a ⊗ 'b)"
    unfolding approx_sprod_def by simp
  show "(\<Squnion>i. approx i·x) = x"
    unfolding approx_sprod_def
    by (simp add: lub_distribs eta_cfun)
  show "approx i·(approx i·x) = approx i·x"
    unfolding approx_sprod_def
    by (simp add: ssplit_def strictify_conv_if)
  have "Rep_Sprod ` {x::'a ⊗ 'b. approx i·x = x} ⊆ {x. approx i·x = x}"
    unfolding approx_sprod_def
    apply (clarify, case_tac x)
     apply (simp add: Rep_Sprod_strict)
    apply (simp add: Rep_Sprod_spair spair_eq_iff)
    done
  hence "finite (Rep_Sprod ` {x::'a ⊗ 'b. approx i·x = x})"
    using finite_fixes_approx by (rule finite_subset)
  thus "finite {x::'a ⊗ 'b. approx i·x = x}"
    by (rule finite_imageD, simp add: inj_on_def Rep_Sprod_inject)
qed

end

lemma approx_spair [simp]:
  "approx i·(:x, y:) = (:approx i·x, approx i·y:)"
unfolding approx_sprod_def
by (simp add: ssplit_def strictify_conv_if)

end