src/HOLCF/Lift.thy
author huffman
Wed Nov 10 17:56:08 2010 -0800 (2010-11-10)
changeset 40502 8e92772bc0e8
parent 40323 4cce7c708402
permissions -rw-r--r--
move map functions to new theory file Map_Functions; add theory file Plain_HOLCF
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@40086
     8
imports Discrete Up
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@16748
    16
lemmas inst_lift_pcpo = Abs_lift_strict [symmetric]
wenzelm@12026
    17
wenzelm@25131
    18
definition
wenzelm@25131
    19
  Def :: "'a \<Rightarrow> 'a lift" where
wenzelm@25131
    20
  "Def x = Abs_lift (up\<cdot>(Discr x))"
wenzelm@12026
    21
wenzelm@12026
    22
subsection {* Lift as a datatype *}
wenzelm@12026
    23
huffman@16748
    24
lemma lift_induct: "\<lbrakk>P \<bottom>; \<And>x. P (Def x)\<rbrakk> \<Longrightarrow> P y"
huffman@16748
    25
apply (induct y)
huffman@16755
    26
apply (rule_tac p=y in upE)
huffman@16748
    27
apply (simp add: Abs_lift_strict)
huffman@16748
    28
apply (case_tac x)
huffman@16748
    29
apply (simp add: Def_def)
huffman@16748
    30
done
wenzelm@12026
    31
haftmann@27104
    32
rep_datatype "\<bottom>\<Colon>'a lift" Def
huffman@40082
    33
  by (erule lift_induct) (simp_all add: Def_def Abs_lift_inject inst_lift_pcpo)
wenzelm@12026
    34
haftmann@27104
    35
lemmas lift_distinct1 = lift.distinct(1)
haftmann@27104
    36
lemmas lift_distinct2 = lift.distinct(2)
haftmann@27104
    37
lemmas Def_not_UU = lift.distinct(2)
haftmann@27104
    38
lemmas Def_inject = lift.inject
wenzelm@12026
    39
wenzelm@12026
    40
huffman@16748
    41
text {* @{term UU} and @{term Def} *}
wenzelm@12026
    42
huffman@16748
    43
lemma not_Undef_is_Def: "(x \<noteq> \<bottom>) = (\<exists>y. x = Def y)"
wenzelm@12026
    44
  by (cases x) simp_all
wenzelm@12026
    45
huffman@16630
    46
lemma lift_definedE: "\<lbrakk>x \<noteq> \<bottom>; \<And>a. x = Def a \<Longrightarrow> R\<rbrakk> \<Longrightarrow> R"
huffman@16630
    47
  by (cases x) simp_all
huffman@16630
    48
wenzelm@12026
    49
text {*
wenzelm@30607
    50
  For @{term "x ~= UU"} in assumptions @{text defined} replaces @{text
wenzelm@12026
    51
  x} by @{text "Def a"} in conclusion. *}
wenzelm@12026
    52
wenzelm@30607
    53
