src/HOLCF/Lift.thy
author huffman
Thu Oct 21 06:03:18 2010 -0700 (2010-10-21)
changeset 40082 f4be971c5746
parent 40009 f2c78550c0b7
child 40086 c339c0e8fdfb
permissions -rw-r--r--
pcpodef (open) 'a lift
slotosch@2640
     1
(*  Title:      HOLCF/Lift.thy
wenzelm@12026
     2
    Author:     Olaf Mueller
slotosch@2640
     3
*)
slotosch@2640
     4
wenzelm@12338
     5
header {* Lifting types of class type to flat pcpo's *}
wenzelm@12026
     6
huffman@15577
     7
theory Lift
huffman@27311
     8
imports Discrete Up Countable
huffman@15577
     9
begin
wenzelm@12026
    10
wenzelm@36452
    11
default_sort type
wenzelm@12026
    12
huffman@40082
    13
pcpodef (open) 'a lift = "UNIV :: 'a discr u set"
wenzelm@29063
    14
by simp_all
wenzelm@12026
    15
huffman@25827
    16
instance lift :: (finite) finite_po
huffman@25827
    17
by (rule typedef_finite_po [OF type_definition_lift])
huffman@25827
    18
huffman@16748
    19
lemmas inst_lift_pcpo = Abs_lift_strict [symmetric]
wenzelm@12026
    20
wenzelm@25131
    21
definition
wenzelm@25131
    22
  Def :: "'a \<Rightarrow> 'a lift" where
wenzelm@25131
    23
  "Def x = Abs_lift (up\<cdot>(Discr x))"
wenzelm@12026
    24
wenzelm@12026
    25
subsection {* Lift as a datatype *}
wenzelm@12026
    26
huffman@16748
    27
lemma lift_induct: "\<lbrakk>P \<bottom>; \<And>x. P (Def x)\<rbrakk> \<Longrightarrow> P y"
huffman@16748
    28
apply (induct y)
huffman@16755
    29
apply (rule_tac p=y in upE)
huffman@16748
    30
apply (simp add: Abs_lift_strict)
huffman@16748
    31
apply (case_tac x)
huffman@16748
    32
apply (simp add: Def_def)
huffman@16748
    33
done
wenzelm@12026
    34
haftmann@27104
    35
rep_datatype "\<bottom>\<Colon>'a lift" Def
huffman@40082
    36
  by (erule lift_induct) (simp_all add: Def_def Abs_lift_inject inst_lift_pcpo)
wenzelm@12026
    37
haftmann@27104
    38
lemmas lift_distinct1 = lift.distinct(1)
haftmann@27104
    39
lemmas lift_distinct2 = lift.distinct(2)
haftmann@27104
    40
lemmas Def_not_UU = lift.distinct(2)
haftmann@27104
    41
lemmas Def_inject = lift.inject
wenzelm@12026
    42
wenzelm@12026
    43
huffman@16748
    44
text {* @{term UU} and @{term Def} *}
wenzelm@12026
    45
huffman@16748
    46
lemma not_Undef_is_Def: "(x \<noteq> \<bottom>) = (\<exists>y. x = Def y)"
wenzelm@12026
    47
  by (cases x) simp_all
wenzelm@12026
    48
huffman@16630
    49
lemma lift_definedE: "\<lbrakk>x \<noteq> \<bottom>; \<And>a. x = Def a \<Longrightarrow> R\<rbrakk> \<Longrightarrow> R"
huffman@16630
    50
  by (cases x) simp_all
huffman@16630
    51
wenzelm@12026
    52
text {*
wenzelm@30607
    53
  For @{term "x ~= UU"} in assumptions @{text defined} replaces @{text
wenzelm@12026
    54
  x} by @{text "Def a"} in conclusion. *}
wenzelm@12026
    55
wenzelm@30607
    56
method_setup defined = {*
wenzelm@30607
    57
  Scan.succeed (fn ctxt => SIMPLE_METHOD'
wenzelm@32149
    58
    (etac @{thm lift_definedE} THEN' asm_simp_tac (simpset_of ctxt)))
wenzelm@30607
    59
*} ""
wenzelm@12026
    60
huffman@16748
    61
lemma DefE: "Def x = \<bottom> \<Longrightarrow> R"
huffman@16748
    62
  by simp
wenzelm@12026
    63
huffman@16748
    64
lemma DefE2: "\<lbrakk>x = Def s; x = \<bottom>\<rbrakk> \<Longrightarrow> R"
wenzelm@12026
    65
  by simp
wenzelm@12026
    66
huffman@31076
    67
lemma Def_below_Def: "Def x \<sqsubseteq> Def y \<longleftrightarrow> x = y"
huffman@40082
    68
by (simp add: below_lift_def Def_def Abs_lift_inverse)
wenzelm@12026
    69
huffman@31076
    70
lemma Def_below_iff [simp]: "Def x \<sqsubseteq> y \<longleftrightarrow> Def x = y"
huffman@31076
    71
by (induct y, simp, simp add: Def_below_Def)
wenzelm@12026
    72
wenzelm@12026
    73
wenzelm@12026
    74
subsection {* Lift is flat *}
wenzelm@12026
    75
wenzelm@12338
    76
instance lift :: (type) flat
huffman@27292
    77
proof
huffman@27292
    78
  fix x y :: "'a lift"
huffman@27292
    79
  assume "x \<sqsubseteq> y" thus "x = \<bottom> \<or> x = y"
huffman@27292
    80
    by (induct x) auto
huffman@27292
    81
qed
wenzelm@12026
    82
huffman@16695
    83
subsection {* Further operations *}
huffman@16695
    84
wenzelm@25131
    85
definition
wenzelm@25131
    86
  flift1 :: "('a \<Rightarrow> 'b::pcpo) \<Rightarrow> ('a lift \<rightarrow> 'b)"  (binder "FLIFT " 10)  where
wenzelm@25131
    87
  "flift1 = (\<lambda>f. (\<Lambda> x. lift_case \<bottom> f x))"
huffman@16695
    88
wenzelm@25131
    89
definition
wenzelm@25131
    90
  flift2 :: "('a \<Rightarrow> 'b) \<Rightarrow> ('a lift \<rightarrow> 'b lift)" where
wenzelm@25131
    91
  "flift2 f = (FLIFT x. Def (f x))"
huffman@16695
    92
huffman@16695
    93
subsection {* Continuity Proofs for flift1, flift2 *}
wenzelm@12026
    94
wenzelm@12026
    95
text {* Need the instance of @{text flat}. *}
wenzelm@12026
    96
huffman@16695
    97
lemma cont_lift_case1: "cont (\<lambda>f. lift_case a f x)"
huffman@16695
    98
apply (induct x)
huffman@16695
    99
apply simp
huffman@16695
   100
apply simp
huffman@18092
   101
apply (rule cont_id [THEN cont2cont_fun])
huffman@16695
   102
done
huffman@16695
   103
huffman@25723
   104
lemma cont_lift_case2: "cont (\<lambda>x. lift_case \<bottom> f x)"
huffman@16695
   105
apply (rule flatdom_strict2cont)
huffman@16695
   106
apply simp
huffman@16695
   107
done
huffman@16695
   108
huffman@16695
   109
lemma cont_flift1: "cont flift1"
huffman@27292
   110
unfolding flift1_def
huffman@16695
   111
apply (rule cont2cont_LAM)
huffman@16695
   112
apply (rule cont_lift_case2)
huffman@16695
   113
apply (rule cont_lift_case1)
huffman@16695
   114
done
huffman@16695
   115
huffman@27310
   116
lemma FLIFT_mono:
huffman@27310
   117
  "(\<And>x. f x \<sqsubseteq> g x) \<Longrightarrow> (FLIFT x. f x) \<sqsubseteq> (FLIFT x. g x)"
huffman@27310
   118
apply (rule monofunE [where f=flift1])
huffman@27310
   119
apply (rule cont2mono [OF cont_flift1])
huffman@40002
   120
apply (simp add: fun_below_iff)
huffman@27310
   121
done
huffman@27310
   122
huffman@37099
   123
lemma cont2cont_flift1 [simp, cont2cont]:
huffman@16695
   124
  "\<lbrakk>\<And>y. cont (\<lambda>x. f x y)\<rbrakk> \<Longrightarrow> cont (\<lambda>x. FLIFT y. f x y)"
huffman@40006
   125
apply (rule cont_flift1 [THEN cont_compose])
huffman@26452
   126
apply simp
huffman@16695
   127
done
huffman@16695
   128
huffman@26452
   129
lemma cont2cont_lift_case [simp]:
huffman@25723
   130
  "\<lbrakk>\<And>y. cont (\<lambda>x. f x y); cont g\<rbrakk> \<Longrightarrow> cont (\<lambda>x. lift_case UU (f x) (g x))"
huffman@16757
   131
apply (subgoal_tac "cont (\<lambda>x. (FLIFT y. f x y)\<cdot>(g x))")
huffman@16757
   132
apply (simp add: flift1_def cont_lift_case2)
huffman@26452
   133
apply simp
huffman@16757
   134
done
huffman@16757
   135
huffman@16757
   136
text {* rewrites for @{term flift1}, @{term flift2} *}
huffman@16757
   137
huffman@16695
   138
lemma flift1_Def [simp]: "flift1 f\<cdot>(Def x) = (f x)"
huffman@16695
   139
by (simp add: flift1_def cont_lift_case2)
huffman@16695
   140
huffman@16695
   141
lemma flift2_Def [simp]: "flift2 f\<cdot>(Def x) = Def (f x)"
huffman@16695
   142
by (simp add: flift2_def)
huffman@16695
   143
huffman@16695
   144
lemma flift1_strict [simp]: "flift1 f\<cdot>\<bottom> = \<bottom>"
huffman@16695
   145
by (simp add: flift1_def cont_lift_case2)
huffman@16695
   146
huffman@16695
   147
lemma flift2_strict [simp]: "flift2 f\<cdot>\<bottom> = \<bottom>"
huffman@16695
   148
by (simp add: flift2_def)
huffman@16695
   149
huffman@16695
   150
lemma flift2_defined [simp]: "x \<noteq> \<bottom> \<Longrightarrow> (flift2 f)\<cdot>x \<noteq> \<bottom>"
huffman@16695
   151
by (erule lift_definedE, simp)
huffman@16695
   152
huffman@19520
   153
lemma flift2_defined_iff [simp]: "(flift2 f\<cdot>x = \<bottom>) = (x = \<bottom>)"
huffman@19520
   154
by (cases x, simp_all)
huffman@19520
   155
slotosch@2640
   156
end