src/HOLCF/Cfun.thy
author huffman
Fri May 27 01:28:51 2005 +0200 (2005-05-27)
changeset 16098 6aef81a6ddd3
parent 16094 a92ee2833938
child 16209 36ee7f6af79f
permissions -rw-r--r--
use TypedefPcpo for all class instances
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@15576
    19
by (rule exI, rule CfunI)
huffman@15576
    20
huffman@15576
    21
syntax
huffman@15576
    22
	Rep_CFun  :: "('a -> 'b) => ('a => 'b)" ("_$_" [999,1000] 999)
huffman@15576
    23
                                                (* application      *)
huffman@15576
    24
        Abs_CFun  :: "('a => 'b) => ('a -> 'b)" (binder "LAM " 10)
huffman@15576
    25
                                                (* abstraction      *)
huffman@15576
    26
        less_cfun :: "[('a -> 'b),('a -> 'b)]=>bool"
huffman@15576
    27
huffman@15576
    28
syntax (xsymbols)
huffman@15576
    29
  "->"		:: "[type, type] => type"      ("(_ \<rightarrow>/ _)" [1,0]0)
huffman@15576
    30
  "LAM "	:: "[idts, 'a => 'b] => ('a -> 'b)"
huffman@15576
    31
					("(3\<Lambda>_./ _)" [0, 10] 10)
huffman@15576
    32
  Rep_CFun      :: "('a -> 'b) => ('a => 'b)"  ("(_\<cdot>_)" [999,1000] 999)
huffman@15576
    33
huffman@15576
    34
syntax (HTML output)
huffman@15576
    35
  Rep_CFun      :: "('a -> 'b) => ('a => 'b)"  ("(_\<cdot>_)" [999,1000] 999)
huffman@15576
    36
huffman@15589
    37
text {*
huffman@15589
    38
  Derive old type definition rules for @{term Abs_CFun} \& @{term Rep_CFun}.
huffman@15589
    39
  @{term Rep_CFun} and @{term Abs_CFun} should be replaced by
huffman@15589
    40
  @{term Rep_Cfun} and @{term Abs_Cfun} in future.
huffman@15589
    41
*}
huffman@15576
    42
huffman@15576
    43
lemma Rep_Cfun: "Rep_CFun fo : CFun"
huffman@15589
    44
by (rule Rep_CFun)
huffman@15576
    45
huffman@15576
    46
lemma Rep_Cfun_inverse: "Abs_CFun (Rep_CFun fo) = fo"
huffman@15589
    47
by (rule Rep_CFun_inverse)
huffman@15576
    48
huffman@15576
    49
lemma Abs_Cfun_inverse: "f:CFun==>Rep_CFun(Abs_CFun f)=f"
huffman@15589
    50
by (erule Abs_CFun_inverse)
huffman@15576
    51
huffman@15589
    52
text {* Additional lemma about the isomorphism between
huffman@15589
    53
        @{typ "'a -> 'b"} and @{term Cfun} *}
huffman@15576
    54
huffman@15576
    55
lemma Abs_Cfun_inverse2: "cont f ==> Rep_CFun (Abs_CFun f) = f"
huffman@15576
    56
apply (rule Abs_Cfun_inverse)
huffman@15576
    57
apply (unfold CFun_def)
huffman@15576
    58
apply (erule mem_Collect_eq [THEN ssubst])
huffman@15576
    59
done
huffman@15576
    60
huffman@15589
    61
text {* Simplification of application *}
huffman@15576
    62
huffman@15576
    63
lemma Cfunapp2: "cont f ==> (Abs_CFun f)$x = f x"
huffman@15589
    64
by (erule Abs_Cfun_inverse2 [THEN fun_cong])
huffman@15576
    65
huffman@15589
    66
text {* Beta - equality for continuous functions *}
huffman@15576
    67
huffman@15576
    68
lemma beta_cfun: "cont(c1) ==> (LAM x .c1 x)$u = c1 u"
huffman@15589
    69
by (rule Cfunapp2)
huffman@15589
    70
huffman@15641
    71
text {* Eta - equality for continuous functions *}
huffman@15641
    72
huffman@15641
    73
lemma eta_cfun: "(LAM x. f$x) = f"
huffman@15641
    74
by (rule Rep_CFun_inverse)
huffman@15641
    75
huffman@16098
    76
subsection {* Class instances *}
huffman@15589
    77
huffman@15589
    78
instance "->"  :: (cpo, cpo) sq_ord ..
huffman@15576
    79
huffman@15589
    80
defs (overloaded)
huffman@15589
    81
  less_cfun_def: "(op <<) == (% fo1 fo2. Rep_CFun fo1 << Rep_CFun fo2 )"
huffman@15576
    82
huffman@16098
    83
lemma adm_CFun: "adm (\<lambda>f. f \<in> CFun)"
huffman@16098
    84
by (simp add: CFun_def, rule admI, rule cont_lub_fun)
huffman@16098
    85
huffman@16098
    86
lemma UU_CFun: "\<bottom> \<in> CFun"
huffman@16098
    87
by (simp add: CFun_def inst_fun_pcpo cont_const)
huffman@16098
    88
huffman@15589
    89
instance "->" :: (cpo, cpo) po
huffman@16094
    90
by (rule typedef_po [OF type_definition_CFun less_cfun_def])
huffman@15589
    91
huffman@16098
    92
instance "->" :: (cpo, cpo) cpo
huffman@16098
    93
