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