src/HOLCF/Lift.thy
author huffman
Fri Mar 04 23:23:47 2005 +0100 (2005-03-04)
changeset 15577 e16da3068ad6
parent 15576 efb95d0d01f7
child 15651 4b393520846e
permissions -rw-r--r--
fix headers
slotosch@2640
     1
(*  Title:      HOLCF/Lift.thy
slotosch@2640
     2
    ID:         $Id$
wenzelm@12026
     3
    Author:     Olaf Mueller
slotosch@2640
     4
*)
slotosch@2640
     5
wenzelm@12338
     6
header {* Lifting types of class type to flat pcpo's *}
wenzelm@12026
     7
huffman@15577
     8
theory Lift
huffman@15577
     9
imports Cprod
huffman@15577
    10
begin
wenzelm@12026
    11
wenzelm@12338
    12
defaultsort type
wenzelm@12026
    13
wenzelm@12026
    14
wenzelm@12026
    15
typedef 'a lift = "UNIV :: 'a option set" ..
wenzelm@12026
    16
wenzelm@12026
    17
constdefs
wenzelm@12026
    18
  Undef :: "'a lift"
wenzelm@12026
    19
  "Undef == Abs_lift None"
wenzelm@12026
    20
  Def :: "'a => 'a lift"
wenzelm@12026
    21
  "Def x == Abs_lift (Some x)"
wenzelm@12026
    22
wenzelm@12338
    23
instance lift :: (type) sq_ord ..
wenzelm@12026
    24
wenzelm@12026
    25
defs (overloaded)
wenzelm@12026
    26
  less_lift_def: "x << y == (x=y | x=Undef)"
wenzelm@12026
    27
wenzelm@12338
    28
instance lift :: (type) po
wenzelm@12026
    29
proof
wenzelm@12026
    30
  fix x y z :: "'a lift"
wenzelm@12026
    31
  show "x << x" by (unfold less_lift_def) blast
wenzelm@12026
    32
  { assume "x << y" and "y << x" thus "x = y" by (unfold less_lift_def) blast }
wenzelm@12026
    33
  { assume "x << y" and "y << z" thus "x << z" by (unfold less_lift_def) blast }
wenzelm@12026
    34
qed
wenzelm@12026
    35
wenzelm@12026
    36
lemma inst_lift_po: "(op <<) = (\<lambda>x y. x = y | x = Undef)"
wenzelm@12026
    37
  -- {* For compatibility with old HOLCF-Version. *}
wenzelm@12026
    38
  by (simp only: less_lift_def [symmetric])
wenzelm@12026
    39
wenzelm@12026
    40
wenzelm@12026
    41
subsection {* Type lift is pointed *}
wenzelm@12026
    42
wenzelm@12026
    43
lemma minimal_lift [iff]: "Undef << x"
wenzelm@12026
    44
  by (simp add: inst_lift_po)
wenzelm@12026
    45
wenzelm@12026
    46
lemma UU_lift_def: "(SOME u. \<forall>y. u \<sqsubseteq> y) = Undef"
wenzelm@12026
    47
  apply (rule minimal2UU [symmetric])
wenzelm@12026
    48
  apply (rule minimal_lift)
wenzelm@12026
    49
  done
wenzelm@12026
    50
wenzelm@12026
    51
lemma least_lift: "EX x::'a lift. ALL y. x << y"
wenzelm@12026
    52
  apply (rule_tac x = Undef in exI)
wenzelm@12026
    53
  apply (rule minimal_lift [THEN allI])
wenzelm@12026
    54
  done
wenzelm@12026
    55
wenzelm@12026
    56
wenzelm@12026
    57
subsection {* Type lift is a cpo *}
wenzelm@12026
    58
wenzelm@12026
    59
text {*
wenzelm@12026
    60
  The following lemmas have already been proved in @{text Pcpo.ML} and
wenzelm@12026
    61
  @{text Fix.ML}, but there class @{text pcpo} is assumed, although
wenzelm@12026
    62
  only @{text po} is necessary and a least element. Therefore they are
wenzelm@12026
    63
  redone here for the @{text po} lift with least element @{text
wenzelm@12026
    64
  Undef}.
wenzelm@12026
    65
*}
wenzelm@12026
    66
wenzelm@12026
    67
lemma notUndef_I: "[| x<<y; x ~= Undef |] ==> y ~= Undef"
wenzelm@12026
    68
  -- {* Tailoring @{text notUU_I} of @{text Pcpo.ML} to @{text Undef} *}
wenzelm@12026
    69
  by (blast intro: antisym_less)
wenzelm@12026
    70
wenzelm@12026
    71
lemma chain_mono2_po: "[| EX j.~Y(j)=Undef; chain(Y::nat=>('a)lift) |]
wenzelm@12026
    72
         ==> EX j. ALL i. j<i-->~Y(i)=Undef"
wenzelm@12026
    73
  -- {* Tailoring @{text chain_mono2} of @{text Pcpo.ML} to @{text Undef} *}
wenzelm@12026
    74
  apply safe
wenzelm@12026
    75
  apply (rule exI)
wenzelm@12026
    76
  apply (intro strip)
wenzelm@12026
    77
  apply (rule notUndef_I)
wenzelm@12026
    78
   apply (erule (1) chain_mono)
wenzelm@12026
    79
  apply assumption
wenzelm@12026
    80
  done
wenzelm@12026
    81
wenzelm@12026
    82
lemma flat_imp_chfin_poo: "(ALL Y. chain(Y::nat=>('a)lift)-->(EX n. max_in_chain n Y))"
wenzelm@12026
    83
  -- {* Tailoring @{text flat_imp_chfin} of @{text Fix.ML} to @{text lift} *}
wenzelm@12026
    84
  apply (unfold max_in_chain_def)
wenzelm@12026
    85
  apply (intro strip)
wenzelm@12026
    86
  apply (rule_tac P = "ALL i. Y (i) = Undef" in case_split)
wenzelm@12026
    87
   apply (rule_tac x = 0 in exI)
wenzelm@12026
    88
   apply (intro strip)
wenzelm@12026
    89
   apply (rule trans)
wenzelm@12026
    90
    apply (erule spec)
wenzelm@12026
    91
   apply (rule sym)
wenzelm@12026
    92
   apply (erule spec)
wenzelm@12026
    93
  apply (subgoal_tac "ALL x y. x << (y:: ('a) lift) --> x=Undef | x=y")
wenzelm@12026
    94
   prefer 2 apply (simp add: inst_lift_po)
wenzelm@12026
    95
  apply (rule chain_mono2_po [THEN exE])
wenzelm@12026
    96
    apply fast
wenzelm@12026
    97
   apply assumption
wenzelm@12026
    98
  apply (rule_tac x = "Suc x" in exI)
wenzelm@12026
    99
  apply (intro strip)
wenzelm@12026
   100
  apply (rule disjE)
wenzelm@12026
   101
    prefer 3 apply assumption
wenzelm@12026
   102
   apply (rule mp)
wenzelm@12026
   103
    apply (drule spec)
wenzelm@12026
   104
    apply (erule spec)
wenzelm@12026
   105
   apply (erule le_imp_less_or_eq [THEN disjE])
wenzelm@12026
   106
    apply (erule chain_mono)
wenzelm@12026
   107
    apply auto
wenzelm@12026
   108
  done
wenzelm@12026
   109
wenzelm@12026
   110
theorem cpo_lift: "chain (Y::nat => 'a lift) ==> EX x. range Y <<| x"
wenzelm@12026
   111
  apply (cut_tac flat_imp_chfin_poo)
wenzelm@12026
   112
  apply (blast intro: lub_finch1)
wenzelm@12026
   113
  done
wenzelm@12026
   114
wenzelm@12338
   115
instance lift :: (type) pcpo
wenzelm@12026
   116
  apply intro_classes
wenzelm@12026
   117
   apply (erule cpo_lift)
wenzelm@12026
   118
  apply (rule least_lift)
wenzelm@12026
   119
  done
wenzelm@12026
   120
wenzelm@12026
   121
lemma inst_lift_pcpo: "UU = Undef"
wenzelm@12026
   122
  -- {* For compatibility with old HOLCF-Version. *}
wenzelm@12026
   123
  by (simp add: UU_def UU_lift_def)
wenzelm@12026
   124
wenzelm@12026
   125
wenzelm@12026
   126
subsection {* Lift as a datatype *}
wenzelm@12026
   127
wenzelm@12026
   128
lemma lift_distinct1: "UU ~= Def x"
wenzelm@12026
   129
  by (simp add: Undef_def Def_def Abs_lift_inject lift_def inst_lift_pcpo)
wenzelm@12026
   130
wenzelm@12026
   131
lemma lift_distinct2: "Def x ~= UU"
wenzelm@12026
   132
  by (simp add: Undef_def Def_def Abs_lift_inject lift_def inst_lift_pcpo)
wenzelm@12026
   133
wenzelm@12026
   134
lemma Def_inject: "(Def x = Def x') = (x = x')"
wenzelm@12026
   135
  by (simp add: Def_def Abs_lift_inject lift_def)
wenzelm@12026
   136
wenzelm@12026
   137
lemma lift_induct: "P UU ==> (!!x. P (Def x)) ==> P y"
wenzelm@12026
   138
  apply (induct y)
wenzelm@12026
   139
  apply (induct_tac y)
wenzelm@12026
   140
   apply (simp_all add: Undef_def Def_def inst_lift_pcpo)
wenzelm@12026
   141
  done
wenzelm@12026
   142
wenzelm@12026
   143
rep_datatype lift
wenzelm@12026
   144
  distinct lift_distinct1 lift_distinct2
wenzelm@12026
   145
  inject Def_inject
wenzelm@12026
   146
  induction lift_induct
wenzelm@12026
   147
wenzelm@12026
   148
lemma Def_not_UU: "Def a ~= UU"
wenzelm@12026
   149
  by simp
wenzelm@12026
   150
wenzelm@12026
   151
wenzelm@12026
   152
subsection {* Further operations *}
wenzelm@12026
   153
wenzelm@12026
   154
consts
wenzelm@12026
   155
 flift1      :: "('a => 'b::pcpo) => ('a lift -> 'b)"
wenzelm@12026
   156
 flift2      :: "('a => 'b)       => ('a lift -> 'b lift)"
wenzelm@12338
   157
 liftpair    ::"'a::type lift * 'b::type lift => ('a * 'b) lift"
slotosch@2640
   158
wenzelm@12026
   159
defs
wenzelm@12026
   160
 flift1_def:
wenzelm@12026
   161
  "flift1 f == (LAM x. (case x of
wenzelm@12026
   162
                   UU => UU
wenzelm@12026
   163
                 | Def y => (f y)))"
