# HG changeset patch # User huffman # Date 1274730137 25200 # Node ID 3f84f1f4de64afc13189615f06464efaaaea6143 # Parent 7ffdbc24b27ff8e22f9eb6da992a467c26edb17d move HOLCF/Sum_Cpo.thy to HOLCF/Library diff -r 7ffdbc24b27f -r 3f84f1f4de64 src/HOLCF/HOLCF.thy --- a/src/HOLCF/HOLCF.thy Mon May 24 12:10:24 2010 -0700 +++ b/src/HOLCF/HOLCF.thy Mon May 24 12:42:17 2010 -0700 @@ -9,7 +9,6 @@ Main Domain Powerdomains - Sum_Cpo begin default_sort pcpo diff -r 7ffdbc24b27f -r 3f84f1f4de64 src/HOLCF/IsaMakefile --- a/src/HOLCF/IsaMakefile Mon May 24 12:10:24 2010 -0700 +++ b/src/HOLCF/IsaMakefile Mon May 24 12:42:17 2010 -0700 @@ -58,7 +58,6 @@ Representable.thy \ Sprod.thy \ Ssum.thy \ - Sum_Cpo.thy \ Tr.thy \ Universal.thy \ UpperPD.thy \ @@ -100,6 +99,7 @@ $(LOG)/HOLCF-Library.gz: $(OUT)/HOLCF \ Library/Stream.thy \ Library/Strict_Fun.thy \ + Library/Sum_Cpo.thy \ Library/HOLCF_Library.thy \ Library/ROOT.ML @$(ISABELLE_TOOL) usedir $(OUT)/HOLCF Library diff -r 7ffdbc24b27f -r 3f84f1f4de64 src/HOLCF/Library/HOLCF_Library.thy --- a/src/HOLCF/Library/HOLCF_Library.thy Mon May 24 12:10:24 2010 -0700 +++ b/src/HOLCF/Library/HOLCF_Library.thy Mon May 24 12:42:17 2010 -0700 @@ -2,6 +2,7 @@ imports Stream Strict_Fun + Sum_Cpo begin end diff -r 7ffdbc24b27f -r 3f84f1f4de64 src/HOLCF/Library/Sum_Cpo.thy --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/HOLCF/Library/Sum_Cpo.thy Mon May 24 12:42:17 2010 -0700 @@ -0,0 +1,265 @@ +(* Title: HOLCF/Sum_Cpo.thy + Author: Brian Huffman +*) + +header {* The cpo of disjoint sums *} + +theory Sum_Cpo +imports Bifinite +begin + +subsection {* Ordering on sum type *} + +instantiation "+" :: (below, below) below +begin + +definition below_sum_def: + "x \ y \ case x of + Inl a \ (case y of Inl b \ a \ b | Inr b \ False) | + Inr a \ (case y of Inl b \ False | Inr b \ a \ b)" + +instance .. +end + +lemma Inl_below_Inl [simp]: "Inl x \ Inl y = x \ y" +unfolding below_sum_def by simp + +lemma Inr_below_Inr [simp]: "Inr x \ Inr y = x \ y" +unfolding below_sum_def by simp + +lemma Inl_below_Inr [simp]: "\ Inl x \ Inr y" +unfolding below_sum_def by simp + +lemma Inr_below_Inl [simp]: "\ Inr x \ Inl y" +unfolding below_sum_def by simp + +lemma Inl_mono: "x \ y \ Inl x \ Inl y" +by simp + +lemma Inr_mono: "x \ y \ Inr x \ Inr y" +by simp + +lemma Inl_belowE: "\Inl a \ x; \b. \x = Inl b; a \ b\ \ R\ \ R" +by (cases x, simp_all) + +lemma Inr_belowE: "\Inr a \ x; \b. \x = Inr b; a \ b\ \ R\ \ R" +by (cases x, simp_all) + +lemmas sum_below_elims = Inl_belowE Inr_belowE + +lemma sum_below_cases: + "\x \ y; + \a b. \x = Inl a; y = Inl b; a \ b\ \ R; + \a b. \x = Inr a; y = Inr b; a \ b\ \ R\ + \ R" +by (cases x, safe elim!: sum_below_elims, auto) + +subsection {* Sum type is a complete partial order *} + +instance "+" :: (po, po) po +proof + fix x :: "'a + 'b" + show "x \ x" + by (induct x, simp_all) +next + fix x y :: "'a + 'b" + assume "x \ y" and "y \ x" thus "x = y" + by (induct x, auto elim!: sum_below_elims intro: below_antisym) +next + fix x y z :: "'a + 'b" + assume "x \ y" and "y \ z" thus "x \ z" + by (induct x, auto elim!: sum_below_elims intro: below_trans) +qed + +lemma monofun_inv_Inl: "monofun (\p. THE a. p = Inl a)" +by (rule monofunI, erule sum_below_cases, simp_all) + +lemma monofun_inv_Inr: "monofun (\p. THE b. p = Inr b)" +by (rule monofunI, erule sum_below_cases, simp_all) + +lemma sum_chain_cases: + assumes Y: "chain Y" + assumes A: "\A. \chain A; Y = (\i. Inl (A i))\ \ R" + assumes B: "\B. \chain B; Y = (\i. Inr (B i))\ \ R" + shows "R" + apply (cases "Y 0") + apply (rule A) + apply (rule ch2ch_monofun [OF monofun_inv_Inl Y]) + apply (rule ext) + apply (cut_tac j=i in chain_mono [OF Y le0], simp) + apply (erule Inl_belowE, simp) + apply (rule B) + apply (rule ch2ch_monofun [OF monofun_inv_Inr Y]) + apply (rule ext) + apply (cut_tac j=i in chain_mono [OF Y le0], simp) + apply (erule Inr_belowE, simp) +done + +lemma is_lub_Inl: "range S <<| x \ range (\i. Inl (S i)) <<| Inl x" + apply (rule is_lubI) + apply (rule ub_rangeI) + apply (simp add: is_ub_lub) + apply (frule ub_rangeD [where i=arbitrary]) + apply (erule Inl_belowE, simp) + apply (erule is_lub_lub) + apply (rule ub_rangeI) + apply (drule ub_rangeD, simp) +done + +lemma is_lub_Inr: "range S <<| x \ range (\i. Inr (S i)) <<| Inr x" + apply (rule is_lubI) + apply (rule ub_rangeI) + apply (simp add: is_ub_lub) + apply (frule ub_rangeD [where i=arbitrary]) + apply (erule Inr_belowE, simp) + apply (erule is_lub_lub) + apply (rule ub_rangeI) + apply (drule ub_rangeD, simp) +done + +instance "+" :: (cpo, cpo) cpo + apply intro_classes + apply (erule sum_chain_cases, safe) + apply (rule exI) + apply (rule is_lub_Inl) + apply (erule cpo_lubI) + apply (rule exI) + apply (rule is_lub_Inr) + apply (erule cpo_lubI) +done + +subsection {* Continuity of \emph{Inl}, \emph{Inr}, and case function *} + +lemma cont_Inl: "cont Inl" +by (intro contI is_lub_Inl cpo_lubI) + +lemma cont_Inr: "cont Inr" +by (intro contI is_lub_Inr cpo_lubI) + +lemmas cont2cont_Inl [simp, cont2cont] = cont_compose [OF cont_Inl] +lemmas cont2cont_Inr [simp, cont2cont] = cont_compose [OF cont_Inr] + +lemmas ch2ch_Inl [simp] = ch2ch_cont [OF cont_Inl] +lemmas ch2ch_Inr [simp] = ch2ch_cont [OF cont_Inr] + +lemmas lub_Inl = cont2contlubE [OF cont_Inl, symmetric] +lemmas lub_Inr = cont2contlubE [OF cont_Inr, symmetric] + +lemma cont_sum_case1: + assumes f: "\a. cont (\x. f x a)" + assumes g: "\b. cont (\x. g x b)" + shows "cont (\x. case y of Inl a \ f x a | Inr b \ g x b)" +by (induct y, simp add: f, simp add: g) + +lemma cont_sum_case2: "\cont f; cont g\ \ cont (sum_case f g)" +apply (rule contI) +apply (erule sum_chain_cases) +apply (simp add: cont2contlubE [OF cont_Inl, symmetric] contE) +apply (simp add: cont2contlubE [OF cont_Inr, symmetric] contE) +done + +lemma cont2cont_sum_case: + assumes f1: "\a. cont (\x. f x a)" and f2: "\x. cont (\a. f x a)" + assumes g1: "\b. cont (\x. g x b)" and g2: "\x. cont (\b. g x b)" + assumes h: "cont (\x. h x)" + shows "cont (\x. case h x of Inl a \ f x a | Inr b \ g x b)" +apply (rule cont_apply [OF h]) +apply (rule cont_sum_case2 [OF f2 g2]) +apply (rule cont_sum_case1 [OF f1 g1]) +done + +lemma cont2cont_sum_case' [simp, cont2cont]: + assumes f: "cont (\p. f (fst p) (snd p))" + assumes g: "cont (\p. g (fst p) (snd p))" + assumes h: "cont (\x. h x)" + shows "cont (\x. case h x of Inl a \ f x a | Inr b \ g x b)" +proof - + note f1 = f [THEN cont_fst_snd_D1] + note f2 = f [THEN cont_fst_snd_D2] + note g1 = g [THEN cont_fst_snd_D1] + note g2 = g [THEN cont_fst_snd_D2] + show ?thesis + apply (rule cont_apply [OF h]) + apply (rule cont_sum_case2 [OF f2 g2]) + apply (rule cont_sum_case1 [OF f1 g1]) + done +qed + +subsection {* Compactness and chain-finiteness *} + +lemma compact_Inl: "compact a \ compact (Inl a)" +apply (rule compactI2) +apply (erule sum_chain_cases, safe) +apply (simp add: lub_Inl) +apply (erule (2) compactD2) +apply (simp add: lub_Inr) +done + +lemma compact_Inr: "compact a \ compact (Inr a)" +apply (rule compactI2) +apply (erule sum_chain_cases, safe) +apply (simp add: lub_Inl) +apply (simp add: lub_Inr) +apply (erule (2) compactD2) +done + +lemma compact_Inl_rev: "compact (Inl a) \ compact a" +unfolding compact_def +by (drule adm_subst [OF cont_Inl], simp) + +lemma compact_Inr_rev: "compact (Inr a) \ compact a" +unfolding compact_def +by (drule adm_subst [OF cont_Inr], simp) + +lemma compact_Inl_iff [simp]: "compact (Inl a) = compact a" +by (safe elim!: compact_Inl compact_Inl_rev) + +lemma compact_Inr_iff [simp]: "compact (Inr a) = compact a" +by (safe elim!: compact_Inr compact_Inr_rev) + +instance "+" :: (chfin, chfin) chfin +apply intro_classes +apply (erule compact_imp_max_in_chain) +apply (case_tac "\i. Y i", simp_all) +done + +instance "+" :: (finite_po, finite_po) finite_po .. + +instance "+" :: (discrete_cpo, discrete_cpo) discrete_cpo +by intro_classes (simp add: below_sum_def split: sum.split) + +subsection {* Sum type is a bifinite domain *} + +instantiation "+" :: (profinite, profinite) profinite +begin + +definition + approx_sum_def: "approx = + (\n. \ x. case x of Inl a \ Inl (approx n\a) | Inr b \ Inr (approx n\b))" + +lemma approx_Inl [simp]: "approx n\(Inl x) = Inl (approx n\x)" + unfolding approx_sum_def by simp + +lemma approx_Inr [simp]: "approx n\(Inr x) = Inr (approx n\x)" + unfolding approx_sum_def by simp + +instance proof + fix i :: nat and x :: "'a + 'b" + show "chain (approx :: nat \ 'a + 'b \ 'a + 'b)" + unfolding approx_sum_def + by (rule ch2ch_LAM, case_tac x, simp_all) + show "(\i. approx i\x) = x" + by (induct x, simp_all add: lub_Inl lub_Inr) + show "approx i\(approx i\x) = approx i\x" + by (induct x, simp_all) + have "{x::'a + 'b. approx i\x = x} \ + {x::'a. approx i\x = x} <+> {x::'b. approx i\x = x}" + by (rule subsetI, case_tac x, simp_all add: InlI InrI) + thus "finite {x::'a + 'b. approx i\x = x}" + by (rule finite_subset, + intro finite_Plus finite_fixes_approx) +qed + +end + +end diff -r 7ffdbc24b27f -r 3f84f1f4de64 src/HOLCF/Sum_Cpo.thy --- a/src/HOLCF/Sum_Cpo.thy Mon May 24 12:10:24 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,265 +0,0 @@ -(* Title: HOLCF/Sum_Cpo.thy - Author: Brian Huffman -*) - -header {* The cpo of disjoint sums *} - -theory Sum_Cpo -imports Bifinite -begin - -subsection {* Ordering on sum type *} - -instantiation "+" :: (below, below) below -begin - -definition below_sum_def: - "x \ y \ case x of - Inl a \ (case y of Inl b \ a \ b | Inr b \ False) | - Inr a \ (case y of Inl b \ False | Inr b \ a \ b)" - -instance .. -end - -lemma Inl_below_Inl [simp]: "Inl x \ Inl y = x \ y" -unfolding below_sum_def by simp - -lemma Inr_below_Inr [simp]: "Inr x \ Inr y = x \ y" -unfolding below_sum_def by simp - -lemma Inl_below_Inr [simp]: "\ Inl x \ Inr y" -unfolding below_sum_def by simp - -lemma Inr_below_Inl [simp]: "\ Inr x \ Inl y" -unfolding below_sum_def by simp - -lemma Inl_mono: "x \ y \ Inl x \ Inl y" -by simp - -lemma Inr_mono: "x \ y \ Inr x \ Inr y" -by simp - -lemma Inl_belowE: "\Inl a \ x; \b. \x = Inl b; a \ b\ \ R\ \ R" -by (cases x, simp_all) - -lemma Inr_belowE: "\Inr a \ x; \b. \x = Inr b; a \ b\ \ R\ \ R" -by (cases x, simp_all) - -lemmas sum_below_elims = Inl_belowE Inr_belowE - -lemma sum_below_cases: - "\x \ y; - \a b. \x = Inl a; y = Inl b; a \ b\ \ R; - \a b. \x = Inr a; y = Inr b; a \ b\ \ R\ - \ R" -by (cases x, safe elim!: sum_below_elims, auto) - -subsection {* Sum type is a complete partial order *} - -instance "+" :: (po, po) po -proof - fix x :: "'a + 'b" - show "x \ x" - by (induct x, simp_all) -next - fix x y :: "'a + 'b" - assume "x \ y" and "y \ x" thus "x = y" - by (induct x, auto elim!: sum_below_elims intro: below_antisym) -next - fix x y z :: "'a + 'b" - assume "x \ y" and "y \ z" thus "x \ z" - by (induct x, auto elim!: sum_below_elims intro: below_trans) -qed - -lemma monofun_inv_Inl: "monofun (\p. THE a. p = Inl a)" -by (rule monofunI, erule sum_below_cases, simp_all) - -lemma monofun_inv_Inr: "monofun (\p. THE b. p = Inr b)" -by (rule monofunI, erule sum_below_cases, simp_all) - -lemma sum_chain_cases: - assumes Y: "chain Y" - assumes A: "\A. \chain A; Y = (\i. Inl (A i))\ \ R" - assumes B: "\B. \chain B; Y = (\i. Inr (B i))\ \ R" - shows "R" - apply (cases "Y 0") - apply (rule A) - apply (rule ch2ch_monofun [OF monofun_inv_Inl Y]) - apply (rule ext) - apply (cut_tac j=i in chain_mono [OF Y le0], simp) - apply (erule Inl_belowE, simp) - apply (rule B) - apply (rule ch2ch_monofun [OF monofun_inv_Inr Y]) - apply (rule ext) - apply (cut_tac j=i in chain_mono [OF Y le0], simp) - apply (erule Inr_belowE, simp) -done - -lemma is_lub_Inl: "range S <<| x \ range (\i. Inl (S i)) <<| Inl x" - apply (rule is_lubI) - apply (rule ub_rangeI) - apply (simp add: is_ub_lub) - apply (frule ub_rangeD [where i=arbitrary]) - apply (erule Inl_belowE, simp) - apply (erule is_lub_lub) - apply (rule ub_rangeI) - apply (drule ub_rangeD, simp) -done - -lemma is_lub_Inr: "range S <<| x \ range (\i. Inr (S i)) <<| Inr x" - apply (rule is_lubI) - apply (rule ub_rangeI) - apply (simp add: is_ub_lub) - apply (frule ub_rangeD [where i=arbitrary]) - apply (erule Inr_belowE, simp) - apply (erule is_lub_lub) - apply (rule ub_rangeI) - apply (drule ub_rangeD, simp) -done - -instance "+" :: (cpo, cpo) cpo - apply intro_classes - apply (erule sum_chain_cases, safe) - apply (rule exI) - apply (rule is_lub_Inl) - apply (erule cpo_lubI) - apply (rule exI) - apply (rule is_lub_Inr) - apply (erule cpo_lubI) -done - -subsection {* Continuity of \emph{Inl}, \emph{Inr}, and case function *} - -lemma cont_Inl: "cont Inl" -by (intro contI is_lub_Inl cpo_lubI) - -lemma cont_Inr: "cont Inr" -by (intro contI is_lub_Inr cpo_lubI) - -lemmas cont2cont_Inl [simp, cont2cont] = cont_compose [OF cont_Inl] -lemmas cont2cont_Inr [simp, cont2cont] = cont_compose [OF cont_Inr] - -lemmas ch2ch_Inl [simp] = ch2ch_cont [OF cont_Inl] -lemmas ch2ch_Inr [simp] = ch2ch_cont [OF cont_Inr] - -lemmas lub_Inl = cont2contlubE [OF cont_Inl, symmetric] -lemmas lub_Inr = cont2contlubE [OF cont_Inr, symmetric] - -lemma cont_sum_case1: - assumes f: "\a. cont (\x. f x a)" - assumes g: "\b. cont (\x. g x b)" - shows "cont (\x. case y of Inl a \ f x a | Inr b \ g x b)" -by (induct y, simp add: f, simp add: g) - -lemma cont_sum_case2: "\cont f; cont g\ \ cont (sum_case f g)" -apply (rule contI) -apply (erule sum_chain_cases) -apply (simp add: cont2contlubE [OF cont_Inl, symmetric] contE) -apply (simp add: cont2contlubE [OF cont_Inr, symmetric] contE) -done - -lemma cont2cont_sum_case: - assumes f1: "\a. cont (\x. f x a)" and f2: "\x. cont (\a. f x a)" - assumes g1: "\b. cont (\x. g x b)" and g2: "\x. cont (\b. g x b)" - assumes h: "cont (\x. h x)" - shows "cont (\x. case h x of Inl a \ f x a | Inr b \ g x b)" -apply (rule cont_apply [OF h]) -apply (rule cont_sum_case2 [OF f2 g2]) -apply (rule cont_sum_case1 [OF f1 g1]) -done - -lemma cont2cont_sum_case' [simp, cont2cont]: - assumes f: "cont (\p. f (fst p) (snd p))" - assumes g: "cont (\p. g (fst p) (snd p))" - assumes h: "cont (\x. h x)" - shows "cont (\x. case h x of Inl a \ f x a | Inr b \ g x b)" -proof - - note f1 = f [THEN cont_fst_snd_D1] - note f2 = f [THEN cont_fst_snd_D2] - note g1 = g [THEN cont_fst_snd_D1] - note g2 = g [THEN cont_fst_snd_D2] - show ?thesis - apply (rule cont_apply [OF h]) - apply (rule cont_sum_case2 [OF f2 g2]) - apply (rule cont_sum_case1 [OF f1 g1]) - done -qed - -subsection {* Compactness and chain-finiteness *} - -lemma compact_Inl: "compact a \ compact (Inl a)" -apply (rule compactI2) -apply (erule sum_chain_cases, safe) -apply (simp add: lub_Inl) -apply (erule (2) compactD2) -apply (simp add: lub_Inr) -done - -lemma compact_Inr: "compact a \ compact (Inr a)" -apply (rule compactI2) -apply (erule sum_chain_cases, safe) -apply (simp add: lub_Inl) -apply (simp add: lub_Inr) -apply (erule (2) compactD2) -done - -lemma compact_Inl_rev: "compact (Inl a) \ compact a" -unfolding compact_def -by (drule adm_subst [OF cont_Inl], simp) - -lemma compact_Inr_rev: "compact (Inr a) \ compact a" -unfolding compact_def -by (drule adm_subst [OF cont_Inr], simp) - -lemma compact_Inl_iff [simp]: "compact (Inl a) = compact a" -by (safe elim!: compact_Inl compact_Inl_rev) - -lemma compact_Inr_iff [simp]: "compact (Inr a) = compact a" -by (safe elim!: compact_Inr compact_Inr_rev) - -instance "+" :: (chfin, chfin) chfin -apply intro_classes -apply (erule compact_imp_max_in_chain) -apply (case_tac "\i. Y i", simp_all) -done - -instance "+" :: (finite_po, finite_po) finite_po .. - -instance "+" :: (discrete_cpo, discrete_cpo) discrete_cpo -by intro_classes (simp add: below_sum_def split: sum.split) - -subsection {* Sum type is a bifinite domain *} - -instantiation "+" :: (profinite, profinite) profinite -begin - -definition - approx_sum_def: "approx = - (\n. \ x. case x of Inl a \ Inl (approx n\a) | Inr b \ Inr (approx n\b))" - -lemma approx_Inl [simp]: "approx n\(Inl x) = Inl (approx n\x)" - unfolding approx_sum_def by simp - -lemma approx_Inr [simp]: "approx n\(Inr x) = Inr (approx n\x)" - unfolding approx_sum_def by simp - -instance proof - fix i :: nat and x :: "'a + 'b" - show "chain (approx :: nat \ 'a + 'b \ 'a + 'b)" - unfolding approx_sum_def - by (rule ch2ch_LAM, case_tac x, simp_all) - show "(\i. approx i\x) = x" - by (induct x, simp_all add: lub_Inl lub_Inr) - show "approx i\(approx i\x) = approx i\x" - by (induct x, simp_all) - have "{x::'a + 'b. approx i\x = x} \ - {x::'a. approx i\x = x} <+> {x::'b. approx i\x = x}" - by (rule subsetI, case_tac x, simp_all add: InlI InrI) - thus "finite {x::'a + 'b. approx i\x = x}" - by (rule finite_subset, - intro finite_Plus finite_fixes_approx) -qed - -end - -end