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