wenzelm@12026
   164
 flift2_def:
wenzelm@12026
   165
  "flift2 f == (LAM x. (case x of
wenzelm@12026
   166
                   UU => UU
wenzelm@12026
   167
                 | Def y => Def (f y)))"
wenzelm@12026
   168
 liftpair_def:
wenzelm@12026
   169
  "liftpair x  == (case (cfst$x) of
wenzelm@12026
   170
                  UU  => UU
wenzelm@12026
   171
                | Def x1 => (case (csnd$x) of
wenzelm@12026
   172
                               UU => UU
wenzelm@12026
   173
                             | Def x2 => Def (x1,x2)))"
wenzelm@12026
   174
wenzelm@12026
   175
wenzelm@12026
   176
declare inst_lift_pcpo [symmetric, simp]
wenzelm@12026
   177
wenzelm@12026
   178
wenzelm@12026
   179
lemma less_lift: "(x::'a lift) << y = (x=y | x=UU)"
wenzelm@12026
   180
  by (simp add: inst_lift_po)
wenzelm@12026
   181
wenzelm@12026
   182
wenzelm@12026
   183
text {* @{text UU} and @{text Def} *}
wenzelm@12026
   184
wenzelm@12026
   185
lemma Lift_exhaust: "x = UU | (EX y. x = Def y)"
wenzelm@12026
   186
  by (induct x) simp_all