by (rule typedef_cpo [OF type_definition_CFun less_cfun_def adm_CFun])
huffman@16098
    94
huffman@16098
    95
instance "->" :: (cpo, pcpo) pcpo
huffman@16098
    96
by (rule typedef_pcpo_UU [OF type_definition_CFun less_cfun_def UU_CFun])
huffman@16098
    97
huffman@16098
    98
lemmas cont_Rep_CFun =
huffman@16098
    99
  typedef_cont_Rep [OF type_definition_CFun less_cfun_def adm_CFun]
huffman@16098
   100
huffman@16098
   101
lemmas cont_Abs_CFun = 
huffman@16098
   102
  typedef_cont_Abs [OF type_definition_CFun less_cfun_def adm_CFun]
huffman@16098
   103
huffman@16098
   104
lemmas strict_Rep_CFun =
huffman@16098
   105
  typedef_strict_Rep [OF type_definition_CFun less_cfun_def UU_CFun]
huffman@16098
   106
huffman@16098
   107
lemmas strict_Abs_CFun =
huffman@16098
   108
  typedef_strict_Abs [OF type_definition_CFun less_cfun_def UU_CFun]
huffman@16098
   109
huffman@15589
   110
text {* for compatibility with old HOLCF-Version *}
huffman@15576
   111
lemma inst_cfun_po: "(op <<)=(%f1 f2. Rep_CFun f1 << Rep_CFun f2)"
huffman@15576
   112
apply (fold less_cfun_def)
huffman@15576
   113
apply (rule refl)
huffman@15576
   114
done
huffman@15576
   115
huffman@15589
   116
text {* lemmas about application of continuous functions *}
huffman@15589
   117
huffman@15589
   118
lemma cfun_cong: "[| f=g; x=y |] ==> f$x = g$y"
huffman@15589
   119
by simp
huffman@15589
   120
huffman@15589
   121
lemma cfun_fun_cong: "f=g ==> f$x = g$x"
huffman@15589
   122
by simp
huffman@15589
   123
huffman@15589
   124
lemma cfun_arg_cong: "x=y ==> f$x = f$y"
huffman@15589
   125
by simp
huffman@15589
   126
huffman@15589
   127
text {* access to @{term less_cfun} in class po *}
huffman@15576
   128
huffman@15576
   129
lemma less_cfun: "( f1 << f2 ) = (Rep_CFun(f1) << Rep_CFun(f2))"
huffman@15589
   130
by (simp add: inst_cfun_po)
huffman@15576
   131
huffman@15589
   132
subsection {* Type @{typ "'a -> 'b"} is pointed *}
huffman@15576
   133
huffman@15576
   134
lemma minimal_cfun: "Abs_CFun(% x. UU) << f"
huffman@15576
   135
apply (subst less_cfun)
huffman@15576
   136
apply (subst Abs_Cfun_inverse2)
huffman@15576
   137
apply (rule cont_const)
huffman@15576
   138
apply (rule minimal_fun)
huffman@15576
   139
done
huffman@15576
   140
huffman@15576
   141
lemmas UU_cfun_def = minimal_cfun [THEN minimal2UU, symmetric, standard]
huffman@15576
   142
huffman@15576
   143
lemma least_cfun: "? x::'a->'b::pcpo.!y. x<<y"
huffman@15576
   144
apply (rule_tac x = "Abs_CFun (% x. UU) " in exI)
huffman@15576
   145
apply (rule minimal_cfun [THEN allI])
huffman@15576
   146
done
huffman@15576
   147
huffman@15589
   148
subsection {* Monotonicity of application *}
huffman@15589
   149
huffman@15589
   150
text {*
huffman@15589
   151
  @{term Rep_CFun} yields continuous functions in @{typ "'a => 'b"}.
huffman@15589
   152
  This is continuity of @{term Rep_CFun} in its 'second' argument:
huffman@15589
   153
  @{prop "cont_Rep_CFun2 ==> monofun_Rep_CFun2 & contlub_Rep_CFun2"}
huffman@15589
   154
*}
huffman@15576
   155
huffman@16085
   156
lemma cont_Rep_CFun2: "cont (Rep_CFun fo)"
huffman@15576
   157
apply (rule_tac P = "cont" in CollectD)
huffman@15576
   158
apply (fold CFun_def)
huffman@15576
   159
apply (rule Rep_Cfun)
huffman@15576
   160
done
huffman@15576
   161
huffman@15576
   162
lemmas monofun_Rep_CFun2 = cont_Rep_CFun2 [THEN cont2mono, standard]
huffman@15589
   163
 -- {* @{thm monofun_Rep_CFun2} *} (* monofun(Rep_CFun(?fo)) *)
huffman@15576
   164
huffman@15576
   165
lemmas contlub_Rep_CFun2 = cont_Rep_CFun2 [THEN cont2contlub, standard]
huffman@15589
   166
 -- {* @{thm contlub_Rep_CFun2} *} (* contlub(Rep_CFun(?fo)) *)
huffman@15576
   167
huffman@15589
   168
text {* expanded thms @{thm [source] cont_Rep_CFun2}, @{thm [source] contlub_Rep_CFun2} look nice with mixfix syntax *}
huffman@15576
   169
huffman@15576
   170
lemmas cont_cfun_arg = cont_Rep_CFun2 [THEN contE, THEN spec, THEN mp]
huffman@15589
   171
  -- {* @{thm cont_cfun_arg} *} (* chain(x1) ==> range (%i. fo3$(x1 i)) <<| fo3$(lub (range ?x1))    *)
