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