wenzelm@12026
   187
wenzelm@12026
   188
lemma Lift_cases: "[| x = UU ==> P; ? a. x = Def a ==> P |] ==> P"
wenzelm@12026
   189
  by (insert Lift_exhaust) blast
wenzelm@12026
   190
wenzelm@12026
   191
lemma not_Undef_is_Def: "(x ~= UU) = (EX y. x = Def y)"
wenzelm@12026
   192
  by (cases x) simp_all
wenzelm@12026
   193
wenzelm@12026
   194
text {*
wenzelm@12026
   195
  For @{term "x ~= UU"} in assumptions @{text def_tac} replaces @{text
wenzelm@12026
   196
  x} by @{text "Def a"} in conclusion. *}
wenzelm@12026
   197
wenzelm@12026
   198
ML {*
wenzelm@12026
   199
  local val not_Undef_is_Def = thm "not_Undef_is_Def"
wenzelm@12026
   200
  in val def_tac = SIMPSET' (fn ss =>
wenzelm@12026
   201
    etac (not_Undef_is_Def RS iffD1 RS exE) THEN' asm_simp_tac ss)
wenzelm@12026
   202
  end;
wenzelm@12026
   203
*}
wenzelm@12026
   204
wenzelm@12026
   205
lemma Undef_eq_UU: "Undef = UU"
wenzelm@12026
   206
  by (rule inst_lift_pcpo [symmetric])