huffman@15576
   172
 
huffman@15576
   173
lemmas contlub_cfun_arg = contlub_Rep_CFun2 [THEN contlubE, THEN spec, THEN mp]
huffman@15589
   174
 -- {* @{thm contlub_cfun_arg} *} (* chain(?x1) ==> ?fo4$(lub (range ?x1)) = lub (range (%i. ?fo4$(?x1 i))) *)
huffman@15576
   175
huffman@15589
   176
text {* @{term Rep_CFun} is monotone in its 'first' argument *}
huffman@15576
   177
huffman@15576
   178
lemma monofun_Rep_CFun1: "monofun(Rep_CFun)"
huffman@16098
   179
by (rule cont_Rep_CFun [THEN cont2mono])
huffman@15576
   180
huffman@15589
   181
text {* monotonicity of application @{term Rep_CFun} in mixfix syntax @{text "[_]_"} *}
huffman@15576
   182
huffman@15576
   183
lemma monofun_cfun_fun: "f1 << f2 ==> f1$x << f2$x"
huffman@15576
   184
apply (rule_tac x = "x" in spec)
huffman@15576
   185
apply (rule less_fun [THEN subst])
huffman@15589
   186
apply (erule monofun_Rep_CFun1 [THEN monofunE [rule_format]])
huffman@15576
   187
done
huffman@15576
   188
huffman@15589
   189
lemmas monofun_cfun_arg = monofun_Rep_CFun2 [THEN monofunE [rule_format], standard]
huffman@15589
   190
 -- {* @{thm monofun_cfun_arg} *} (* ?x2 << ?x1 ==> ?fo5$?x2 << ?fo5$?x1 *)
huffman@15576
   191
huffman@15576
   192
lemma chain_monofun: "chain Y ==> chain (%i. f\<cdot>(Y i))"
huffman@15576
   193
apply (rule chainI)
huffman@15576
   194
apply (rule monofun_cfun_arg)
huffman@15576
   195
apply (erule chainE)
huffman@15576
   196
done
huffman@15576
   197
huffman@15589
   198
text {* monotonicity of @{term Rep_CFun} in both arguments in mixfix syntax @{text "[_]_"} *}
huffman@15576
   199
huffman@15576
   200
lemma monofun_cfun: "[|f1<<f2;x1<<x2|] ==> f1$x1 << f2$x2"
huffman@15576
   201
apply (rule trans_less)
huffman@15576
   202
apply (erule monofun_cfun_arg)
huffman@15576
   203
apply (erule monofun_cfun_fun)
huffman@15576
   204
done
huffman@15576
   205
huffman@15576
   206
lemma strictI: "f$x = UU ==> f$UU = UU"
huffman@15576
   207
apply (rule eq_UU_iff [THEN iffD2])
huffman@15576
   208
apply (erule subst)
huffman@15576
   209
apply (rule minimal [THEN monofun_cfun_arg])
huffman@15576
   210
done
huffman@15576
   211
huffman@15589
   212
subsection {* Type @{typ "'a -> 'b"} is a cpo *}
huffman@15576
   213
huffman@15589
   214
text {* ch2ch - rules for the type @{typ "'a -> 'b"} use MF2 lemmas from Cont.thy *}
huffman@15576
   215
huffman@15576
   216
lemma ch2ch_Rep_CFunR: "chain(Y) ==> chain(%i. f$(Y i))"
huffman@15589
   217
by (erule monofun_Rep_CFun2 [THEN ch2ch_MF2R])
huffman@15576
   218
huffman@15576
   219
lemmas ch2ch_Rep_CFunL = monofun_Rep_CFun1 [THEN ch2ch_MF2L, standard]
huffman@15589
   220
 -- {* @{thm ch2ch_Rep_CFunL} *} (* chain(?F) ==> chain (%i. ?F i$?x) *)
huffman@15576
   221
huffman@15589
   222
text {* the lub of a chain of continous functions is monotone: uses MF2 lemmas from Cont.thy *}
huffman@15576
   223
huffman@15576
   224
lemma lub_cfun_mono: "chain(F) ==> monofun(% x. lub(range(% j.(F j)$x)))"
huffman@15576
   225
apply (rule lub_MF2_mono)
huffman@15576
   226
apply (rule monofun_Rep_CFun1)
huffman@15576
   227
apply (rule monofun_Rep_CFun2 [THEN allI])
huffman@15576
   228
apply assumption
huffman@15576
   229
done
huffman@15576
   230
huffman@15589
   231
text {* a lemma about the exchange of lubs for type @{typ "'a -> 'b"}: uses MF2 lemmas from Cont.thy *}
huffman@15576
   232
huffman@15576
   233
lemma ex_lubcfun: "[| chain(F); chain(Y) |] ==> 
huffman@15576
   234
                lub(range(%j. lub(range(%i. F(j)$(Y i))))) = 
huffman@15576
   235
                lub(range(%i. lub(range(%j. F(j)$(Y i)))))"
huffman@15576
   236
apply (rule ex_lubMF2)
huffman@15576
   237
apply (rule monofun_Rep_CFun1)
huffman@15576
   238
apply (rule monofun_Rep_CFun2 [THEN allI])
huffman@15576
   239
apply assumption
huffman@15576
   240
apply assumption
huffman@15576
   241
done
huffman@15576
   242
huffman@15589
   243
text {* the lub of a chain of cont. functions is continuous *}
huffman@15576
   244
huffman@15576
   245
