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