src/HOL/HOLCF/Cfun.thy
author huffman
Sat Nov 27 16:08:10 2010 -0800 (2010-11-27)
changeset 40774 0437dbc127b3
parent 40772 src/HOLCF/Cfun.thy@c8b52f9e1680
child 40794 d28d41ee4cef
permissions -rw-r--r--
moved directory src/HOLCF to src/HOL/HOLCF;
added HOLCF theories to src/HOL/IsaMakefile;
     1 (*  Title:      HOLCF/Cfun.thy
     2     Author:     Franz Regensburger
     3     Author:     Brian Huffman
     4 *)
     5 
     6 header {* The type of continuous functions *}
     7 
     8 theory Cfun
     9 imports Cpodef Fun_Cpo Product_Cpo
    10 begin
    11 
    12 default_sort cpo
    13 
    14 subsection {* Definition of continuous function type *}
    15 
    16 cpodef ('a, 'b) cfun (infixr "->" 0) = "{f::'a => 'b. cont f}"
    17 by (auto intro: cont_const adm_cont)
    18 
    19 type_notation (xsymbols)
    20   cfun  ("(_ \<rightarrow>/ _)" [1, 0] 0)
    21 
    22 notation
    23   Rep_cfun  ("(_$/_)" [999,1000] 999)
    24 
    25 notation (xsymbols)
    26   Rep_cfun  ("(_\<cdot>/_)" [999,1000] 999)
    27 
    28 notation (HTML output)
    29   Rep_cfun  ("(_\<cdot>/_)" [999,1000] 999)
    30 
    31 subsection {* Syntax for continuous lambda abstraction *}
    32 
    33 syntax "_cabs" :: "'a"
    34 
    35 parse_translation {*
    36 (* rewrite (_cabs x t) => (Abs_cfun (%x. t)) *)
    37   [mk_binder_tr (@{syntax_const "_cabs"}, @{const_syntax Abs_cfun})];
    38 *}
    39 
    40 text {* To avoid eta-contraction of body: *}
    41 typed_print_translation {*
    42   let
    43     fun cabs_tr' _ _ [Abs abs] = let
    44           val (x,t) = atomic_abs_tr' abs
    45         in Syntax.const @{syntax_const "_cabs"} $ x $ t end
    46 
    47       | cabs_tr' _ T [t] = let
    48           val xT = domain_type (domain_type T);
    49           val abs' = ("x",xT,(incr_boundvars 1 t)$Bound 0);
    50           val (x,t') = atomic_abs_tr' abs';
    51         in Syntax.const @{syntax_const "_cabs"} $ x $ t' end;
    52 
    53   in [(@{const_syntax Abs_cfun}, cabs_tr')] end;
    54 *}
    55 
    56 text {* Syntax for nested abstractions *}
    57 
    58 syntax
    59   "_Lambda" :: "[cargs, 'a] \<Rightarrow> logic"  ("(3LAM _./ _)" [1000, 10] 10)
    60 
    61 syntax (xsymbols)
    62   "_Lambda" :: "[cargs, 'a] \<Rightarrow> logic" ("(3\<Lambda> _./ _)" [1000, 10] 10)
    63 
    64 parse_ast_translation {*
    65 (* rewrite (LAM x y z. t) => (_cabs x (_cabs y (_cabs z t))) *)
    66 (* cf. Syntax.lambda_ast_tr from src/Pure/Syntax/syn_trans.ML *)
    67   let
    68     fun Lambda_ast_tr [pats, body] =
    69           Syntax.fold_ast_p @{syntax_const "_cabs"}
    70             (Syntax.unfold_ast @{syntax_const "_cargs"} pats, body)
    71       | Lambda_ast_tr asts = raise Syntax.AST ("Lambda_ast_tr", asts);
    72   in [(@{syntax_const "_Lambda"}, Lambda_ast_tr)] end;
    73 *}
    74 
    75 print_ast_translation {*
    76 (* rewrite (_cabs x (_cabs y (_cabs z t))) => (LAM x y z. t) *)
    77 (* cf. Syntax.abs_ast_tr' from src/Pure/Syntax/syn_trans.ML *)
    78   let
    79     fun cabs_ast_tr' asts =
    80       (case Syntax.unfold_ast_p @{syntax_const "_cabs"}
    81           (Syntax.Appl (Syntax.Constant @{syntax_const "_cabs"} :: asts)) of
    82         ([], _) => raise Syntax.AST ("cabs_ast_tr'", asts)
    83       | (xs, body) => Syntax.Appl
    84           [Syntax.Constant @{syntax_const "_Lambda"},
    85            Syntax.fold_ast @{syntax_const "_cargs"} xs, body]);
    86   in [(@{syntax_const "_cabs"}, cabs_ast_tr')] end
    87 *}
    88 
    89 text {* Dummy patterns for continuous abstraction *}
    90 translations
    91   "\<Lambda> _. t" => "CONST Abs_cfun (\<lambda> _. t)"
    92 
    93 subsection {* Continuous function space is pointed *}
    94 
    95 lemma UU_cfun: "\<bottom> \<in> cfun"
    96 by (simp add: cfun_def inst_fun_pcpo)
    97 
    98 instance cfun :: (cpo, discrete_cpo) discrete_cpo
    99 by intro_classes (simp add: below_cfun_def Rep_cfun_inject)
   100 
   101 instance cfun :: (cpo, pcpo) pcpo
   102 by (rule typedef_pcpo [OF type_definition_cfun below_cfun_def UU_cfun])
   103 
   104 lemmas Rep_cfun_strict =
   105   typedef_Rep_strict [OF type_definition_cfun below_cfun_def UU_cfun]
   106 
   107 lemmas Abs_cfun_strict =
   108   typedef_Abs_strict [OF type_definition_cfun below_cfun_def UU_cfun]
   109 
   110 text {* function application is strict in its first argument *}
   111 
   112 lemma Rep_cfun_strict1 [simp]: "\<bottom>\<cdot>x = \<bottom>"
   113 by (simp add: Rep_cfun_strict)
   114 
   115 lemma LAM_strict [simp]: "(\<Lambda> x. \<bottom>) = \<bottom>"
   116 by (simp add: inst_fun_pcpo [symmetric] Abs_cfun_strict)
   117 
   118 text {* for compatibility with old HOLCF-Version *}
   119 lemma inst_cfun_pcpo: "\<bottom> = (\<Lambda> x. \<bottom>)"
   120 by simp
   121 
   122 subsection {* Basic properties of continuous functions *}
   123 
   124 text {* Beta-equality for continuous functions *}
   125 
   126 lemma Abs_cfun_inverse2: "cont f \<Longrightarrow> Rep_cfun (Abs_cfun f) = f"
   127 by (simp add: Abs_cfun_inverse cfun_def)
   128 
   129 lemma beta_cfun: "cont f \<Longrightarrow> (\<Lambda> x. f x)\<cdot>u = f u"
   130 by (simp add: Abs_cfun_inverse2)
   131 
   132 text {* Beta-reduction simproc *}
   133 
   134 text {*
   135   Given the term @{term "(\<Lambda> x. f x)\<cdot>y"}, the procedure tries to
   136   construct the theorem @{term "(\<Lambda> x. f x)\<cdot>y == f y"}.  If this
   137   theorem cannot be completely solved by the cont2cont rules, then
   138   the procedure returns the ordinary conditional @{text beta_cfun}
   139   rule.
   140 
   141   The simproc does not solve any more goals that would be solved by
   142   using @{text beta_cfun} as a simp rule.  The advantage of the
   143   simproc is that it can avoid deeply-nested calls to the simplifier
   144   that would otherwise be caused by large continuity side conditions.
   145 *}
   146 
   147 simproc_setup beta_cfun_proc ("Abs_cfun f\<cdot>x") = {*
   148   fn phi => fn ss => fn ct =>
   149     let
   150       val dest = Thm.dest_comb;
   151       val (f, x) = (apfst (snd o dest o snd o dest) o dest) ct;
   152       val [T, U] = Thm.dest_ctyp (ctyp_of_term f);
   153       val tr = instantiate' [SOME T, SOME U] [SOME f, SOME x]
   154           (mk_meta_eq @{thm beta_cfun});
   155       val rules = Cont2ContData.get (Simplifier.the_context ss);
   156       val tac = SOLVED' (REPEAT_ALL_NEW (match_tac rules));
   157     in SOME (perhaps (SINGLE (tac 1)) tr) end
   158 *}
   159 
   160 text {* Eta-equality for continuous functions *}
   161 
   162 lemma eta_cfun: "(\<Lambda> x. f\<cdot>x) = f"
   163 by (rule Rep_cfun_inverse)
   164 
   165 text {* Extensionality for continuous functions *}
   166 
   167 lemma cfun_eq_iff: "f = g \<longleftrightarrow> (\<forall>x. f\<cdot>x = g\<cdot>x)"
   168 by (simp add: Rep_cfun_inject [symmetric] fun_eq_iff)
   169 
   170 lemma cfun_eqI: "(\<And>x. f\<cdot>x = g\<cdot>x) \<Longrightarrow> f = g"
   171 by (simp add: cfun_eq_iff)
   172 
   173 text {* Extensionality wrt. ordering for continuous functions *}
   174 
   175 lemma cfun_below_iff: "f \<sqsubseteq> g \<longleftrightarrow> (\<forall>x. f\<cdot>x \<sqsubseteq> g\<cdot>x)" 
   176 by (simp add: below_cfun_def fun_below_iff)
   177 
   178 lemma cfun_belowI: "(\<And>x. f\<cdot>x \<sqsubseteq> g\<cdot>x) \<Longrightarrow> f \<sqsubseteq> g"
   179 by (simp add: cfun_below_iff)
   180 
   181 text {* Congruence for continuous function application *}
   182 
   183 lemma cfun_cong: "\<lbrakk>f = g; x = y\<rbrakk> \<Longrightarrow> f\<cdot>x = g\<cdot>y"
   184 by simp
   185 
   186 lemma cfun_fun_cong: "f = g \<Longrightarrow> f\<cdot>x = g\<cdot>x"
   187 by simp
   188 
   189 lemma cfun_arg_cong: "x = y \<Longrightarrow> f\<cdot>x = f\<cdot>y"
   190 by simp
   191 
   192 subsection {* Continuity of application *}
   193 
   194 lemma cont_Rep_cfun1: "cont (\<lambda>f. f\<cdot>x)"
   195 by (rule cont_Rep_cfun [THEN cont2cont_fun])
   196 
   197 lemma cont_Rep_cfun2: "cont (\<lambda>x. f\<cdot>x)"
   198 apply (cut_tac x=f in Rep_cfun)
   199 apply (simp add: cfun_def)
   200 done
   201 
   202 lemmas monofun_Rep_cfun = cont_Rep_cfun [THEN cont2mono]
   203 
   204 lemmas monofun_Rep_cfun1 = cont_Rep_cfun1 [THEN cont2mono, standard]
   205 lemmas monofun_Rep_cfun2 = cont_Rep_cfun2 [THEN cont2mono, standard]
   206 
   207 text {* contlub, cont properties of @{term Rep_cfun} in each argument *}
   208 
   209 lemma contlub_cfun_arg: "chain Y \<Longrightarrow> f\<cdot>(\<Squnion>i. Y i) = (\<Squnion>i. f\<cdot>(Y i))"
   210 by (rule cont_Rep_cfun2 [THEN cont2contlubE])
   211 
   212 lemma contlub_cfun_fun: "chain F \<Longrightarrow> (\<Squnion>i. F i)\<cdot>x = (\<Squnion>i. F i\<cdot>x)"
   213 by (rule cont_Rep_cfun1 [THEN cont2contlubE])
   214 
   215 text {* monotonicity of application *}
   216 
   217 lemma monofun_cfun_fun: "f \<sqsubseteq> g \<Longrightarrow> f\<cdot>x \<sqsubseteq> g\<cdot>x"
   218 by (simp add: cfun_below_iff)
   219 
   220 lemma monofun_cfun_arg: "x \<sqsubseteq> y \<Longrightarrow> f\<cdot>x \<sqsubseteq> f\<cdot>y"
   221 by (rule monofun_Rep_cfun2 [THEN monofunE])
   222 
   223 lemma monofun_cfun: "\<lbrakk>f \<sqsubseteq> g; x \<sqsubseteq> y\<rbrakk> \<Longrightarrow> f\<cdot>x \<sqsubseteq> g\<cdot>y"
   224 by (rule below_trans [OF monofun_cfun_fun monofun_cfun_arg])
   225 
   226 text {* ch2ch - rules for the type @{typ "'a -> 'b"} *}
   227 
   228 lemma chain_monofun: "chain Y \<Longrightarrow> chain (\<lambda>i. f\<cdot>(Y i))"
   229 by (erule monofun_Rep_cfun2 [THEN ch2ch_monofun])
   230 
   231 lemma ch2ch_Rep_cfunR: "chain Y \<Longrightarrow> chain (\<lambda>i. f\<cdot>(Y i))"
   232 by (rule monofun_Rep_cfun2 [THEN ch2ch_monofun])
   233 
   234 lemma ch2ch_Rep_cfunL: "chain F \<Longrightarrow> chain (\<lambda>i. (F i)\<cdot>x)"
   235 by (rule monofun_Rep_cfun1 [THEN ch2ch_monofun])
   236 
   237 lemma ch2ch_Rep_cfun [simp]:
   238   "\<lbrakk>chain F; chain Y\<rbrakk> \<Longrightarrow> chain (\<lambda>i. (F i)\<cdot>(Y i))"
   239 by (simp add: chain_def monofun_cfun)
   240 
   241 lemma ch2ch_LAM [simp]:
   242   "\<lbrakk>\<And>x. chain (\<lambda>i. S i x); \<And>i. cont (\<lambda>x. S i x)\<rbrakk> \<Longrightarrow> chain (\<lambda>i. \<Lambda> x. S i x)"
   243 by (simp add: chain_def cfun_below_iff)
   244 
   245 text {* contlub, cont properties of @{term Rep_cfun} in both arguments *}
   246 
   247 lemma contlub_cfun: 
   248   "\<lbrakk>chain F; chain Y\<rbrakk> \<Longrightarrow> (\<Squnion>i. F i)\<cdot>(\<Squnion>i. Y i) = (\<Squnion>i. F i\<cdot>(Y i))"
   249 by (simp add: contlub_cfun_fun contlub_cfun_arg diag_lub)
   250 
   251 lemma cont_cfun: 
   252   "\<lbrakk>chain F; chain Y\<rbrakk> \<Longrightarrow> range (\<lambda>i. F i\<cdot>(Y i)) <<| (\<Squnion>i. F i)\<cdot>(\<Squnion>i. Y i)"
   253 apply (rule thelubE)
   254 apply (simp only: ch2ch_Rep_cfun)
   255 apply (simp only: contlub_cfun)
   256 done
   257 
   258 lemma contlub_LAM:
   259   "\<lbrakk>\<And>x. chain (\<lambda>i. F i x); \<And>i. cont (\<lambda>x. F i x)\<rbrakk>
   260     \<Longrightarrow> (\<Lambda> x. \<Squnion>i. F i x) = (\<Squnion>i. \<Lambda> x. F i x)"
   261 apply (simp add: lub_cfun)
   262 apply (simp add: Abs_cfun_inverse2)
   263 apply (simp add: thelub_fun ch2ch_lambda)
   264 done
   265 
   266 lemmas lub_distribs = 
   267   contlub_cfun [symmetric]
   268   contlub_LAM [symmetric]
   269 
   270 text {* strictness *}
   271 
   272 lemma strictI: "f\<cdot>x = \<bottom> \<Longrightarrow> f\<cdot>\<bottom> = \<bottom>"
   273 apply (rule UU_I)
   274 apply (erule subst)
   275 apply (rule minimal [THEN monofun_cfun_arg])
   276 done
   277 
   278 text {* type @{typ "'a -> 'b"} is chain complete *}
   279 
   280 lemma lub_cfun: "chain F \<Longrightarrow> range F <<| (\<Lambda> x. \<Squnion>i. F i\<cdot>x)"
   281 by (simp only: contlub_cfun_fun [symmetric] eta_cfun thelubE)
   282 
   283 lemma thelub_cfun: "chain F \<Longrightarrow> (\<Squnion>i. F i) = (\<Lambda> x. \<Squnion>i. F i\<cdot>x)"
   284 by (rule lub_cfun [THEN lub_eqI])
   285 
   286 subsection {* Continuity simplification procedure *}
   287 
   288 text {* cont2cont lemma for @{term Rep_cfun} *}
   289 
   290 lemma cont2cont_APP [simp, cont2cont]:
   291   assumes f: "cont (\<lambda>x. f x)"
   292   assumes t: "cont (\<lambda>x. t x)"
   293   shows "cont (\<lambda>x. (f x)\<cdot>(t x))"
   294 proof -
   295   have 1: "\<And>y. cont (\<lambda>x. (f x)\<cdot>y)"
   296     using cont_Rep_cfun1 f by (rule cont_compose)
   297   show "cont (\<lambda>x. (f x)\<cdot>(t x))"
   298     using t cont_Rep_cfun2 1 by (rule cont_apply)
   299 qed
   300 
   301 text {*
   302   Two specific lemmas for the combination of LCF and HOL terms.
   303   These lemmas are needed in theories that use types like @{typ "'a \<rightarrow> 'b \<Rightarrow> 'c"}.
   304 *}
   305 
   306 lemma cont_APP_app [simp]: "\<lbrakk>cont f; cont g\<rbrakk> \<Longrightarrow> cont (\<lambda>x. ((f x)\<cdot>(g x)) s)"
   307 by (rule cont2cont_APP [THEN cont2cont_fun])
   308 
   309 lemma cont_APP_app_app [simp]: "\<lbrakk>cont f; cont g\<rbrakk> \<Longrightarrow> cont (\<lambda>x. ((f x)\<cdot>(g x)) s t)"
   310 by (rule cont_APP_app [THEN cont2cont_fun])
   311 
   312 
   313 text {* cont2mono Lemma for @{term "%x. LAM y. c1(x)(y)"} *}
   314 
   315 lemma cont2mono_LAM:
   316   "\<lbrakk>\<And>x. cont (\<lambda>y. f x y); \<And>y. monofun (\<lambda>x. f x y)\<rbrakk>
   317     \<Longrightarrow> monofun (\<lambda>x. \<Lambda> y. f x y)"
   318   unfolding monofun_def cfun_below_iff by simp
   319 
   320 text {* cont2cont Lemma for @{term "%x. LAM y. f x y"} *}
   321 
   322 text {*
   323   Not suitable as a cont2cont rule, because on nested lambdas
   324   it causes exponential blow-up in the number of subgoals.
   325 *}
   326 
   327 lemma cont2cont_LAM:
   328   assumes f1: "\<And>x. cont (\<lambda>y. f x y)"
   329   assumes f2: "\<And>y. cont (\<lambda>x. f x y)"
   330   shows "cont (\<lambda>x. \<Lambda> y. f x y)"
   331 proof (rule cont_Abs_cfun)
   332   fix x
   333   from f1 show "f x \<in> cfun" by (simp add: cfun_def)
   334   from f2 show "cont f" by (rule cont2cont_lambda)
   335 qed
   336 
   337 text {*
   338   This version does work as a cont2cont rule, since it
   339   has only a single subgoal.
   340 *}
   341 
   342 lemma cont2cont_LAM' [simp, cont2cont]:
   343   fixes f :: "'a::cpo \<Rightarrow> 'b::cpo \<Rightarrow> 'c::cpo"
   344   assumes f: "cont (\<lambda>p. f (fst p) (snd p))"
   345   shows "cont (\<lambda>x. \<Lambda> y. f x y)"
   346 using assms by (simp add: cont2cont_LAM prod_cont_iff)
   347 
   348 lemma cont2cont_LAM_discrete [simp, cont2cont]:
   349   "(\<And>y::'a::discrete_cpo. cont (\<lambda>x. f x y)) \<Longrightarrow> cont (\<lambda>x. \<Lambda> y. f x y)"
   350 by (simp add: cont2cont_LAM)
   351 
   352 subsection {* Miscellaneous *}
   353 
   354 text {* Monotonicity of @{term Abs_cfun} *}
   355 
   356 lemma monofun_LAM:
   357   "\<lbrakk>cont f; cont g; \<And>x. f x \<sqsubseteq> g x\<rbrakk> \<Longrightarrow> (\<Lambda> x. f x) \<sqsubseteq> (\<Lambda> x. g x)"
   358 by (simp add: cfun_below_iff)
   359 
   360 text {* some lemmata for functions with flat/chfin domain/range types *}
   361 
   362 lemma chfin_Rep_cfunR: "chain (Y::nat => 'a::cpo->'b::chfin)  
   363       ==> !s. ? n. (LUB i. Y i)$s = Y n$s"
   364 apply (rule allI)
   365 apply (subst contlub_cfun_fun)
   366 apply assumption
   367 apply (fast intro!: lub_eqI chfin lub_finch2 chfin2finch ch2ch_Rep_cfunL)
   368 done
   369 
   370 lemma adm_chfindom: "adm (\<lambda>(u::'a::cpo \<rightarrow> 'b::chfin). P(u\<cdot>s))"
   371 by (rule adm_subst, simp, rule adm_chfin)
   372 
   373 subsection {* Continuous injection-retraction pairs *}
   374 
   375 text {* Continuous retractions are strict. *}
   376 
   377 lemma retraction_strict:
   378   "\<forall>x. f\<cdot>(g\<cdot>x) = x \<Longrightarrow> f\<cdot>\<bottom> = \<bottom>"
   379 apply (rule UU_I)
   380 apply (drule_tac x="\<bottom>" in spec)
   381 apply (erule subst)
   382 apply (rule monofun_cfun_arg)
   383 apply (rule minimal)
   384 done
   385 
   386 lemma injection_eq:
   387   "\<forall>x. f\<cdot>(g\<cdot>x) = x \<Longrightarrow> (g\<cdot>x = g\<cdot>y) = (x = y)"
   388 apply (rule iffI)
   389 apply (drule_tac f=f in cfun_arg_cong)
   390 apply simp
   391 apply simp
   392 done
   393 
   394 lemma injection_below:
   395   "\<forall>x. f\<cdot>(g\<cdot>x) = x \<Longrightarrow> (g\<cdot>x \<sqsubseteq> g\<cdot>y) = (x \<sqsubseteq> y)"
   396 apply (rule iffI)
   397 apply (drule_tac f=f in monofun_cfun_arg)
   398 apply simp
   399 apply (erule monofun_cfun_arg)
   400 done
   401 
   402 lemma injection_defined_rev:
   403   "\<lbrakk>\<forall>x. f\<cdot>(g\<cdot>x) = x; g\<cdot>z = \<bottom>\<rbrakk> \<Longrightarrow> z = \<bottom>"
   404 apply (drule_tac f=f in cfun_arg_cong)
   405 apply (simp add: retraction_strict)
   406 done
   407 
   408 lemma injection_defined:
   409   "\<lbrakk>\<forall>x. f\<cdot>(g\<cdot>x) = x; z \<noteq> \<bottom>\<rbrakk> \<Longrightarrow> g\<cdot>z \<noteq> \<bottom>"
   410 by (erule contrapos_nn, rule injection_defined_rev)
   411 
   412 text {* a result about functions with flat codomain *}
   413 
   414 lemma flat_eqI: "\<lbrakk>(x::'a::flat) \<sqsubseteq> y; x \<noteq> \<bottom>\<rbrakk> \<Longrightarrow> x = y"
   415 by (drule ax_flat, simp)
   416 
   417 lemma flat_codom:
   418   "f\<cdot>x = (c::'b::flat) \<Longrightarrow> f\<cdot>\<bottom> = \<bottom> \<or> (\<forall>z. f\<cdot>z = c)"
   419 apply (case_tac "f\<cdot>x = \<bottom>")
   420 apply (rule disjI1)
   421 apply (rule UU_I)
   422 apply (erule_tac t="\<bottom>" in subst)
   423 apply (rule minimal [THEN monofun_cfun_arg])
   424 apply clarify
   425 apply (rule_tac a = "f\<cdot>\<bottom>" in refl [THEN box_equals])
   426 apply (erule minimal [THEN monofun_cfun_arg, THEN flat_eqI])
   427 apply (erule minimal [THEN monofun_cfun_arg, THEN flat_eqI])
   428 done
   429 
   430 subsection {* Identity and composition *}
   431 
   432 definition
   433   ID :: "'a \<rightarrow> 'a" where
   434   "ID = (\<Lambda> x. x)"
   435 
   436 definition
   437   cfcomp  :: "('b \<rightarrow> 'c) \<rightarrow> ('a \<rightarrow> 'b) \<rightarrow> 'a \<rightarrow> 'c" where
   438   oo_def: "cfcomp = (\<Lambda> f g x. f\<cdot>(g\<cdot>x))"
   439 
   440 abbreviation
   441   cfcomp_syn :: "['b \<rightarrow> 'c, 'a \<rightarrow> 'b] \<Rightarrow> 'a \<rightarrow> 'c"  (infixr "oo" 100)  where
   442   "f oo g == cfcomp\<cdot>f\<cdot>g"
   443 
   444 lemma ID1 [simp]: "ID\<cdot>x = x"
   445 by (simp add: ID_def)
   446 
   447 lemma cfcomp1: "(f oo g) = (\<Lambda> x. f\<cdot>(g\<cdot>x))"
   448 by (simp add: oo_def)
   449 
   450 lemma cfcomp2 [simp]: "(f oo g)\<cdot>x = f\<cdot>(g\<cdot>x)"
   451 by (simp add: cfcomp1)
   452 
   453 lemma cfcomp_LAM: "cont g \<Longrightarrow> f oo (\<Lambda> x. g x) = (\<Lambda> x. f\<cdot>(g x))"
   454 by (simp add: cfcomp1)
   455 
   456 lemma cfcomp_strict [simp]: "\<bottom> oo f = \<bottom>"
   457 by (simp add: cfun_eq_iff)
   458 
   459 text {*
   460   Show that interpretation of (pcpo,@{text "_->_"}) is a category.
   461   The class of objects is interpretation of syntactical class pcpo.
   462   The class of arrows  between objects @{typ 'a} and @{typ 'b} is interpret. of @{typ "'a -> 'b"}.
   463   The identity arrow is interpretation of @{term ID}.
   464   The composition of f and g is interpretation of @{text "oo"}.
   465 *}
   466 
   467 lemma ID2 [simp]: "f oo ID = f"
   468 by (rule cfun_eqI, simp)
   469 
   470 lemma ID3 [simp]: "ID oo f = f"
   471 by (rule cfun_eqI, simp)
   472 
   473 lemma assoc_oo: "f oo (g oo h) = (f oo g) oo h"
   474 by (rule cfun_eqI, simp)
   475 
   476 subsection {* Strictified functions *}
   477 
   478 default_sort pcpo
   479 
   480 definition
   481   seq :: "'a \<rightarrow> 'b \<rightarrow> 'b" where
   482   "seq = (\<Lambda> x. if x = \<bottom> then \<bottom> else ID)"
   483 
   484 lemma cont_seq: "cont (\<lambda>x. if x = \<bottom> then \<bottom> else y)"
   485 unfolding cont_def is_lub_def is_ub_def ball_simps
   486 by (simp add: lub_eq_bottom_iff)
   487 
   488 lemma seq_conv_if: "seq\<cdot>x = (if x = \<bottom> then \<bottom> else ID)"
   489 unfolding seq_def by (simp add: cont_seq)
   490 
   491 lemma seq1 [simp]: "seq\<cdot>\<bottom> = \<bottom>"
   492 by (simp add: seq_conv_if)
   493 
   494 lemma seq2 [simp]: "x \<noteq> \<bottom> \<Longrightarrow> seq\<cdot>x = ID"
   495 by (simp add: seq_conv_if)
   496 
   497 lemma seq3 [simp]: "seq\<cdot>x\<cdot>\<bottom> = \<bottom>"
   498 by (simp add: seq_conv_if)
   499 
   500 definition
   501   strictify  :: "('a \<rightarrow> 'b) \<rightarrow> 'a \<rightarrow> 'b" where
   502   "strictify = (\<Lambda> f x. seq\<cdot>x\<cdot>(f\<cdot>x))"
   503 
   504 lemma strictify_conv_if: "strictify\<cdot>f\<cdot>x = (if x = \<bottom> then \<bottom> else f\<cdot>x)"
   505 unfolding strictify_def by simp
   506 
   507 lemma strictify1 [simp]: "strictify\<cdot>f\<cdot>\<bottom> = \<bottom>"
   508 by (simp add: strictify_conv_if)
   509 
   510 lemma strictify2 [simp]: "x \<noteq> \<bottom> \<Longrightarrow> strictify\<cdot>f\<cdot>x = f\<cdot>x"
   511 by (simp add: strictify_conv_if)
   512 
   513 subsection {* Continuity of let-bindings *}
   514 
   515 lemma cont2cont_Let:
   516   assumes f: "cont (\<lambda>x. f x)"
   517   assumes g1: "\<And>y. cont (\<lambda>x. g x y)"
   518   assumes g2: "\<And>x. cont (\<lambda>y. g x y)"
   519   shows "cont (\<lambda>x. let y = f x in g x y)"
   520 unfolding Let_def using f g2 g1 by (rule cont_apply)
   521 
   522 lemma cont2cont_Let' [simp, cont2cont]:
   523   assumes f: "cont (\<lambda>x. f x)"
   524   assumes g: "cont (\<lambda>p. g (fst p) (snd p))"
   525   shows "cont (\<lambda>x. let y = f x in g x y)"
   526 using f
   527 proof (rule cont2cont_Let)
   528   fix x show "cont (\<lambda>y. g x y)"
   529     using g by (simp add: prod_cont_iff)
   530 next
   531   fix y show "cont (\<lambda>x. g x y)"
   532     using g by (simp add: prod_cont_iff)
   533 qed
   534 
   535 text {* The simple version (suggested by Joachim Breitner) is needed if
   536   the type of the defined term is not a cpo. *}
   537 
   538 lemma cont2cont_Let_simple [simp, cont2cont]:
   539   assumes "\<And>y. cont (\<lambda>x. g x y)"
   540   shows "cont (\<lambda>x. let y = t in g x y)"
   541 unfolding Let_def using assms .
   542 
   543 end