\import Logic
\import Meta
\import Paths
\data Bool | false | true
\func So (b : Bool) : \Prop
| true => \Sigma
| false => Empty
\where {
\lemma fromSo {b : Bool} (s : So b) : b = true \elim b
| true => idp
\lemma toSo {b : Bool} (p : b = true) : So b
=> transportInv So p ()
}
\func not (b : Bool) : Bool
| true => false
| false => true
\lemma not-isInv {b : Bool} : not (not b) = b
=> cases b idp
\func if {A : \Type} (b : Bool) (then else : A) : A \elim b
| true => then
| false => else
\func \infixl 3 and (x y : Bool) : Bool \elim x
| true => y
| false => false
\where {
\lemma toSigma {x y : Bool} (p : x and y = true) : \Sigma (x = true) (y = true) \elim x, y, p
| true, true, _ => (idp,idp)
\lemma fromSigma {x y : Bool} (p : \Sigma (x = true) (y = true)) : x and y = true \elim x, y, p
| true, true, _ => idp
| false, _, ((),_)
| _, false, (_,())
}
\func \infixl 2 or (x y : Bool) : Bool \elim x
| true => true
| false => y
\where {
\lemma toOr {x y : Bool} (p : x or y = true) : (x = true) || (y = true) \elim x, y, p
| true, _, _ => byLeft idp
| _, true, _ => byRight idp
\lemma fromOr {x y : Bool} (p : (x = true) || (y = true)) : x or y = true \elim x, y, p
| true, _, _ => idp
| false, true, _ => idp
| false, false, byLeft ()
| false, false, byRight ()
}
\func \infixl 2 xor (a b : Bool) : Bool \with
| false, false => false
| false, true => true
| true, false => true
| true, true => false
\lemma true/=false (p : true = false) : Empty => transport So p ()
\lemma bool-ext {x y : Bool} (p : x = true -> y = true) (q : y = true -> x = true) : x = y \elim x, y
| false, false => idp
| false, true => q idp
| true, false => inv (p idp)
| true, true => idp
\lemma bool-false {x : Bool} (p : x = true -> Empty) : x = false \elim x
| false => idp
| true => absurd (p idp)
\lemma not-char {b : Bool} : not b = true <-> b = false \elim b
| false => (\lam _ => idp, \lam _ => idp)
| true => (\lam p => inv p, \lam p => inv p)
\lemma and-assoc {a b c : Bool} : (a and b) and c = a and (b and c)
=> cases (a,b,c) idp
\lemma and-comm {a b : Bool} : a and b = b and a
=> cases (a,b) idp
\lemma and-idemp {a : Bool} : a and a = a
=> cases a idp
\lemma xor-assoc {a b c : Bool} : (a xor b) xor c = a xor (b xor c)
=> cases (a,b,c) idp
\lemma xor-comm {a b : Bool} : a xor b = b xor a
=> cases (a,b) idp
\lemma xor_false-left {a : Bool} : false xor a = a
=> cases a idp
\lemma xor_false-right {a : Bool} : a xor false = a
=> cases a idp
\lemma xor-self {a : Bool} : a xor a = false
=> cases a idp
\lemma and-xor-ldistr {a b c : Bool} : a and (b xor c) = (a and b) xor (a and c)
=> cases (a,b,c) idp
\lemma xor-or-and {a b : Bool} : (a xor b) xor (a and b) = a or b
=> cases (a,b) idp
\lemma or-false {a : Bool} : a or false = a
=> cases a idp