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