src/HOL/HOLCF/Lift.thy
author wenzelm
Tue Sep 26 20:54:40 2017 +0200 (23 months ago)
changeset 66695 91500c024c7f
parent 62175 8ffc4d0e652d
child 69597 ff784d5a5bfb
permissions -rw-r--r--
tuned;
     1 (*  Title:      HOL/HOLCF/Lift.thy
     2     Author:     Olaf Mueller
     3 *)
     4 
     5 section \<open>Lifting types of class type to flat pcpo's\<close>
     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 \<open>Lift as a datatype\<close>
    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>::'a lift" Def
    33   by (erule lift_induct) (simp_all add: Def_def Abs_lift_inject inst_lift_pcpo)
    34 
    35 text \<open>@{term bottom} and @{term Def}\<close>
    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 \<open>
    44   For @{term "x ~= \<bottom>"} in assumptions \<open>defined\<close> replaces \<open>x\<close> by \<open>Def a\<close> in conclusion.\<close>
    45 
    46 method_setup defined = \<open>
    47   Scan.succeed (fn ctxt => SIMPLE_METHOD'
    48     (eresolve_tac ctxt @{thms lift_definedE} THEN' asm_simp_tac ctxt))
    49 \<close>
    50 
    51 lemma DefE: "Def x = \<bottom> \<Longrightarrow> R"
    52   by simp
    53 
    54 lemma DefE2: "\<lbrakk>x = Def s; x = \<bottom>\<rbrakk> \<Longrightarrow> R"
    55   by simp
    56 
    57 lemma Def_below_Def: "Def x \<sqsubseteq> Def y \<longleftrightarrow> x = y"
    58 by (simp add: below_lift_def Def_def Abs_lift_inverse)
    59 
    60 lemma Def_below_iff [simp]: "Def x \<sqsubseteq> y \<longleftrightarrow> Def x = y"
    61 by (induct y, simp, simp add: Def_below_Def)
    62 
    63 
    64 subsection \<open>Lift is flat\<close>
    65 
    66 instance lift :: (type) flat
    67 proof
    68   fix x y :: "'a lift"
    69   assume "x \<sqsubseteq> y" thus "x = \<bottom> \<or> x = y"
    70     by (induct x) auto
    71 qed
    72 
    73 subsection \<open>Continuity of @{const case_lift}\<close>
    74 
    75 lemma case_lift_eq: "case_lift \<bottom> f x = fup\<cdot>(\<Lambda> y. f (undiscr y))\<cdot>(Rep_lift x)"
    76 apply (induct x, unfold lift.case)
    77 apply (simp add: Rep_lift_strict)
    78 apply (simp add: Def_def Abs_lift_inverse)
    79 done
    80 
    81 lemma cont2cont_case_lift [simp]:
    82   "\<lbrakk>\<And>y. cont (\<lambda>x. f x y); cont g\<rbrakk> \<Longrightarrow> cont (\<lambda>x. case_lift \<bottom> (f x) (g x))"
    83 unfolding case_lift_eq by (simp add: cont_Rep_lift)
    84 
    85 subsection \<open>Further operations\<close>
    86 
    87 definition
    88   flift1 :: "('a \<Rightarrow> 'b::pcpo) \<Rightarrow> ('a lift \<rightarrow> 'b)"  (binder "FLIFT " 10)  where
    89   "flift1 = (\<lambda>f. (\<Lambda> x. case_lift \<bottom> f x))"
    90 
    91 translations
    92   "\<Lambda>(XCONST Def x). t" => "CONST flift1 (\<lambda>x. t)"
    93   "\<Lambda>(CONST Def x). FLIFT y. t" <= "FLIFT x y. t"
    94   "\<Lambda>(CONST Def x). t" <= "FLIFT x. t"
    95 
    96 definition
    97   flift2 :: "('a \<Rightarrow> 'b) \<Rightarrow> ('a lift \<rightarrow> 'b lift)" where
    98   "flift2 f = (FLIFT x. Def (f x))"
    99 
   100 lemma flift1_Def [simp]: "flift1 f\<cdot>(Def x) = (f x)"
   101 by (simp add: flift1_def)
   102 
   103 lemma flift2_Def [simp]: "flift2 f\<cdot>(Def x) = Def (f x)"
   104 by (simp add: flift2_def)
   105 
   106 lemma flift1_strict [simp]: "flift1 f\<cdot>\<bottom> = \<bottom>"
   107 by (simp add: flift1_def)
   108 
   109 lemma flift2_strict [simp]: "flift2 f\<cdot>\<bottom> = \<bottom>"
   110 by (simp add: flift2_def)
   111 
   112 lemma flift2_defined [simp]: "x \<noteq> \<bottom> \<Longrightarrow> (flift2 f)\<cdot>x \<noteq> \<bottom>"
   113 by (erule lift_definedE, simp)
   114 
   115 lemma flift2_bottom_iff [simp]: "(flift2 f\<cdot>x = \<bottom>) = (x = \<bottom>)"
   116 by (cases x, simp_all)
   117 
   118 lemma FLIFT_mono:
   119   "(\<And>x. f x \<sqsubseteq> g x) \<Longrightarrow> (FLIFT x. f x) \<sqsubseteq> (FLIFT x. g x)"
   120 by (rule cfun_belowI, case_tac x, simp_all)
   121 
   122 lemma cont2cont_flift1 [simp, cont2cont]:
   123   "\<lbrakk>\<And>y. cont (\<lambda>x. f x y)\<rbrakk> \<Longrightarrow> cont (\<lambda>x. FLIFT y. f x y)"
   124 by (simp add: flift1_def cont2cont_LAM)
   125 
   126 end