src/HOLCF/Cfun.thy
author huffman
Tue Oct 12 05:48:32 2010 -0700 (2010-10-12)
changeset 40005 3e3611136a13
parent 40003 427106657e04
child 40006 116e94f9543b
permissions -rw-r--r--
remove unused lemmas
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@16699
    16
lemma Ex_cont: "\<exists>f. cont f"
huffman@16699
    17
by (rule exI, rule cont_const)
huffman@16699
    18
huffman@16699
    19
lemma adm_cont: "adm cont"
huffman@16699
    20
by (rule admI, rule cont_lub_fun)
huffman@16699
    21
huffman@35525
    22
cpodef (CFun)  ('a, 'b) cfun (infixr "->" 0) = "{f::'a => 'b. cont f}"
wenzelm@29063
    23
by (simp_all add: Ex_cont adm_cont)
huffman@15576
    24
wenzelm@35427
    25
type_notation (xsymbols)
huffman@35525
    26
  cfun  ("(_ \<rightarrow>/ _)" [1, 0] 0)
huffman@17816
    27
wenzelm@25131
    28
notation
wenzelm@25131
    29
  Rep_CFun  ("(_$/_)" [999,1000] 999)
huffman@15576
    30
wenzelm@25131
    31
notation (xsymbols)
wenzelm@25131
    32
  Rep_CFun  ("(_\<cdot>/_)" [999,1000] 999)
huffman@15576
    33
wenzelm@25131
    34
notation (HTML output)
wenzelm@25131
    35
  Rep_CFun  ("(_\<cdot>/_)" [999,1000] 999)
huffman@17816
    36
huffman@17832
    37
subsection {* Syntax for continuous lambda abstraction *}
huffman@17832
    38
huffman@18078
    39
syntax "_cabs" :: "'a"
huffman@18078
    40
huffman@18078
    41
parse_translation {*
wenzelm@35115
    42
(* rewrite (_cabs x t) => (Abs_CFun (%x. t)) *)
wenzelm@35115
    43
  [mk_binder_tr (@{syntax_const "_cabs"}, @{const_syntax Abs_CFun})];
huffman@18078
    44
*}
huffman@17816
    45
huffman@17832
    46
text {* To avoid eta-contraction of body: *}
huffman@18087
    47
