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