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