lemma cont_lubcfun: "chain(F) ==> cont(% x. lub(range(% j. F(j)$x)))"
huffman@15576
   246
apply (rule monocontlub2cont)
huffman@15576
   247
apply (erule lub_cfun_mono)
huffman@15589
   248
apply (rule contlubI [rule_format])
huffman@15576
   249
apply (subst contlub_cfun_arg [THEN ext])
huffman@15576
   250
apply assumption
huffman@15576
   251
apply (erule ex_lubcfun)
huffman@15576
   252
apply assumption
huffman@15576
   253
done
huffman@15576
   254
huffman@15589
   255
text {* type @{typ "'a -> 'b"} is chain complete *}
huffman@15576
   256
huffman@15576
   257
lemma lub_cfun: "chain(CCF) ==> range(CCF) <<| (LAM x. lub(range(% i. CCF(i)$x)))"
huffman@15576
   258
apply (rule is_lubI)
huffman@15576
   259
apply (rule ub_rangeI)
huffman@15576
   260
apply (subst less_cfun)
huffman@15576
   261
apply (subst Abs_Cfun_inverse2)
huffman@15576
   262
apply (erule cont_lubcfun)
huffman@15576
   263
apply (rule lub_fun [THEN is_lubD1, THEN ub_rangeD])
huffman@15576
   264
apply (erule monofun_Rep_CFun1 [THEN ch2ch_monofun])
huffman@15576
   265
apply (subst less_cfun)
huffman@15576
   266
apply (subst Abs_Cfun_inverse2)
huffman@15576
   267
apply (erule cont_lubcfun)
huffman@15576
   268
apply (rule lub_fun [THEN is_lub_lub])
huffman@15576
   269
apply (erule monofun_Rep_CFun1 [THEN ch2ch_monofun])
huffman@15576
   270
apply (erule monofun_Rep_CFun1 [THEN ub2ub_monofun])
huffman@15576
   271
done
huffman@15576
   272
huffman@15576
   273
lemmas thelub_cfun = lub_cfun [THEN thelubI, standard]
huffman@15589
   274
 -- {* @{thm thelub_cfun} *} (* 
huffman@15576
   275
chain(?CCF1) ==>  lub (range ?CCF1) = (LAM x. lub (range (%i. ?CCF1 i$x)))
huffman@15576
   276
*)
huffman@15576
   277
huffman@15589
   278
subsection {* Miscellaneous *}
huffman@15589
   279
huffman@15589
   280
text {* Extensionality in @{typ "'a -> 'b"} *}
huffman@15576
   281
huffman@15576
   282
lemma ext_cfun: "(!!x. f$x = g$x) ==> f = g"
huffman@15589
   283
apply (rule Rep_CFun_inject [THEN iffD1])
huffman@15576
   284
apply (rule ext)
huffman@15576
   285
apply simp
huffman@15576
   286
done
huffman@15576
   287
huffman@15589
   288
text {* Monotonicity of @{term Abs_CFun} *}
huffman@15576
   289
huffman@15576
   290
lemma semi_monofun_Abs_CFun: "[| cont(f); cont(g); f<<g|] ==> Abs_CFun(f)<<Abs_CFun(g)"
huffman@15589
   291
by (simp add: less_cfun Abs_Cfun_inverse2)
huffman@15576
   292
huffman@15589
   293
text {* Extensionality wrt. @{term "op <<"} in @{typ "'a -> 'b"} *}
huffman@15576
   294
huffman@15576
   295
lemma less_cfun2: "(!!x. f$x << g$x) ==> f << g"
huffman@15576
   296
apply (rule_tac t = "f" in Rep_Cfun_inverse [THEN subst])
huffman@15576
   297
apply (rule_tac t = "g" in Rep_Cfun_inverse [THEN subst])
huffman@15576
   298
apply (rule semi_monofun_Abs_CFun)
huffman@15576
   299
apply (rule cont_Rep_CFun2)
huffman@15576
   300
apply (rule cont_Rep_CFun2)
huffman@15576
   301
apply (rule less_fun [THEN iffD2])
huffman@15576
   302
apply simp
huffman@15576
   303
done
huffman@15576
   304
huffman@15589
   305
text {* for compatibility with old HOLCF-Version *}
huffman@15576
   306
lemma inst_cfun_pcpo: "UU = Abs_CFun(%x. UU)"
huffman@15576
   307
apply (simp add: UU_def UU_cfun_def)
huffman@15576
   308
done
huffman@15576
   309
huffman@15589
   310
subsection {* Continuity of application *}
huffman@15589
   311
huffman@15589
   312
text {* the contlub property for @{term Rep_CFun} its 'first' argument *}
huffman@15576
   313
huffman@15576
   314
lemma contlub_Rep_CFun1: "contlub(Rep_CFun)"
huffman@16098
   315
by (rule cont_Rep_CFun [THEN cont2contlub])
huffman@15576
   316
huffman@15589
   317
text {* the cont property for @{term Rep_CFun} in its first argument *}
huffman@15576
   318
huffman@15576
   319
lemma cont_Rep_CFun1: "cont(Rep_CFun)"
huffman@16098
   320
by (rule cont_Rep_CFun)
huffman@15576
   321
huffman@15589
   322
text {* contlub, cont properties of @{term Rep_CFun} in its first argument in mixfix @{text "_[_]"} *}
huffman@15576
   323
huffman@15576
   324
lemma contlub_cfun_fun: 
huffman@15576
   325