wenzelm@12026
   207
wenzelm@12026
   208
lemma DefE: "Def x = UU ==> R"
wenzelm@12026
   209
  by simp
wenzelm@12026
   210
wenzelm@12026
   211
lemma DefE2: "[| x = Def s; x = UU |] ==> R"
wenzelm@12026
   212
  by simp
wenzelm@12026
   213
wenzelm@12026
   214
lemma Def_inject_less_eq: "Def x << Def y = (x = y)"
wenzelm@12026
   215
  by (simp add: less_lift_def)
wenzelm@12026
   216
wenzelm@12026
   217
lemma Def_less_is_eq [simp]: "Def x << y = (Def x = y)"
wenzelm@12026
   218
  by (simp add: less_lift)
wenzelm@12026
   219
wenzelm@12026
   220
wenzelm@12026
   221
subsection {* Lift is flat *}
wenzelm@12026
   222
wenzelm@12338
   223
instance lift :: (type) flat
wenzelm@12026
   224
proof
wenzelm@12026
   225
  show "ALL x y::'a lift. x << y --> x = UU | x = y"
wenzelm@12026
   226
    by (simp add: less_lift)
wenzelm@12026
   227
qed
wenzelm@12026
   228
wenzelm@12026
   229
defaultsort pcpo
wenzelm@12026
   230
wenzelm@12026
   231
wenzelm@12026
   232
text {*
wenzelm@12026
   233
  \medskip Two specific lemmas for the combination of LCF and HOL
wenzelm@12026
   234
  terms.
wenzelm@12026
   235
*}
wenzelm@12026
   236
wenzelm@12026
   237
lemma cont_Rep_CFun_app: "[|cont g; cont f|] ==> cont(%x. ((f x)$(g x)) s)"
wenzelm@12026
   238
  apply (rule cont2cont_CF1L)
wenzelm@12026
   239
  apply (tactic "resolve_tac cont_lemmas1 1")+
wenzelm@12026
   240
   apply auto
wenzelm@12026
   241
  done
wenzelm@12026
   242
wenzelm@12026
   243
lemma cont_Rep_CFun_app_app: "[|cont g; cont f|] ==> cont(%x. ((f x)$(g x)) s t)"
wenzelm@12026
   244
  apply (rule cont2cont_CF1L)
wenzelm@12026
   245
  apply (erule cont_Rep_CFun_app)
wenzelm@12026
   246
  apply assumption
wenzelm@12026
   247
  done
slotosch@2640
   248
wenzelm@12026
   249
text {* Continuity of if-then-else. *}
wenzelm@12026
   250
wenzelm@12026
   251
lemma cont_if: "[| cont f1; cont f2 |] ==> cont (%x. if b then f1 x else f2 x)"
wenzelm@12026
   252
  by (cases b) simp_all
wenzelm@12026
   253
wenzelm@12026
   254
wenzelm@12026
   255
subsection {* Continuity Proofs for flift1, flift2, if *}
wenzelm@12026
   256
wenzelm@12026
   257
text {* Need the instance of @{text flat}. *}
wenzelm@12026
   258
wenzelm@12026
   259
lemma cont_flift1_arg: "cont (lift_case UU f)"
wenzelm@12026
   260
  -- {* @{text flift1} is continuous in its argument itself. *}
wenzelm@12026
   261
  apply (rule flatdom_strict2cont)
wenzelm@12026
   262
  apply simp
wenzelm@12026
   263
  done
wenzelm@12026
   264
wenzelm@12026
   265
lemma cont_flift1_not_arg: "!!f. [| !! a. cont (%y. (f y) a) |] ==>
wenzelm@12026
   266
           cont (%y. lift_case UU (f y))"
wenzelm@12026
   267
  -- {* @{text flift1} is continuous in a variable that occurs only
wenzelm@12026
   268
    in the @{text Def} branch. *}
wenzelm@12026
   269
  apply (rule cont2cont_CF1L_rev)
wenzelm@12026
   270
  apply (intro strip)
wenzelm@12026
   271
  apply (case_tac y)
wenzelm@12026
   272
   apply simp
wenzelm@12026
   273
  apply simp
wenzelm@12026
   274
  done
wenzelm@12026
   275
