src/HOL/HOLCF/Cfun.thy
author huffman
Mon Dec 06 08:30:00 2010 -0800 (2010-12-06)
changeset 41027 c599955d9806
parent 40834 a1249aeff5b6
child 41030 ff7d177128ef
permissions -rw-r--r--
add lemmas lub_APP, lub_LAM
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@40772
     9
imports Cpodef 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@40834
   195
by (rule cont_Rep_cfun [OF cont_id, 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 contlub_cfun_fun: "chain F \<Longrightarrow> (\<Squnion>i. F i)\<cdot>x = (\<Squnion>i. F i\<cdot>x)"
huffman@40327
   213
by (rule cont_Rep_cfun1 [THEN cont2contlubE])
huffman@15576
   214
huffman@16209
   215
text {* monotonicity of application *}
huffman@16209
   216
huffman@16209
   217
lemma monofun_cfun_fun: "f \<sqsubseteq> g \<Longrightarrow> f\<cdot>x \<sqsubseteq> g\<cdot>x"
huffman@40002
   218
by (simp add: cfun_below_iff)
huffman@15576
   219
huffman@16209
   220
lemma monofun_cfun_arg: "x \<sqsubseteq> y \<Longrightarrow> f\<cdot>x \<sqsubseteq> f\<cdot>y"
huffman@40327
   221
by (rule monofun_Rep_cfun2 [THEN monofunE])
huffman@15576
   222
huffman@16209
   223
lemma monofun_cfun: "\<lbrakk>f \<sqsubseteq> g; x \<sqsubseteq> y\<rbrakk> \<Longrightarrow> f\<cdot>x \<sqsubseteq> g\<cdot>y"
huffman@31076
   224
by (rule below_trans [OF monofun_cfun_fun monofun_cfun_arg])
huffman@15576
   225
huffman@16209
   226
text {* ch2ch - rules for the type @{typ "'a -> 'b"} *}
huffman@15576
   227
huffman@16209
   228
lemma chain_monofun: "chain Y \<Longrightarrow> chain (\<lambda>i. f\<cdot>(Y i))"
huffman@40327
   229
by (erule monofun_Rep_cfun2 [THEN ch2ch_monofun])
huffman@16209
   230
huffman@40327
   231
lemma ch2ch_Rep_cfunR: "chain Y \<Longrightarrow> chain (\<lambda>i. f\<cdot>(Y i))"
huffman@40327
   232
by (rule monofun_Rep_cfun2 [THEN ch2ch_monofun])
huffman@15576
   233
huffman@40327
   234
lemma ch2ch_Rep_cfunL: "chain F \<Longrightarrow> chain (\<lambda>i. (F i)\<cdot>x)"
huffman@40327
   235
by (rule monofun_Rep_cfun1 [THEN ch2ch_monofun])
huffman@15576
   236
huffman@40327
   237
lemma ch2ch_Rep_cfun [simp]:
huffman@18076
   238
  "\<lbrakk>chain F; chain Y\<rbrakk> \<Longrightarrow> chain (\<lambda>i. (F i)\<cdot>(Y i))"
huffman@25884
   239
by (simp add: chain_def monofun_cfun)
huffman@15576
   240
huffman@25884
   241
lemma ch2ch_LAM [simp]:
huffman@25884
   242
  "\<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
   243
by (simp add: chain_def cfun_below_iff)
huffman@18092
   244
huffman@40327
   245
text {* contlub, cont properties of @{term Rep_cfun} in both arguments *}
huffman@15576
   246
huffman@41027
   247
lemma lub_APP:
huffman@41027
   248
  "\<lbrakk>chain F; chain Y\<rbrakk> \<Longrightarrow> (\<Squnion>i. F i\<cdot>(Y i)) = (\<Squnion>i. F i)\<cdot>(\<Squnion>i. Y i)"
huffman@18076
   249
by (simp add: contlub_cfun_fun contlub_cfun_arg diag_lub)
huffman@15576
   250
huffman@41027
   251
lemma cont_cfun:
huffman@16209
   252
  "\<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
   253
apply (rule thelubE)
huffman@40327
   254
apply (simp only: ch2ch_Rep_cfun)
huffman@41027
   255
apply (simp only: lub_APP)
huffman@16209
   256
done
huffman@16209
   257
huffman@41027
   258
lemma lub_LAM:
huffman@18092
   259
  "\<lbrakk>\<And>x. chain (\<lambda>i. F i x); \<And>i. cont (\<lambda>x. F i x)\<rbrakk>
huffman@41027
   260
    \<Longrightarrow> (\<Squnion>i. \<Lambda> x. F i x) = (\<Lambda> x. \<Squnion>i. F i x)"
huffman@40770
   261
apply (simp add: lub_cfun)
huffman@40327
   262
apply (simp add: Abs_cfun_inverse2)
huffman@18092
   263
apply (simp add: thelub_fun ch2ch_lambda)
huffman@18092
   264
done
huffman@18092
   265
huffman@41027
   266
lemmas lub_distribs = lub_APP lub_LAM
huffman@25901
   267
huffman@16209
   268
text {* strictness *}
huffman@16209
   269
huffman@16209
   270
lemma strictI: "f\<cdot>x = \<bottom> \<Longrightarrow> f\<cdot>\<bottom> = \<bottom>"
huffman@16209
   271
apply (rule UU_I)
huffman@15576
   272
apply (erule subst)
huffman@15576
   273
apply (rule minimal [THEN monofun_cfun_arg])
huffman@15576
   274
done
huffman@15576
   275
huffman@15589
   276
text {* type @{typ "'a -> 'b"} is chain complete *}
huffman@15576
   277
huffman@16920
   278
lemma lub_cfun: "chain F \<Longrightarrow> range F <<| (\<Lambda> x. \<Squnion>i. F i\<cdot>x)"
huffman@41027
   279
by (simp only: contlub_cfun_fun [symmetric] eta_cfun cpo_lubI)
huffman@15576
   280
huffman@27413
   281
lemma thelub_cfun: "chain F \<Longrightarrow> (\<Squnion>i. F i) = (\<Lambda> x. \<Squnion>i. F i\<cdot>x)"
huffman@40771
   282
by (rule lub_cfun [THEN lub_eqI])
huffman@15576
   283
huffman@17832
   284
subsection {* Continuity simplification procedure *}
huffman@15589
   285
huffman@40327
   286
text {* cont2cont lemma for @{term Rep_cfun} *}
huffman@15576
   287
huffman@40326
   288
lemma cont2cont_APP [simp, cont2cont]:
huffman@29049
   289
  assumes f: "cont (\<lambda>x. f x)"
huffman@29049
   290
  assumes t: "cont (\<lambda>x. t x)"
huffman@29049
   291
  shows "cont (\<lambda>x. (f x)\<cdot>(t x))"
huffman@29049
   292
proof -
huffman@40006
   293
  have 1: "\<And>y. cont (\<lambda>x. (f x)\<cdot>y)"
huffman@40327
   294
    using cont_Rep_cfun1 f by (rule cont_compose)
huffman@40006
   295
  show "cont (\<lambda>x. (f x)\<cdot>(t x))"
huffman@40327
   296
    using t cont_Rep_cfun2 1 by (rule cont_apply)
huffman@29049
   297
qed
huffman@15576
   298
huffman@40008
   299
text {*
huffman@40008
   300
  Two specific lemmas for the combination of LCF and HOL terms.
huffman@40008
   301
  These lemmas are needed in theories that use types like @{typ "'a \<rightarrow> 'b \<Rightarrow> 'c"}.
huffman@40008
   302
*}
huffman@40008
   303
huffman@40326
   304
lemma cont_APP_app [simp]: "\<lbrakk>cont f; cont g\<rbrakk> \<Longrightarrow> cont (\<lambda>x. ((f x)\<cdot>(g x)) s)"
huffman@40326
   305
by (rule cont2cont_APP [THEN cont2cont_fun])
huffman@40008
   306
huffman@40326
   307
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
   308
by (rule cont_APP_app [THEN cont2cont_fun])
huffman@40008
   309
huffman@40008
   310
huffman@15589
   311
text {* cont2mono Lemma for @{term "%x. LAM y. c1(x)(y)"} *}
huffman@15576
   312
huffman@15576
   313
lemma cont2mono_LAM:
huffman@29049
   314
  "\<lbrakk>\<And>x. cont (\<lambda>y. f x y); \<And>y. monofun (\<lambda>x. f x y)\<rbrakk>
huffman@29049
   315
    \<Longrightarrow> monofun (\<lambda>x. \<Lambda> y. f x y)"
huffman@40002
   316
  unfolding monofun_def cfun_below_iff by simp
huffman@15576
   317
huffman@29049
   318
text {* cont2cont Lemma for @{term "%x. LAM y. f x y"} *}
huffman@15576
   319
huffman@29530
   320
text {*
huffman@29530
   321
  Not suitable as a cont2cont rule, because on nested lambdas
huffman@29530
   322
  it causes exponential blow-up in the number of subgoals.
huffman@29530
   323
*}
huffman@29530
   324
huffman@15576
   325
lemma cont2cont_LAM:
huffman@29049
   326
  assumes f1: "\<And>x. cont (\<lambda>y. f x y)"
huffman@29049
   327
  assumes f2: "\<And>y. cont (\<lambda>x. f x y)"
huffman@29049
   328
  shows "cont (\<lambda>x. \<Lambda> y. f x y)"
huffman@40327
   329
proof (rule cont_Abs_cfun)
huffman@29049
   330
  fix x
huffman@40327
   331
  from f1 show "f x \<in> cfun" by (simp add: cfun_def)
huffman@29049
   332
  from f2 show "cont f" by (rule cont2cont_lambda)
huffman@29049
   333
qed
huffman@15576
   334
huffman@29530
   335
text {*
huffman@29530
   336
  This version does work as a cont2cont rule, since it
huffman@29530
   337
  has only a single subgoal.
huffman@29530
   338
*}
huffman@29530
   339
huffman@37079
   340
lemma cont2cont_LAM' [simp, cont2cont]:
huffman@29530
   341
  fixes f :: "'a::cpo \<Rightarrow> 'b::cpo \<Rightarrow> 'c::cpo"
huffman@29530
   342
  assumes f: "cont (\<lambda>p. f (fst p) (snd p))"
huffman@29530
   343
  shows "cont (\<lambda>x. \<Lambda> y. f x y)"
huffman@39808
   344
using assms by (simp add: cont2cont_LAM prod_cont_iff)
huffman@29530
   345
huffman@37079
   346
lemma cont2cont_LAM_discrete [simp, cont2cont]:
huffman@29530
   347
  "(\<And>y::'a::discrete_cpo. cont (\<lambda>x. f x y)) \<Longrightarrow> cont (\<lambda>x. \<Lambda> y. f x y)"
huffman@29530
   348
by (simp add: cont2cont_LAM)
huffman@15576
   349
huffman@17832
   350
subsection {* Miscellaneous *}
huffman@17832
   351
huffman@40327
   352
text {* Monotonicity of @{term Abs_cfun} *}
huffman@15576
   353
huffman@40433
   354
lemma monofun_LAM:
huffman@40433
   355
  "\<lbrakk>cont f; cont g; \<And>x. f x \<sqsubseteq> g x\<rbrakk> \<Longrightarrow> (\<Lambda> x. f x) \<sqsubseteq> (\<Lambda> x. g x)"
huffman@40433
   356
by (simp add: cfun_below_iff)
huffman@15576
   357
huffman@15589
   358
text {* some lemmata for functions with flat/chfin domain/range types *}
huffman@15576
   359
huffman@40327
   360
lemma chfin_Rep_cfunR: "chain (Y::nat => 'a::cpo->'b::chfin)  
huffman@27413
   361
      ==> !s. ? n. (LUB i. Y i)$s = Y n$s"
huffman@15576
   362
apply (rule allI)
huffman@15576
   363
apply (subst contlub_cfun_fun)
huffman@15576
   364
apply assumption
huffman@40771
   365
apply (fast intro!: lub_eqI chfin lub_finch2 chfin2finch ch2ch_Rep_cfunL)
huffman@15576
   366
done
huffman@15576
   367
huffman@18089
   368
lemma adm_chfindom: "adm (\<lambda>(u::'a::cpo \<rightarrow> 'b::chfin). P(u\<cdot>s))"
huffman@18089
   369
by (rule adm_subst, simp, rule adm_chfin)
huffman@18089
   370
huffman@16085
   371
subsection {* Continuous injection-retraction pairs *}
huffman@15589
   372
huffman@16085
   373
text {* Continuous retractions are strict. *}
huffman@15576
   374
huffman@16085
   375
lemma retraction_strict:
huffman@16085
   376
  "\<forall>x. f\<cdot>(g\<cdot>x) = x \<Longrightarrow> f\<cdot>\<bottom> = \<bottom>"
huffman@15576
   377
apply (rule UU_I)
huffman@16085
   378
apply (drule_tac x="\<bottom>" in spec)
huffman@16085
   379
apply (erule subst)
huffman@16085
   380
apply (rule monofun_cfun_arg)
huffman@16085
   381
apply (rule minimal)
huffman@15576
   382
done
huffman@15576
   383
huffman@16085
   384
lemma injection_eq:
huffman@16085
   385
  "\<forall>x. f\<cdot>(g\<cdot>x) = x \<Longrightarrow> (g\<cdot>x = g\<cdot>y) = (x = y)"
huffman@16085
   386
apply (rule iffI)
huffman@16085
   387
apply (drule_tac f=f in cfun_arg_cong)
huffman@16085
   388
apply simp
huffman@16085
   389
apply simp
huffman@15576
   390
done
huffman@15576
   391
huffman@31076
   392
lemma injection_below:
huffman@16314
   393
  "\<forall>x. f\<cdot>(g\<cdot>x) = x \<Longrightarrow> (g\<cdot>x \<sqsubseteq> g\<cdot>y) = (x \<sqsubseteq> y)"
huffman@16314
   394
apply (rule iffI)
huffman@16314
   395
apply (drule_tac f=f in monofun_cfun_arg)
huffman@16314
   396
apply simp
huffman@16314
   397
apply (erule monofun_cfun_arg)
huffman@16314
   398
done
huffman@16314
   399
huffman@16085
   400
lemma injection_defined_rev:
huffman@16085
   401
  "\<lbrakk>\<forall>x. f\<cdot>(g\<cdot>x) = x; g\<cdot>z = \<bottom>\<rbrakk> \<Longrightarrow> z = \<bottom>"
huffman@16085
   402
apply (drule_tac f=f in cfun_arg_cong)
huffman@16085
   403
apply (simp add: retraction_strict)
huffman@15576
   404
done
huffman@15576
   405
huffman@16085
   406
lemma injection_defined:
huffman@16085
   407
  "\<lbrakk>\<forall>x. f\<cdot>(g\<cdot>x) = x; z \<noteq> \<bottom>\<rbrakk> \<Longrightarrow> g\<cdot>z \<noteq> \<bottom>"
huffman@16085
   408
by (erule contrapos_nn, rule injection_defined_rev)
huffman@16085
   409
huffman@15589
   410
text {* a result about functions with flat codomain *}
huffman@15576
   411
huffman@16085
   412
lemma flat_eqI: "\<lbrakk>(x::'a::flat) \<sqsubseteq> y; x \<noteq> \<bottom>\<rbrakk> \<Longrightarrow> x = y"
huffman@25920
   413
by (drule ax_flat, simp)
huffman@16085
   414
huffman@16085
   415
lemma flat_codom:
huffman@16085
   416
  "f\<cdot>x = (c::'b::flat) \<Longrightarrow> f\<cdot>\<bottom> = \<bottom> \<or> (\<forall>z. f\<cdot>z = c)"
huffman@16085
   417
apply (case_tac "f\<cdot>x = \<bottom>")
huffman@15576
   418
apply (rule disjI1)
huffman@15576
   419
apply (rule UU_I)
huffman@16085
   420
apply (erule_tac t="\<bottom>" in subst)
huffman@15576
   421
apply (rule minimal [THEN monofun_cfun_arg])
huffman@16085
   422
apply clarify
huffman@16085
   423
apply (rule_tac a = "f\<cdot>\<bottom>" in refl [THEN box_equals])
huffman@16085
   424
apply (erule minimal [THEN monofun_cfun_arg, THEN flat_eqI])
huffman@16085
   425
apply (erule minimal [THEN monofun_cfun_arg, THEN flat_eqI])
huffman@15589
   426
done
huffman@15589
   427
huffman@15589
   428
subsection {* Identity and composition *}
huffman@15589
   429
wenzelm@25135
   430
definition
wenzelm@25135
   431
  ID :: "'a \<rightarrow> 'a" where
wenzelm@25135
   432
  "ID = (\<Lambda> x. x)"
wenzelm@25135
   433
wenzelm@25135
   434
definition
wenzelm@25135
   435
  cfcomp  :: "('b \<rightarrow> 'c) \<rightarrow> ('a \<rightarrow> 'b) \<rightarrow> 'a \<rightarrow> 'c" where
wenzelm@25135
   436
  oo_def: "cfcomp = (\<Lambda> f g x. f\<cdot>(g\<cdot>x))"
huffman@15589
   437
wenzelm@25131
   438
abbreviation
wenzelm@25131
   439
  cfcomp_syn :: "['b \<rightarrow> 'c, 'a \<rightarrow> 'b] \<Rightarrow> 'a \<rightarrow> 'c"  (infixr "oo" 100)  where
wenzelm@25131
   440
  "f oo g == cfcomp\<cdot>f\<cdot>g"
huffman@15589
   441
huffman@16085
   442
lemma ID1 [simp]: "ID\<cdot>x = x"
huffman@16085
   443
by (simp add: ID_def)
huffman@15576
   444
huffman@16085
   445
lemma cfcomp1: "(f oo g) = (\<Lambda> x. f\<cdot>(g\<cdot>x))"
huffman@15589
   446
by (simp add: oo_def)
huffman@15576
   447
huffman@16085
   448
lemma cfcomp2 [simp]: "(f oo g)\<cdot>x = f\<cdot>(g\<cdot>x)"
huffman@15589
   449
by (simp add: cfcomp1)
huffman@15576
   450
huffman@27274
   451
lemma cfcomp_LAM: "cont g \<Longrightarrow> f oo (\<Lambda> x. g x) = (\<Lambda> x. f\<cdot>(g x))"
huffman@27274
   452
by (simp add: cfcomp1)
huffman@27274
   453
huffman@19709
   454
lemma cfcomp_strict [simp]: "\<bottom> oo f = \<bottom>"
huffman@40002
   455
by (simp add: cfun_eq_iff)
huffman@19709
   456
huffman@15589
   457
text {*
huffman@15589
   458
  Show that interpretation of (pcpo,@{text "_->_"}) is a category.
huffman@15589
   459
  The class of objects is interpretation of syntactical class pcpo.
huffman@15589
   460
  The class of arrows  between objects @{typ 'a} and @{typ 'b} is interpret. of @{typ "'a -> 'b"}.
huffman@15589
   461
  The identity arrow is interpretation of @{term ID}.
huffman@15589
   462
  The composition of f and g is interpretation of @{text "oo"}.
huffman@15589
   463
*}
huffman@15576
   464
huffman@16085
   465
lemma ID2 [simp]: "f oo ID = f"
huffman@40002
   466
by (rule cfun_eqI, simp)
huffman@15576
   467
huffman@16085
   468
lemma ID3 [simp]: "ID oo f = f"
huffman@40002
   469
by (rule cfun_eqI, simp)
huffman@15576
   470
huffman@15576
   471
lemma assoc_oo: "f oo (g oo h) = (f oo g) oo h"
huffman@40002
   472
by (rule cfun_eqI, simp)
huffman@15576
   473
huffman@16085
   474
subsection {* Strictified functions *}
huffman@16085
   475
wenzelm@36452
   476
default_sort pcpo
huffman@16085
   477
wenzelm@25131
   478
definition
huffman@40767
   479
  seq :: "'a \<rightarrow> 'b \<rightarrow> 'b" where
huffman@40767
   480
  "seq = (\<Lambda> x. if x = \<bottom> then \<bottom> else ID)"
huffman@16085
   481
huffman@40794
   482
lemma cont2cont_if_bottom [cont2cont, simp]:
huffman@40794
   483
  assumes f: "cont (\<lambda>x. f x)" and g: "cont (\<lambda>x. g x)"
huffman@40794
   484
  shows "cont (\<lambda>x. if f x = \<bottom> then \<bottom> else g x)"
huffman@40794
   485
proof (rule cont_apply [OF f])
huffman@40794
   486
  show "\<And>x. cont (\<lambda>y. if y = \<bottom> then \<bottom> else g x)"
huffman@40794
   487
    unfolding cont_def is_lub_def is_ub_def ball_simps
huffman@40794
   488
    by (simp add: lub_eq_bottom_iff)
huffman@40794
   489
  show "\<And>y. cont (\<lambda>x. if y = \<bottom> then \<bottom> else g x)"
huffman@40794
   490
    by (simp add: g)
huffman@40794
   491
qed
huffman@16085
   492
huffman@40767
   493
lemma seq_conv_if: "seq\<cdot>x = (if x = \<bottom> then \<bottom> else ID)"
huffman@40794
   494
unfolding seq_def by simp
huffman@16085
   495
huffman@40767
   496
lemma seq1 [simp]: "seq\<cdot>\<bottom> = \<bottom>"
huffman@40767
   497
by (simp add: seq_conv_if)
huffman@16085
   498
huffman@40767
   499
lemma seq2 [simp]: "x \<noteq> \<bottom> \<Longrightarrow> seq\<cdot>x = ID"
huffman@40767
   500
by (simp add: seq_conv_if)
huffman@40046
   501
huffman@40767
   502
lemma seq3 [simp]: "seq\<cdot>x\<cdot>\<bottom> = \<bottom>"
huffman@40767
   503
by (simp add: seq_conv_if)
huffman@40093
   504
huffman@40093
   505
definition
huffman@40046
   506
  strictify  :: "('a \<rightarrow> 'b) \<rightarrow> 'a \<rightarrow> 'b" where
huffman@40767
   507
  "strictify = (\<Lambda> f x. seq\<cdot>x\<cdot>(f\<cdot>x))"
huffman@16085
   508
huffman@17815
   509
lemma strictify_conv_if: "strictify\<cdot>f\<cdot>x = (if x = \<bottom> then \<bottom> else f\<cdot>x)"
huffman@40046
   510
unfolding strictify_def by simp
huffman@16085
   511
huffman@16085
   512
lemma strictify1 [simp]: "strictify\<cdot>f\<cdot>\<bottom> = \<bottom>"
huffman@17815
   513
by (simp add: strictify_conv_if)
huffman@16085
   514
huffman@16085
   515
lemma strictify2 [simp]: "x \<noteq> \<bottom> \<Longrightarrow> strictify\<cdot>f\<cdot>x = f\<cdot>x"
huffman@17815
   516
by (simp add: strictify_conv_if)
huffman@16085
   517
huffman@35933
   518
subsection {* Continuity of let-bindings *}
huffman@17816
   519
huffman@35933
   520
lemma cont2cont_Let:
huffman@35933
   521
  assumes f: "cont (\<lambda>x. f x)"
huffman@35933
   522
  assumes g1: "\<And>y. cont (\<lambda>x. g x y)"
huffman@35933
   523
  assumes g2: "\<And>x. cont (\<lambda>y. g x y)"
huffman@35933
   524
  shows "cont (\<lambda>x. let y = f x in g x y)"
huffman@35933
   525
unfolding Let_def using f g2 g1 by (rule cont_apply)
huffman@17816
   526
huffman@37079
   527
lemma cont2cont_Let' [simp, cont2cont]:
huffman@35933
   528
  assumes f: "cont (\<lambda>x. f x)"
huffman@35933
   529
  assumes g: "cont (\<lambda>p. g (fst p) (snd p))"
huffman@35933
   530
  shows "cont (\<lambda>x. let y = f x in g x y)"
huffman@35933
   531
using f
huffman@35933
   532
proof (rule cont2cont_Let)
huffman@35933
   533
  fix x show "cont (\<lambda>y. g x y)"
huffman@40003
   534
    using g by (simp add: prod_cont_iff)
huffman@35933
   535
next
huffman@35933
   536
  fix y show "cont (\<lambda>x. g x y)"
huffman@40003
   537
    using g by (simp add: prod_cont_iff)
huffman@35933
   538
qed
huffman@17816
   539
huffman@39145
   540
text {* The simple version (suggested by Joachim Breitner) is needed if
huffman@39145
   541
  the type of the defined term is not a cpo. *}
huffman@39145
   542
huffman@39145
   543
lemma cont2cont_Let_simple [simp, cont2cont]:
huffman@39145
   544
  assumes "\<And>y. cont (\<lambda>x. g x y)"
huffman@39145
   545
  shows "cont (\<lambda>x. let y = t in g x y)"
huffman@39145
   546
unfolding Let_def using assms .
huffman@39145
   547
huffman@15576
   548
end