method_setup defined = {*
wenzelm@30607
    54
  Scan.succeed (fn ctxt => SIMPLE_METHOD'
wenzelm@32149
    55
    (etac @{thm lift_definedE} THEN' asm_simp_tac (simpset_of ctxt)))
wenzelm@30607
    56
*} ""
wenzelm@12026
    57
huffman@16748
    58
lemma DefE: "Def x = \<bottom> \<Longrightarrow> R"
huffman@16748
    59
  by simp
wenzelm@12026
    60
huffman@16748
    61
lemma DefE2: "\<lbrakk>x = Def s; x = \<bottom>\<rbrakk> \<Longrightarrow> R"
wenzelm@12026
    62
  by simp
wenzelm@12026
    63
huffman@31076
    64
lemma Def_below_Def: "Def x \<sqsubseteq> Def y \<longleftrightarrow> x = y"
huffman@40082
    65
by (simp add: below_lift_def Def_def Abs_lift_inverse)
wenzelm@12026
    66
huffman@31076
    67
lemma Def_below_iff [simp]: "Def x \<sqsubseteq> y \<longleftrightarrow> Def x = y"
huffman@31076
    68
by (induct y, simp, simp add: Def_below_Def)
wenzelm@12026
    69
wenzelm@12026
    70
wenzelm@12026
    71
subsection {* Lift is flat *}
wenzelm@12026
    72
wenzelm@12338
    73
instance lift :: (type) flat
huffman@27292
    74
proof
huffman@27292
    75
  fix x y :: "'a lift"
huffman@27292
    76
  assume "x \<sqsubseteq> y" thus "x = \<bottom> \<or> x = y"
huffman@27292
    77
    by (induct x) auto
huffman@27292
    78
qed
wenzelm@12026
    79
huffman@40088
    80
subsection {* Continuity of @{const lift_case} *}
huffman@40088
    81
huffman@40088
    82
lemma lift_case_eq: "lift_case \<bottom> f x = fup\<cdot>(\<Lambda> y. f (undiscr y))\<cdot>(Rep_lift x)"
huffman@40088
    83
apply (induct x, unfold lift.cases)
huffman@40088
    84
apply (simp add: Rep_lift_strict)
huffman@40088
    85
apply (simp add: Def_def Abs_lift_inverse)
huffman@40088
    86
done
huffman@40088
    87
huffman@40088
    88
lemma cont2cont_lift_case [simp]:
huffman@40088
    89
  "\<lbrakk>\<And>y. cont (\<lambda>x. f x y); cont g\<rbrakk> \<Longrightarrow> cont (\<lambda>x. lift_case \<bottom> (f x) (g x))"
huffman@40088
    90
unfolding lift_case_eq by (simp add: cont_Rep_lift [THEN cont_compose])
huffman@40088
    91
huffman@16695
    92
subsection {* Further operations *}
huffman@16695
    93
wenzelm@25131
    94
definition
wenzelm@25131
    95
  flift1 :: "('a \<Rightarrow> 'b::pcpo) \<Rightarrow> ('a lift \<rightarrow> 'b)"  (binder "FLIFT " 10)  where
wenzelm@25131
    96
  "flift1 = (\<lambda>f. (\<Lambda> x. lift_case \<bottom> f x))"
huffman@16695
    97
huffman@40323
    98
translations
huffman@40323
    99
  "\<Lambda>(XCONST Def x). t" => "CONST flift1 (\<lambda>x. t)"
huffman@40323
   100
  "\<Lambda>(CONST Def x). FLIFT y. t" <= "FLIFT x y. t"
huffman@40323
   101
  "\<Lambda>(CONST Def x). t" <= "FLIFT x. t"
huffman@40323
   102
wenzelm@25131
   103
definition
wenzelm@25131
   104
  flift2 :: "('a \<Rightarrow> 'b) \<Rightarrow> ('a lift \<rightarrow> 'b lift)" where
wenzelm@25131
   105
  "flift2 f = (FLIFT x. Def (f x))"
huffman@16695
   106
huffman@16695
   107
lemma flift1_Def [simp]: "flift1 f\<cdot>(Def x) = (f x)"
huffman@40088
   108
by (simp add: flift1_def)
huffman@16695
   109
huffman@16695
   110
lemma flift2_Def [simp]: "flift2 f\<cdot>(Def x) = Def (f x)"
huffman@16695
   111
by (simp add: flift2_def)
huffman@16695
   112
huffman@16695
   113
lemma flift1_strict [simp]: "flift1 f\<cdot>\<bottom> = \<bottom>"
huffman@40088
   114
by (simp add: flift1_def)
huffman@16695
   115
huffman@16695
   116
lemma flift2_strict [simp]: "flift2 f\<cdot>\<bottom> = \<bottom>"
huffman@16695
   117
by (simp add: flift2_def)
huffman@16695
   118
huffman@16695
   119
lemma flift2_defined [simp]: "x \<noteq> \<bottom> \<Longrightarrow> (flift2 f)\<cdot>x \<noteq> \<bottom>"
huffman@16695
   120
by (erule lift_definedE, simp)
huffman@16695
   121
huffman@40321
   122
lemma flift2_bottom_iff [simp]: "(flift2 f\<cdot>x = \<bottom>) = (x = \<bottom>)"
huffman@19520
   123
by (cases x, simp_all)
huffman@19520
   124
huffman@40088
   125
lemma FLIFT_mono:
huffman@40088
   126
  "(\<And>x. f x \<sqsubseteq> g x) \<Longrightarrow> (FLIFT x. f x) \<sqsubseteq> (FLIFT x. g x)"
huffman@40088
   127
by (rule cfun_belowI, case_tac x, simp_all)
huffman@40088
   128
huffman@40088
   129
lemma cont2cont_flift1 [simp, cont2cont]:
huffman@40088
   130
  "\<lbrakk>\<And>y. cont (\<lambda>x. f x y)\<rbrakk> \<Longrightarrow> cont (\<lambda>x. FLIFT y. f x y)"
huffman@40088
   131
by (simp add: flift1_def cont2cont_LAM)
huffman@40088
   132
slotosch@2640
   133
end