--- a/src/HOLCF/Fixrec.thy Mon May 24 09:32:52 2010 -0700
+++ b/src/HOLCF/Fixrec.thy Mon May 24 11:29:49 2010 -0700
@@ -64,7 +64,6 @@
"case m of XCONST fail \<Rightarrow> t1 | XCONST succeed\<cdot>x \<Rightarrow> t2"
== "CONST match_case\<cdot>t1\<cdot>(\<Lambda> x. t2)\<cdot>m"
-
subsubsection {* Run operator *}
definition
@@ -109,334 +108,6 @@
lemma mplus_assoc: "(x +++ y) +++ z = x +++ (y +++ z)"
by (cases x, simp_all)
-subsubsection {* Fatbar combinator *}
-
-definition
- fatbar :: "('a \<rightarrow> 'b match) \<rightarrow> ('a \<rightarrow> 'b match) \<rightarrow> ('a \<rightarrow> 'b match)" where
- "fatbar = (\<Lambda> a b x. a\<cdot>x +++ b\<cdot>x)"
-
-abbreviation
- fatbar_syn :: "['a \<rightarrow> 'b match, 'a \<rightarrow> 'b match] \<Rightarrow> 'a \<rightarrow> 'b match" (infixr "\<parallel>" 60) where
- "m1 \<parallel> m2 == fatbar\<cdot>m1\<cdot>m2"
-
-lemma fatbar1: "m\<cdot>x = \<bottom> \<Longrightarrow> (m \<parallel> ms)\<cdot>x = \<bottom>"
-by (simp add: fatbar_def)
-
-lemma fatbar2: "m\<cdot>x = fail \<Longrightarrow> (m \<parallel> ms)\<cdot>x = ms\<cdot>x"
-by (simp add: fatbar_def)
-
-lemma fatbar3: "m\<cdot>x = succeed\<cdot>y \<Longrightarrow> (m \<parallel> ms)\<cdot>x = succeed\<cdot>y"
-by (simp add: fatbar_def)
-
-lemmas fatbar_simps = fatbar1 fatbar2 fatbar3
-
-lemma run_fatbar1: "m\<cdot>x = \<bottom> \<Longrightarrow> run\<cdot>((m \<parallel> ms)\<cdot>x) = \<bottom>"
-by (simp add: fatbar_def)
-
-lemma run_fatbar2: "m\<cdot>x = fail \<Longrightarrow> run\<cdot>((m \<parallel> ms)\<cdot>x) = run\<cdot>(ms\<cdot>x)"
-by (simp add: fatbar_def)
-
-lemma run_fatbar3: "m\<cdot>x = succeed\<cdot>y \<Longrightarrow> run\<cdot>((m \<parallel> ms)\<cdot>x) = y"
-by (simp add: fatbar_def)
-
-lemmas run_fatbar_simps [simp] = run_fatbar1 run_fatbar2 run_fatbar3
-
-subsection {* Case branch combinator *}
-
-definition
- branch :: "('a \<rightarrow> 'b match) \<Rightarrow> ('b \<rightarrow> 'c) \<rightarrow> ('a \<rightarrow> 'c match)" where
- "branch p \<equiv> \<Lambda> r x. match_case\<cdot>fail\<cdot>(\<Lambda> y. succeed\<cdot>(r\<cdot>y))\<cdot>(p\<cdot>x)"
-
-lemma branch_simps:
- "p\<cdot>x = \<bottom> \<Longrightarrow> branch p\<cdot>r\<cdot>x = \<bottom>"
- "p\<cdot>x = fail \<Longrightarrow> branch p\<cdot>r\<cdot>x = fail"
- "p\<cdot>x = succeed\<cdot>y \<Longrightarrow> branch p\<cdot>r\<cdot>x = succeed\<cdot>(r\<cdot>y)"
-by (simp_all add: branch_def)
-
-lemma branch_succeed [simp]: "branch succeed\<cdot>r\<cdot>x = succeed\<cdot>(r\<cdot>x)"
-by (simp add: branch_def)
-
-subsubsection {* Cases operator *}
-
-definition
- cases :: "'a match \<rightarrow> 'a::pcpo" where
- "cases = match_case\<cdot>\<bottom>\<cdot>ID"
-
-text {* rewrite rules for cases *}
-
-lemma cases_strict [simp]: "cases\<cdot>\<bottom> = \<bottom>"
-by (simp add: cases_def)
-
-lemma cases_fail [simp]: "cases\<cdot>fail = \<bottom>"
-by (simp add: cases_def)
-
-lemma cases_succeed [simp]: "cases\<cdot>(succeed\<cdot>x) = x"
-by (simp add: cases_def)
-
-subsection {* Case syntax *}
-
-nonterminals
- Case_syn Cases_syn
-
-syntax
- "_Case_syntax":: "['a, Cases_syn] => 'b" ("(Case _ of/ _)" 10)
- "_Case1" :: "['a, 'b] => Case_syn" ("(2_ =>/ _)" 10)
- "" :: "Case_syn => Cases_syn" ("_")
- "_Case2" :: "[Case_syn, Cases_syn] => Cases_syn" ("_/ | _")
-
-syntax (xsymbols)
- "_Case1" :: "['a, 'b] => Case_syn" ("(2_ \<Rightarrow>/ _)" 10)
-
-translations
- "_Case_syntax x ms" == "CONST Fixrec.cases\<cdot>(ms\<cdot>x)"
- "_Case2 m ms" == "m \<parallel> ms"
-
-text {* Parsing Case expressions *}
-
-syntax
- "_pat" :: "'a"
- "_variable" :: "'a"
- "_noargs" :: "'a"
-
-translations
- "_Case1 p r" => "CONST branch (_pat p)\<cdot>(_variable p r)"
- "_variable (_args x y) r" => "CONST csplit\<cdot>(_variable x (_variable y r))"
- "_variable _noargs r" => "CONST unit_when\<cdot>r"
-
-parse_translation {*
-(* rewrite (_pat x) => (succeed) *)
-(* rewrite (_variable x t) => (Abs_CFun (%x. t)) *)
- [(@{syntax_const "_pat"}, fn _ => Syntax.const @{const_syntax Fixrec.succeed}),
- mk_binder_tr (@{syntax_const "_variable"}, @{const_syntax Abs_CFun})];
-*}
-
-text {* Printing Case expressions *}
-
-syntax
- "_match" :: "'a"
-
-print_translation {*
- let
- fun dest_LAM (Const (@{const_syntax Rep_CFun},_) $ Const (@{const_syntax unit_when},_) $ t) =
- (Syntax.const @{syntax_const "_noargs"}, t)
- | dest_LAM (Const (@{const_syntax Rep_CFun},_) $ Const (@{const_syntax csplit},_) $ t) =
- let
- val (v1, t1) = dest_LAM t;
- val (v2, t2) = dest_LAM t1;
- in (Syntax.const @{syntax_const "_args"} $ v1 $ v2, t2) end
- | dest_LAM (Const (@{const_syntax Abs_CFun},_) $ t) =
- let
- val abs =
- case t of Abs abs => abs
- | _ => ("x", dummyT, incr_boundvars 1 t $ Bound 0);
- val (x, t') = atomic_abs_tr' abs;
- in (Syntax.const @{syntax_const "_variable"} $ x, t') end
- | dest_LAM _ = raise Match; (* too few vars: abort translation *)
-
- fun Case1_tr' [Const(@{const_syntax branch},_) $ p, r] =
- let val (v, t) = dest_LAM r in
- Syntax.const @{syntax_const "_Case1"} $
- (Syntax.const @{syntax_const "_match"} $ p $ v) $ t
- end;
-
- in [(@{const_syntax Rep_CFun}, Case1_tr')] end;
-*}
-
-translations
- "x" <= "_match (CONST Fixrec.succeed) (_variable x)"
-
-
-subsection {* Pattern combinators for data constructors *}
-
-types ('a, 'b) pat = "'a \<rightarrow> 'b match"
-
-definition
- cpair_pat :: "('a, 'c) pat \<Rightarrow> ('b, 'd) pat \<Rightarrow> ('a \<times> 'b, 'c \<times> 'd) pat" where
- "cpair_pat p1 p2 = (\<Lambda>(x, y).
- match_case\<cdot>fail\<cdot>(\<Lambda> a. match_case\<cdot>fail\<cdot>(\<Lambda> b. succeed\<cdot>(a, b))\<cdot>(p2\<cdot>y))\<cdot>(p1\<cdot>x))"
-
-definition
- spair_pat ::
- "('a, 'c) pat \<Rightarrow> ('b, 'd) pat \<Rightarrow> ('a::pcpo \<otimes> 'b::pcpo, 'c \<times> 'd) pat" where
- "spair_pat p1 p2 = (\<Lambda>(:x, y:). cpair_pat p1 p2\<cdot>(x, y))"
-
-definition
- sinl_pat :: "('a, 'c) pat \<Rightarrow> ('a::pcpo \<oplus> 'b::pcpo, 'c) pat" where
- "sinl_pat p = sscase\<cdot>p\<cdot>(\<Lambda> x. fail)"
-
-definition
- sinr_pat :: "('b, 'c) pat \<Rightarrow> ('a::pcpo \<oplus> 'b::pcpo, 'c) pat" where
- "sinr_pat p = sscase\<cdot>(\<Lambda> x. fail)\<cdot>p"
-
-definition
- up_pat :: "('a, 'b) pat \<Rightarrow> ('a u, 'b) pat" where
- "up_pat p = fup\<cdot>p"
-
-definition
- TT_pat :: "(tr, unit) pat" where
- "TT_pat = (\<Lambda> b. If b then succeed\<cdot>() else fail fi)"
-
-definition
- FF_pat :: "(tr, unit) pat" where
- "FF_pat = (\<Lambda> b. If b then fail else succeed\<cdot>() fi)"
-
-definition
- ONE_pat :: "(one, unit) pat" where
- "ONE_pat = (\<Lambda> ONE. succeed\<cdot>())"
-
-text {* Parse translations (patterns) *}
-translations
- "_pat (XCONST Pair x y)" => "CONST cpair_pat (_pat x) (_pat y)"
- "_pat (XCONST spair\<cdot>x\<cdot>y)" => "CONST spair_pat (_pat x) (_pat y)"
- "_pat (XCONST sinl\<cdot>x)" => "CONST sinl_pat (_pat x)"
- "_pat (XCONST sinr\<cdot>x)" => "CONST sinr_pat (_pat x)"
- "_pat (XCONST up\<cdot>x)" => "CONST up_pat (_pat x)"
- "_pat (XCONST TT)" => "CONST TT_pat"
- "_pat (XCONST FF)" => "CONST FF_pat"
- "_pat (XCONST ONE)" => "CONST ONE_pat"
-
-text {* CONST version is also needed for constructors with special syntax *}
-translations
- "_pat (CONST Pair x y)" => "CONST cpair_pat (_pat x) (_pat y)"
- "_pat (CONST spair\<cdot>x\<cdot>y)" => "CONST spair_pat (_pat x) (_pat y)"
-
-text {* Parse translations (variables) *}
-translations
- "_variable (XCONST Pair x y) r" => "_variable (_args x y) r"
- "_variable (XCONST spair\<cdot>x\<cdot>y) r" => "_variable (_args x y) r"
- "_variable (XCONST sinl\<cdot>x) r" => "_variable x r"
- "_variable (XCONST sinr\<cdot>x) r" => "_variable x r"
- "_variable (XCONST up\<cdot>x) r" => "_variable x r"
- "_variable (XCONST TT) r" => "_variable _noargs r"
- "_variable (XCONST FF) r" => "_variable _noargs r"
- "_variable (XCONST ONE) r" => "_variable _noargs r"
-
-translations
- "_variable (CONST Pair x y) r" => "_variable (_args x y) r"
- "_variable (CONST spair\<cdot>x\<cdot>y) r" => "_variable (_args x y) r"
-
-text {* Print translations *}
-translations
- "CONST Pair (_match p1 v1) (_match p2 v2)"
- <= "_match (CONST cpair_pat p1 p2) (_args v1 v2)"
- "CONST spair\<cdot>(_match p1 v1)\<cdot>(_match p2 v2)"
- <= "_match (CONST spair_pat p1 p2) (_args v1 v2)"
- "CONST sinl\<cdot>(_match p1 v1)" <= "_match (CONST sinl_pat p1) v1"
- "CONST sinr\<cdot>(_match p1 v1)" <= "_match (CONST sinr_pat p1) v1"
- "CONST up\<cdot>(_match p1 v1)" <= "_match (CONST up_pat p1) v1"
- "CONST TT" <= "_match (CONST TT_pat) _noargs"
- "CONST FF" <= "_match (CONST FF_pat) _noargs"
- "CONST ONE" <= "_match (CONST ONE_pat) _noargs"
-
-lemma cpair_pat1:
- "branch p\<cdot>r\<cdot>x = \<bottom> \<Longrightarrow> branch (cpair_pat p q)\<cdot>(csplit\<cdot>r)\<cdot>(x, y) = \<bottom>"
-apply (simp add: branch_def cpair_pat_def)
-apply (cases "p\<cdot>x", simp_all)
-done
-
-lemma cpair_pat2:
- "branch p\<cdot>r\<cdot>x = fail \<Longrightarrow> branch (cpair_pat p q)\<cdot>(csplit\<cdot>r)\<cdot>(x, y) = fail"
-apply (simp add: branch_def cpair_pat_def)
-apply (cases "p\<cdot>x", simp_all)
-done
-
-lemma cpair_pat3:
- "branch p\<cdot>r\<cdot>x = succeed\<cdot>s \<Longrightarrow>
- branch (cpair_pat p q)\<cdot>(csplit\<cdot>r)\<cdot>(x, y) = branch q\<cdot>s\<cdot>y"
-apply (simp add: branch_def cpair_pat_def)
-apply (cases "p\<cdot>x", simp_all)
-apply (cases "q\<cdot>y", simp_all)
-done
-
-lemmas cpair_pat [simp] =
- cpair_pat1 cpair_pat2 cpair_pat3
-
-lemma spair_pat [simp]:
- "branch (spair_pat p1 p2)\<cdot>r\<cdot>\<bottom> = \<bottom>"
- "\<lbrakk>x \<noteq> \<bottom>; y \<noteq> \<bottom>\<rbrakk>
- \<Longrightarrow> branch (spair_pat p1 p2)\<cdot>r\<cdot>(:x, y:) =
- branch (cpair_pat p1 p2)\<cdot>r\<cdot>(x, y)"
-by (simp_all add: branch_def spair_pat_def)
-
-lemma sinl_pat [simp]:
- "branch (sinl_pat p)\<cdot>r\<cdot>\<bottom> = \<bottom>"
- "x \<noteq> \<bottom> \<Longrightarrow> branch (sinl_pat p)\<cdot>r\<cdot>(sinl\<cdot>x) = branch p\<cdot>r\<cdot>x"
- "y \<noteq> \<bottom> \<Longrightarrow> branch (sinl_pat p)\<cdot>r\<cdot>(sinr\<cdot>y) = fail"
-by (simp_all add: branch_def sinl_pat_def)
-
-lemma sinr_pat [simp]:
- "branch (sinr_pat p)\<cdot>r\<cdot>\<bottom> = \<bottom>"
- "x \<noteq> \<bottom> \<Longrightarrow> branch (sinr_pat p)\<cdot>r\<cdot>(sinl\<cdot>x) = fail"
- "y \<noteq> \<bottom> \<Longrightarrow> branch (sinr_pat p)\<cdot>r\<cdot>(sinr\<cdot>y) = branch p\<cdot>r\<cdot>y"
-by (simp_all add: branch_def sinr_pat_def)
-
-lemma up_pat [simp]:
- "branch (up_pat p)\<cdot>r\<cdot>\<bottom> = \<bottom>"
- "branch (up_pat p)\<cdot>r\<cdot>(up\<cdot>x) = branch p\<cdot>r\<cdot>x"
-by (simp_all add: branch_def up_pat_def)
-
-lemma TT_pat [simp]:
- "branch TT_pat\<cdot>(unit_when\<cdot>r)\<cdot>\<bottom> = \<bottom>"
- "branch TT_pat\<cdot>(unit_when\<cdot>r)\<cdot>TT = succeed\<cdot>r"
- "branch TT_pat\<cdot>(unit_when\<cdot>r)\<cdot>FF = fail"
-by (simp_all add: branch_def TT_pat_def)
-
-lemma FF_pat [simp]:
- "branch FF_pat\<cdot>(unit_when\<cdot>r)\<cdot>\<bottom> = \<bottom>"
- "branch FF_pat\<cdot>(unit_when\<cdot>r)\<cdot>TT = fail"
- "branch FF_pat\<cdot>(unit_when\<cdot>r)\<cdot>FF = succeed\<cdot>r"
-by (simp_all add: branch_def FF_pat_def)
-
-lemma ONE_pat [simp]:
- "branch ONE_pat\<cdot>(unit_when\<cdot>r)\<cdot>\<bottom> = \<bottom>"
- "branch ONE_pat\<cdot>(unit_when\<cdot>r)\<cdot>ONE = succeed\<cdot>r"
-by (simp_all add: branch_def ONE_pat_def)
-
-
-subsection {* Wildcards, as-patterns, and lazy patterns *}
-
-definition
- wild_pat :: "'a \<rightarrow> unit match" where
- "wild_pat = (\<Lambda> x. succeed\<cdot>())"
-
-definition
- as_pat :: "('a \<rightarrow> 'b match) \<Rightarrow> 'a \<rightarrow> ('a \<times> 'b) match" where
- "as_pat p = (\<Lambda> x. match_case\<cdot>fail\<cdot>(\<Lambda> a. succeed\<cdot>(x, a))\<cdot>(p\<cdot>x))"
-
-definition
- lazy_pat :: "('a \<rightarrow> 'b::pcpo match) \<Rightarrow> ('a \<rightarrow> 'b match)" where
- "lazy_pat p = (\<Lambda> x. succeed\<cdot>(cases\<cdot>(p\<cdot>x)))"
-
-text {* Parse translations (patterns) *}
-translations
- "_pat _" => "CONST wild_pat"
-
-text {* Parse translations (variables) *}
-translations
- "_variable _ r" => "_variable _noargs r"
-
-text {* Print translations *}
-translations
- "_" <= "_match (CONST wild_pat) _noargs"
-
-lemma wild_pat [simp]: "branch wild_pat\<cdot>(unit_when\<cdot>r)\<cdot>x = succeed\<cdot>r"
-by (simp add: branch_def wild_pat_def)
-
-lemma as_pat [simp]:
- "branch (as_pat p)\<cdot>(csplit\<cdot>r)\<cdot>x = branch p\<cdot>(r\<cdot>x)\<cdot>x"
-apply (simp add: branch_def as_pat_def)
-apply (cases "p\<cdot>x", simp_all)
-done
-
-lemma lazy_pat [simp]:
- "branch p\<cdot>r\<cdot>x = \<bottom> \<Longrightarrow> branch (lazy_pat p)\<cdot>r\<cdot>x = succeed\<cdot>(r\<cdot>\<bottom>)"
- "branch p\<cdot>r\<cdot>x = fail \<Longrightarrow> branch (lazy_pat p)\<cdot>r\<cdot>x = succeed\<cdot>(r\<cdot>\<bottom>)"
- "branch p\<cdot>r\<cdot>x = succeed\<cdot>s \<Longrightarrow> branch (lazy_pat p)\<cdot>r\<cdot>x = succeed\<cdot>s"
-apply (simp_all add: branch_def lazy_pat_def)
-apply (cases "p\<cdot>x", simp_all)+
-done
-
-
subsection {* Match functions for built-in types *}
default_sort pcpo
@@ -584,6 +255,6 @@
(@{const_name UU}, @{const_name match_UU}) ]
*}
-hide_const (open) succeed fail run cases
+hide_const (open) succeed fail run
end