typed_print_translation {*
huffman@18078
    48
  let
huffman@18087
    49
    fun cabs_tr' _ _ [Abs abs] = let
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@18087
    53
      | cabs_tr' _ T [t] = let
huffman@18087
    54
          val xT = domain_type (domain_type T);
huffman@18087
    55
          val abs' = ("x",xT,(incr_boundvars 1 t)$Bound 0);
huffman@18087
    56
          val (x,t') = atomic_abs_tr' abs';
wenzelm@35115
    57
        in Syntax.const @{syntax_const "_cabs"} $ x $ t' end;
huffman@18087
    58
wenzelm@25131
    59
  in [(@{const_syntax Abs_CFun}, cabs_tr')] end;
huffman@17816
    60
*}
huffman@17816
    61
huffman@18087
    62
text {* Syntax for nested abstractions *}
huffman@17832
    63
huffman@17832
    64
syntax
huffman@18078
    65
  "_Lambda" :: "[cargs, 'a] \<Rightarrow> logic"  ("(3LAM _./ _)" [1000, 10] 10)
huffman@17832
    66
huffman@17832
    67
syntax (xsymbols)
huffman@25927
    68
  "_Lambda" :: "[cargs, 'a] \<Rightarrow> logic" ("(3\<Lambda> _./ _)" [1000, 10] 10)
huffman@17832
    69
huffman@17816
    70
parse_ast_translation {*
wenzelm@35115
    71
(* rewrite (LAM x y z. t) => (_cabs x (_cabs y (_cabs z t))) *)
wenzelm@35115
    72
(* cf. Syntax.lambda_ast_tr from src/Pure/Syntax/syn_trans.ML *)
huffman@18078
    73
  let
huffman@18078
    74
    fun Lambda_ast_tr [pats, body] =
wenzelm@35115
    75
          Syntax.fold_ast_p @{syntax_const "_cabs"}
wenzelm@35115
    76
            (Syntax.unfold_ast @{syntax_const "_cargs"} pats, body)
huffman@18078
    77
      | Lambda_ast_tr asts = raise Syntax.AST ("Lambda_ast_tr", asts);
wenzelm@35115
    78
  in [(@{syntax_const "_Lambda"}, Lambda_ast_tr)] end;
huffman@17816
    79
*}
huffman@17816
    80
huffman@17816
    81
print_ast_translation {*
wenzelm@35115
    82
(* rewrite (_cabs x (_cabs y (_cabs z t))) => (LAM x y z. t) *)
wenzelm@35115
    83
(* cf. Syntax.abs_ast_tr' from src/Pure/Syntax/syn_trans.ML *)
huffman@18078
    84
  let
huffman@18078
    85
    fun cabs_ast_tr' asts =
wenzelm@35115
    86
      (case Syntax.unfold_ast_p @{syntax_const "_cabs"}
wenzelm@35115
    87
          (Syntax.Appl (Syntax.Constant @{syntax_const "_cabs"} :: asts)) of
huffman@18078
    88
        ([], _) => raise Syntax.AST ("cabs_ast_tr'", asts)
huffman@18078
    89
      | (xs, body) => Syntax.Appl
wenzelm@35115
    90
          [Syntax.Constant @{syntax_const "_Lambda"},
wenzelm@35115
    91
           Syntax.fold_ast @{syntax_const "_cargs"} xs, body]);
wenzelm@35115
    92
  in [(@{syntax_const "_cabs"}, cabs_ast_tr')] end
huffman@17816
    93
*}
huffman@15641
    94
huffman@18087
    95
text {* Dummy patterns for continuous abstraction *}
huffman@18079
    96
translations
wenzelm@25131
    97
  "\<Lambda> _. t" => "CONST Abs_CFun (\<lambda> _. t)"
huffman@18087
    98
huffman@17832
    99
subsection {* Continuous function space is pointed *}
huffman@15589
   100
huffman@16098
   101
lemma UU_CFun: "\<bottom> \<in> CFun"
huffman@37079
   102
by (simp add: CFun_def inst_fun_pcpo)
huffman@16098
   103
huffman@35525
   104
instance cfun :: (finite_po, finite_po) finite_po
huffman@25827
   105
by (rule typedef_finite_po [OF type_definition_CFun])
huffman@25827
   106
huffman@35525
   107
instance cfun :: (finite_po, chfin) chfin
huffman@31076
   108
by (rule typedef_chfin [OF type_definition_CFun below_CFun_def])
huffman@25827
   109
huffman@35525
   110
instance cfun :: (cpo, discrete_cpo) discrete_cpo
huffman@31076
   111
by intro_classes (simp add: below_CFun_def Rep_CFun_inject)
huffman@26025
   112
huffman@35525
   113
instance cfun :: (cpo, pcpo) pcpo
huffman@31076
   114
by (rule typedef_pcpo [OF type_definition_CFun below_CFun_def UU_CFun])
huffman@16098
   115
huffman@16209
   116
lemmas Rep_CFun_strict =
huffman@31076
   117
  typedef_Rep_strict [OF type_definition_CFun below_CFun_def UU_CFun]
huffman@16209
   118
huffman@16209
   119
lemmas Abs_CFun_strict =
huffman@31076
   120
  typedef_Abs_strict [OF type_definition_CFun below_CFun_def UU_CFun]
huffman@16098
   121
huffman@17832
   122
text {* function application is strict in its first argument *}
huffman@17832
   123
huffman@17832
   124
lemma Rep_CFun_strict1 [simp]: "\<bottom>\<cdot>x = \<bottom>"
huffman@17832
   125
by (simp add: Rep_CFun_strict)
huffman@17832
   126
huffman@35641
   127
lemma LAM_strict [simp]: "(\<Lambda> x. \<bottom>) = \<bottom>"
huffman@35641
   128
by (simp add: inst_fun_pcpo [symmetric] Abs_CFun_strict)
huffman@35641
   129
huffman@17832
   130
text {* for compatibility with old HOLCF-Version *}
huffman@17832
   131
lemma inst_cfun_pcpo: "\<bottom> = (\<Lambda> x. \<bottom>)"
huffman@35641
   132
by simp
huffman@17832
   133
huffman@17832
   134
subsection {* Basic properties of continuous functions *}
huffman@17832
   135
huffman@17832
   136
text {* Beta-equality for continuous functions *}
huffman@16209
   137
huffman@16209
   138
lemma Abs_CFun_inverse2: "cont f \<Longrightarrow> Rep_CFun (Abs_CFun f) = f"
huffman@16209
   139
by (simp add: Abs_CFun_inverse CFun_def)
huffman@16098
   140
huffman@37083
   141
lemma beta_cfun: "cont f \<Longrightarrow> (\<Lambda> x. f x)\<cdot>u = f u"
huffman@16209
   142
by (simp add: Abs_CFun_inverse2)
huffman@16209
   143
huffman@37083
   144
text {* Beta-reduction simproc *}
huffman@37083
   145
huffman@37083
   146
text {*
huffman@37083
   147
  Given the term @{term "(\<Lambda> x. f x)\<cdot>y"}, the procedure tries to
huffman@37083
   148
  construct the theorem @{term "(\<Lambda> x. f x)\<cdot>y == f y"}.  If this
huffman@37083
   149
  theorem cannot be completely solved by the cont2cont rules, then
huffman@37083
   150
  the procedure returns the ordinary conditional @{text beta_cfun}
huffman@37083
   151
  rule.
huffman@37083
   152
huffman@37083
   153
  The simproc does not solve any more goals that would be solved by
huffman@37083
   154
  using @{text beta_cfun} as a simp rule.  The advantage of the
huffman@37083
   155
  simproc is that it can avoid deeply-nested calls to the simplifier
huffman@37083
   156
  that would otherwise be caused by large continuity side conditions.
huffman@37083
   157
*}
huffman@37083
   158
huffman@37083
   159
simproc_setup beta_cfun_proc ("Abs_CFun f\<cdot>x") = {*
huffman@37083
   160
  fn phi => fn ss => fn ct =>
huffman@37083
   161
    let
huffman@37083
   162
      val dest = Thm.dest_comb;
huffman@37083
   163
      val (f, x) = (apfst (snd o dest o snd o dest) o dest) ct;
huffman@37083
   164
      val [T, U] = Thm.dest_ctyp (ctyp_of_term f);
huffman@37083
   165
      val tr = instantiate' [SOME T, SOME U] [SOME f, SOME x]
huffman@37083
   166
          (mk_meta_eq @{thm beta_cfun});
huffman@37083
   167
      val rules = Cont2ContData.get (Simplifier.the_context ss);
huffman@37083
   168
      val tac = SOLVED' (REPEAT_ALL_NEW (match_tac rules));
huffman@37083
   169
    in SOME (perhaps (SINGLE (tac 1)) tr) end
huffman@37083
   170
*}
huffman@37083
   171
huffman@16209
   172
text {* Eta-equality for continuous functions *}
huffman@16209
   173
huffman@16209
   174
lemma eta_cfun: "(\<Lambda> x. f\<cdot>x) = f"
huffman@16209
   175
by (rule Rep_CFun_inverse)
huffman@16209
   176
huffman@16209
   177
text {* Extensionality for continuous functions *}
huffman@16209
   178
huffman@40002
   179
lemma cfun_eq_iff: "f = g \<longleftrightarrow> (\<forall>x. f\<cdot>x = g\<cdot>x)"
nipkow@39302
   180
by (simp add: Rep_CFun_inject [symmetric] fun_eq_iff)
huffman@17832
   181
huffman@40002
   182
lemma cfun_eqI: "(\<And>x. f\<cdot>x = g\<cdot>x) \<Longrightarrow> f = g"
huffman@40002
   183
by (simp add: cfun_eq_iff)
huffman@17832
   184
huffman@17832
   185
text {* Extensionality wrt. ordering for continuous functions *}
huffman@15576
   186
huffman@40002
   187
lemma cfun_below_iff: "f \<sqsubseteq> g \<longleftrightarrow> (\<forall>x. f\<cdot>x \<sqsubseteq> g\<cdot>x)" 
huffman@40002
   188
by (simp add: below_CFun_def fun_below_iff)
huffman@17832
   189
huffman@40002
   190
lemma cfun_belowI: "(\<And>x. f\<cdot>x \<sqsubseteq> g\<cdot>x) \<Longrightarrow> f \<sqsubseteq> g"
huffman@40002
   191
by (simp add: cfun_below_iff)
huffman@17832
   192
huffman@17832
   193
text {* Congruence for continuous function application *}
huffman@15589
   194
huffman@16209
   195
lemma cfun_cong: "\<lbrakk>f = g; x = y\<rbrakk> \<Longrightarrow> f\<cdot>x = g\<cdot>y"
huffman@15589
   196
by simp
huffman@15589
   197
huffman@16209
   198
lemma cfun_fun_cong: "f = g \<Longrightarrow> f\<cdot>x = g\<cdot>x"
huffman@15589
   199
by simp
huffman@15589
   200
huffman@16209
   201
lemma cfun_arg_cong: "x = y \<Longrightarrow> f\<cdot>x = f\<cdot>y"
huffman@15589
   202
by simp
huffman@15589
   203
huffman@16209
   204
subsection {* Continuity of application *}
huffman@15576
   205
huffman@16209
   206
lemma cont_Rep_CFun1: "cont (\<lambda>f. f\<cdot>x)"
huffman@18092
   207
by (rule cont_Rep_CFun [THEN cont2cont_fun])
huffman@15576
   208
huffman@16209
   209
lemma cont_Rep_CFun2: "cont (\<lambda>x. f\<cdot>x)"
huffman@18092
   210
apply (cut_tac x=f in Rep_CFun)
huffman@18092
   211
apply (simp add: CFun_def)
huffman@15576
   212
done
huffman@15576
   213
huffman@16209
   214
lemmas monofun_Rep_CFun = cont_Rep_CFun [THEN cont2mono]
huffman@15589
   215
huffman@16209
   216
lemmas monofun_Rep_CFun1 = cont_Rep_CFun1 [THEN cont2mono, standard]
huffman@16209
   217
lemmas monofun_Rep_CFun2 = cont_Rep_CFun2 [THEN cont2mono, standard]
huffman@16209
   218
huffman@16209
   219
text {* contlub, cont properties of @{term Rep_CFun} in each argument *}
huffman@16209
   220
huffman@27413
   221
lemma contlub_cfun_arg: "chain Y \<Longrightarrow> f\<cdot>(\<Squnion>i. Y i) = (\<Squnion>i. f\<cdot>(Y i))"
huffman@35914
   222
by (rule cont_Rep_CFun2 [THEN cont2contlubE])
huffman@15576
   223
huffman@27413
   224
lemma cont_cfun_arg: "chain Y \<Longrightarrow> range (\<lambda>i. f\<cdot>(Y i)) <<| f\<cdot>(\<Squnion>i. Y i)"
huffman@16209
   225
by (rule cont_Rep_CFun2 [THEN contE])
huffman@16209
   226
huffman@27413
   227
lemma contlub_cfun_fun: "chain F \<Longrightarrow> (\<Squnion>i. F i)\<cdot>x = (\<Squnion>i. F i\<cdot>x)"
huffman@35914
   228
by (rule cont_Rep_CFun1 [THEN cont2contlubE])
huffman@15576
   229
huffman@27413
   230
lemma cont_cfun_fun: "chain F \<Longrightarrow> range (\<lambda>i. F i\<cdot>x) <<| (\<Squnion>i. F i)\<cdot>x"
huffman@16209
   231
by (rule cont_Rep_CFun1 [THEN contE])
huffman@15576
   232
huffman@16209
   233
text {* monotonicity of application *}
huffman@16209
   234
huffman@16209
   235
lemma monofun_cfun_fun: "f \<sqsubseteq> g \<Longrightarrow> f\<cdot>x \<sqsubseteq> g\<cdot>x"
huffman@40002
   236
by (simp add: cfun_below_iff)
huffman@15576
   237
huffman@16209
   238
lemma monofun_cfun_arg: "x \<sqsubseteq> y \<Longrightarrow> f\<cdot>x \<sqsubseteq> f\<cdot>y"
huffman@16209
   239
by (rule monofun_Rep_CFun2 [THEN monofunE])
huffman@15576
   240
huffman@16209
   241
lemma monofun_cfun: "\<lbrakk>f \<sqsubseteq> g; x \<sqsubseteq> y\<rbrakk> \<Longrightarrow> f\<cdot>x \<sqsubseteq> g\<cdot>y"
huffman@31076
   242
by (rule below_trans [OF monofun_cfun_fun monofun_cfun_arg])
huffman@15576
   243
huffman@16209
   244
text {* ch2ch - rules for the type @{typ "'a -> 'b"} *}
huffman@15576
   245
huffman@16209
   246
lemma chain_monofun: "chain Y \<Longrightarrow> chain (\<lambda>i. f\<cdot>(Y i))"
huffman@16209
   247
by (erule monofun_Rep_CFun2 [THEN ch2ch_monofun])
huffman@16209
   248
huffman@16209
   249
lemma ch2ch_Rep_CFunR: "chain Y \<Longrightarrow> chain (\<lambda>i. f\<cdot>(Y i))"
huffman@16209
   250
by (rule monofun_Rep_CFun2 [THEN ch2ch_monofun])
huffman@15576
   251
huffman@16209
   252
lemma ch2ch_Rep_CFunL: "chain F \<Longrightarrow> chain (\<lambda>i. (F i)\<cdot>x)"
huffman@16209
   253
by (rule monofun_Rep_CFun1 [THEN ch2ch_monofun])
huffman@15576
   254
huffman@18076
   255
lemma ch2ch_Rep_CFun [simp]:
huffman@18076
   256
  "\<lbrakk>chain F; chain Y\<rbrakk> \<Longrightarrow> chain (\<lambda>i. (F i)\<cdot>(Y i))"
huffman@25884
   257
by (simp add: chain_def monofun_cfun)
huffman@15576
   258
huffman@25884
   259
lemma ch2ch_LAM [simp]:
huffman@25884
   260
  "\<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
   261
by (simp add: chain_def cfun_below_iff)
huffman@18092
   262
huffman@16209
   263
text {* contlub, cont properties of @{term Rep_CFun} in both arguments *}
huffman@15576
   264
huffman@16209
   265
lemma contlub_cfun: 
huffman@16209
   266
  "\<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
   267
by (simp add: contlub_cfun_fun contlub_cfun_arg diag_lub)
huffman@15576
   268
huffman@16209
   269
lemma cont_cfun: 
huffman@16209
   270
  "\<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
   271
apply (rule thelubE)
huffman@16209
   272
apply (simp only: ch2ch_Rep_CFun)
huffman@16209
   273
apply (simp only: contlub_cfun)
huffman@16209
   274
done
huffman@16209
   275
huffman@18092
   276
lemma contlub_LAM:
huffman@18092
   277
  "\<lbrakk>\<And>x. chain (\<lambda>i. F i x); \<And>i. cont (\<lambda>x. F i x)\<rbrakk>
huffman@18092
   278
    \<Longrightarrow> (\<Lambda> x. \<Squnion>i. F i x) = (\<Squnion>i. \<Lambda> x. F i x)"
huffman@25884
   279
apply (simp add: thelub_CFun)
huffman@18092
   280
apply (simp add: Abs_CFun_inverse2)
huffman@18092
   281
apply (simp add: thelub_fun ch2ch_lambda)
huffman@18092
   282
done
huffman@18092
   283
huffman@25901
   284
lemmas lub_distribs = 
huffman@25901
   285
  contlub_cfun [symmetric]
huffman@25901
   286
  contlub_LAM [symmetric]
huffman@25901
   287
huffman@16209
   288
text {* strictness *}
huffman@16209
   289
huffman@16209
   290
lemma strictI: "f\<cdot>x = \<bottom> \<Longrightarrow> f\<cdot>\<bottom> = \<bottom>"
huffman@16209
   291
apply (rule UU_I)
huffman@15576
   292
apply (erule subst)
huffman@15576
   293
apply (rule minimal [THEN monofun_cfun_arg])
huffman@15576
   294
done
huffman@15576
   295
huffman@15589
   296
text {* type @{typ "'a -> 'b"} is chain complete *}
huffman@15576
   297
huffman@16920
   298
lemma lub_cfun: "chain F \<Longrightarrow> range F <<| (\<Lambda> x. \<Squnion>i. F i\<cdot>x)"
huffman@16920
   299
by (simp only: contlub_cfun_fun [symmetric] eta_cfun thelubE)
huffman@15576
   300
huffman@27413
   301
lemma thelub_cfun: "chain F \<Longrightarrow> (\<Squnion>i. F i) = (\<Lambda> x. \<Squnion>i. F i\<cdot>x)"
huffman@16920
   302
by (rule lub_cfun [THEN thelubI])
huffman@15576
   303
huffman@17832
   304
subsection {* Continuity simplification procedure *}
huffman@15589
   305
huffman@15589
   306
text {* cont2cont lemma for @{term Rep_CFun} *}
huffman@15576
   307
huffman@37079
   308
lemma cont2cont_Rep_CFun [simp, cont2cont]:
huffman@29049
   309
  assumes f: "cont (\<lambda>x. f x)"
huffman@29049
   310
  assumes t: "cont (\<lambda>x. t x)"
huffman@29049
   311
  shows "cont (\<lambda>x. (f x)\<cdot>(t x))"
huffman@29049
   312
proof -
huffman@29049
   313
  have "cont (\<lambda>x. Rep_CFun (f x))"
huffman@29049
   314
    using cont_Rep_CFun f by (rule cont2cont_app3)
huffman@29049
   315
  thus "cont (\<lambda>x. (f x)\<cdot>(t x))"
huffman@29049
   316
    using cont_Rep_CFun2 t by (rule cont2cont_app2)
huffman@29049
   317
qed
huffman@15576
   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@29049
   337
proof (rule cont_Abs_CFun)
huffman@29049
   338
  fix x
huffman@29049
   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@16055
   359
  cont_const cont_id cont_Rep_CFun2 cont2cont_Rep_CFun cont2cont_LAM
huffman@16055
   360
huffman@17832
   361
subsection {* Miscellaneous *}
huffman@17832
   362
huffman@17832
   363
text {* Monotonicity of @{term Abs_CFun} *}
huffman@15576
   364
huffman@17832
   365
lemma semi_monofun_Abs_CFun:
huffman@17832
   366
  "\<lbrakk>cont f; cont g; f \<sqsubseteq> g\<rbrakk> \<Longrightarrow> Abs_CFun f \<sqsubseteq> Abs_CFun g"
huffman@31076
   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@15576
   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@15576
   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
wenzelm@25131
   531
  strictify  :: "('a \<rightarrow> 'b) \<rightarrow> 'a \<rightarrow> 'b" where
wenzelm@25131
   532
  "strictify = (\<Lambda> f x. if x = \<bottom> then \<bottom> else f\<cdot>x)"
huffman@16085
   533
huffman@16085
   534
text {* results about strictify *}
huffman@16085
   535
huffman@17815
   536
lemma cont_strictify1: "cont (\<lambda>f. if x = \<bottom> then \<bottom> else f\<cdot>x)"
huffman@35168
   537
by simp
huffman@16085
   538
huffman@17815
   539
lemma monofun_strictify2: "monofun (\<lambda>x. if x = \<bottom> then \<bottom> else f\<cdot>x)"
huffman@17815
   540
apply (rule monofunI)
huffman@25786
   541
apply (auto simp add: monofun_cfun_arg)
huffman@16085
   542
done
huffman@16085
   543
huffman@35914
   544
lemma cont_strictify2: "cont (\<lambda>x. if x = \<bottom> then \<bottom> else f\<cdot>x)"
huffman@35914
   545
apply (rule contI2)
huffman@35914
   546
apply (rule monofun_strictify2)
huffman@35914
   547
apply (case_tac "(\<Squnion>i. Y i) = \<bottom>", simp)
huffman@35914
   548
apply (simp add: contlub_cfun_arg del: if_image_distrib)
huffman@35914
   549
apply (drule chain_UU_I_inverse2, clarify, rename_tac j)
huffman@35914
   550
apply (rule lub_mono2, rule_tac x=j in exI, simp_all)
huffman@35914
   551
apply (auto dest!: chain_mono_less)
huffman@16085
   552
done
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@29530
   555
  unfolding strictify_def
huffman@29530
   556
  by (simp add: cont_strictify1 cont_strictify2 cont2cont_LAM)
huffman@16085
   557
huffman@16085
   558
lemma strictify1 [simp]: "strictify\<cdot>f\<cdot>\<bottom> = \<bottom>"
huffman@17815
   559
by (simp add: strictify_conv_if)
huffman@16085
   560
huffman@16085
   561
lemma strictify2 [simp]: "x \<noteq> \<bottom> \<Longrightarrow> strictify\<cdot>f\<cdot>x = f\<cdot>x"
huffman@17815
   562
by (simp add: strictify_conv_if)
huffman@16085
   563
huffman@35933
   564
subsection {* Continuity of let-bindings *}
huffman@17816
   565
huffman@35933
   566
lemma cont2cont_Let:
huffman@35933
   567
  assumes f: "cont (\<lambda>x. f x)"
huffman@35933
   568
  assumes g1: "\<And>y. cont (\<lambda>x. g x y)"
huffman@35933
   569
  assumes g2: "\<And>x. cont (\<lambda>y. g x y)"
huffman@35933
   570
  shows "cont (\<lambda>x. let y = f x in g x y)"
huffman@35933
   571
unfolding Let_def using f g2 g1 by (rule cont_apply)
huffman@17816
   572
huffman@37079
   573
lemma cont2cont_Let' [simp, cont2cont]:
huffman@35933
   574
  assumes f: "cont (\<lambda>x. f x)"
huffman@35933
   575
  assumes g: "cont (\<lambda>p. g (fst p) (snd p))"
huffman@35933
   576
  shows "cont (\<lambda>x. let y = f x in g x y)"
huffman@35933
   577
using f
huffman@35933
   578
proof (rule cont2cont_Let)
huffman@35933
   579
  fix x show "cont (\<lambda>y. g x y)"
huffman@40003
   580
    using g by (simp add: prod_cont_iff)
huffman@35933
   581
next
huffman@35933
   582
  fix y show "cont (\<lambda>x. g x y)"
huffman@40003
   583
    using g by (simp add: prod_cont_iff)
huffman@35933
   584
qed
huffman@17816
   585
huffman@39145
   586
text {* The simple version (suggested by Joachim Breitner) is needed if
huffman@39145
   587
  the type of the defined term is not a cpo. *}
huffman@39145
   588
huffman@39145
   589
lemma cont2cont_Let_simple [simp, cont2cont]:
huffman@39145
   590
  assumes "\<And>y. cont (\<lambda>x. g x y)"
huffman@39145
   591
  shows "cont (\<lambda>x. let y = t in g x y)"
huffman@39145
   592
unfolding Let_def using assms .
huffman@39145
   593
huffman@15576
   594
end