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