src/HOL/HOLCF/Cfun.thy
author huffman
Mon Dec 06 10:08:33 2010 -0800 (2010-12-06)
changeset 41030 ff7d177128ef
parent 41027 c599955d9806
child 41031 9883d1417ce1
permissions -rw-r--r--
rename lub_fun -> is_lub_fun, thelub_fun -> lub_fun
     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 [OF cont_id, 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 lub_APP:
   248   "\<lbrakk>chain F; chain Y\<rbrakk> \<Longrightarrow> (\<Squnion>i. F i\<cdot>(Y i)) = (\<Squnion>i. F i)\<cdot>(\<Squnion>i. 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: lub_APP)
   256 done
   257 
   258 lemma lub_LAM:
   259   "\<lbrakk>\<And>x. chain (\<lambda>i. F i x); \<And>i. cont (\<lambda>x. F i x)\<rbrakk>
   260     \<Longrightarrow> (\<Squnion>i. \<Lambda> x. F i x) = (\<Lambda> x. \<Squnion>i. F i x)"
   261 apply (simp add: lub_cfun)
   262 apply (simp add: Abs_cfun_inverse2)
   263 apply (simp add: lub_fun ch2ch_lambda)
   264 done
   265 
   266 lemmas lub_distribs = lub_APP lub_LAM
   267 
   268 text {* strictness *}
   269 
   270 lemma strictI: "f\<cdot>x = \<bottom> \<Longrightarrow> f\<cdot>\<bottom> = \<bottom>"
   271 apply (rule UU_I)
   272 apply (erule subst)
   273 apply (rule minimal [THEN monofun_cfun_arg])
   274 done
   275 
   276 text {* type @{typ "'a -> 'b"} is chain complete *}
   277 
   278 lemma lub_cfun: "chain F \<Longrightarrow> range F <<| (\<Lambda> x. \<Squnion>i. F i\<cdot>x)"
   279 by (simp only: contlub_cfun_fun [symmetric] eta_cfun cpo_lubI)
   280 
   281 lemma thelub_cfun: "chain F \<Longrightarrow> (\<Squnion>i. F i) = (\<Lambda> x. \<Squnion>i. F i\<cdot>x)"
   282 by (rule lub_cfun [THEN lub_eqI])
   283 
   284 subsection {* Continuity simplification procedure *}
   285 
   286 text {* cont2cont lemma for @{term Rep_cfun} *}
   287 
   288 lemma cont2cont_APP [simp, cont2cont]:
   289   assumes f: "cont (\<lambda>x. f x)"
   290   assumes t: "cont (\<lambda>x. t x)"
   291   shows "cont (\<lambda>x. (f x)\<cdot>(t x))"
   292 proof -
   293   have 1: "\<And>y. cont (\<lambda>x. (f x)\<cdot>y)"
   294     using cont_Rep_cfun1 f by (rule cont_compose)
   295   show "cont (\<lambda>x. (f x)\<cdot>(t x))"
   296     using t cont_Rep_cfun2 1 by (rule cont_apply)
   297 qed
   298 
   299 text {*
   300   Two specific lemmas for the combination of LCF and HOL terms.
   301   These lemmas are needed in theories that use types like @{typ "'a \<rightarrow> 'b \<Rightarrow> 'c"}.
   302 *}
   303 
   304 lemma cont_APP_app [simp]: "\<lbrakk>cont f; cont g\<rbrakk> \<Longrightarrow> cont (\<lambda>x. ((f x)\<cdot>(g x)) s)"
   305 by (rule cont2cont_APP [THEN cont2cont_fun])
   306 
   307 lemma cont_APP_app_app [simp]: "\<lbrakk>cont f; cont g\<rbrakk> \<Longrightarrow> cont (\<lambda>x. ((f x)\<cdot>(g x)) s t)"
   308 by (rule cont_APP_app [THEN cont2cont_fun])
   309 
   310 
   311 text {* cont2mono Lemma for @{term "%x. LAM y. c1(x)(y)"} *}
   312 
   313 lemma cont2mono_LAM:
   314   "\<lbrakk>\<And>x. cont (\<lambda>y. f x y); \<And>y. monofun (\<lambda>x. f x y)\<rbrakk>
   315     \<Longrightarrow> monofun (\<lambda>x. \<Lambda> y. f x y)"
   316   unfolding monofun_def cfun_below_iff by simp
   317 
   318 text {* cont2cont Lemma for @{term "%x. LAM y. f x y"} *}
   319 
   320 text {*
   321   Not suitable as a cont2cont rule, because on nested lambdas
   322   it causes exponential blow-up in the number of subgoals.
   323 *}
   324 
   325 lemma cont2cont_LAM:
   326   assumes f1: "\<And>x. cont (\<lambda>y. f x y)"
   327   assumes f2: "\<And>y. cont (\<lambda>x. f x y)"
   328   shows "cont (\<lambda>x. \<Lambda> y. f x y)"
   329 proof (rule cont_Abs_cfun)
   330   fix x
   331   from f1 show "f x \<in> cfun" by (simp add: cfun_def)
   332   from f2 show "cont f" by (rule cont2cont_lambda)
   333 qed
   334 
   335 text {*
   336   This version does work as a cont2cont rule, since it
   337   has only a single subgoal.
   338 *}
   339 
   340 lemma cont2cont_LAM' [simp, cont2cont]:
   341   fixes f :: "'a::cpo \<Rightarrow> 'b::cpo \<Rightarrow> 'c::cpo"
   342   assumes f: "cont (\<lambda>p. f (fst p) (snd p))"
   343   shows "cont (\<lambda>x. \<Lambda> y. f x y)"
   344 using assms by (simp add: cont2cont_LAM prod_cont_iff)
   345 
   346 lemma cont2cont_LAM_discrete [simp, cont2cont]:
   347   "(\<And>y::'a::discrete_cpo. cont (\<lambda>x. f x y)) \<Longrightarrow> cont (\<lambda>x. \<Lambda> y. f x y)"
   348 by (simp add: cont2cont_LAM)
   349 
   350 subsection {* Miscellaneous *}
   351 
   352 text {* Monotonicity of @{term Abs_cfun} *}
   353 
   354 lemma monofun_LAM:
   355   "\<lbrakk>cont f; cont g; \<And>x. f x \<sqsubseteq> g x\<rbrakk> \<Longrightarrow> (\<Lambda> x. f x) \<sqsubseteq> (\<Lambda> x. g x)"
   356 by (simp add: cfun_below_iff)
   357 
   358 text {* some lemmata for functions with flat/chfin domain/range types *}
   359 
   360 lemma chfin_Rep_cfunR: "chain (Y::nat => 'a::cpo->'b::chfin)  
   361       ==> !s. ? n. (LUB i. Y i)$s = Y n$s"
   362 apply (rule allI)
   363 apply (subst contlub_cfun_fun)
   364 apply assumption
   365 apply (fast intro!: lub_eqI chfin lub_finch2 chfin2finch ch2ch_Rep_cfunL)
   366 done
   367 
   368 lemma adm_chfindom: "adm (\<lambda>(u::'a::cpo \<rightarrow> 'b::chfin). P(u\<cdot>s))"
   369 by (rule adm_subst, simp, rule adm_chfin)
   370 
   371 subsection {* Continuous injection-retraction pairs *}
   372 
   373 text {* Continuous retractions are strict. *}
   374 
   375 lemma retraction_strict:
   376   "\<forall>x. f\<cdot>(g\<cdot>x) = x \<Longrightarrow> f\<cdot>\<bottom> = \<bottom>"
   377 apply (rule UU_I)
   378 apply (drule_tac x="\<bottom>" in spec)
   379 apply (erule subst)
   380 apply (rule monofun_cfun_arg)
   381 apply (rule minimal)
   382 done
   383 
   384 lemma injection_eq:
   385   "\<forall>x. f\<cdot>(g\<cdot>x) = x \<Longrightarrow> (g\<cdot>x = g\<cdot>y) = (x = y)"
   386 apply (rule iffI)
   387 apply (drule_tac f=f in cfun_arg_cong)
   388 apply simp
   389 apply simp
   390 done
   391 
   392 lemma injection_below:
   393   "\<forall>x. f\<cdot>(g\<cdot>x) = x \<Longrightarrow> (g\<cdot>x \<sqsubseteq> g\<cdot>y) = (x \<sqsubseteq> y)"
   394 apply (rule iffI)
   395 apply (drule_tac f=f in monofun_cfun_arg)
   396 apply simp
   397 apply (erule monofun_cfun_arg)
   398 done
   399 
   400 lemma injection_defined_rev:
   401   "\<lbrakk>\<forall>x. f\<cdot>(g\<cdot>x) = x; g\<cdot>z = \<bottom>\<rbrakk> \<Longrightarrow> z = \<bottom>"
   402 apply (drule_tac f=f in cfun_arg_cong)
   403 apply (simp add: retraction_strict)
   404 done
   405 
   406 lemma injection_defined:
   407   "\<lbrakk>\<forall>x. f\<cdot>(g\<cdot>x) = x; z \<noteq> \<bottom>\<rbrakk> \<Longrightarrow> g\<cdot>z \<noteq> \<bottom>"
   408 by (erule contrapos_nn, rule injection_defined_rev)
   409 
   410 text {* a result about functions with flat codomain *}
   411 
   412 lemma flat_eqI: "\<lbrakk>(x::'a::flat) \<sqsubseteq> y; x \<noteq> \<bottom>\<rbrakk> \<Longrightarrow> x = y"
   413 by (drule ax_flat, simp)
   414 
   415 lemma flat_codom:
   416   "f\<cdot>x = (c::'b::flat) \<Longrightarrow> f\<cdot>\<bottom> = \<bottom> \<or> (\<forall>z. f\<cdot>z = c)"
   417 apply (case_tac "f\<cdot>x = \<bottom>")
   418 apply (rule disjI1)
   419 apply (rule UU_I)
   420 apply (erule_tac t="\<bottom>" in subst)
   421 apply (rule minimal [THEN monofun_cfun_arg])
   422 apply clarify
   423 apply (rule_tac a = "f\<cdot>\<bottom>" in refl [THEN box_equals])
   424 apply (erule minimal [THEN monofun_cfun_arg, THEN flat_eqI])
   425 apply (erule minimal [THEN monofun_cfun_arg, THEN flat_eqI])
   426 done
   427 
   428 subsection {* Identity and composition *}
   429 
   430 definition
   431   ID :: "'a \<rightarrow> 'a" where
   432   "ID = (\<Lambda> x. x)"
   433 
   434 definition
   435   cfcomp  :: "('b \<rightarrow> 'c) \<rightarrow> ('a \<rightarrow> 'b) \<rightarrow> 'a \<rightarrow> 'c" where
   436   oo_def: "cfcomp = (\<Lambda> f g x. f\<cdot>(g\<cdot>x))"
   437 
   438 abbreviation
   439   cfcomp_syn :: "['b \<rightarrow> 'c, 'a \<rightarrow> 'b] \<Rightarrow> 'a \<rightarrow> 'c"  (infixr "oo" 100)  where
   440   "f oo g == cfcomp\<cdot>f\<cdot>g"
   441 
   442 lemma ID1 [simp]: "ID\<cdot>x = x"
   443 by (simp add: ID_def)
   444 
   445 lemma cfcomp1: "(f oo g) = (\<Lambda> x. f\<cdot>(g\<cdot>x))"
   446 by (simp add: oo_def)
   447 
   448 lemma cfcomp2 [simp]: "(f oo g)\<cdot>x = f\<cdot>(g\<cdot>x)"
   449 by (simp add: cfcomp1)
   450 
   451 lemma cfcomp_LAM: "cont g \<Longrightarrow> f oo (\<Lambda> x. g x) = (\<Lambda> x. f\<cdot>(g x))"
   452 by (simp add: cfcomp1)
   453 
   454 lemma cfcomp_strict [simp]: "\<bottom> oo f = \<bottom>"
   455 by (simp add: cfun_eq_iff)
   456 
   457 text {*
   458   Show that interpretation of (pcpo,@{text "_->_"}) is a category.
   459   The class of objects is interpretation of syntactical class pcpo.
   460   The class of arrows  between objects @{typ 'a} and @{typ 'b} is interpret. of @{typ "'a -> 'b"}.
   461   The identity arrow is interpretation of @{term ID}.
   462   The composition of f and g is interpretation of @{text "oo"}.
   463 *}
   464 
   465 lemma ID2 [simp]: "f oo ID = f"
   466 by (rule cfun_eqI, simp)
   467 
   468 lemma ID3 [simp]: "ID oo f = f"
   469 by (rule cfun_eqI, simp)
   470 
   471 lemma assoc_oo: "f oo (g oo h) = (f oo g) oo h"
   472 by (rule cfun_eqI, simp)
   473 
   474 subsection {* Strictified functions *}
   475 
   476 default_sort pcpo
   477 
   478 definition
   479   seq :: "'a \<rightarrow> 'b \<rightarrow> 'b" where
   480   "seq = (\<Lambda> x. if x = \<bottom> then \<bottom> else ID)"
   481 
   482 lemma cont2cont_if_bottom [cont2cont, simp]:
   483   assumes f: "cont (\<lambda>x. f x)" and g: "cont (\<lambda>x. g x)"
   484   shows "cont (\<lambda>x. if f x = \<bottom> then \<bottom> else g x)"
   485 proof (rule cont_apply [OF f])
   486   show "\<And>x. cont (\<lambda>y. if y = \<bottom> then \<bottom> else g x)"
   487     unfolding cont_def is_lub_def is_ub_def ball_simps
   488     by (simp add: lub_eq_bottom_iff)
   489   show "\<And>y. cont (\<lambda>x. if y = \<bottom> then \<bottom> else g x)"
   490     by (simp add: g)
   491 qed
   492 
   493 lemma seq_conv_if: "seq\<cdot>x = (if x = \<bottom> then \<bottom> else ID)"
   494 unfolding seq_def by simp
   495 
   496 lemma seq1 [simp]: "seq\<cdot>\<bottom> = \<bottom>"
   497 by (simp add: seq_conv_if)
   498 
   499 lemma seq2 [simp]: "x \<noteq> \<bottom> \<Longrightarrow> seq\<cdot>x = ID"
   500 by (simp add: seq_conv_if)
   501 
   502 lemma seq3 [simp]: "seq\<cdot>x\<cdot>\<bottom> = \<bottom>"
   503 by (simp add: seq_conv_if)
   504 
   505 definition
   506   strictify  :: "('a \<rightarrow> 'b) \<rightarrow> 'a \<rightarrow> 'b" where
   507   "strictify = (\<Lambda> f x. seq\<cdot>x\<cdot>(f\<cdot>x))"
   508 
   509 lemma strictify_conv_if: "strictify\<cdot>f\<cdot>x = (if x = \<bottom> then \<bottom> else f\<cdot>x)"
   510 unfolding strictify_def by simp
   511 
   512 lemma strictify1 [simp]: "strictify\<cdot>f\<cdot>\<bottom> = \<bottom>"
   513 by (simp add: strictify_conv_if)
   514 
   515 lemma strictify2 [simp]: "x \<noteq> \<bottom> \<Longrightarrow> strictify\<cdot>f\<cdot>x = f\<cdot>x"
   516 by (simp add: strictify_conv_if)
   517 
   518 subsection {* Continuity of let-bindings *}
   519 
   520 lemma cont2cont_Let:
   521   assumes f: "cont (\<lambda>x. f x)"
   522   assumes g1: "\<And>y. cont (\<lambda>x. g x y)"
   523   assumes g2: "\<And>x. cont (\<lambda>y. g x y)"
   524   shows "cont (\<lambda>x. let y = f x in g x y)"
   525 unfolding Let_def using f g2 g1 by (rule cont_apply)
   526 
   527 lemma cont2cont_Let' [simp, cont2cont]:
   528   assumes f: "cont (\<lambda>x. f x)"
   529   assumes g: "cont (\<lambda>p. g (fst p) (snd p))"
   530   shows "cont (\<lambda>x. let y = f x in g x y)"
   531 using f
   532 proof (rule cont2cont_Let)
   533   fix x show "cont (\<lambda>y. g x y)"
   534     using g by (simp add: prod_cont_iff)
   535 next
   536   fix y show "cont (\<lambda>x. g x y)"
   537     using g by (simp add: prod_cont_iff)
   538 qed
   539 
   540 text {* The simple version (suggested by Joachim Breitner) is needed if
   541   the type of the defined term is not a cpo. *}
   542 
   543 lemma cont2cont_Let_simple [simp, cont2cont]:
   544   assumes "\<And>y. cont (\<lambda>x. g x y)"
   545   shows "cont (\<lambda>x. let y = t in g x y)"
   546 unfolding Let_def using assms .
   547 
   548 end