Theory Data_Bool

section ‹Data: Bool›

theory Data_Bool
  imports Type_Classes
begin

subsection ‹Class instances›

text ‹Eq›

lemma eq_eqI[case_names bottomLTR bottomRTL LTR RTL]:
  "(x =   y = )  (y =   x = )  (x = TT  y = TT)  (y = TT  x = TT)  x = y"
by (metis Exh_tr)

lemma eq_tr_simps [simp]:
  shows "eqTTTT = TT" and "eqTTFF = FF"
    and "eqFFTT = FF" and "eqFFFF = TT"
  unfolding TT_def FF_def eq_lift_def by simp_all

text ‹Ord›

lemma compare_tr_simps [simp]:
  "compareFFFF = EQ"
  "compareFFTT = LT"
  "compareTTFF = GT"
  "compareTTTT = EQ"
  unfolding TT_def FF_def compare_lift_def
  by simp_all

subsection ‹Lemmas›

lemma andalso_eq_TT_iff [simp]:
  "(x andalso y) = TT  x = TT  y = TT"
  by (cases x, simp_all)

lemma andalso_eq_FF_iff [simp]:
  "(x andalso y) = FF  x = FF  (x = TT  y = FF)"
  by (cases x, simp_all)

lemma andalso_eq_bottom_iff [simp]:
  "(x andalso y) =   x =   (x = TT  y = )"
  by (cases x, simp_all)

lemma orelse_eq_FF_iff [simp]:
  "(x orelse y) = FF  x = FF  y = FF"
  by (cases x, simp_all)

lemma orelse_assoc [simp]:
  "((x orelse y) orelse z) = (x orelse y orelse z)"
  by (cases x) auto

lemma andalso_assoc [simp]:
  "((x andalso y) andalso z) = (x andalso y andalso z)"
  by (cases x) auto

lemma neg_orelse [simp]:
  "neg(x orelse y) = (negx andalso negy)"
  by (cases x) auto

lemma neg_andalso [simp]:
  "neg(x andalso y) = (negx orelse negy)"
  by (cases x) auto

text ‹Not suitable as default simp rules, because they cause the
  simplifier to loop:›
lemma neg_eq_simps:
  "negx = TT  x = FF"
  "negx = FF  x = TT"
  "negx =   x = "
  by (cases x, simp_all)+

lemma neg_eq_TT_iff [simp]: "negx = TT  x = FF"
  by (cases x, simp_all)+

lemma neg_eq_FF_iff [simp]: "negx = FF  x = TT"
  by (cases x, simp_all)+

lemma neg_eq_bottom_iff [simp]: "negx =   x = "
  by (cases x, simp_all)+

(* TODO: set up reorient_proc for TT and FF *)

lemma neg_eq [simp]:
  "negx = negy  x = y"
  by (cases y, simp_all)

lemma neg_neg [simp]:
  "neg(negx) = x"
  by (cases x, auto)

lemma neg_comp_neg [simp]:
  "neg oo neg = ID"
  by (metis cfun_eqI cfcomp2 neg_neg ID1)

end