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