src/HOL/HOLCF/Cfun.thy
author huffman
Thu Dec 23 11:52:26 2010 -0800 (2010-12-23)
changeset 41400 1a7557cc686a
parent 41322 43a5b9a0ee8a
child 41430 1aa23e9f2c87
permissions -rw-r--r--
replaced separate lemmas seq{1,2,3} with seq_simps
     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   Update: The simproc now uses rule @{text Abs_cfun_inverse2} instead
   147   of @{text beta_cfun}, to avoid problems with eta-contraction.
   148 *}
   149 
   150 simproc_setup beta_cfun_proc ("Rep_cfun (Abs_cfun f)") = {*
   151   fn phi => fn ss => fn ct =>
   152     let
   153       val dest = Thm.dest_comb;
   154       val f = (snd o dest o snd o dest) ct;
   155       val [T, U] = Thm.dest_ctyp (ctyp_of_term f);
   156       val tr = instantiate' [SOME T, SOME U] [SOME f]
   157           (mk_meta_eq @{thm Abs_cfun_inverse2});
   158       val rules = Cont2ContData.get (Simplifier.the_context ss);
   159       val tac = SOLVED' (REPEAT_ALL_NEW (match_tac rules));
   160     in SOME (perhaps (SINGLE (tac 1)) tr) end
   161 *}
   162 
   163 text {* Eta-equality for continuous functions *}
   164 
   165 lemma eta_cfun: "(\<Lambda> x. f\<cdot>x) = f"
   166 by (rule Rep_cfun_inverse)
   167 
   168 text {* Extensionality for continuous functions *}
   169 
   170 lemma cfun_eq_iff: "f = g \<longleftrightarrow> (\<forall>x. f\<cdot>x = g\<cdot>x)"
   171 by (simp add: Rep_cfun_inject [symmetric] fun_eq_iff)
   172 
   173 lemma cfun_eqI: "(\<And>x. f\<cdot>x = g\<cdot>x) \<Longrightarrow> f = g"
   174 by (simp add: cfun_eq_iff)
   175 
   176 text {* Extensionality wrt. ordering for continuous functions *}
   177 
   178 lemma cfun_below_iff: "f \<sqsubseteq> g \<longleftrightarrow> (\<forall>x. f\<cdot>x \<sqsubseteq> g\<cdot>x)" 
   179 by (simp add: below_cfun_def fun_below_iff)
   180 
   181 lemma cfun_belowI: "(\<And>x. f\<cdot>x \<sqsubseteq> g\<cdot>x) \<Longrightarrow> f \<sqsubseteq> g"
   182 by (simp add: cfun_below_iff)
   183 
   184 text {* Congruence for continuous function application *}
   185 
   186 lemma cfun_cong: "\<lbrakk>f = g; x = y\<rbrakk> \<Longrightarrow> f\<cdot>x = g\<cdot>y"
   187 by simp
   188 
   189 lemma cfun_fun_cong: "f = g \<Longrightarrow> f\<cdot>x = g\<cdot>x"
   190 by simp
   191 
   192 lemma cfun_arg_cong: "x = y \<Longrightarrow> f\<cdot>x = f\<cdot>y"
   193 by simp
   194 
   195 subsection {* Continuity of application *}
   196 
   197 lemma cont_Rep_cfun1: "cont (\<lambda>f. f\<cdot>x)"
   198 by (rule cont_Rep_cfun [OF cont_id, THEN cont2cont_fun])
   199 
   200 lemma cont_Rep_cfun2: "cont (\<lambda>x. f\<cdot>x)"
   201 apply (cut_tac x=f in Rep_cfun)
   202 apply (simp add: cfun_def)
   203 done
   204 
   205 lemmas monofun_Rep_cfun = cont_Rep_cfun [THEN cont2mono]
   206 
   207 lemmas monofun_Rep_cfun1 = cont_Rep_cfun1 [THEN cont2mono, standard]
   208 lemmas monofun_Rep_cfun2 = cont_Rep_cfun2 [THEN cont2mono, standard]
   209 
   210 text {* contlub, cont properties of @{term Rep_cfun} in each argument *}
   211 
   212 lemma contlub_cfun_arg: "chain Y \<Longrightarrow> f\<cdot>(\<Squnion>i. Y i) = (\<Squnion>i. f\<cdot>(Y i))"
   213 by (rule cont_Rep_cfun2 [THEN cont2contlubE])
   214 
   215 lemma contlub_cfun_fun: "chain F \<Longrightarrow> (\<Squnion>i. F i)\<cdot>x = (\<Squnion>i. F i\<cdot>x)"
   216 by (rule cont_Rep_cfun1 [THEN cont2contlubE])
   217 
   218 text {* monotonicity of application *}
   219 
   220 lemma monofun_cfun_fun: "f \<sqsubseteq> g \<Longrightarrow> f\<cdot>x \<sqsubseteq> g\<cdot>x"
   221 by (simp add: cfun_below_iff)
   222 
   223 lemma monofun_cfun_arg: "x \<sqsubseteq> y \<Longrightarrow> f\<cdot>x \<sqsubseteq> f\<cdot>y"
   224 by (rule monofun_Rep_cfun2 [THEN monofunE])
   225 
   226 lemma monofun_cfun: "\<lbrakk>f \<sqsubseteq> g; x \<sqsubseteq> y\<rbrakk> \<Longrightarrow> f\<cdot>x \<sqsubseteq> g\<cdot>y"
   227 by (rule below_trans [OF monofun_cfun_fun monofun_cfun_arg])
   228 
   229 text {* ch2ch - rules for the type @{typ "'a -> 'b"} *}
   230 
   231 lemma chain_monofun: "chain Y \<Longrightarrow> chain (\<lambda>i. f\<cdot>(Y i))"
   232 by (erule monofun_Rep_cfun2 [THEN ch2ch_monofun])
   233 
   234 lemma ch2ch_Rep_cfunR: "chain Y \<Longrightarrow> chain (\<lambda>i. f\<cdot>(Y i))"
   235 by (rule monofun_Rep_cfun2 [THEN ch2ch_monofun])
   236 
   237 lemma ch2ch_Rep_cfunL: "chain F \<Longrightarrow> chain (\<lambda>i. (F i)\<cdot>x)"
   238 by (rule monofun_Rep_cfun1 [THEN ch2ch_monofun])
   239 
   240 lemma ch2ch_Rep_cfun [simp]:
   241   "\<lbrakk>chain F; chain Y\<rbrakk> \<Longrightarrow> chain (\<lambda>i. (F i)\<cdot>(Y i))"
   242 by (simp add: chain_def monofun_cfun)
   243 
   244 lemma ch2ch_LAM [simp]:
   245   "\<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)"
   246 by (simp add: chain_def cfun_below_iff)
   247 
   248 text {* contlub, cont properties of @{term Rep_cfun} in both arguments *}
   249 
   250 lemma lub_APP:
   251   "\<lbrakk>chain F; chain Y\<rbrakk> \<Longrightarrow> (\<Squnion>i. F i\<cdot>(Y i)) = (\<Squnion>i. F i)\<cdot>(\<Squnion>i. Y i)"
   252 by (simp add: contlub_cfun_fun contlub_cfun_arg diag_lub)
   253 
   254 lemma lub_LAM:
   255   "\<lbrakk>\<And>x. chain (\<lambda>i. F i x); \<And>i. cont (\<lambda>x. F i x)\<rbrakk>
   256     \<Longrightarrow> (\<Squnion>i. \<Lambda> x. F i x) = (\<Lambda> x. \<Squnion>i. F i x)"
   257 by (simp add: lub_cfun lub_fun ch2ch_lambda)
   258 
   259 lemmas lub_distribs = lub_APP lub_LAM
   260 
   261 text {* strictness *}
   262 
   263 lemma strictI: "f\<cdot>x = \<bottom> \<Longrightarrow> f\<cdot>\<bottom> = \<bottom>"
   264 apply (rule UU_I)
   265 apply (erule subst)
   266 apply (rule minimal [THEN monofun_cfun_arg])
   267 done
   268 
   269 text {* type @{typ "'a -> 'b"} is chain complete *}
   270 
   271 lemma lub_cfun: "chain F \<Longrightarrow> (\<Squnion>i. F i) = (\<Lambda> x. \<Squnion>i. F i\<cdot>x)"
   272 by (simp add: lub_cfun lub_fun ch2ch_lambda)
   273 
   274 subsection {* Continuity simplification procedure *}
   275 
   276 text {* cont2cont lemma for @{term Rep_cfun} *}
   277 
   278 lemma cont2cont_APP [simp, cont2cont]:
   279   assumes f: "cont (\<lambda>x. f x)"
   280   assumes t: "cont (\<lambda>x. t x)"
   281   shows "cont (\<lambda>x. (f x)\<cdot>(t x))"
   282 proof -
   283   have 1: "\<And>y. cont (\<lambda>x. (f x)\<cdot>y)"
   284     using cont_Rep_cfun1 f by (rule cont_compose)
   285   show "cont (\<lambda>x. (f x)\<cdot>(t x))"
   286     using t cont_Rep_cfun2 1 by (rule cont_apply)
   287 qed
   288 
   289 text {*
   290   Two specific lemmas for the combination of LCF and HOL terms.
   291   These lemmas are needed in theories that use types like @{typ "'a \<rightarrow> 'b \<Rightarrow> 'c"}.
   292 *}
   293 
   294 lemma cont_APP_app [simp]: "\<lbrakk>cont f; cont g\<rbrakk> \<Longrightarrow> cont (\<lambda>x. ((f x)\<cdot>(g x)) s)"
   295 by (rule cont2cont_APP [THEN cont2cont_fun])
   296 
   297 lemma cont_APP_app_app [simp]: "\<lbrakk>cont f; cont g\<rbrakk> \<Longrightarrow> cont (\<lambda>x. ((f x)\<cdot>(g x)) s t)"
   298 by (rule cont_APP_app [THEN cont2cont_fun])
   299 
   300 
   301 text {* cont2mono Lemma for @{term "%x. LAM y. c1(x)(y)"} *}
   302 
   303 lemma cont2mono_LAM:
   304   "\<lbrakk>\<And>x. cont (\<lambda>y. f x y); \<And>y. monofun (\<lambda>x. f x y)\<rbrakk>
   305     \<Longrightarrow> monofun (\<lambda>x. \<Lambda> y. f x y)"
   306   unfolding monofun_def cfun_below_iff by simp
   307 
   308 text {* cont2cont Lemma for @{term "%x. LAM y. f x y"} *}
   309 
   310 text {*
   311   Not suitable as a cont2cont rule, because on nested lambdas
   312   it causes exponential blow-up in the number of subgoals.
   313 *}
   314 
   315 lemma cont2cont_LAM:
   316   assumes f1: "\<And>x. cont (\<lambda>y. f x y)"
   317   assumes f2: "\<And>y. cont (\<lambda>x. f x y)"
   318   shows "cont (\<lambda>x. \<Lambda> y. f x y)"
   319 proof (rule cont_Abs_cfun)
   320   fix x
   321   from f1 show "f x \<in> cfun" by (simp add: cfun_def)
   322   from f2 show "cont f" by (rule cont2cont_lambda)
   323 qed
   324 
   325 text {*
   326   This version does work as a cont2cont rule, since it
   327   has only a single subgoal.
   328 *}
   329 
   330 lemma cont2cont_LAM' [simp, cont2cont]:
   331   fixes f :: "'a::cpo \<Rightarrow> 'b::cpo \<Rightarrow> 'c::cpo"
   332   assumes f: "cont (\<lambda>p. f (fst p) (snd p))"
   333   shows "cont (\<lambda>x. \<Lambda> y. f x y)"
   334 using assms by (simp add: cont2cont_LAM prod_cont_iff)
   335 
   336 lemma cont2cont_LAM_discrete [simp, cont2cont]:
   337   "(\<And>y::'a::discrete_cpo. cont (\<lambda>x. f x y)) \<Longrightarrow> cont (\<lambda>x. \<Lambda> y. f x y)"
   338 by (simp add: cont2cont_LAM)
   339 
   340 subsection {* Miscellaneous *}
   341 
   342 text {* Monotonicity of @{term Abs_cfun} *}
   343 
   344 lemma monofun_LAM:
   345   "\<lbrakk>cont f; cont g; \<And>x. f x \<sqsubseteq> g x\<rbrakk> \<Longrightarrow> (\<Lambda> x. f x) \<sqsubseteq> (\<Lambda> x. g x)"
   346 by (simp add: cfun_below_iff)
   347 
   348 text {* some lemmata for functions with flat/chfin domain/range types *}
   349 
   350 lemma chfin_Rep_cfunR: "chain (Y::nat => 'a::cpo->'b::chfin)  
   351       ==> !s. ? n. (LUB i. Y i)$s = Y n$s"
   352 apply (rule allI)
   353 apply (subst contlub_cfun_fun)
   354 apply assumption
   355 apply (fast intro!: lub_eqI chfin lub_finch2 chfin2finch ch2ch_Rep_cfunL)
   356 done
   357 
   358 lemma adm_chfindom: "adm (\<lambda>(u::'a::cpo \<rightarrow> 'b::chfin). P(u\<cdot>s))"
   359 by (rule adm_subst, simp, rule adm_chfin)
   360 
   361 subsection {* Continuous injection-retraction pairs *}
   362 
   363 text {* Continuous retractions are strict. *}
   364 
   365 lemma retraction_strict:
   366   "\<forall>x. f\<cdot>(g\<cdot>x) = x \<Longrightarrow> f\<cdot>\<bottom> = \<bottom>"
   367 apply (rule UU_I)
   368 apply (drule_tac x="\<bottom>" in spec)
   369 apply (erule subst)
   370 apply (rule monofun_cfun_arg)
   371 apply (rule minimal)
   372 done
   373 
   374 lemma injection_eq:
   375   "\<forall>x. f\<cdot>(g\<cdot>x) = x \<Longrightarrow> (g\<cdot>x = g\<cdot>y) = (x = y)"
   376 apply (rule iffI)
   377 apply (drule_tac f=f in cfun_arg_cong)
   378 apply simp
   379 apply simp
   380 done
   381 
   382 lemma injection_below:
   383   "\<forall>x. f\<cdot>(g\<cdot>x) = x \<Longrightarrow> (g\<cdot>x \<sqsubseteq> g\<cdot>y) = (x \<sqsubseteq> y)"
   384 apply (rule iffI)
   385 apply (drule_tac f=f in monofun_cfun_arg)
   386 apply simp
   387 apply (erule monofun_cfun_arg)
   388 done
   389 
   390 lemma injection_defined_rev:
   391   "\<lbrakk>\<forall>x. f\<cdot>(g\<cdot>x) = x; g\<cdot>z = \<bottom>\<rbrakk> \<Longrightarrow> z = \<bottom>"
   392 apply (drule_tac f=f in cfun_arg_cong)
   393 apply (simp add: retraction_strict)
   394 done
   395 
   396 lemma injection_defined:
   397   "\<lbrakk>\<forall>x. f\<cdot>(g\<cdot>x) = x; z \<noteq> \<bottom>\<rbrakk> \<Longrightarrow> g\<cdot>z \<noteq> \<bottom>"
   398 by (erule contrapos_nn, rule injection_defined_rev)
   399 
   400 text {* a result about functions with flat codomain *}
   401 
   402 lemma flat_eqI: "\<lbrakk>(x::'a::flat) \<sqsubseteq> y; x \<noteq> \<bottom>\<rbrakk> \<Longrightarrow> x = y"
   403 by (drule ax_flat, simp)
   404 
   405 lemma flat_codom:
   406   "f\<cdot>x = (c::'b::flat) \<Longrightarrow> f\<cdot>\<bottom> = \<bottom> \<or> (\<forall>z. f\<cdot>z = c)"
   407 apply (case_tac "f\<cdot>x = \<bottom>")
   408 apply (rule disjI1)
   409 apply (rule UU_I)
   410 apply (erule_tac t="\<bottom>" in subst)
   411 apply (rule minimal [THEN monofun_cfun_arg])
   412 apply clarify
   413 apply (rule_tac a = "f\<cdot>\<bottom>" in refl [THEN box_equals])
   414 apply (erule minimal [THEN monofun_cfun_arg, THEN flat_eqI])
   415 apply (erule minimal [THEN monofun_cfun_arg, THEN flat_eqI])
   416 done
   417 
   418 subsection {* Identity and composition *}
   419 
   420 definition
   421   ID :: "'a \<rightarrow> 'a" where
   422   "ID = (\<Lambda> x. x)"
   423 
   424 definition
   425   cfcomp  :: "('b \<rightarrow> 'c) \<rightarrow> ('a \<rightarrow> 'b) \<rightarrow> 'a \<rightarrow> 'c" where
   426   oo_def: "cfcomp = (\<Lambda> f g x. f\<cdot>(g\<cdot>x))"
   427 
   428 abbreviation
   429   cfcomp_syn :: "['b \<rightarrow> 'c, 'a \<rightarrow> 'b] \<Rightarrow> 'a \<rightarrow> 'c"  (infixr "oo" 100)  where
   430   "f oo g == cfcomp\<cdot>f\<cdot>g"
   431 
   432 lemma ID1 [simp]: "ID\<cdot>x = x"
   433 by (simp add: ID_def)
   434 
   435 lemma cfcomp1: "(f oo g) = (\<Lambda> x. f\<cdot>(g\<cdot>x))"
   436 by (simp add: oo_def)
   437 
   438 lemma cfcomp2 [simp]: "(f oo g)\<cdot>x = f\<cdot>(g\<cdot>x)"
   439 by (simp add: cfcomp1)
   440 
   441 lemma cfcomp_LAM: "cont g \<Longrightarrow> f oo (\<Lambda> x. g x) = (\<Lambda> x. f\<cdot>(g x))"
   442 by (simp add: cfcomp1)
   443 
   444 lemma cfcomp_strict [simp]: "\<bottom> oo f = \<bottom>"
   445 by (simp add: cfun_eq_iff)
   446 
   447 text {*
   448   Show that interpretation of (pcpo,@{text "_->_"}) is a category.
   449   The class of objects is interpretation of syntactical class pcpo.
   450   The class of arrows  between objects @{typ 'a} and @{typ 'b} is interpret. of @{typ "'a -> 'b"}.
   451   The identity arrow is interpretation of @{term ID}.
   452   The composition of f and g is interpretation of @{text "oo"}.
   453 *}
   454 
   455 lemma ID2 [simp]: "f oo ID = f"
   456 by (rule cfun_eqI, simp)
   457 
   458 lemma ID3 [simp]: "ID oo f = f"
   459 by (rule cfun_eqI, simp)
   460 
   461 lemma assoc_oo: "f oo (g oo h) = (f oo g) oo h"
   462 by (rule cfun_eqI, simp)
   463 
   464 subsection {* Strictified functions *}
   465 
   466 default_sort pcpo
   467 
   468 definition
   469   seq :: "'a \<rightarrow> 'b \<rightarrow> 'b" where
   470   "seq = (\<Lambda> x. if x = \<bottom> then \<bottom> else ID)"
   471 
   472 lemma cont2cont_if_bottom [cont2cont, simp]:
   473   assumes f: "cont (\<lambda>x. f x)" and g: "cont (\<lambda>x. g x)"
   474   shows "cont (\<lambda>x. if f x = \<bottom> then \<bottom> else g x)"
   475 proof (rule cont_apply [OF f])
   476   show "\<And>x. cont (\<lambda>y. if y = \<bottom> then \<bottom> else g x)"
   477     unfolding cont_def is_lub_def is_ub_def ball_simps
   478     by (simp add: lub_eq_bottom_iff)
   479   show "\<And>y. cont (\<lambda>x. if y = \<bottom> then \<bottom> else g x)"
   480     by (simp add: g)
   481 qed
   482 
   483 lemma seq_conv_if: "seq\<cdot>x = (if x = \<bottom> then \<bottom> else ID)"
   484 unfolding seq_def by simp
   485 
   486 lemma seq_simps [simp]:
   487   "seq\<cdot>\<bottom> = \<bottom>"
   488   "seq\<cdot>x\<cdot>\<bottom> = \<bottom>"
   489   "x \<noteq> \<bottom> \<Longrightarrow> seq\<cdot>x = ID"
   490 by (simp_all add: seq_conv_if)
   491 
   492 definition
   493   strictify  :: "('a \<rightarrow> 'b) \<rightarrow> 'a \<rightarrow> 'b" where
   494   "strictify = (\<Lambda> f x. seq\<cdot>x\<cdot>(f\<cdot>x))"
   495 
   496 lemma strictify_conv_if: "strictify\<cdot>f\<cdot>x = (if x = \<bottom> then \<bottom> else f\<cdot>x)"
   497 unfolding strictify_def by simp
   498 
   499 lemma strictify1 [simp]: "strictify\<cdot>f\<cdot>\<bottom> = \<bottom>"
   500 by (simp add: strictify_conv_if)
   501 
   502 lemma strictify2 [simp]: "x \<noteq> \<bottom> \<Longrightarrow> strictify\<cdot>f\<cdot>x = f\<cdot>x"
   503 by (simp add: strictify_conv_if)
   504 
   505 subsection {* Continuity of let-bindings *}
   506 
   507 lemma cont2cont_Let:
   508   assumes f: "cont (\<lambda>x. f x)"
   509   assumes g1: "\<And>y. cont (\<lambda>x. g x y)"
   510   assumes g2: "\<And>x. cont (\<lambda>y. g x y)"
   511   shows "cont (\<lambda>x. let y = f x in g x y)"
   512 unfolding Let_def using f g2 g1 by (rule cont_apply)
   513 
   514 lemma cont2cont_Let' [simp, cont2cont]:
   515   assumes f: "cont (\<lambda>x. f x)"
   516   assumes g: "cont (\<lambda>p. g (fst p) (snd p))"
   517   shows "cont (\<lambda>x. let y = f x in g x y)"
   518 using f
   519 proof (rule cont2cont_Let)
   520   fix x show "cont (\<lambda>y. g x y)"
   521     using g by (simp add: prod_cont_iff)
   522 next
   523   fix y show "cont (\<lambda>x. g x y)"
   524     using g by (simp add: prod_cont_iff)
   525 qed
   526 
   527 text {* The simple version (suggested by Joachim Breitner) is needed if
   528   the type of the defined term is not a cpo. *}
   529 
   530 lemma cont2cont_Let_simple [simp, cont2cont]:
   531   assumes "\<And>y. cont (\<lambda>x. g x y)"
   532   shows "cont (\<lambda>x. let y = t in g x y)"
   533 unfolding Let_def using assms .
   534 
   535 end