"chain(FY) ==> 
huffman@15576
   326
  lub(range FY)$x = lub(range (%i. FY(i)$x))"
huffman@15576
   327
apply (rule trans)
huffman@15576
   328
apply (erule contlub_Rep_CFun1 [THEN contlubE, THEN spec, THEN mp, THEN fun_cong])
huffman@15576
   329
apply (subst thelub_fun)
huffman@15576
   330
apply (erule monofun_Rep_CFun1 [THEN ch2ch_monofun])
huffman@15576
   331
apply (rule refl)
huffman@15576
   332
done
huffman@15576
   333
huffman@15576
   334
lemma cont_cfun_fun: 
huffman@15576
   335
"chain(FY) ==> 
huffman@15576
   336
  range(%i. FY(i)$x) <<| lub(range FY)$x"
huffman@15576
   337
apply (rule thelubE)
huffman@15576
   338
apply (erule ch2ch_Rep_CFunL)
huffman@15576
   339
apply (erule contlub_cfun_fun [symmetric])
huffman@15576
   340
done
huffman@15576
   341
huffman@15589
   342
text {* contlub, cont  properties of @{term Rep_CFun} in both argument in mixfix @{text "_[_]"} *}
huffman@15576
   343
huffman@15576
   344
lemma contlub_cfun: 
huffman@15576
   345
"[|chain(FY);chain(TY)|] ==> 
huffman@15576
   346
  (lub(range FY))$(lub(range TY)) = lub(range(%i. FY(i)$(TY i)))"
huffman@15576
   347
apply (rule contlub_CF2)
huffman@15576
   348
apply (rule cont_Rep_CFun1)
huffman@15576
   349
apply (rule allI)
huffman@15576
   350
apply (rule cont_Rep_CFun2)
huffman@15576
   351
apply assumption
huffman@15576
   352
apply assumption
huffman@15576
   353
done
huffman@15576
   354
huffman@15576
   355
lemma cont_cfun: 
huffman@15576
   356
"[|chain(FY);chain(TY)|] ==> 
huffman@15576
   357
  range(%i.(FY i)$(TY i)) <<| (lub (range FY))$(lub(range TY))"
huffman@15576
   358
apply (rule thelubE)
huffman@15576
   359
apply (rule monofun_Rep_CFun1 [THEN ch2ch_MF2LR])
huffman@15576
   360
apply (rule allI)
huffman@15576
   361
apply (rule monofun_Rep_CFun2)
huffman@15576
   362
apply assumption
huffman@15576
   363
apply assumption
huffman@15576
   364
apply (erule contlub_cfun [symmetric])
huffman@15576
   365
apply assumption
huffman@15576
   366
done
huffman@15576
   367
huffman@15589
   368
text {* cont2cont lemma for @{term Rep_CFun} *}
huffman@15576
   369
huffman@15576
   370
lemma cont2cont_Rep_CFun: "[|cont(%x. ft x);cont(%x. tt x)|] ==> cont(%x. (ft x)$(tt x))"
huffman@15576
   371
apply (best intro: cont2cont_app2 cont_const cont_Rep_CFun1 cont_Rep_CFun2)
huffman@15576
   372
done
huffman@15576
   373
huffman@15589
   374
text {* cont2mono Lemma for @{term "%x. LAM y. c1(x)(y)"} *}
huffman@15576
   375
huffman@15576
   376
lemma cont2mono_LAM:
huffman@15576
   377
assumes p1: "!!x. cont(c1 x)"
huffman@15576
   378
assumes p2: "!!y. monofun(%x. c1 x y)"
huffman@15576
   379
shows "monofun(%x. LAM y. c1 x y)"
huffman@16098
   380
apply (rule monofunI [rule_format])
huffman@16098
   381
apply (rule less_cfun2)
huffman@16098
   382
apply (simp add: beta_cfun p1)
huffman@16098
   383
apply (erule p2 [THEN monofunE [rule_format]])
huffman@15576
   384
done
huffman@15576
   385
huffman@15589
   386
text {* cont2cont Lemma for @{term "%x. LAM y. c1 x y"} *}
huffman@15576
   387
huffman@15576
   388
lemma cont2cont_LAM:
huffman@15576
   389
assumes p1: "!!x. cont(c1 x)"
huffman@15576
   390
assumes p2: "!!y. cont(%x. c1 x y)"
huffman@15576
   391
shows "cont(%x. LAM y. c1 x y)"
huffman@16098
   392
apply (rule cont_Abs_CFun)
huffman@16098
   393
apply (simp add: p1 CFun_def)
huffman@16098
   394
apply (simp add: p2 cont2cont_CF1L_rev)
huffman@15576
   395
done
huffman@15576
   396
huffman@15641
   397
text {* cont2cont Lemma for @{term "%x. LAM y. c1 x$y"} *}
huffman@15641
   398
huffman@15641
   399
lemma cont2cont_eta: "cont c1 ==> cont (%x. LAM y. c1 x$y)"
huffman@15641
   400
by (simp only: eta_cfun)
huffman@15641
   401
huffman@15589
   402
text {* cont2cont tactic *}
huffman@15576
   403
huffman@16055
   404
lemmas cont_lemmas1 =
huffman@16055
   405
  cont_const cont_id cont_Rep_CFun2 cont2cont_Rep_CFun cont2cont_LAM
huffman@16055
   406
huffman@16055
   407
