src/HOL/HOLCF/Tr.thy
author wenzelm
Sat Nov 04 15:24:40 2017 +0100 (20 months ago)
changeset 67003 49850a679c2c
parent 62175 8ffc4d0e652d
child 67312 0d25e02759b7
permissions -rw-r--r--
more robust sorted_entries;
     1 (*  Title:      HOL/HOLCF/Tr.thy
     2     Author:     Franz Regensburger
     3 *)
     4 
     5 section \<open>The type of lifted booleans\<close>
     6 
     7 theory Tr
     8 imports Lift
     9 begin
    10 
    11 subsection \<open>Type definition and constructors\<close>
    12 
    13 type_synonym
    14   tr = "bool lift"
    15 
    16 translations
    17   (type) "tr" <= (type) "bool lift"
    18 
    19 definition
    20   TT :: "tr" where
    21   "TT = Def True"
    22 
    23 definition
    24   FF :: "tr" where
    25   "FF = Def False"
    26 
    27 text \<open>Exhaustion and Elimination for type @{typ tr}\<close>
    28 
    29 lemma Exh_tr: "t = \<bottom> \<or> t = TT \<or> t = FF"
    30 unfolding FF_def TT_def by (induct t) auto
    31 
    32 lemma trE [case_names bottom TT FF, cases type: tr]:
    33   "\<lbrakk>p = \<bottom> \<Longrightarrow> Q; p = TT \<Longrightarrow> Q; p = FF \<Longrightarrow> Q\<rbrakk> \<Longrightarrow> Q"
    34 unfolding FF_def TT_def by (induct p) auto
    35 
    36 lemma tr_induct [case_names bottom TT FF, induct type: tr]:
    37   "\<lbrakk>P \<bottom>; P TT; P FF\<rbrakk> \<Longrightarrow> P x"
    38 by (cases x) simp_all
    39 
    40 text \<open>distinctness for type @{typ tr}\<close>
    41 
    42 lemma dist_below_tr [simp]:
    43   "TT \<notsqsubseteq> \<bottom>" "FF \<notsqsubseteq> \<bottom>" "TT \<notsqsubseteq> FF" "FF \<notsqsubseteq> TT"
    44 unfolding TT_def FF_def by simp_all
    45 
    46 lemma dist_eq_tr [simp]:
    47   "TT \<noteq> \<bottom>" "FF \<noteq> \<bottom>" "TT \<noteq> FF" "\<bottom> \<noteq> TT" "\<bottom> \<noteq> FF" "FF \<noteq> TT"
    48 unfolding TT_def FF_def by simp_all
    49 
    50 lemma TT_below_iff [simp]: "TT \<sqsubseteq> x \<longleftrightarrow> x = TT"
    51 by (induct x) simp_all
    52 
    53 lemma FF_below_iff [simp]: "FF \<sqsubseteq> x \<longleftrightarrow> x = FF"
    54 by (induct x) simp_all
    55 
    56 lemma not_below_TT_iff [simp]: "x \<notsqsubseteq> TT \<longleftrightarrow> x = FF"
    57 by (induct x) simp_all
    58 
    59 lemma not_below_FF_iff [simp]: "x \<notsqsubseteq> FF \<longleftrightarrow> x = TT"
    60 by (induct x) simp_all
    61 
    62 
    63 subsection \<open>Case analysis\<close>
    64 
    65 default_sort pcpo
    66 
    67 definition tr_case :: "'a \<rightarrow> 'a \<rightarrow> tr \<rightarrow> 'a" where
    68   "tr_case = (\<Lambda> t e (Def b). if b then t else e)"
    69 
    70 abbreviation
    71   cifte_syn :: "[tr, 'c, 'c] \<Rightarrow> 'c"  ("(If (_)/ then (_)/ else (_))" [0, 0, 60] 60)
    72 where
    73   "If b then e1 else e2 == tr_case\<cdot>e1\<cdot>e2\<cdot>b"
    74 
    75 translations
    76   "\<Lambda> (XCONST TT). t" == "CONST tr_case\<cdot>t\<cdot>\<bottom>"
    77   "\<Lambda> (XCONST FF). t" == "CONST tr_case\<cdot>\<bottom>\<cdot>t"
    78 
    79 lemma ifte_thms [simp]:
    80   "If \<bottom> then e1 else e2 = \<bottom>"
    81   "If FF then e1 else e2 = e2"
    82   "If TT then e1 else e2 = e1"
    83 by (simp_all add: tr_case_def TT_def FF_def)
    84 
    85 
    86 subsection \<open>Boolean connectives\<close>
    87 
    88 definition
    89   trand :: "tr \<rightarrow> tr \<rightarrow> tr" where
    90   andalso_def: "trand = (\<Lambda> x y. If x then y else FF)"
    91 abbreviation
    92   andalso_syn :: "tr \<Rightarrow> tr \<Rightarrow> tr"  ("_ andalso _" [36,35] 35)  where
    93   "x andalso y == trand\<cdot>x\<cdot>y"
    94 
    95 definition
    96   tror :: "tr \<rightarrow> tr \<rightarrow> tr" where
    97   orelse_def: "tror = (\<Lambda> x y. If x then TT else y)"
    98 abbreviation
    99   orelse_syn :: "tr \<Rightarrow> tr \<Rightarrow> tr"  ("_ orelse _"  [31,30] 30)  where
   100   "x orelse y == tror\<cdot>x\<cdot>y"
   101 
   102 definition
   103   neg :: "tr \<rightarrow> tr" where
   104   "neg = flift2 Not"
   105 
   106 definition
   107   If2 :: "[tr, 'c, 'c] \<Rightarrow> 'c" where
   108   "If2 Q x y = (If Q then x else y)"
   109 
   110 text \<open>tactic for tr-thms with case split\<close>
   111 
   112 lemmas tr_defs = andalso_def orelse_def neg_def tr_case_def TT_def FF_def
   113 
   114 text \<open>lemmas about andalso, orelse, neg and if\<close>
   115 
   116 lemma andalso_thms [simp]:
   117   "(TT andalso y) = y"
   118   "(FF andalso y) = FF"
   119   "(\<bottom> andalso y) = \<bottom>"
   120   "(y andalso TT) = y"
   121   "(y andalso y) = y"
   122 apply (unfold andalso_def, simp_all)
   123 apply (cases y, simp_all)
   124 apply (cases y, simp_all)
   125 done
   126 
   127 lemma orelse_thms [simp]:
   128   "(TT orelse y) = TT"
   129   "(FF orelse y) = y"
   130   "(\<bottom> orelse y) = \<bottom>"
   131   "(y orelse FF) = y"
   132   "(y orelse y) = y"
   133 apply (unfold orelse_def, simp_all)
   134 apply (cases y, simp_all)
   135 apply (cases y, simp_all)
   136 done
   137 
   138 lemma neg_thms [simp]:
   139   "neg\<cdot>TT = FF"
   140   "neg\<cdot>FF = TT"
   141   "neg\<cdot>\<bottom> = \<bottom>"
   142 by (simp_all add: neg_def TT_def FF_def)
   143 
   144 text \<open>split-tac for If via If2 because the constant has to be a constant\<close>
   145 
   146 lemma split_If2:
   147   "P (If2 Q x y) = ((Q = \<bottom> \<longrightarrow> P \<bottom>) \<and> (Q = TT \<longrightarrow> P x) \<and> (Q = FF \<longrightarrow> P y))"
   148 apply (unfold If2_def)
   149 apply (cases Q)
   150 apply (simp_all)
   151 done
   152 
   153 (* FIXME unused!? *)
   154 ML \<open>
   155 fun split_If_tac ctxt =
   156   simp_tac (put_simpset HOL_basic_ss ctxt addsimps [@{thm If2_def} RS sym])
   157     THEN' (split_tac ctxt [@{thm split_If2}])
   158 \<close>
   159 
   160 subsection "Rewriting of HOLCF operations to HOL functions"
   161 
   162 lemma andalso_or:
   163   "t \<noteq> \<bottom> \<Longrightarrow> ((t andalso s) = FF) = (t = FF \<or> s = FF)"
   164 apply (cases t)
   165 apply simp_all
   166 done
   167 
   168 lemma andalso_and:
   169   "t \<noteq> \<bottom> \<Longrightarrow> ((t andalso s) \<noteq> FF) = (t \<noteq> FF \<and> s \<noteq> FF)"
   170 apply (cases t)
   171 apply simp_all
   172 done
   173 
   174 lemma Def_bool1 [simp]: "(Def x \<noteq> FF) = x"
   175 by (simp add: FF_def)
   176 
   177 lemma Def_bool2 [simp]: "(Def x = FF) = (\<not> x)"
   178 by (simp add: FF_def)
   179 
   180 lemma Def_bool3 [simp]: "(Def x = TT) = x"
   181 by (simp add: TT_def)
   182 
   183 lemma Def_bool4 [simp]: "(Def x \<noteq> TT) = (\<not> x)"
   184 by (simp add: TT_def)
   185 
   186 lemma If_and_if:
   187   "(If Def P then A else B) = (if P then A else B)"
   188 apply (cases "Def P")
   189 apply (auto simp add: TT_def[symmetric] FF_def[symmetric])
   190 done
   191 
   192 subsection \<open>Compactness\<close>
   193 
   194 lemma compact_TT: "compact TT"
   195 by (rule compact_chfin)
   196 
   197 lemma compact_FF: "compact FF"
   198 by (rule compact_chfin)
   199 
   200 end