src/HOL/HOLCF/Lift.thy
author blanchet
Thu Sep 11 18:54:36 2014 +0200 (2014-09-11)
changeset 58306 117ba6cbe414
parent 55642 63beb38e9258
child 58880 0baae4311a9f
permissions -rw-r--r--
renamed 'rep_datatype' to 'old_rep_datatype' (HOL)
     1 (*  Title:      HOL/HOLCF/Lift.thy
     2     Author:     Olaf Mueller
     3 *)
     4 
     5 header {* Lifting types of class type to flat pcpo's *}
     6 
     7 theory Lift
     8 imports Discrete Up
     9 begin
    10 
    11 default_sort type
    12 
    13 pcpodef 'a lift = "UNIV :: 'a discr u set"
    14 by simp_all
    15 
    16 lemmas inst_lift_pcpo = Abs_lift_strict [symmetric]
    17 
    18 definition
    19   Def :: "'a \<Rightarrow> 'a lift" where
    20   "Def x = Abs_lift (up\<cdot>(Discr x))"
    21 
    22 subsection {* Lift as a datatype *}
    23 
    24 lemma lift_induct: "\<lbrakk>P \<bottom>; \<And>x. P (Def x)\<rbrakk> \<Longrightarrow> P y"
    25 apply (induct y)
    26 apply (rule_tac p=y in upE)
    27 apply (simp add: Abs_lift_strict)
    28 apply (case_tac x)
    29 apply (simp add: Def_def)
    30 done
    31 
    32 old_rep_datatype "\<bottom>\<Colon>'a lift" Def
    33   by (erule lift_induct) (simp_all add: Def_def Abs_lift_inject inst_lift_pcpo)
    34 
    35 text {* @{term bottom} and @{term Def} *}
    36 
    37 lemma not_Undef_is_Def: "(x \<noteq> \<bottom>) = (\<exists>y. x = Def y)"
    38   by (cases x) simp_all
    39 
    40 lemma lift_definedE: "\<lbrakk>x \<noteq> \<bottom>; \<And>a. x = Def a \<Longrightarrow> R\<rbrakk> \<Longrightarrow> R"
    41   by (cases x) simp_all
    42 
    43 text {*
    44   For @{term "x ~= \<bottom>"} in assumptions @{text defined} replaces @{text
    45   x} by @{text "Def a"} in conclusion. *}
    46 
    47 method_setup defined = {*
    48   Scan.succeed (fn ctxt => SIMPLE_METHOD'
    49     (etac @{thm lift_definedE} THEN' asm_simp_tac ctxt))
    50 *}
    51 
    52 lemma DefE: "Def x = \<bottom> \<Longrightarrow> R"
    53   by simp
    54 
    55 lemma DefE2: "\<lbrakk>x = Def s; x = \<bottom>\<rbrakk> \<Longrightarrow> R"
    56   by simp
    57 
    58 lemma Def_below_Def: "Def x \<sqsubseteq> Def y \<longleftrightarrow> x = y"
    59 by (simp add: below_lift_def Def_def Abs_lift_inverse)
    60 
    61 lemma Def_below_iff [simp]: "Def x \<sqsubseteq> y \<longleftrightarrow> Def x = y"
    62 by (induct y, simp, simp add: Def_below_Def)
    63 
    64 
    65 subsection {* Lift is flat *}
    66 
    67 instance lift :: (type) flat
    68 proof
    69   fix x y :: "'a lift"
    70   assume "x \<sqsubseteq> y" thus "x = \<bottom> \<or> x = y"
    71     by (induct x) auto
    72 qed
    73 
    74 subsection {* Continuity of @{const case_lift} *}
    75 
    76 lemma case_lift_eq: "case_lift \<bottom> f x = fup\<cdot>(\<Lambda> y. f (undiscr y))\<cdot>(Rep_lift x)"
    77 apply (induct x, unfold lift.case)
    78 apply (simp add: Rep_lift_strict)
    79 apply (simp add: Def_def Abs_lift_inverse)
    80 done
    81 
    82 lemma cont2cont_case_lift [simp]:
    83   "\<lbrakk>\<And>y. cont (\<lambda>x. f x y); cont g\<rbrakk> \<Longrightarrow> cont (\<lambda>x. case_lift \<bottom> (f x) (g x))"
    84 unfolding case_lift_eq by (simp add: cont_Rep_lift)
    85 
    86 subsection {* Further operations *}
    87 
    88 definition
    89   flift1 :: "('a \<Rightarrow> 'b::pcpo) \<Rightarrow> ('a lift \<rightarrow> 'b)"  (binder "FLIFT " 10)  where
    90   "flift1 = (\<lambda>f. (\<Lambda> x. case_lift \<bottom> f x))"
    91 
    92 translations
    93   "\<Lambda>(XCONST Def x). t" => "CONST flift1 (\<lambda>x. t)"
    94   "\<Lambda>(CONST Def x). FLIFT y. t" <= "FLIFT x y. t"
    95   "\<Lambda>(CONST Def x). t" <= "FLIFT x. t"
    96 
    97 definition
    98   flift2 :: "('a \<Rightarrow> 'b) \<Rightarrow> ('a lift \<rightarrow> 'b lift)" where
    99   "flift2 f = (FLIFT x. Def (f x))"
   100 
   101 lemma flift1_Def [simp]: "flift1 f\<cdot>(Def x) = (f x)"
   102 by (simp add: flift1_def)
   103 
   104 lemma flift2_Def [simp]: "flift2 f\<cdot>(Def x) = Def (f x)"
   105 by (simp add: flift2_def)
   106 
   107 lemma flift1_strict [simp]: "flift1 f\<cdot>\<bottom> = \<bottom>"
   108 by (simp add: flift1_def)
   109 
   110 lemma flift2_strict [simp]: "flift2 f\<cdot>\<bottom> = \<bottom>"
   111 by (simp add: flift2_def)
   112 
   113 lemma flift2_defined [simp]: "x \<noteq> \<bottom> \<Longrightarrow> (flift2 f)\<cdot>x \<noteq> \<bottom>"
   114 by (erule lift_definedE, simp)
   115 
   116 lemma flift2_bottom_iff [simp]: "(flift2 f\<cdot>x = \<bottom>) = (x = \<bottom>)"
   117 by (cases x, simp_all)
   118 
   119 lemma FLIFT_mono:
   120   "(\<And>x. f x \<sqsubseteq> g x) \<Longrightarrow> (FLIFT x. f x) \<sqsubseteq> (FLIFT x. g x)"
   121 by (rule cfun_belowI, case_tac x, simp_all)
   122 
   123 lemma cont2cont_flift1 [simp, cont2cont]:
   124   "\<lbrakk>\<And>y. cont (\<lambda>x. f x y)\<rbrakk> \<Longrightarrow> cont (\<lambda>x. FLIFT y. f x y)"
   125 by (simp add: flift1_def cont2cont_LAM)
   126 
   127 end