text {*
huffman@16055
   408
  Continuity simproc by Brian Huffman.
huffman@16055
   409
  Given the term @{term "cont f"}, the procedure tries to
huffman@16055
   410
  construct the theorem @{prop "cont f == True"}. If this
huffman@16055
   411
  theorem cannot be completely solved by the introduction
huffman@16055
   412
  rules, then the procedure returns a conditional rewrite
huffman@16055
   413
  rule with the unsolved subgoals as premises.
huffman@16055
   414
*}
huffman@15576
   415
huffman@16055
   416
ML_setup {*
huffman@16055
   417
local
huffman@16055
   418
  val rules = thms "cont_lemmas1";
huffman@16055
   419
  fun solve_cont sg _ t =
huffman@16055
   420
    let val tr = instantiate' [] [SOME (cterm_of sg t)] Eq_TrueI;
huffman@16055
   421
        val tac = REPEAT_ALL_NEW (resolve_tac rules) 1;
huffman@16055
   422
    in Option.map fst (Seq.pull (tac tr)) end;
huffman@16055
   423
in
huffman@16055
   424
  val cont_proc = Simplifier.simproc (Theory.sign_of (the_context ()))
huffman@16055
   425
        "continuity" ["cont f"] solve_cont;
huffman@16055
   426
end;
huffman@16055
   427
Addsimprocs [cont_proc];
huffman@16055
   428
*}
huffman@15576
   429
huffman@15589
   430
text {* HINT: @{text cont_tac} is now installed in simplifier in Lift.ML ! *}
huffman@15576
   431
huffman@15576
   432
(*val cont_tac = (fn i => (resolve_tac cont_lemmas i));*)
huffman@15576
   433
(*val cont_tacR = (fn i => (REPEAT (cont_tac i)));*)
huffman@15576
   434
huffman@15589
   435
text {* function application @{text "_[_]"} is strict in its first arguments *}
huffman@15576
   436
huffman@16085
   437
lemma strict_Rep_CFun1 [simp]: "\<bottom>\<cdot>x = \<bottom>"
huffman@15589
   438
by (simp add: inst_cfun_pcpo beta_cfun)
huffman@15576
   439
huffman@15589
   440
text {* Instantiate the simplifier *}
huffman@15589
   441
huffman@15589
   442
declare beta_cfun [simp]
huffman@15576
   443
huffman@15589
   444
text {* some lemmata for functions with flat/chfin domain/range types *}
huffman@15576
   445
huffman@15576
   446
lemma chfin_Rep_CFunR: "chain (Y::nat => 'a::cpo->'b::chfin)  
huffman@15576
   447
      ==> !s. ? n. lub(range(Y))$s = Y n$s"
huffman@15576
   448
apply (rule allI)
huffman@15576
   449
apply (subst contlub_cfun_fun)
huffman@15576
   450
apply assumption
huffman@15576
   451
apply (fast intro!: thelubI chfin lub_finch2 chfin2finch ch2ch_Rep_CFunL)
huffman@15576
   452
done
huffman@15576
   453
huffman@16085
   454
subsection {* Continuous injection-retraction pairs *}
huffman@15589
   455
huffman@16085
   456
text {* Continuous retractions are strict. *}
huffman@15576
   457
huffman@16085
   458
lemma retraction_strict:
huffman@16085
   459
  "\<forall>x. f\<cdot>(g\<cdot>x) = x \<Longrightarrow> f\<cdot>\<bottom> = \<bottom>"
huffman@15576
   460
apply (rule UU_I)
huffman@16085
   461
apply (drule_tac x="\<bottom>" in spec)
huffman@16085
   462
apply (erule subst)
huffman@16085
   463
apply (rule monofun_cfun_arg)
huffman@16085
   464
apply (rule minimal)
huffman@15576
   465
done
huffman@15576
   466
huffman@16085
   467
lemma injection_eq:
huffman@16085
   468
  "\<forall>x. f\<cdot>(g\<cdot>x) = x \<Longrightarrow> (g\<cdot>x = g\<cdot>y) = (x = y)"
huffman@16085
   469
apply (rule iffI)
huffman@16085
   470
apply (drule_tac f=f in cfun_arg_cong)
huffman@16085
   471
apply simp
huffman@16085
   472
apply simp
huffman@15576
   473
done
huffman@15576
   474
huffman@16085
   475
lemma injection_defined_rev:
huffman@16085
   476
  "\<lbrakk>\<forall>x. f\<cdot>(g\<cdot>x) = x; g\<cdot>z = \<bottom>\<rbrakk> \<Longrightarrow> z = \<bottom>"
huffman@16085
   477
apply (drule_tac f=f in cfun_arg_cong)
huffman@16085
   478
apply (simp add: retraction_strict)
huffman@15576
   479
done
huffman@15576
   480
huffman@16085
   481
lemma injection_defined:
huffman@16085
   482
  "\<lbrakk>\<forall>x. f\<cdot>(g\<cdot>x) = x; z \<noteq> \<bottom>\<rbrakk> \<Longrightarrow> g\<cdot>z \<noteq> \<bottom>"
huffman@16085
   483
by (erule contrapos_nn, rule injection_defined_rev)
huffman@16085
   484
huffman@16085
   485
text {* propagation of flatness and chain-finiteness by retractions *}
huffman@16085
   486
huffman@16085
   487
lemma chfin2chfin:
huffman@16085
   488
  "\<forall>y. (f::'a::chfin \<rightarrow> 'b)\<cdot>(g\<cdot>y) = y
