src/HOLCF/Cfun.thy
author huffman
Sun Mar 14 19:48:33 2010 -0700 (2010-03-14)
changeset 35794 8cd7134275cc
parent 35641 a17bc4cec23a
child 35914 91a7311177c4
permissions -rw-r--r--
use headers consistently
     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 Pcpodef Ffun Product_Cpo
    10 begin
    11 
    12 defaultsort cpo
    13 
    14 subsection {* Definition of continuous function type *}
    15 
    16 lemma Ex_cont: "\<exists>f. cont f"
    17 by (rule exI, rule cont_const)
    18 
    19 lemma adm_cont: "adm cont"
    20 by (rule admI, rule cont_lub_fun)
    21 
    22 cpodef (CFun)  ('a, 'b) cfun (infixr "->" 0) = "{f::'a => 'b. cont f}"
    23 by (simp_all add: Ex_cont adm_cont)
    24 
    25 type_notation (xsymbols)
    26   cfun  ("(_ \<rightarrow>/ _)" [1, 0] 0)
    27 
    28 notation
    29   Rep_CFun  ("(_$/_)" [999,1000] 999)
    30 
    31 notation (xsymbols)
    32   Rep_CFun  ("(_\<cdot>/_)" [999,1000] 999)
    33 
    34 notation (HTML output)
    35   Rep_CFun  ("(_\<cdot>/_)" [999,1000] 999)
    36 
    37 subsection {* Syntax for continuous lambda abstraction *}
    38 
    39 syntax "_cabs" :: "'a"
    40 
    41 parse_translation {*
    42 (* rewrite (_cabs x t) => (Abs_CFun (%x. t)) *)
    43   [mk_binder_tr (@{syntax_const "_cabs"}, @{const_syntax Abs_CFun})];
    44 *}
    45 
    46 text {* To avoid eta-contraction of body: *}
    47 typed_print_translation {*
    48   let
    49     fun cabs_tr' _ _ [Abs abs] = let
    50           val (x,t) = atomic_abs_tr' abs
    51         in Syntax.const @{syntax_const "_cabs"} $ x $ t end
    52 
    53       | cabs_tr' _ T [t] = let
    54           val xT = domain_type (domain_type T);
    55           val abs' = ("x",xT,(incr_boundvars 1 t)$Bound 0);
    56           val (x,t') = atomic_abs_tr' abs';
    57         in Syntax.const @{syntax_const "_cabs"} $ x $ t' end;
    58 
    59   in [(@{const_syntax Abs_CFun}, cabs_tr')] end;
    60 *}
    61 
    62 text {* Syntax for nested abstractions *}
    63 
    64 syntax
    65   "_Lambda" :: "[cargs, 'a] \<Rightarrow> logic"  ("(3LAM _./ _)" [1000, 10] 10)
    66 
    67 syntax (xsymbols)
    68   "_Lambda" :: "[cargs, 'a] \<Rightarrow> logic" ("(3\<Lambda> _./ _)" [1000, 10] 10)
    69 
    70 parse_ast_translation {*
    71 (* rewrite (LAM x y z. t) => (_cabs x (_cabs y (_cabs z t))) *)
    72 (* cf. Syntax.lambda_ast_tr from src/Pure/Syntax/syn_trans.ML *)
    73   let
    74     fun Lambda_ast_tr [pats, body] =
    75           Syntax.fold_ast_p @{syntax_const "_cabs"}
    76             (Syntax.unfold_ast @{syntax_const "_cargs"} pats, body)
    77       | Lambda_ast_tr asts = raise Syntax.AST ("Lambda_ast_tr", asts);
    78   in [(@{syntax_const "_Lambda"}, Lambda_ast_tr)] end;
    79 *}
    80 
    81 print_ast_translation {*
    82 (* rewrite (_cabs x (_cabs y (_cabs z t))) => (LAM x y z. t) *)
    83 (* cf. Syntax.abs_ast_tr' from src/Pure/Syntax/syn_trans.ML *)
    84   let
    85     fun cabs_ast_tr' asts =
    86       (case Syntax.unfold_ast_p @{syntax_const "_cabs"}
    87           (Syntax.Appl (Syntax.Constant @{syntax_const "_cabs"} :: asts)) of
    88         ([], _) => raise Syntax.AST ("cabs_ast_tr'", asts)
    89       | (xs, body) => Syntax.Appl
    90           [Syntax.Constant @{syntax_const "_Lambda"},
    91            Syntax.fold_ast @{syntax_const "_cargs"} xs, body]);
    92   in [(@{syntax_const "_cabs"}, cabs_ast_tr')] end
    93 *}
    94 
    95 text {* Dummy patterns for continuous abstraction *}
    96 translations
    97   "\<Lambda> _. t" => "CONST Abs_CFun (\<lambda> _. t)"
    98 
    99 
   100 subsection {* Continuous function space is pointed *}
   101 
   102 lemma UU_CFun: "\<bottom> \<in> CFun"
   103 by (simp add: CFun_def inst_fun_pcpo cont_const)
   104 
   105 instance cfun :: (finite_po, finite_po) finite_po
   106 by (rule typedef_finite_po [OF type_definition_CFun])
   107 
   108 instance cfun :: (finite_po, chfin) chfin
   109 by (rule typedef_chfin [OF type_definition_CFun below_CFun_def])
   110 
   111 instance cfun :: (cpo, discrete_cpo) discrete_cpo
   112 by intro_classes (simp add: below_CFun_def Rep_CFun_inject)
   113 
   114 instance cfun :: (cpo, pcpo) pcpo
   115 by (rule typedef_pcpo [OF type_definition_CFun below_CFun_def UU_CFun])
   116 
   117 lemmas Rep_CFun_strict =
   118   typedef_Rep_strict [OF type_definition_CFun below_CFun_def UU_CFun]
   119 
   120 lemmas Abs_CFun_strict =
   121   typedef_Abs_strict [OF type_definition_CFun below_CFun_def UU_CFun]
   122 
   123 text {* function application is strict in its first argument *}
   124 
   125 lemma Rep_CFun_strict1 [simp]: "\<bottom>\<cdot>x = \<bottom>"
   126 by (simp add: Rep_CFun_strict)
   127 
   128 lemma LAM_strict [simp]: "(\<Lambda> x. \<bottom>) = \<bottom>"
   129 by (simp add: inst_fun_pcpo [symmetric] Abs_CFun_strict)
   130 
   131 text {* for compatibility with old HOLCF-Version *}
   132 lemma inst_cfun_pcpo: "\<bottom> = (\<Lambda> x. \<bottom>)"
   133 by simp
   134 
   135 subsection {* Basic properties of continuous functions *}
   136 
   137 text {* Beta-equality for continuous functions *}
   138 
   139 lemma Abs_CFun_inverse2: "cont f \<Longrightarrow> Rep_CFun (Abs_CFun f) = f"
   140 by (simp add: Abs_CFun_inverse CFun_def)
   141 
   142 lemma beta_cfun [simp]: "cont f \<Longrightarrow> (\<Lambda> x. f x)\<cdot>u = f u"
   143 by (simp add: Abs_CFun_inverse2)
   144 
   145 text {* Eta-equality for continuous functions *}
   146 
   147 lemma eta_cfun: "(\<Lambda> x. f\<cdot>x) = f"
   148 by (rule Rep_CFun_inverse)
   149 
   150 text {* Extensionality for continuous functions *}
   151 
   152 lemma expand_cfun_eq: "(f = g) = (\<forall>x. f\<cdot>x = g\<cdot>x)"
   153 by (simp add: Rep_CFun_inject [symmetric] expand_fun_eq)
   154 
   155 lemma ext_cfun: "(\<And>x. f\<cdot>x = g\<cdot>x) \<Longrightarrow> f = g"
   156 by (simp add: expand_cfun_eq)
   157 
   158 text {* Extensionality wrt. ordering for continuous functions *}
   159 
   160 lemma expand_cfun_below: "f \<sqsubseteq> g = (\<forall>x. f\<cdot>x \<sqsubseteq> g\<cdot>x)" 
   161 by (simp add: below_CFun_def expand_fun_below)
   162 
   163 lemma below_cfun_ext: "(\<And>x. f\<cdot>x \<sqsubseteq> g\<cdot>x) \<Longrightarrow> f \<sqsubseteq> g"
   164 by (simp add: expand_cfun_below)
   165 
   166 text {* Congruence for continuous function application *}
   167 
   168 lemma cfun_cong: "\<lbrakk>f = g; x = y\<rbrakk> \<Longrightarrow> f\<cdot>x = g\<cdot>y"
   169 by simp
   170 
   171 lemma cfun_fun_cong: "f = g \<Longrightarrow> f\<cdot>x = g\<cdot>x"
   172 by simp
   173 
   174 lemma cfun_arg_cong: "x = y \<Longrightarrow> f\<cdot>x = f\<cdot>y"
   175 by simp
   176 
   177 subsection {* Continuity of application *}
   178 
   179 lemma cont_Rep_CFun1: "cont (\<lambda>f. f\<cdot>x)"
   180 by (rule cont_Rep_CFun [THEN cont2cont_fun])
   181 
   182 lemma cont_Rep_CFun2: "cont (\<lambda>x. f\<cdot>x)"
   183 apply (cut_tac x=f in Rep_CFun)
   184 apply (simp add: CFun_def)
   185 done
   186 
   187 lemmas monofun_Rep_CFun = cont_Rep_CFun [THEN cont2mono]
   188 lemmas contlub_Rep_CFun = cont_Rep_CFun [THEN cont2contlub]
   189 
   190 lemmas monofun_Rep_CFun1 = cont_Rep_CFun1 [THEN cont2mono, standard]
   191 lemmas contlub_Rep_CFun1 = cont_Rep_CFun1 [THEN cont2contlub, standard]
   192 lemmas monofun_Rep_CFun2 = cont_Rep_CFun2 [THEN cont2mono, standard]
   193 lemmas contlub_Rep_CFun2 = cont_Rep_CFun2 [THEN cont2contlub, standard]
   194 
   195 text {* contlub, cont properties of @{term Rep_CFun} in each argument *}
   196 
   197 lemma contlub_cfun_arg: "chain Y \<Longrightarrow> f\<cdot>(\<Squnion>i. Y i) = (\<Squnion>i. f\<cdot>(Y i))"
   198 by (rule contlub_Rep_CFun2 [THEN contlubE])
   199 
   200 lemma cont_cfun_arg: "chain Y \<Longrightarrow> range (\<lambda>i. f\<cdot>(Y i)) <<| f\<cdot>(\<Squnion>i. Y i)"
   201 by (rule cont_Rep_CFun2 [THEN contE])
   202 
   203 lemma contlub_cfun_fun: "chain F \<Longrightarrow> (\<Squnion>i. F i)\<cdot>x = (\<Squnion>i. F i\<cdot>x)"
   204 by (rule contlub_Rep_CFun1 [THEN contlubE])
   205 
   206 lemma cont_cfun_fun: "chain F \<Longrightarrow> range (\<lambda>i. F i\<cdot>x) <<| (\<Squnion>i. F i)\<cdot>x"
   207 by (rule cont_Rep_CFun1 [THEN contE])
   208 
   209 text {* monotonicity of application *}
   210 
   211 lemma monofun_cfun_fun: "f \<sqsubseteq> g \<Longrightarrow> f\<cdot>x \<sqsubseteq> g\<cdot>x"
   212 by (simp add: expand_cfun_below)
   213 
   214 lemma monofun_cfun_arg: "x \<sqsubseteq> y \<Longrightarrow> f\<cdot>x \<sqsubseteq> f\<cdot>y"
   215 by (rule monofun_Rep_CFun2 [THEN monofunE])
   216 
   217 lemma monofun_cfun: "\<lbrakk>f \<sqsubseteq> g; x \<sqsubseteq> y\<rbrakk> \<Longrightarrow> f\<cdot>x \<sqsubseteq> g\<cdot>y"
   218 by (rule below_trans [OF monofun_cfun_fun monofun_cfun_arg])
   219 
   220 text {* ch2ch - rules for the type @{typ "'a -> 'b"} *}
   221 
   222 lemma chain_monofun: "chain Y \<Longrightarrow> chain (\<lambda>i. f\<cdot>(Y i))"
   223 by (erule monofun_Rep_CFun2 [THEN ch2ch_monofun])
   224 
   225 lemma ch2ch_Rep_CFunR: "chain Y \<Longrightarrow> chain (\<lambda>i. f\<cdot>(Y i))"
   226 by (rule monofun_Rep_CFun2 [THEN ch2ch_monofun])
   227 
   228 lemma ch2ch_Rep_CFunL: "chain F \<Longrightarrow> chain (\<lambda>i. (F i)\<cdot>x)"
   229 by (rule monofun_Rep_CFun1 [THEN ch2ch_monofun])
   230 
   231 lemma ch2ch_Rep_CFun [simp]:
   232   "\<lbrakk>chain F; chain Y\<rbrakk> \<Longrightarrow> chain (\<lambda>i. (F i)\<cdot>(Y i))"
   233 by (simp add: chain_def monofun_cfun)
   234 
   235 lemma ch2ch_LAM [simp]:
   236   "\<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)"
   237 by (simp add: chain_def expand_cfun_below)
   238 
   239 text {* contlub, cont properties of @{term Rep_CFun} in both arguments *}
   240 
   241 lemma contlub_cfun: 
   242   "\<lbrakk>chain F; chain Y\<rbrakk> \<Longrightarrow> (\<Squnion>i. F i)\<cdot>(\<Squnion>i. Y i) = (\<Squnion>i. F i\<cdot>(Y i))"
   243 by (simp add: contlub_cfun_fun contlub_cfun_arg diag_lub)
   244 
   245 lemma cont_cfun: 
   246   "\<lbrakk>chain F; chain Y\<rbrakk> \<Longrightarrow> range (\<lambda>i. F i\<cdot>(Y i)) <<| (\<Squnion>i. F i)\<cdot>(\<Squnion>i. Y i)"
   247 apply (rule thelubE)
   248 apply (simp only: ch2ch_Rep_CFun)
   249 apply (simp only: contlub_cfun)
   250 done
   251 
   252 lemma contlub_LAM:
   253   "\<lbrakk>\<And>x. chain (\<lambda>i. F i x); \<And>i. cont (\<lambda>x. F i x)\<rbrakk>
   254     \<Longrightarrow> (\<Lambda> x. \<Squnion>i. F i x) = (\<Squnion>i. \<Lambda> x. F i x)"
   255 apply (simp add: thelub_CFun)
   256 apply (simp add: Abs_CFun_inverse2)
   257 apply (simp add: thelub_fun ch2ch_lambda)
   258 done
   259 
   260 lemmas lub_distribs = 
   261   contlub_cfun [symmetric]
   262   contlub_LAM [symmetric]
   263 
   264 text {* strictness *}
   265 
   266 lemma strictI: "f\<cdot>x = \<bottom> \<Longrightarrow> f\<cdot>\<bottom> = \<bottom>"
   267 apply (rule UU_I)
   268 apply (erule subst)
   269 apply (rule minimal [THEN monofun_cfun_arg])
   270 done
   271 
   272 text {* the lub of a chain of continous functions is monotone *}
   273 
   274 lemma lub_cfun_mono: "chain F \<Longrightarrow> monofun (\<lambda>x. \<Squnion>i. F i\<cdot>x)"
   275 apply (drule ch2ch_monofun [OF monofun_Rep_CFun])
   276 apply (simp add: thelub_fun [symmetric])
   277 apply (erule monofun_lub_fun)
   278 apply (simp add: monofun_Rep_CFun2)
   279 done
   280 
   281 text {* a lemma about the exchange of lubs for type @{typ "'a -> 'b"} *}
   282 
   283 lemma ex_lub_cfun:
   284   "\<lbrakk>chain F; chain Y\<rbrakk> \<Longrightarrow> (\<Squnion>j. \<Squnion>i. F j\<cdot>(Y i)) = (\<Squnion>i. \<Squnion>j. F j\<cdot>(Y i))"
   285 by (simp add: diag_lub)
   286 
   287 text {* the lub of a chain of cont. functions is continuous *}
   288 
   289 lemma cont_lub_cfun: "chain F \<Longrightarrow> cont (\<lambda>x. \<Squnion>i. F i\<cdot>x)"
   290 apply (rule cont2cont_lub)
   291 apply (erule monofun_Rep_CFun [THEN ch2ch_monofun])
   292 apply (rule cont_Rep_CFun2)
   293 done
   294 
   295 text {* type @{typ "'a -> 'b"} is chain complete *}
   296 
   297 lemma lub_cfun: "chain F \<Longrightarrow> range F <<| (\<Lambda> x. \<Squnion>i. F i\<cdot>x)"
   298 by (simp only: contlub_cfun_fun [symmetric] eta_cfun thelubE)
   299 
   300 lemma thelub_cfun: "chain F \<Longrightarrow> (\<Squnion>i. F i) = (\<Lambda> x. \<Squnion>i. F i\<cdot>x)"
   301 by (rule lub_cfun [THEN thelubI])
   302 
   303 subsection {* Continuity simplification procedure *}
   304 
   305 text {* cont2cont lemma for @{term Rep_CFun} *}
   306 
   307 lemma cont2cont_Rep_CFun [cont2cont]:
   308   assumes f: "cont (\<lambda>x. f x)"
   309   assumes t: "cont (\<lambda>x. t x)"
   310   shows "cont (\<lambda>x. (f x)\<cdot>(t x))"
   311 proof -
   312   have "cont (\<lambda>x. Rep_CFun (f x))"
   313     using cont_Rep_CFun f by (rule cont2cont_app3)
   314   thus "cont (\<lambda>x. (f x)\<cdot>(t x))"
   315     using cont_Rep_CFun2 t by (rule cont2cont_app2)
   316 qed
   317 
   318 text {* cont2mono Lemma for @{term "%x. LAM y. c1(x)(y)"} *}
   319 
   320 lemma cont2mono_LAM:
   321   "\<lbrakk>\<And>x. cont (\<lambda>y. f x y); \<And>y. monofun (\<lambda>x. f x y)\<rbrakk>
   322     \<Longrightarrow> monofun (\<lambda>x. \<Lambda> y. f x y)"
   323   unfolding monofun_def expand_cfun_below by simp
   324 
   325 text {* cont2cont Lemma for @{term "%x. LAM y. f x y"} *}
   326 
   327 text {*
   328   Not suitable as a cont2cont rule, because on nested lambdas
   329   it causes exponential blow-up in the number of subgoals.
   330 *}
   331 
   332 lemma cont2cont_LAM:
   333   assumes f1: "\<And>x. cont (\<lambda>y. f x y)"
   334   assumes f2: "\<And>y. cont (\<lambda>x. f x y)"
   335   shows "cont (\<lambda>x. \<Lambda> y. f x y)"
   336 proof (rule cont_Abs_CFun)
   337   fix x
   338   from f1 show "f x \<in> CFun" by (simp add: CFun_def)
   339   from f2 show "cont f" by (rule cont2cont_lambda)
   340 qed
   341 
   342 text {*
   343   This version does work as a cont2cont rule, since it
   344   has only a single subgoal.
   345 *}
   346 
   347 lemma cont2cont_LAM' [cont2cont]:
   348   fixes f :: "'a::cpo \<Rightarrow> 'b::cpo \<Rightarrow> 'c::cpo"
   349   assumes f: "cont (\<lambda>p. f (fst p) (snd p))"
   350   shows "cont (\<lambda>x. \<Lambda> y. f x y)"
   351 proof (rule cont2cont_LAM)
   352   fix x :: 'a show "cont (\<lambda>y. f x y)"
   353     using f by (rule cont_fst_snd_D2)
   354 next
   355   fix y :: 'b show "cont (\<lambda>x. f x y)"
   356     using f by (rule cont_fst_snd_D1)
   357 qed
   358 
   359 lemma cont2cont_LAM_discrete [cont2cont]:
   360   "(\<And>y::'a::discrete_cpo. cont (\<lambda>x. f x y)) \<Longrightarrow> cont (\<lambda>x. \<Lambda> y. f x y)"
   361 by (simp add: cont2cont_LAM)
   362 
   363 lemmas cont_lemmas1 =
   364   cont_const cont_id cont_Rep_CFun2 cont2cont_Rep_CFun cont2cont_LAM
   365 
   366 subsection {* Miscellaneous *}
   367 
   368 text {* Monotonicity of @{term Abs_CFun} *}
   369 
   370 lemma semi_monofun_Abs_CFun:
   371   "\<lbrakk>cont f; cont g; f \<sqsubseteq> g\<rbrakk> \<Longrightarrow> Abs_CFun f \<sqsubseteq> Abs_CFun g"
   372 by (simp add: below_CFun_def Abs_CFun_inverse2)
   373 
   374 text {* some lemmata for functions with flat/chfin domain/range types *}
   375 
   376 lemma chfin_Rep_CFunR: "chain (Y::nat => 'a::cpo->'b::chfin)  
   377       ==> !s. ? n. (LUB i. Y i)$s = Y n$s"
   378 apply (rule allI)
   379 apply (subst contlub_cfun_fun)
   380 apply assumption
   381 apply (fast intro!: thelubI chfin lub_finch2 chfin2finch ch2ch_Rep_CFunL)
   382 done
   383 
   384 lemma adm_chfindom: "adm (\<lambda>(u::'a::cpo \<rightarrow> 'b::chfin). P(u\<cdot>s))"
   385 by (rule adm_subst, simp, rule adm_chfin)
   386 
   387 subsection {* Continuous injection-retraction pairs *}
   388 
   389 text {* Continuous retractions are strict. *}
   390 
   391 lemma retraction_strict:
   392   "\<forall>x. f\<cdot>(g\<cdot>x) = x \<Longrightarrow> f\<cdot>\<bottom> = \<bottom>"
   393 apply (rule UU_I)
   394 apply (drule_tac x="\<bottom>" in spec)
   395 apply (erule subst)
   396 apply (rule monofun_cfun_arg)
   397 apply (rule minimal)
   398 done
   399 
   400 lemma injection_eq:
   401   "\<forall>x. f\<cdot>(g\<cdot>x) = x \<Longrightarrow> (g\<cdot>x = g\<cdot>y) = (x = y)"
   402 apply (rule iffI)
   403 apply (drule_tac f=f in cfun_arg_cong)
   404 apply simp
   405 apply simp
   406 done
   407 
   408 lemma injection_below:
   409   "\<forall>x. f\<cdot>(g\<cdot>x) = x \<Longrightarrow> (g\<cdot>x \<sqsubseteq> g\<cdot>y) = (x \<sqsubseteq> y)"
   410 apply (rule iffI)
   411 apply (drule_tac f=f in monofun_cfun_arg)
   412 apply simp
   413 apply (erule monofun_cfun_arg)
   414 done
   415 
   416 lemma injection_defined_rev:
   417   "\<lbrakk>\<forall>x. f\<cdot>(g\<cdot>x) = x; g\<cdot>z = \<bottom>\<rbrakk> \<Longrightarrow> z = \<bottom>"
   418 apply (drule_tac f=f in cfun_arg_cong)
   419 apply (simp add: retraction_strict)
   420 done
   421 
   422 lemma injection_defined:
   423   "\<lbrakk>\<forall>x. f\<cdot>(g\<cdot>x) = x; z \<noteq> \<bottom>\<rbrakk> \<Longrightarrow> g\<cdot>z \<noteq> \<bottom>"
   424 by (erule contrapos_nn, rule injection_defined_rev)
   425 
   426 text {* propagation of flatness and chain-finiteness by retractions *}
   427 
   428 lemma chfin2chfin:
   429   "\<forall>y. (f::'a::chfin \<rightarrow> 'b)\<cdot>(g\<cdot>y) = y
   430     \<Longrightarrow> \<forall>Y::nat \<Rightarrow> 'b. chain Y \<longrightarrow> (\<exists>n. max_in_chain n Y)"
   431 apply clarify
   432 apply (drule_tac f=g in chain_monofun)
   433 apply (drule chfin)
   434 apply (unfold max_in_chain_def)
   435 apply (simp add: injection_eq)
   436 done
   437 
   438 lemma flat2flat:
   439   "\<forall>y. (f::'a::flat \<rightarrow> 'b::pcpo)\<cdot>(g\<cdot>y) = y
   440     \<Longrightarrow> \<forall>x y::'b. x \<sqsubseteq> y \<longrightarrow> x = \<bottom> \<or> x = y"
   441 apply clarify
   442 apply (drule_tac f=g in monofun_cfun_arg)
   443 apply (drule ax_flat)
   444 apply (erule disjE)
   445 apply (simp add: injection_defined_rev)
   446 apply (simp add: injection_eq)
   447 done
   448 
   449 text {* a result about functions with flat codomain *}
   450 
   451 lemma flat_eqI: "\<lbrakk>(x::'a::flat) \<sqsubseteq> y; x \<noteq> \<bottom>\<rbrakk> \<Longrightarrow> x = y"
   452 by (drule ax_flat, simp)
   453 
   454 lemma flat_codom:
   455   "f\<cdot>x = (c::'b::flat) \<Longrightarrow> f\<cdot>\<bottom> = \<bottom> \<or> (\<forall>z. f\<cdot>z = c)"
   456 apply (case_tac "f\<cdot>x = \<bottom>")
   457 apply (rule disjI1)
   458 apply (rule UU_I)
   459 apply (erule_tac t="\<bottom>" in subst)
   460 apply (rule minimal [THEN monofun_cfun_arg])
   461 apply clarify
   462 apply (rule_tac a = "f\<cdot>\<bottom>" in refl [THEN box_equals])
   463 apply (erule minimal [THEN monofun_cfun_arg, THEN flat_eqI])
   464 apply (erule minimal [THEN monofun_cfun_arg, THEN flat_eqI])
   465 done
   466 
   467 
   468 subsection {* Identity and composition *}
   469 
   470 definition
   471   ID :: "'a \<rightarrow> 'a" where
   472   "ID = (\<Lambda> x. x)"
   473 
   474 definition
   475   cfcomp  :: "('b \<rightarrow> 'c) \<rightarrow> ('a \<rightarrow> 'b) \<rightarrow> 'a \<rightarrow> 'c" where
   476   oo_def: "cfcomp = (\<Lambda> f g x. f\<cdot>(g\<cdot>x))"
   477 
   478 abbreviation
   479   cfcomp_syn :: "['b \<rightarrow> 'c, 'a \<rightarrow> 'b] \<Rightarrow> 'a \<rightarrow> 'c"  (infixr "oo" 100)  where
   480   "f oo g == cfcomp\<cdot>f\<cdot>g"
   481 
   482 lemma ID1 [simp]: "ID\<cdot>x = x"
   483 by (simp add: ID_def)
   484 
   485 lemma cfcomp1: "(f oo g) = (\<Lambda> x. f\<cdot>(g\<cdot>x))"
   486 by (simp add: oo_def)
   487 
   488 lemma cfcomp2 [simp]: "(f oo g)\<cdot>x = f\<cdot>(g\<cdot>x)"
   489 by (simp add: cfcomp1)
   490 
   491 lemma cfcomp_LAM: "cont g \<Longrightarrow> f oo (\<Lambda> x. g x) = (\<Lambda> x. f\<cdot>(g x))"
   492 by (simp add: cfcomp1)
   493 
   494 lemma cfcomp_strict [simp]: "\<bottom> oo f = \<bottom>"
   495 by (simp add: expand_cfun_eq)
   496 
   497 text {*
   498   Show that interpretation of (pcpo,@{text "_->_"}) is a category.
   499   The class of objects is interpretation of syntactical class pcpo.
   500   The class of arrows  between objects @{typ 'a} and @{typ 'b} is interpret. of @{typ "'a -> 'b"}.
   501   The identity arrow is interpretation of @{term ID}.
   502   The composition of f and g is interpretation of @{text "oo"}.
   503 *}
   504 
   505 lemma ID2 [simp]: "f oo ID = f"
   506 by (rule ext_cfun, simp)
   507 
   508 lemma ID3 [simp]: "ID oo f = f"
   509 by (rule ext_cfun, simp)
   510 
   511 lemma assoc_oo: "f oo (g oo h) = (f oo g) oo h"
   512 by (rule ext_cfun, simp)
   513 
   514 
   515 subsection {* Strictified functions *}
   516 
   517 defaultsort pcpo
   518 
   519 definition
   520   strictify  :: "('a \<rightarrow> 'b) \<rightarrow> 'a \<rightarrow> 'b" where
   521   "strictify = (\<Lambda> f x. if x = \<bottom> then \<bottom> else f\<cdot>x)"
   522 
   523 text {* results about strictify *}
   524 
   525 lemma cont_strictify1: "cont (\<lambda>f. if x = \<bottom> then \<bottom> else f\<cdot>x)"
   526 by simp
   527 
   528 lemma monofun_strictify2: "monofun (\<lambda>x. if x = \<bottom> then \<bottom> else f\<cdot>x)"
   529 apply (rule monofunI)
   530 apply (auto simp add: monofun_cfun_arg)
   531 done
   532 
   533 (*FIXME: long proof*)
   534 lemma contlub_strictify2: "contlub (\<lambda>x. if x = \<bottom> then \<bottom> else f\<cdot>x)"
   535 apply (rule contlubI)
   536 apply (case_tac "(\<Squnion>i. Y i) = \<bottom>")
   537 apply (drule (1) chain_UU_I)
   538 apply simp
   539 apply (simp del: if_image_distrib)
   540 apply (simp only: contlub_cfun_arg)
   541 apply (rule lub_equal2)
   542 apply (rule chain_mono2 [THEN exE])
   543 apply (erule chain_UU_I_inverse2)
   544 apply (assumption)
   545 apply (rule_tac x=x in exI, clarsimp)
   546 apply (erule chain_monofun)
   547 apply (erule monofun_strictify2 [THEN ch2ch_monofun])
   548 done
   549 
   550 lemmas cont_strictify2 =
   551   monocontlub2cont [OF monofun_strictify2 contlub_strictify2, standard]
   552 
   553 lemma strictify_conv_if: "strictify\<cdot>f\<cdot>x = (if x = \<bottom> then \<bottom> else f\<cdot>x)"
   554   unfolding strictify_def
   555   by (simp add: cont_strictify1 cont_strictify2 cont2cont_LAM)
   556 
   557 lemma strictify1 [simp]: "strictify\<cdot>f\<cdot>\<bottom> = \<bottom>"
   558 by (simp add: strictify_conv_if)
   559 
   560 lemma strictify2 [simp]: "x \<noteq> \<bottom> \<Longrightarrow> strictify\<cdot>f\<cdot>x = f\<cdot>x"
   561 by (simp add: strictify_conv_if)
   562 
   563 subsection {* Continuous let-bindings *}
   564 
   565 definition
   566   CLet :: "'a \<rightarrow> ('a \<rightarrow> 'b) \<rightarrow> 'b" where
   567   "CLet = (\<Lambda> s f. f\<cdot>s)"
   568 
   569 syntax
   570   "_CLet" :: "[letbinds, 'a] => 'a" ("(Let (_)/ in (_))" 10)
   571 
   572 translations
   573   "_CLet (_binds b bs) e" == "_CLet b (_CLet bs e)"
   574   "Let x = a in e" == "CONST CLet\<cdot>a\<cdot>(\<Lambda> x. e)"
   575 
   576 end