wenzelm@12026
   276
lemma cont_flift1_arg_and_not_arg: "!!f. [| !! a. cont (%y. (f y) a); cont g|] ==>
wenzelm@12026
   277
    cont (%y. lift_case UU (f y) (g y))"
wenzelm@12026
   278
  -- {* @{text flift1} is continuous in a variable that occurs either
wenzelm@12026
   279
    in the @{text Def} branch or in the argument. *}
wenzelm@12026
   280
  apply (rule_tac tt = g in cont2cont_app)
wenzelm@12026
   281
    apply (rule cont_flift1_not_arg)
wenzelm@12026
   282
    apply auto
wenzelm@12026
   283
  apply (rule cont_flift1_arg)
wenzelm@12026
   284
  done
wenzelm@12026
   285
wenzelm@12026
   286
lemma cont_flift2_arg: "cont (lift_case UU (%y. Def (f y)))"
wenzelm@12026
   287
  -- {* @{text flift2} is continuous in its argument itself. *}
wenzelm@12026
   288
  apply (rule flatdom_strict2cont)
wenzelm@12026
   289
  apply simp
wenzelm@12026
   290
  done
wenzelm@12026
   291
wenzelm@12026
   292
text {*
oheimb@14096
   293
  \medskip Extension of @{text cont_tac} and installation of simplifier.
wenzelm@12026
   294
*}
wenzelm@12026
   295
wenzelm@12026
   296
lemma cont2cont_CF1L_rev2: "(!!y. cont (%x. c1 x y)) ==> cont c1"
wenzelm@12026
   297
  apply (rule cont2cont_CF1L_rev)
wenzelm@12026
   298
  apply simp
wenzelm@12026
   299
  done
wenzelm@12026
   300
wenzelm@12026
   301
lemmas cont_lemmas_ext [simp] =
wenzelm@12026
   302
  cont_flift1_arg cont_flift2_arg
wenzelm@12026
   303
  cont_flift1_arg_and_not_arg cont2cont_CF1L_rev2
wenzelm@12026
   304
  cont_Rep_CFun_app cont_Rep_CFun_app_app cont_if
wenzelm@12026
   305
wenzelm@12026
   306
ML_setup {*
wenzelm@12026
   307
val cont_lemmas2 = cont_lemmas1 @ thms "cont_lemmas_ext";
wenzelm@12026
   308
wenzelm@12026
   309
fun cont_tac  i = resolve_tac cont_lemmas2 i;
wenzelm@12026
   310
fun cont_tacR i = REPEAT (cont_tac i);
wenzelm@12026
   311
wenzelm@12026
   312
local val flift1_def = thm "flift1_def" and flift2_def = thm "flift2_def"
wenzelm@12026
   313
in fun cont_tacRs i =
wenzelm@12026
   314
  simp_tac (simpset() addsimps [flift1_def, flift2_def]) i THEN
wenzelm@12026
   315
  REPEAT (cont_tac i)
wenzelm@12026
   316
end;
wenzelm@12026
   317
wenzelm@12026
   318
simpset_ref() := simpset() addSolver
wenzelm@12026
   319
  (mk_solver "cont_tac" (K (DEPTH_SOLVE_1 o cont_tac)));
wenzelm@12026
   320
*}
wenzelm@12026
   321
wenzelm@12026
   322
wenzelm@12026
   323
subsection {* flift1, flift2 *}
wenzelm@12026
   324
wenzelm@12026
   325
lemma flift1_Def [simp]: "flift1 f$(Def x) = (f x)"
wenzelm@12026
   326
  by (simp add: flift1_def)
wenzelm@12026
   327
wenzelm@12026
   328
lemma flift2_Def [simp]: "flift2 f$(Def x) = Def (f x)"
wenzelm@12026
   329
  by (simp add: flift2_def)
wenzelm@12026
   330
wenzelm@12026
   331
lemma flift1_UU [simp]: "flift1 f$UU = UU"
wenzelm@12026
   332
  by (simp add: flift1_def)
wenzelm@12026
   333
wenzelm@12026
   334
lemma flift2_UU [simp]: "flift2 f$UU = UU"
wenzelm@12026
   335
  by (simp add: flift2_def)
wenzelm@12026
   336
wenzelm@12026
   337
lemma flift2_nUU [simp]: "x~=UU ==> (flift2 f)$x~=UU"
wenzelm@12026
   338
  by (tactic "def_tac 1")
slotosch@2640
   339
slotosch@2640
   340
end