huffman@16085
   489
    \<Longrightarrow> \<forall>Y::nat \<Rightarrow> 'b. chain Y \<longrightarrow> (\<exists>n. max_in_chain n Y)"
huffman@16085
   490
apply clarify
huffman@16085
   491
apply (drule_tac f=g in chain_monofun)
huffman@16085
   492
apply (drule chfin [rule_format])
huffman@16085
   493
apply (unfold max_in_chain_def)
huffman@16085
   494
apply (simp add: injection_eq)
huffman@16085
   495
done
huffman@16085
   496
huffman@16085
   497
lemma flat2flat:
huffman@16085
   498
  "\<forall>y. (f::'a::flat \<rightarrow> 'b::pcpo)\<cdot>(g\<cdot>y) = y
huffman@16085
   499
    \<Longrightarrow> \<forall>x y::'b. x \<sqsubseteq> y \<longrightarrow> x = \<bottom> \<or> x = y"
huffman@16085
   500
apply clarify
huffman@16085
   501
apply (drule_tac fo=g in monofun_cfun_arg)
huffman@16085
   502
apply (drule ax_flat [rule_format])
huffman@16085
   503
apply (erule disjE)
huffman@16085
   504
apply (simp add: injection_defined_rev)
huffman@16085
   505
apply (simp add: injection_eq)
huffman@15576
   506
done
huffman@15576
   507
huffman@15589
   508
text {* a result about functions with flat codomain *}
huffman@15576
   509
huffman@16085
   510
lemma flat_eqI: "\<lbrakk>(x::'a::flat) \<sqsubseteq> y; x \<noteq> \<bottom>\<rbrakk> \<Longrightarrow> x = y"
huffman@16085
   511
by (drule ax_flat [rule_format], simp)
huffman@16085
   512
huffman@16085
   513
lemma flat_codom:
huffman@16085
   514
  "f\<cdot>x = (c::'b::flat) \<Longrightarrow> f\<cdot>\<bottom> = \<bottom> \<or> (\<forall>z. f\<cdot>z = c)"
huffman@16085
   515
apply (case_tac "f\<cdot>x = \<bottom>")
huffman@15576
   516
apply (rule disjI1)
huffman@15576
   517
apply (rule UU_I)
huffman@16085
   518
apply (erule_tac t="\<bottom>" in subst)
huffman@15576
   519
apply (rule minimal [THEN monofun_cfun_arg])
huffman@16085
   520
apply clarify
huffman@16085
   521
apply (rule_tac a = "f\<cdot>\<bottom>" in refl [THEN box_equals])
huffman@16085
   522
apply (erule minimal [THEN monofun_cfun_arg, THEN flat_eqI])
huffman@16085
   523
apply (erule minimal [THEN monofun_cfun_arg, THEN flat_eqI])
huffman@15589
   524
done
huffman@15589
   525
huffman@15589
   526
huffman@15589
   527
subsection {* Identity and composition *}
huffman@15589
   528
huffman@15589
   529
consts
huffman@16085
   530
  ID      :: "'a \<rightarrow> 'a"
huffman@16085
   531
  cfcomp  :: "('b \<rightarrow> 'c) \<rightarrow> ('a \<rightarrow> 'b) \<rightarrow> 'a \<rightarrow> 'c"
huffman@15589
   532
huffman@16085
   533
syntax  "@oo" :: "['b \<rightarrow> 'c, 'a \<rightarrow> 'b] \<Rightarrow> 'a \<rightarrow> 'c" (infixr "oo" 100)
huffman@15589
   534
     
huffman@16085
   535
translations  "f1 oo f2" == "cfcomp$f1$f2"
huffman@15589
   536
huffman@15589
   537
defs
huffman@16085
   538
  ID_def: "ID \<equiv> (\<Lambda> x. x)"
huffman@16085
   539
  oo_def: "cfcomp \<equiv> (\<Lambda> f g x. f\<cdot>(g\<cdot>x))" 
huffman@15589
   540
huffman@16085
   541
lemma ID1 [simp]: "ID\<cdot>x = x"
huffman@16085
   542
by (simp add: ID_def)
huffman@15576
   543
huffman@16085
   544
lemma cfcomp1: "(f oo g) = (\<Lambda> x. f\<cdot>(g\<cdot>x))"
huffman@15589
   545
by (simp add: oo_def)
huffman@15576
   546
huffman@16085
   547
lemma cfcomp2 [simp]: "(f oo g)\<cdot>x = f\<cdot>(g\<cdot>x)"
huffman@15589
   548
by (simp add: cfcomp1)
huffman@15576
   549
huffman@15589
   550
text {*
huffman@15589
   551
  Show that interpretation of (pcpo,@{text "_->_"}) is a category.
huffman@15589
   552
  The class of objects is interpretation of syntactical class pcpo.
huffman@15589
   553
  The class of arrows  between objects @{typ 'a} and @{typ 'b} is interpret. of @{typ "'a -> 'b"}.
huffman@15589
   554
  The identity arrow is interpretation of @{term ID}.
huffman@15589
   555
  The composition of f and g is interpretation of @{text "oo"}.
huffman@15589
   556
*}
huffman@15576
   557
huffman@16085
   558
lemma ID2 [simp]: "f oo ID = f"
huffman@15589
   559
by (rule ext_cfun, simp)
huffman@15576
   560
huffman@16085
   561
lemma ID3 [simp]: "ID oo f = f"
huffman@15589
   562
by (rule ext_cfun, simp)
huffman@15576
   563
huffman@15576
   564
