src/HOLCF/Cfun.thy
author huffman
Tue Jul 01 02:19:53 2008 +0200 (2008-07-01)
changeset 27413 3154f3765cc7
parent 27274 1c97c471db82
child 29049 4e5b9e508e1e
permissions -rw-r--r--
replace lub (range Y) with (LUB i. Y i)
huffman@15600
     1
(*  Title:      HOLCF/Cfun.thy
huffman@15576
     2
    ID:         $Id$
huffman@15576
     3
    Author:     Franz Regensburger
huffman@15576
     4
huffman@15576
     5
Definition of the type ->  of continuous functions.
huffman@15576
     6
*)
huffman@15576
     7
huffman@15576
     8
header {* The type of continuous functions *}
huffman@15576
     9
huffman@15577
    10
theory Cfun
huffman@25786
    11
imports Pcpodef Ffun
wenzelm@23152
    12
uses ("Tools/cont_proc.ML")
huffman@15577
    13
begin
huffman@15576
    14
huffman@15576
    15
defaultsort cpo
huffman@15576
    16
huffman@15589
    17
subsection {* Definition of continuous function type *}
huffman@15589
    18
huffman@16699
    19
lemma Ex_cont: "\<exists>f. cont f"
huffman@16699
    20
by (rule exI, rule cont_const)
huffman@16699
    21
huffman@16699
    22
lemma adm_cont: "adm cont"
huffman@16699
    23
by (rule admI, rule cont_lub_fun)
huffman@16699
    24
huffman@17817
    25
cpodef (CFun)  ('a, 'b) "->" (infixr "->" 0) = "{f::'a => 'b. cont f}"
huffman@16699
    26
by (simp add: Ex_cont adm_cont)
huffman@15576
    27
huffman@17816
    28
syntax (xsymbols)
huffman@17816
    29
  "->"     :: "[type, type] => type"      ("(_ \<rightarrow>/ _)" [1,0]0)
huffman@17816
    30
wenzelm@25131
    31
notation
wenzelm@25131
    32
  Rep_CFun  ("(_$/_)" [999,1000] 999)
huffman@15576
    33
wenzelm@25131
    34
notation (xsymbols)
wenzelm@25131
    35
  Rep_CFun  ("(_\<cdot>/_)" [999,1000] 999)
huffman@15576
    36
wenzelm@25131
    37
notation (HTML output)
wenzelm@25131
    38
  Rep_CFun  ("(_\<cdot>/_)" [999,1000] 999)
huffman@17816
    39
huffman@17832
    40
subsection {* Syntax for continuous lambda abstraction *}
huffman@17832
    41
huffman@18078
    42
syntax "_cabs" :: "'a"
huffman@18078
    43
huffman@18078
    44
parse_translation {*
huffman@18087
    45
(* rewrites (_cabs x t) => (Abs_CFun (%x. t)) *)
wenzelm@25131
    46
  [mk_binder_tr ("_cabs", @{const_syntax Abs_CFun})];
huffman@18078
    47
*}
huffman@17816
    48
huffman@17832
    49
text {* To avoid eta-contraction of body: *}
huffman@18087
    50
