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