lemma assoc_oo: "f oo (g oo h) = (f oo g) oo h"
huffman@15589
   565
by (rule ext_cfun, simp)
huffman@15576
   566
huffman@16085
   567
huffman@16085
   568
subsection {* Strictified functions *}
huffman@16085
   569
huffman@16085
   570
defaultsort pcpo
huffman@16085
   571
huffman@16085
   572
consts  
huffman@16085
   573
  Istrictify :: "('a \<rightarrow> 'b) \<Rightarrow> 'a \<Rightarrow> 'b"
huffman@16085
   574
  strictify  :: "('a \<rightarrow> 'b) \<rightarrow> 'a \<rightarrow> 'b"
huffman@16085
   575
huffman@16085
   576
defs
huffman@16085
   577
  Istrictify_def: "Istrictify f x \<equiv> if x = \<bottom> then \<bottom> else f\<cdot>x"    
huffman@16085
   578
  strictify_def:  "strictify \<equiv> (\<Lambda> f x. Istrictify f x)"
huffman@16085
   579
huffman@16085
   580
text {* results about strictify *}
huffman@16085
   581
huffman@16085
   582
lemma Istrictify1: "Istrictify f \<bottom> = \<bottom>"
huffman@16085
   583
by (simp add: Istrictify_def)
huffman@16085
   584
huffman@16085
   585
lemma Istrictify2: "x \<noteq> \<bottom> \<Longrightarrow> Istrictify f x = f\<cdot>x"
huffman@16085
   586
by (simp add: Istrictify_def)
huffman@16085
   587
huffman@16085
   588
lemma monofun_Istrictify1: "monofun (\<lambda>f. Istrictify f x)"
huffman@16085
   589
apply (rule monofunI [rule_format])
huffman@16085
   590
apply (simp add: Istrictify_def monofun_cfun_fun)
huffman@16085
   591
done
huffman@16085
   592
huffman@16085
   593
lemma monofun_Istrictify2: "monofun (\<lambda>x. Istrictify f x)"
huffman@16085
   594
apply (rule monofunI [rule_format])
huffman@16085
   595
apply (simp add: Istrictify_def monofun_cfun_arg)
huffman@16085
   596
apply clarify
huffman@16085
   597
apply (simp add: eq_UU_iff)
huffman@16085
   598
done
huffman@16085
   599
huffman@16085
   600
lemma contlub_Istrictify1: "contlub (\<lambda>f. Istrictify f x)"
huffman@16085
   601
apply (rule contlubI [rule_format])
huffman@16085
   602
apply (case_tac "x = \<bottom>")
huffman@16085
   603
apply (simp add: Istrictify1)
huffman@16093
   604
apply (simp add: thelub_const)
huffman@16085
   605
apply (simp add: Istrictify2)
huffman@16085
   606
apply (erule contlub_cfun_fun)
huffman@16085
   607
done
huffman@16085
   608
huffman@16085
   609
lemma contlub_Istrictify2: "contlub (\<lambda>x. Istrictify f x)"
huffman@16085
   610
apply (rule contlubI [rule_format])
huffman@16085
   611
apply (case_tac "lub (range Y) = \<bottom>")
huffman@16085
   612
apply (simp add: Istrictify1 chain_UU_I)
huffman@16093
   613
apply (simp add: thelub_const)
huffman@16085
   614
apply (simp add: Istrictify2)
huffman@16085
   615
apply (simp add: contlub_cfun_arg)
huffman@16085
   616
apply (rule lub_equal2)
huffman@16085
   617
apply (rule chain_mono2 [THEN exE])
huffman@16085
   618
apply (erule chain_UU_I_inverse2)
huffman@16085
   619
apply (assumption)
huffman@16085
   620
apply (blast intro: Istrictify2 [symmetric])
huffman@16085
   621
apply (erule chain_monofun)
huffman@16085
   622
apply (erule monofun_Istrictify2 [THEN ch2ch_monofun])
huffman@16085
   623
done
huffman@16085
   624
huffman@16085
   625
lemmas cont_Istrictify1 =
huffman@16085
   626
  monocontlub2cont [OF monofun_Istrictify1 contlub_Istrictify1, standard]
huffman@16085
   627
huffman@16085
   628
lemmas cont_Istrictify2 =
huffman@16085
   629
  monocontlub2cont [OF monofun_Istrictify2 contlub_Istrictify2, standard]
huffman@16085
   630
huffman@16085
   631
lemma strictify1 [simp]: "strictify\<cdot>f\<cdot>\<bottom> = \<bottom>"
huffman@16085
   632
apply (unfold strictify_def)
huffman@16085
   633
apply (simp add: cont_Istrictify1 cont_Istrictify2)
huffman@16085
   634
apply (rule Istrictify1)
huffman@16085
   635
done
huffman@16085
   636
huffman@16085
   637
lemma strictify2 [simp]: "x \<noteq> \<bottom> \<Longrightarrow> strictify\<cdot>f\<cdot>x = f\<cdot>x"
huffman@16085
   638
apply (unfold strictify_def)
huffman@16085
   639
apply (simp add: cont_Istrictify1 cont_Istrictify2)
huffman@16085
   640
apply (erule Istrictify2)
huffman@16085
   641
done
huffman@16085
   642
huffman@16085
   643
lemma strictify_conv_if: "strictify\<cdot>f\<cdot>x = (if x = \<bottom> then \<bottom> else f\<cdot>x)"
huffman@16085
   644
by simp
huffman@16085
   645
huffman@15576
   646
end