typed_print_translation {*
huffman@18078
    51
  let
huffman@18087
    52
    fun cabs_tr' _ _ [Abs abs] = let
huffman@18087
    53
          val (x,t) = atomic_abs_tr' abs
huffman@18087
    54
        in Syntax.const "_cabs" $ x $ t end
huffman@18087
    55
huffman@18087
    56
      | cabs_tr' _ T [t] = let
huffman@18087
    57
          val xT = domain_type (domain_type T);
huffman@18087
    58
          val abs' = ("x",xT,(incr_boundvars 1 t)$Bound 0);
huffman@18087
    59
          val (x,t') = atomic_abs_tr' abs';
huffman@18087
    60
        in Syntax.const "_cabs" $ x $ t' end;
huffman@18087
    61
wenzelm@25131
    62
  in [(@{const_syntax Abs_CFun}, cabs_tr')] end;
huffman@17816
    63
*}
huffman@17816
    64
huffman@18087
    65
text {* Syntax for nested abstractions *}
huffman@17832
    66
huffman@17832
    67
syntax
huffman@18078
    68
  "_Lambda" :: "[cargs, 'a] \<Rightarrow> logic"  ("(3LAM _./ _)" [1000, 10] 10)
huffman@17832
    69
huffman@17832
    70
syntax (xsymbols)
huffman@25927
    71
  "_Lambda" :: "[cargs, 'a] \<Rightarrow> logic" ("(3\<Lambda> _./ _)" [1000, 10] 10)
huffman@17832
    72
huffman@17816
    73
parse_ast_translation {*
huffman@18087
    74
(* rewrites (LAM x y z. t) => (_cabs x (_cabs y (_cabs z t))) *)
huffman@18078
    75
(* cf. Syntax.lambda_ast_tr from Syntax/syn_trans.ML *)
huffman@18078
    76
  let
huffman@18078
    77
    fun Lambda_ast_tr [pats, body] =
huffman@18078
    78
          Syntax.fold_ast_p "_cabs" (Syntax.unfold_ast "_cargs" pats, body)
huffman@18078
    79
      | Lambda_ast_tr asts = raise Syntax.AST ("Lambda_ast_tr", asts);
huffman@18078
    80
  in [("_Lambda", Lambda_ast_tr)] end;
huffman@17816
    81
*}
huffman@17816
    82
huffman@17816
    83
print_ast_translation {*
huffman@18087
    84
(* rewrites (_cabs x (_cabs y (_cabs z t))) => (LAM x y z. t) *)
huffman@18078
    85
(* cf. Syntax.abs_ast_tr' from Syntax/syn_trans.ML *)
huffman@18078
    86
  let
huffman@18078
    87
    fun cabs_ast_tr' asts =
huffman@18078
    88
      (case Syntax.unfold_ast_p "_cabs"
huffman@18078
    89
          (Syntax.Appl (Syntax.Constant "_cabs" :: asts)) of
huffman@18078
    90
        ([], _) => raise Syntax.AST ("cabs_ast_tr'", asts)
huffman@18078
    91
      | (xs, body) => Syntax.Appl
huffman@18078
    92
          [Syntax.Constant "_Lambda", Syntax.fold_ast "_cargs" xs, body]);
huffman@18078
    93
  in [("_cabs", cabs_ast_tr')] end;
huffman@17816
    94
*}
huffman@15641
    95
huffman@18087
    96
text {* Dummy patterns for continuous abstraction *}
huffman@18079
    97
translations
wenzelm@25131
    98
  "\<Lambda> _. t" => "CONST Abs_CFun (\<lambda> _. t)"
huffman@18087
    99
huffman@18079
   100
huffman@17832
   101
subsection {* Continuous function space is pointed *}
huffman@15589
   102
huffman@16098
   103
lemma UU_CFun: "\<bottom> \<in> CFun"
huffman@16098
   104
by (simp add: CFun_def inst_fun_pcpo cont_const)
huffman@16098
   105
huffman@25827
   106
instance "->" :: (finite_po, finite_po) finite_po
huffman@25827
   107
by (rule typedef_finite_po [OF type_definition_CFun])
huffman@25827
   108
huffman@25827
   109
instance "->" :: (finite_po, chfin) chfin
huffman@25827
   110
by (rule typedef_chfin [OF type_definition_CFun less_CFun_def])
huffman@25827
   111
huffman@26025
   112
instance "->" :: (cpo, discrete_cpo) discrete_cpo
huffman@26025
   113
by intro_classes (simp add: less_CFun_def Rep_CFun_inject)
huffman@26025
   114
huffman@16098
   115
instance "->" :: (cpo, pcpo) pcpo
huffman@16920
   116
by (rule typedef_pcpo [OF type_definition_CFun less_CFun_def UU_CFun])
huffman@16098
   117
huffman@16209
   118
lemmas Rep_CFun_strict =
huffman@16699
   119
  typedef_Rep_strict [OF type_definition_CFun less_CFun_def UU_CFun]
huffman@16209
   120
huffman@16209
   121
lemmas Abs_CFun_strict =
huffman@16699
   122
  typedef_Abs_strict [OF type_definition_CFun less_CFun_def UU_CFun]
huffman@16098
   123
huffman@17832
   124
text {* function application is strict in its first argument *}
huffman@17832
   125
huffman@17832
   126
lemma Rep_CFun_strict1 [simp]: "\<bottom>\<cdot>x = \<bottom>"
huffman@17832
   127
by (simp add: Rep_CFun_strict)
huffman@17832
   128
huffman@17832
   129
text {* for compatibility with old HOLCF-Version *}
huffman@17832
   130
lemma inst_cfun_pcpo: "\<bottom> = (\<Lambda> x. \<bottom>)"
huffman@17832
   131
by (simp add: inst_fun_pcpo [symmetric] Abs_CFun_strict)
huffman@17832
   132
huffman@17832
   133
subsection {* Basic properties of continuous functions *}
huffman@17832
   134
huffman@17832
   135
text {* Beta-equality for continuous functions *}
huffman@16209
   136
huffman@16209
   137
lemma Abs_CFun_inverse2: "cont f \<Longrightarrow> Rep_CFun (Abs_CFun f) = f"
huffman@16209
   138
by (simp add: Abs_CFun_inverse CFun_def)
huffman@16098
   139
huffman@16209
   140
lemma beta_cfun [simp]: "cont f \<Longrightarrow> (\<Lambda> x. f x)\<cdot>u = f u"
huffman@16209
   141
by (simp add: Abs_CFun_inverse2)
huffman@16209
   142
huffman@16209
   143
text {* Eta-equality for continuous functions *}
huffman@16209
   144
huffman@16209
   145
lemma eta_cfun: "(\<Lambda> x. f\<cdot>x) = f"
huffman@16209
   146
by (rule Rep_CFun_inverse)
huffman@16209
   147
huffman@16209
   148
text {* Extensionality for continuous functions *}
huffman@16209
   149
huffman@17832
   150
lemma expand_cfun_eq: "(f = g) = (\<forall>x. f\<cdot>x = g\<cdot>x)"
huffman@17832
   151
by (simp add: Rep_CFun_inject [symmetric] expand_fun_eq)
huffman@17832
   152
huffman@16209
   153
lemma ext_cfun: "(\<And>x. f\<cdot>x = g\<cdot>x) \<Longrightarrow> f = g"
huffman@17832
   154
by (simp add: expand_cfun_eq)
huffman@17832
   155
huffman@17832
   156
text {* Extensionality wrt. ordering for continuous functions *}
huffman@15576
   157
huffman@17832
   158
lemma expand_cfun_less: "f \<sqsubseteq> g = (\<forall>x. f\<cdot>x \<sqsubseteq> g\<cdot>x)" 
huffman@17832
   159
by (simp add: less_CFun_def expand_fun_less)
huffman@17832
   160
huffman@17832
   161
lemma less_cfun_ext: "(\<And>x. f\<cdot>x \<sqsubseteq> g\<cdot>x) \<Longrightarrow> f \<sqsubseteq> g"
huffman@17832
   162
by (simp add: expand_cfun_less)
huffman@17832
   163
huffman@17832
   164
text {* Congruence for continuous function application *}
huffman@15589
   165
huffman@16209
   166
lemma cfun_cong: "\<lbrakk>f = g; x = y\<rbrakk> \<Longrightarrow> f\<cdot>x = g\<cdot>y"
huffman@15589
   167
by simp
huffman@15589
   168
huffman@16209
   169
lemma cfun_fun_cong: "f = g \<Longrightarrow> f\<cdot>x = g\<cdot>x"
huffman@15589
   170
by simp
huffman@15589
   171
huffman@16209
   172
lemma cfun_arg_cong: "x = y \<Longrightarrow> f\<cdot>x = f\<cdot>y"
huffman@15589
   173
by simp
huffman@15589
   174
huffman@16209
   175
subsection {* Continuity of application *}
huffman@15576
   176
huffman@16209
   177
lemma cont_Rep_CFun1: "cont (\<lambda>f. f\<cdot>x)"
huffman@18092
   178
by (rule cont_Rep_CFun [THEN cont2cont_fun])
huffman@15576
   179
huffman@16209
   180
lemma cont_Rep_CFun2: "cont (\<lambda>x. f\<cdot>x)"
huffman@18092
   181
apply (cut_tac x=f in Rep_CFun)
huffman@18092
   182
apply (simp add: CFun_def)
huffman@15576
   183
done
huffman@15576
   184
huffman@16209
   185
lemmas monofun_Rep_CFun = cont_Rep_CFun [THEN cont2mono]
huffman@16209
   186
lemmas contlub_Rep_CFun = cont_Rep_CFun [THEN cont2contlub]
huffman@15589
   187
huffman@16209
   188
lemmas monofun_Rep_CFun1 = cont_Rep_CFun1 [THEN cont2mono, standard]
huffman@16209
   189
lemmas contlub_Rep_CFun1 = cont_Rep_CFun1 [THEN cont2contlub, standard]
huffman@16209
   190
lemmas monofun_Rep_CFun2 = cont_Rep_CFun2 [THEN cont2mono, standard]
huffman@16209
   191
lemmas contlub_Rep_CFun2 = cont_Rep_CFun2 [THEN cont2contlub, standard]
huffman@16209
   192
huffman@16209
   193
text {* contlub, cont properties of @{term Rep_CFun} in each argument *}
huffman@16209
   194
huffman@27413
   195
lemma contlub_cfun_arg: "chain Y \<Longrightarrow> f\<cdot>(\<Squnion>i. Y i) = (\<Squnion>i. f\<cdot>(Y i))"
huffman@16209
   196
by (rule contlub_Rep_CFun2 [THEN contlubE])
huffman@15576
   197
huffman@27413
   198
lemma cont_cfun_arg: "chain Y \<Longrightarrow> range (\<lambda>i. f\<cdot>(Y i)) <<| f\<cdot>(\<Squnion>i. Y i)"
huffman@16209
   199
by (rule cont_Rep_CFun2 [THEN contE])
huffman@16209
   200
huffman@27413
   201
lemma contlub_cfun_fun: "chain F \<Longrightarrow> (\<Squnion>i. F i)\<cdot>x = (\<Squnion>i. F i\<cdot>x)"
huffman@16209
   202
by (rule contlub_Rep_CFun1 [THEN contlubE])
huffman@15576
   203
huffman@27413
   204
lemma cont_cfun_fun: "chain F \<Longrightarrow> range (\<lambda>i. F i\<cdot>x) <<| (\<Squnion>i. F i)\<cdot>x"
huffman@16209
   205
by (rule cont_Rep_CFun1 [THEN contE])
huffman@15576
   206
huffman@16209
   207
text {* monotonicity of application *}
huffman@16209
   208
huffman@16209
   209
lemma monofun_cfun_fun: "f \<sqsubseteq> g \<Longrightarrow> f\<cdot>x \<sqsubseteq> g\<cdot>x"
huffman@17832
   210
by (simp add: expand_cfun_less)
huffman@15576
   211
huffman@16209
   212
lemma monofun_cfun_arg: "x \<sqsubseteq> y \<Longrightarrow> f\<cdot>x \<sqsubseteq> f\<cdot>y"
huffman@16209
   213
by (rule monofun_Rep_CFun2 [THEN monofunE])
huffman@15576
   214
huffman@16209
   215
lemma monofun_cfun: "\<lbrakk>f \<sqsubseteq> g; x \<sqsubseteq> y\<rbrakk> \<Longrightarrow> f\<cdot>x \<sqsubseteq> g\<cdot>y"
huffman@16209
   216
by (rule trans_less [OF monofun_cfun_fun monofun_cfun_arg])
huffman@15576
   217
huffman@16209
   218
text {* ch2ch - rules for the type @{typ "'a -> 'b"} *}
huffman@15576
   219
huffman@16209
   220
lemma chain_monofun: "chain Y \<Longrightarrow> chain (\<lambda>i. f\<cdot>(Y i))"
huffman@16209
   221
by (erule monofun_Rep_CFun2 [THEN ch2ch_monofun])
huffman@16209
   222
huffman@16209
   223
lemma ch2ch_Rep_CFunR: "chain Y \<Longrightarrow> chain (\<lambda>i. f\<cdot>(Y i))"
huffman@16209
   224
by (rule monofun_Rep_CFun2 [THEN ch2ch_monofun])
huffman@15576
   225
huffman@16209
   226
lemma ch2ch_Rep_CFunL: "chain F \<Longrightarrow> chain (\<lambda>i. (F i)\<cdot>x)"
huffman@16209
   227
by (rule monofun_Rep_CFun1 [THEN ch2ch_monofun])
huffman@15576
   228
huffman@18076
   229
lemma ch2ch_Rep_CFun [simp]:
huffman@18076
   230
  "\<lbrakk>chain F; chain Y\<rbrakk> \<Longrightarrow> chain (\<lambda>i. (F i)\<cdot>(Y i))"
huffman@25884
   231
by (simp add: chain_def monofun_cfun)
huffman@15576
   232
huffman@25884
   233
lemma ch2ch_LAM [simp]:
huffman@25884
   234
  "\<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@18092
   235
by (simp add: chain_def expand_cfun_less)
huffman@18092
   236
huffman@16209
   237
text {* contlub, cont properties of @{term Rep_CFun} in both arguments *}
huffman@15576
   238
huffman@16209
   239
lemma contlub_cfun: 
huffman@16209
   240
  "\<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
   241
by (simp add: contlub_cfun_fun contlub_cfun_arg diag_lub)
huffman@15576
   242
huffman@16209
   243
lemma cont_cfun: 
huffman@16209
   244
  "\<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
   245
apply (rule thelubE)
huffman@16209
   246
apply (simp only: ch2ch_Rep_CFun)
huffman@16209
   247
apply (simp only: contlub_cfun)
huffman@16209
   248
done
huffman@16209
   249
huffman@18092
   250
lemma contlub_LAM:
huffman@18092
   251
  "\<lbrakk>\<And>x. chain (\<lambda>i. F i x); \<And>i. cont (\<lambda>x. F i x)\<rbrakk>
huffman@18092
   252
    \<Longrightarrow> (\<Lambda> x. \<Squnion>i. F i x) = (\<Squnion>i. \<Lambda> x. F i x)"
huffman@25884
   253
apply (simp add: thelub_CFun)
huffman@18092
   254
apply (simp add: Abs_CFun_inverse2)
huffman@18092
   255
apply (simp add: thelub_fun ch2ch_lambda)
huffman@18092
   256
done
huffman@18092
   257
huffman@25901
   258
lemmas lub_distribs = 
huffman@25901
   259
  contlub_cfun [symmetric]
huffman@25901
   260
  contlub_LAM [symmetric]
huffman@25901
   261
huffman@16209
   262
text {* strictness *}
huffman@16209
   263
huffman@16209
   264
lemma strictI: "f\<cdot>x = \<bottom> \<Longrightarrow> f\<cdot>\<bottom> = \<bottom>"
huffman@16209
   265
apply (rule UU_I)
huffman@15576
   266
apply (erule subst)
huffman@15576
   267
apply (rule minimal [THEN monofun_cfun_arg])
huffman@15576
   268
done
huffman@15576
   269
huffman@16209
   270
text {* the lub of a chain of continous functions is monotone *}
huffman@15576
   271
huffman@16209
   272
lemma lub_cfun_mono: "chain F \<Longrightarrow> monofun (\<lambda>x. \<Squnion>i. F i\<cdot>x)"
huffman@16209
   273
apply (drule ch2ch_monofun [OF monofun_Rep_CFun])
huffman@16209
   274
apply (simp add: thelub_fun [symmetric])
huffman@16209
   275
apply (erule monofun_lub_fun)
huffman@16209
   276
apply (simp add: monofun_Rep_CFun2)
huffman@15576
   277
done
huffman@15576
   278
huffman@16386
   279
text {* a lemma about the exchange of lubs for type @{typ "'a -> 'b"} *}
huffman@15576
   280
huffman@16699
   281
lemma ex_lub_cfun:
huffman@16699
   282
  "\<lbrakk>chain F; chain Y\<rbrakk> \<Longrightarrow> (\<Squnion>j. \<Squnion>i. F j\<cdot>(Y i)) = (\<Squnion>i. \<Squnion>j. F j\<cdot>(Y i))"
huffman@18076
   283
by (simp add: diag_lub)
huffman@15576
   284
huffman@15589
   285
text {* the lub of a chain of cont. functions is continuous *}
huffman@15576
   286
huffman@16209
   287
lemma cont_lub_cfun: "chain F \<Longrightarrow> cont (\<lambda>x. \<Squnion>i. F i\<cdot>x)"
huffman@16209
   288
apply (rule cont2cont_lub)
huffman@16209
   289
apply (erule monofun_Rep_CFun [THEN ch2ch_monofun])
huffman@16209
   290
apply (rule cont_Rep_CFun2)
huffman@15576
   291
done
huffman@15576
   292
huffman@15589
   293
text {* type @{typ "'a -> 'b"} is chain complete *}
huffman@15576
   294
huffman@16920
   295
lemma lub_cfun: "chain F \<Longrightarrow> range F <<| (\<Lambda> x. \<Squnion>i. F i\<cdot>x)"
huffman@16920
   296
by (simp only: contlub_cfun_fun [symmetric] eta_cfun thelubE)
huffman@15576
   297
huffman@27413
   298
lemma thelub_cfun: "chain F \<Longrightarrow> (\<Squnion>i. F i) = (\<Lambda> x. \<Squnion>i. F i\<cdot>x)"
huffman@16920
   299
by (rule lub_cfun [THEN thelubI])
huffman@15576
   300
huffman@17832
   301
subsection {* Continuity simplification procedure *}
huffman@15589
   302
huffman@15589
   303
text {* cont2cont lemma for @{term Rep_CFun} *}
huffman@15576
   304
huffman@16209
   305
lemma cont2cont_Rep_CFun:
huffman@16209
   306
  "\<lbrakk>cont f; cont t\<rbrakk> \<Longrightarrow> cont (\<lambda>x. (f x)\<cdot>(t x))"
huffman@16209
   307
by (best intro: cont2cont_app2 cont_const cont_Rep_CFun cont_Rep_CFun2)
huffman@15576
   308
huffman@15589
   309
text {* cont2mono Lemma for @{term "%x. LAM y. c1(x)(y)"} *}
huffman@15576
   310
huffman@15576
   311
lemma cont2mono_LAM:
huffman@15576
   312
assumes p1: "!!x. cont(c1 x)"
huffman@15576
   313
assumes p2: "!!y. monofun(%x. c1 x y)"
huffman@15576
   314
shows "monofun(%x. LAM y. c1 x y)"
huffman@16209
   315
apply (rule monofunI)
huffman@16209
   316
apply (rule less_cfun_ext)
huffman@16209
   317
apply (simp add: p1)
huffman@16209
   318
apply (erule p2 [THEN monofunE])
huffman@15576
   319
done
huffman@15576
   320
huffman@15589
   321
text {* cont2cont Lemma for @{term "%x. LAM y. c1 x y"} *}
huffman@15576
   322
huffman@15576
   323
lemma cont2cont_LAM:
huffman@15576
   324
assumes p1: "!!x. cont(c1 x)"
huffman@15576
   325
assumes p2: "!!y. cont(%x. c1 x y)"
huffman@15576
   326
shows "cont(%x. LAM y. c1 x y)"
huffman@16098
   327
apply (rule cont_Abs_CFun)
huffman@16098
   328
apply (simp add: p1 CFun_def)
huffman@17832
   329
apply (simp add: p2 cont2cont_lambda)
huffman@15576
   330
done
huffman@15576
   331
huffman@16386
   332
text {* continuity simplification procedure *}
huffman@15576
   333
huffman@16055
   334
lemmas cont_lemmas1 =
huffman@16055
   335
  cont_const cont_id cont_Rep_CFun2 cont2cont_Rep_CFun cont2cont_LAM
huffman@16055
   336
wenzelm@23152
   337
use "Tools/cont_proc.ML";
huffman@16386
   338
setup ContProc.setup;
huffman@15576
   339
huffman@15576
   340
(*val cont_tac = (fn i => (resolve_tac cont_lemmas i));*)
huffman@15576
   341
(*val cont_tacR = (fn i => (REPEAT (cont_tac i)));*)
huffman@15576
   342
huffman@17832
   343
subsection {* Miscellaneous *}
huffman@17832
   344
huffman@17832
   345
text {* Monotonicity of @{term Abs_CFun} *}
huffman@15576
   346
huffman@17832
   347
lemma semi_monofun_Abs_CFun:
huffman@17832
   348
  "\<lbrakk>cont f; cont g; f \<sqsubseteq> g\<rbrakk> \<Longrightarrow> Abs_CFun f \<sqsubseteq> Abs_CFun g"
huffman@17832
   349
by (simp add: less_CFun_def Abs_CFun_inverse2)
huffman@15576
   350
huffman@15589
   351
text {* some lemmata for functions with flat/chfin domain/range types *}
huffman@15576
   352
huffman@15576
   353
lemma chfin_Rep_CFunR: "chain (Y::nat => 'a::cpo->'b::chfin)  
huffman@27413
   354
      ==> !s. ? n. (LUB i. Y i)$s = Y n$s"
huffman@15576
   355
apply (rule allI)
huffman@15576
   356
apply (subst contlub_cfun_fun)
huffman@15576
   357
apply assumption
huffman@15576
   358
apply (fast intro!: thelubI chfin lub_finch2 chfin2finch ch2ch_Rep_CFunL)
huffman@15576
   359
done
huffman@15576
   360
huffman@18089
   361
lemma adm_chfindom: "adm (\<lambda>(u::'a::cpo \<rightarrow> 'b::chfin). P(u\<cdot>s))"
huffman@18089
   362
by (rule adm_subst, simp, rule adm_chfin)
huffman@18089
   363
huffman@16085
   364
subsection {* Continuous injection-retraction pairs *}
huffman@15589
   365
huffman@16085
   366
text {* Continuous retractions are strict. *}
huffman@15576
   367
huffman@16085
   368
lemma retraction_strict:
huffman@16085
   369
  "\<forall>x. f\<cdot>(g\<cdot>x) = x \<Longrightarrow> f\<cdot>\<bottom> = \<bottom>"
huffman@15576
   370
apply (rule UU_I)
huffman@16085
   371
apply (drule_tac x="\<bottom>" in spec)
huffman@16085
   372
apply (erule subst)
huffman@16085
   373
apply (rule monofun_cfun_arg)
huffman@16085
   374
apply (rule minimal)
huffman@15576
   375
done
huffman@15576
   376
huffman@16085
   377
lemma injection_eq:
huffman@16085
   378
  "\<forall>x. f\<cdot>(g\<cdot>x) = x \<Longrightarrow> (g\<cdot>x = g\<cdot>y) = (x = y)"
huffman@16085
   379
apply (rule iffI)
huffman@16085
   380
apply (drule_tac f=f in cfun_arg_cong)
huffman@16085
   381
apply simp
huffman@16085
   382
apply simp
huffman@15576
   383
done
huffman@15576
   384
huffman@16314
   385
lemma injection_less:
huffman@16314
   386
  "\<forall>x. f\<cdot>(g\<cdot>x) = x \<Longrightarrow> (g\<cdot>x \<sqsubseteq> g\<cdot>y) = (x \<sqsubseteq> y)"
huffman@16314
   387
apply (rule iffI)
huffman@16314
   388
apply (drule_tac f=f in monofun_cfun_arg)
huffman@16314
   389
apply simp
huffman@16314
   390
apply (erule monofun_cfun_arg)
huffman@16314
   391
done
huffman@16314
   392
huffman@16085
   393
lemma injection_defined_rev:
huffman@16085
   394
  "\<lbrakk>\<forall>x. f\<cdot>(g\<cdot>x) = x; g\<cdot>z = \<bottom>\<rbrakk> \<Longrightarrow> z = \<bottom>"
huffman@16085
   395
apply (drule_tac f=f in cfun_arg_cong)
huffman@16085
   396
apply (simp add: retraction_strict)
huffman@15576
   397
done
huffman@15576
   398
huffman@16085
   399
lemma injection_defined:
huffman@16085
   400
  "\<lbrakk>\<forall>x. f\<cdot>(g\<cdot>x) = x; z \<noteq> \<bottom>\<rbrakk> \<Longrightarrow> g\<cdot>z \<noteq> \<bottom>"
huffman@16085
   401
by (erule contrapos_nn, rule injection_defined_rev)
huffman@16085
   402
huffman@16085
   403
text {* propagation of flatness and chain-finiteness by retractions *}
huffman@16085
   404
huffman@16085
   405
lemma chfin2chfin:
huffman@16085
   406
  "\<forall>y. (f::'a::chfin \<rightarrow> 'b)\<cdot>(g\<cdot>y) = y
huffman@16085
   407
    \<Longrightarrow> \<forall>Y::nat \<Rightarrow> 'b. chain Y \<longrightarrow> (\<exists>n. max_in_chain n Y)"
huffman@16085
   408
apply clarify
huffman@16085
   409
apply (drule_tac f=g in chain_monofun)
huffman@25921
   410
apply (drule chfin)
huffman@16085
   411
apply (unfold max_in_chain_def)
huffman@16085
   412
apply (simp add: injection_eq)
huffman@16085
   413
done
huffman@16085
   414
huffman@16085
   415
lemma flat2flat:
huffman@16085
   416
  "\<forall>y. (f::'a::flat \<rightarrow> 'b::pcpo)\<cdot>(g\<cdot>y) = y
huffman@16085
   417
    \<Longrightarrow> \<forall>x y::'b. x \<sqsubseteq> y \<longrightarrow> x = \<bottom> \<or> x = y"
huffman@16085
   418
apply clarify
huffman@16209
   419
apply (drule_tac f=g in monofun_cfun_arg)
huffman@25920
   420
apply (drule ax_flat)
huffman@16085
   421
apply (erule disjE)
huffman@16085
   422
apply (simp add: injection_defined_rev)
huffman@16085
   423
apply (simp add: injection_eq)
huffman@15576
   424
done
huffman@15576
   425
huffman@15589
   426
text {* a result about functions with flat codomain *}
huffman@15576
   427
huffman@16085
   428
lemma flat_eqI: "\<lbrakk>(x::'a::flat) \<sqsubseteq> y; x \<noteq> \<bottom>\<rbrakk> \<Longrightarrow> x = y"
huffman@25920
   429
by (drule ax_flat, simp)
huffman@16085
   430
huffman@16085
   431
lemma flat_codom:
huffman@16085
   432
  "f\<cdot>x = (c::'b::flat) \<Longrightarrow> f\<cdot>\<bottom> = \<bottom> \<or> (\<forall>z. f\<cdot>z = c)"
huffman@16085
   433
apply (case_tac "f\<cdot>x = \<bottom>")
huffman@15576
   434
apply (rule disjI1)
huffman@15576
   435
apply (rule UU_I)
huffman@16085
   436
apply (erule_tac t="\<bottom>" in subst)
huffman@15576
   437
apply (rule minimal [THEN monofun_cfun_arg])
huffman@16085
   438
apply clarify
huffman@16085
   439
apply (rule_tac a = "f\<cdot>\<bottom>" in refl [THEN box_equals])
huffman@16085
   440
apply (erule minimal [THEN monofun_cfun_arg, THEN flat_eqI])
huffman@16085
   441
apply (erule minimal [THEN monofun_cfun_arg, THEN flat_eqI])
huffman@15589
   442
done
huffman@15589
   443
huffman@15589
   444
huffman@15589
   445
subsection {* Identity and composition *}
huffman@15589
   446
wenzelm@25135
   447
definition
wenzelm@25135
   448
  ID :: "'a \<rightarrow> 'a" where
wenzelm@25135
   449
  "ID = (\<Lambda> x. x)"
wenzelm@25135
   450
wenzelm@25135
   451
definition
wenzelm@25135
   452
  cfcomp  :: "('b \<rightarrow> 'c) \<rightarrow> ('a \<rightarrow> 'b) \<rightarrow> 'a \<rightarrow> 'c" where
wenzelm@25135
   453
  oo_def: "cfcomp = (\<Lambda> f g x. f\<cdot>(g\<cdot>x))"
huffman@15589
   454
wenzelm@25131
   455
abbreviation
wenzelm@25131
   456
  cfcomp_syn :: "['b \<rightarrow> 'c, 'a \<rightarrow> 'b] \<Rightarrow> 'a \<rightarrow> 'c"  (infixr "oo" 100)  where
wenzelm@25131
   457
  "f oo g == cfcomp\<cdot>f\<cdot>g"
huffman@15589
   458
huffman@16085
   459
lemma ID1 [simp]: "ID\<cdot>x = x"
huffman@16085
   460
by (simp add: ID_def)
huffman@15576
   461
huffman@16085
   462
lemma cfcomp1: "(f oo g) = (\<Lambda> x. f\<cdot>(g\<cdot>x))"
huffman@15589
   463
by (simp add: oo_def)
huffman@15576
   464
huffman@16085
   465
lemma cfcomp2 [simp]: "(f oo g)\<cdot>x = f\<cdot>(g\<cdot>x)"
huffman@15589
   466
by (simp add: cfcomp1)
huffman@15576
   467
huffman@27274
   468
lemma cfcomp_LAM: "cont g \<Longrightarrow> f oo (\<Lambda> x. g x) = (\<Lambda> x. f\<cdot>(g x))"
huffman@27274
   469
by (simp add: cfcomp1)
huffman@27274
   470
huffman@19709
   471
lemma cfcomp_strict [simp]: "\<bottom> oo f = \<bottom>"
huffman@19709
   472
by (simp add: expand_cfun_eq)
huffman@19709
   473
huffman@15589
   474
text {*
huffman@15589
   475
  Show that interpretation of (pcpo,@{text "_->_"}) is a category.
huffman@15589
   476
  The class of objects is interpretation of syntactical class pcpo.
huffman@15589
   477
  The class of arrows  between objects @{typ 'a} and @{typ 'b} is interpret. of @{typ "'a -> 'b"}.
huffman@15589
   478
  The identity arrow is interpretation of @{term ID}.
huffman@15589
   479
  The composition of f and g is interpretation of @{text "oo"}.
huffman@15589
   480
*}
huffman@15576
   481
huffman@16085
   482
lemma ID2 [simp]: "f oo ID = f"
huffman@15589
   483
by (rule ext_cfun, simp)
huffman@15576
   484
huffman@16085
   485
lemma ID3 [simp]: "ID oo f = f"
huffman@15589
   486
by (rule ext_cfun, simp)
huffman@15576
   487
huffman@15576
   488
lemma assoc_oo: "f oo (g oo h) = (f oo g) oo h"
huffman@15589
   489
by (rule ext_cfun, simp)
huffman@15576
   490
huffman@16085
   491
huffman@16085
   492
subsection {* Strictified functions *}
huffman@16085
   493
huffman@16085
   494
defaultsort pcpo
huffman@16085
   495
wenzelm@25131
   496
definition
wenzelm@25131
   497
  strictify  :: "('a \<rightarrow> 'b) \<rightarrow> 'a \<rightarrow> 'b" where
wenzelm@25131
   498
  "strictify = (\<Lambda> f x. if x = \<bottom> then \<bottom> else f\<cdot>x)"
huffman@16085
   499
huffman@16085
   500
text {* results about strictify *}
huffman@16085
   501
huffman@17815
   502
lemma cont_strictify1: "cont (\<lambda>f. if x = \<bottom> then \<bottom> else f\<cdot>x)"
huffman@17815
   503
by (simp add: cont_if)
huffman@16085
   504
huffman@17815
   505
lemma monofun_strictify2: "monofun (\<lambda>x. if x = \<bottom> then \<bottom> else f\<cdot>x)"
huffman@17815
   506
apply (rule monofunI)
huffman@25786
   507
apply (auto simp add: monofun_cfun_arg)
huffman@16085
   508
done
huffman@16085
   509
huffman@17815
   510
(*FIXME: long proof*)
huffman@25723
   511
lemma contlub_strictify2: "contlub (\<lambda>x. if x = \<bottom> then \<bottom> else f\<cdot>x)"
huffman@16209
   512
apply (rule contlubI)
huffman@27413
   513
apply (case_tac "(\<Squnion>i. Y i) = \<bottom>")
huffman@16699
   514
apply (drule (1) chain_UU_I)
huffman@18076
   515
apply simp
huffman@17815
   516
apply (simp del: if_image_distrib)
huffman@17815
   517
apply (simp only: contlub_cfun_arg)
huffman@16085
   518
apply (rule lub_equal2)
huffman@16085
   519
apply (rule chain_mono2 [THEN exE])
huffman@16085
   520
apply (erule chain_UU_I_inverse2)
huffman@16085
   521
apply (assumption)
huffman@17815
   522
apply (rule_tac x=x in exI, clarsimp)
huffman@16085
   523
apply (erule chain_monofun)
huffman@17815
   524
apply (erule monofun_strictify2 [THEN ch2ch_monofun])
huffman@16085
   525
done
huffman@16085
   526
huffman@17815
   527
lemmas cont_strictify2 =
huffman@17815
   528
  monocontlub2cont [OF monofun_strictify2 contlub_strictify2, standard]
huffman@17815
   529
huffman@17815
   530
lemma strictify_conv_if: "strictify\<cdot>f\<cdot>x = (if x = \<bottom> then \<bottom> else f\<cdot>x)"
huffman@17815
   531
by (unfold strictify_def, simp add: cont_strictify1 cont_strictify2)
huffman@16085
   532
huffman@16085
   533
lemma strictify1 [simp]: "strictify\<cdot>f\<cdot>\<bottom> = \<bottom>"
huffman@17815
   534
by (simp add: strictify_conv_if)
huffman@16085
   535
huffman@16085
   536
lemma strictify2 [simp]: "x \<noteq> \<bottom> \<Longrightarrow> strictify\<cdot>f\<cdot>x = f\<cdot>x"
huffman@17815
   537
by (simp add: strictify_conv_if)
huffman@16085
   538
huffman@17816
   539
subsection {* Continuous let-bindings *}
huffman@17816
   540
wenzelm@25131
   541
definition
wenzelm@25131
   542
  CLet :: "'a \<rightarrow> ('a \<rightarrow> 'b) \<rightarrow> 'b" where
wenzelm@25131
   543
  "CLet = (\<Lambda> s f. f\<cdot>s)"
huffman@17816
   544
huffman@17816
   545
syntax
huffman@17816
   546
  "_CLet" :: "[letbinds, 'a] => 'a" ("(Let (_)/ in (_))" 10)
huffman@17816
   547
huffman@17816
   548
translations
huffman@17816
   549
  "_CLet (_binds b bs) e" == "_CLet b (_CLet bs e)"
wenzelm@25131
   550
  "Let x = a in e" == "CONST CLet\<cdot>a\<cdot>(\<Lambda> x. e)"
huffman@17816
   551
huffman@15576
   552
end