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