QJMKKLU2UF45IRLVJHSQQ6PHTLHHX34Z4ROJGQLBRQTMQ54D6G5AC
4L2YWRMCKZ56NCRC44XVDZQ5BEKHX26C4GQZ5TIL35Y33VKFTBCQC
XNPLRKJ4ZK442XNJ5BC7TO3DKXGXFSOSGBZBPW5HZZDHY3IVD6FAC
CO3C7GSZ2X62ALXW2EAWDHCRSXCNVKIIHCL47GYZ32OHZER4NLZQC
NYMIFK2WBHU4G34QF4GZP63ATL2EQC6PLAQLWZMUTPDGDPQUEKVQC
Y25HAVMY4WAD43DQ5PHLHUPDKW7X6DWJVP3VKYVQ3AE25S6ESSXAC
2DQ47UENKWPVS6XYO73Q2KCHTNG6GQVP2CKP24V2OQ4F4T3KAFMAC
4KXMGXQ6PTWVMINMKRCQE7DIJXUYMO7SVNR6AQ243QULY7IZLUYAC
GEBWJGHFGLPFE6PGT5D7W3PL57NPMQRPDUK54GTN4344W6QT7DPAC
6D4TYQRJMN6QEKASHJ3ZN3E7TXF5IEQ3G4ATTZZ5AZC56VXMWFZAC
RUIGRXTKM6BQ532W7KU3RKDXMRNRGDVGMA2ODMX2D2F3PCLF3GAQC
WJJ6PMS6GYR5NIQI6Q6YH6WQSTJ3U56F3KZJOSYHTRAZ5MKIPXAAC
QL75BDYCNRAF2NPJP3MJHUPM6JRIGJQWK2OG2NWKBOVZUZ75CHOAC
import Builtin
import Algebra.Group.Magma
import Algebra.Group.Semigroup
import Algebra.Group.Monoid
import Algebra.Lattice.JoinSemilattice
import Algebra.Lattice.MeetSemilattice
import Algebra.Relation.Equivalence
import Algebra.Relation.Preorder
import Algebra.Relation.Order
import Data.Either
%default total
--
-- Values
--
public export
data Boolean = False | True
--
-- Relation
--
data BooleanEquiv : (a, b : Boolean) -> Type where
BothFalse : BooleanEquiv False False
BothTrue : BooleanEquiv True True
public export
Uninhabited (BooleanEquiv False True) where
uninhabited BothFalse impossible
uninhabited BothTrue impossible
public export
Uninhabited (BooleanEquiv True False) where
uninhabited BothFalse impossible
uninhabited BothTrue impossible
public export
Equivalence Boolean where
Equiv = BooleanEquiv
decEquiv False False = Yes BothFalse
decEquiv True True = Yes BothTrue
decEquiv False True = No absurd
decEquiv True False = No absurd
data BooleanLTE : (a, b : Boolean) -> Type where
FalseLTEAny : BooleanLTE False b
TrueLTETrue : BooleanLTE True True
public export
Uninhabited (BooleanLTE True False) where
uninhabited FalseLTEAny impossible
uninhabited TrueLTETrue impossible
public export
Preorder Boolean where
LTE = BooleanLTE
decLTE False _ = Yes FalseLTEAny
decLTE True False = No absurd
decLTE True True = Yes TrueLTETrue
proofReflexivity False = FalseLTEAny
proofReflexivity True = TrueLTETrue
proofTransitivity False False _ FalseLTEAny FalseLTEAny = FalseLTEAny
proofTransitivity False True True FalseLTEAny TrueLTETrue = FalseLTEAny
proofTransitivity True True True TrueLTETrue TrueLTETrue = TrueLTETrue
data BooleanLT : (a, b : Boolean) -> Type where
FalseLTTrue : BooleanLT False True
public export
Uninhabited (BooleanLT False False) where
uninhabited FalseLTTrue impossible
public export
Uninhabited (BooleanLT True _) where
uninhabited FalseLTTrue impossible
public export
Order Boolean where
LT = BooleanLT
decLT False False = No absurd
decLT False True = Yes FalseLTTrue
decLT True _ = No absurd
proofAntisymetry False False FalseLTEAny FalseLTEAny = BothFalse
proofAntisymetry True True TrueLTETrue TrueLTETrue = BothTrue
proofLTThenLTE FalseLTTrue = FalseLTEAny
proofLTEThenLTOrEquiv False False FalseLTEAny = Right BothFalse
proofLTEThenLTOrEquiv False True FalseLTEAny = Left FalseLTTrue
proofLTEThenLTOrEquiv True True TrueLTETrue = Right BothTrue
--
-- Operations
--
not : Boolean -> Boolean
not False = True
not True = False
proofNotInvolution : (a : Boolean) -> not (not a) = a
proofNotInvolution False = Refl
proofNotInvolution True = Refl
public export
disj : Boolean -> Boolean -> Boolean
disj False False = False
disj _ _ = True
export
proofDisjLeftIdentity : (a : Boolean) -> False `disj` a = a
proofDisjLeftIdentity False = Refl
proofDisjLeftIdentity True = Refl
export
proofDisjRightIdentity : (a : Boolean) -> a `disj` False = a
proofDisjRightIdentity False = Refl
proofDisjRightIdentity True = Refl
export
proofDisjLeftAnnihilation : (a : Boolean) -> True `disj` a = True
proofDisjLeftAnnihilation False = Refl
proofDisjLeftAnnihilation True = Refl
export
proofDisjRightAnnihilation : (a : Boolean) -> a `disj` True = True
proofDisjRightAnnihilation False = Refl
proofDisjRightAnnihilation True = Refl
export
proofDisjCommutative : (a, b : Boolean) -> a `disj` b = b `disj` a
proofDisjCommutative False b =
rewrite proofDisjLeftIdentity b in
rewrite proofDisjRightIdentity b in
Refl
proofDisjCommutative True b = rewrite proofDisjRightAnnihilation b in Refl
public export
[BooleanDisjMagma] Magma Boolean where
(<>) = disj
public export
[BooleanDisjCommutativeMagma] CommutativeMagma Boolean using BooleanDisjMagma where
proofCommutative = proofDisjCommutative
public export
[BooleanDisjSemigroup] Semigroup Boolean using BooleanDisjMagma where
proofAssociative False b c =
rewrite proofDisjLeftIdentity b in
rewrite proofDisjLeftIdentity (b `disj` c) in
Refl
proofAssociative True b c = Refl
public export
[BooleanDisjCommutativeSemigroup] CommutativeSemigroup Boolean using BooleanDisjCommutativeMagma BooleanDisjSemigroup where
public export
[BooleanDisjMonoid] Monoid Boolean using BooleanDisjSemigroup where
id = False
proofLeftIdentity = proofDisjLeftIdentity
proofRightIdentity = proofDisjRightIdentity
public export
[BooleanDisjCommutativeMonoid] CommutativeMonoid Boolean using BooleanDisjCommutativeSemigroup BooleanDisjMonoid where
public export
conj : Boolean -> Boolean -> Boolean
conj True True = True
conj _ _ = False
export
proofConjLeftIdentity : (a : Boolean) -> True `conj` a = a
proofConjLeftIdentity False = Refl
proofConjLeftIdentity True = Refl
export
proofConjRightIdentity : (a : Boolean) -> a `conj` True = a
proofConjRightIdentity False = Refl
proofConjRightIdentity True = Refl
export
proofConjLeftAnnihilation : (a : Boolean) -> False `conj` a = False
proofConjLeftAnnihilation False = Refl
proofConjLeftAnnihilation True = Refl
export
proofConjRightAnnihilation : (a : Boolean) -> a `conj` False = False
proofConjRightAnnihilation False = Refl
proofConjRightAnnihilation True = Refl
export
proofConjCommutative : (a, b : Boolean) -> a `conj` b = b `conj` a
proofConjCommutative False b = rewrite proofConjRightAnnihilation b in Refl
proofConjCommutative True b =
rewrite proofConjLeftIdentity b in
rewrite proofConjRightIdentity b in
Refl
public export
[BooleanConjMagma] Magma Boolean where
(<>) = conj
public export
[BooleanConjCommutativeMagma] CommutativeMagma Boolean using BooleanConjMagma where
proofCommutative = proofConjCommutative
public export
[BooleanConjSemigroup] Semigroup Boolean using BooleanConjMagma where
proofAssociative False b c = Refl
proofAssociative True b c =
rewrite proofConjLeftIdentity b in
rewrite proofConjLeftIdentity (b `conj` c) in
Refl
public export
[BooleanConjMonoid] Monoid Boolean using BooleanConjSemigroup where
id = True
proofLeftIdentity = proofConjLeftIdentity
proofRightIdentity = proofConjRightIdentity
--
-- Lattice
--
public export
MeetSemilattice Boolean where
(/\) = conj
proofIdempotence False = Refl
proofIdempotence True = Refl
proofAssociative = proofAssociative @{BooleanConjSemigroup}
proofCommutative = proofConjCommutative
proofLowerBound False False = (FalseLTEAny, FalseLTEAny)
proofLowerBound False True = (FalseLTEAny, FalseLTEAny)
proofLowerBound True False = (FalseLTEAny, FalseLTEAny)
proofLowerBound True True = (TrueLTETrue, TrueLTETrue)
proofGreatestLowerBound False y z FalseLTEAny FalseLTEAny = FalseLTEAny
proofGreatestLowerBound True True True TrueLTETrue TrueLTETrue = TrueLTETrue
public export
JoinSemilattice Boolean where
(\/) = disj
proofIdempotence False = Refl
proofIdempotence True = Refl
proofAssociative = proofAssociative @{BooleanDisjSemigroup}
proofCommutative = proofDisjCommutative
proofUpperBound False False = (FalseLTEAny, FalseLTEAny)
proofUpperBound False True = (FalseLTEAny, TrueLTETrue)
proofUpperBound True False = (TrueLTETrue, FalseLTEAny)
proofUpperBound True True = (TrueLTETrue, TrueLTETrue)
proofLeastUpperBound False False False FalseLTEAny FalseLTEAny = FalseLTEAny
proofLeastUpperBound True False False FalseLTEAny FalseLTEAny = FalseLTEAny
proofLeastUpperBound True False True FalseLTEAny TrueLTETrue = TrueLTETrue
proofLeastUpperBound True True False TrueLTETrue FalseLTEAny = TrueLTETrue
proofLeastUpperBound True True True TrueLTETrue TrueLTETrue = TrueLTETrue
--
-- Util
--
public export
decToBoolean : Dec t -> Boolean
decToBoolean (Yes _) = True
decToBoolean (No _) = False
import public Data.Boolean.Basic
import public Data.Boolean.Equivalence
import public Data.Boolean.Order
import public Data.Boolean.Group
import public Data.Boolean.Lattice
module Data.Boolean.Order
import Builtin
import Algebra.Relation.Equivalence
import Algebra.Relation.Preorder
import Algebra.Relation.Order
import public Data.Boolean.Basic
import public Data.Boolean.Equivalence
%default total
public export
data BooleanLTE : (a, b : Boolean) -> Type where
FalseLTEAny : BooleanLTE False b
TrueLTETrue : BooleanLTE True True
public export
Uninhabited (BooleanLTE True False) where
uninhabited FalseLTEAny impossible
uninhabited TrueLTETrue impossible
public export
Preorder Boolean where
LTE = BooleanLTE
decLTE False _ = Yes FalseLTEAny
decLTE True False = No absurd
decLTE True True = Yes TrueLTETrue
proofReflexivity False = FalseLTEAny
proofReflexivity True = TrueLTETrue
proofTransitivity False False _ FalseLTEAny FalseLTEAny = FalseLTEAny
proofTransitivity False True True FalseLTEAny TrueLTETrue = FalseLTEAny
proofTransitivity True True True TrueLTETrue TrueLTETrue = TrueLTETrue
data BooleanLT : (a, b : Boolean) -> Type where
FalseLTTrue : BooleanLT False True
public export
Uninhabited (BooleanLT False False) where
uninhabited FalseLTTrue impossible
public export
Uninhabited (BooleanLT True _) where
uninhabited FalseLTTrue impossible
public export
Order Boolean where
LT = BooleanLT
decLT False False = No absurd
decLT False True = Yes FalseLTTrue
decLT True _ = No absurd
proofAntisymetry False False FalseLTEAny FalseLTEAny = BothFalse
proofAntisymetry True True TrueLTETrue TrueLTETrue = BothTrue
proofLTThenLTE FalseLTTrue = FalseLTEAny
proofLTEThenLTOrEquiv False False FalseLTEAny = Right BothFalse
proofLTEThenLTOrEquiv False True FalseLTEAny = Left FalseLTTrue
proofLTEThenLTOrEquiv True True TrueLTETrue = Right BothTrue
module Data.Boolean.Lattice
import Builtin
import Algebra.Group.Magma
import Algebra.Group.Semigroup
import Algebra.Lattice.MeetSemilattice
import Algebra.Lattice.JoinSemilattice
import Algebra.Relation.Preorder
import Algebra.Relation.Order
import public Data.Boolean.Basic
import public Data.Boolean.Order
import public Data.Boolean.Group
%default total
public export
JoinSemilattice Boolean where
(\/) = disj
proofIdempotence False = Refl
proofIdempotence True = Refl
proofAssociative = proofAssociative @{BooleanDisjSemigroup}
proofCommutative = proofDisjCommutative
proofUpperBound False False = (FalseLTEAny, FalseLTEAny)
proofUpperBound False True = (FalseLTEAny, TrueLTETrue)
proofUpperBound True False = (TrueLTETrue, FalseLTEAny)
proofUpperBound True True = (TrueLTETrue, TrueLTETrue)
proofLeastUpperBound False False False FalseLTEAny FalseLTEAny = FalseLTEAny
proofLeastUpperBound True False False FalseLTEAny FalseLTEAny = FalseLTEAny
proofLeastUpperBound True False True FalseLTEAny TrueLTETrue = TrueLTETrue
proofLeastUpperBound True True False TrueLTETrue FalseLTEAny = TrueLTETrue
proofLeastUpperBound True True True TrueLTETrue TrueLTETrue = TrueLTETrue
public export
MeetSemilattice Boolean where
(/\) = conj
proofIdempotence False = Refl
proofIdempotence True = Refl
proofAssociative = proofAssociative @{BooleanConjSemigroup}
proofCommutative = proofConjCommutative
proofLowerBound False False = (FalseLTEAny, FalseLTEAny)
proofLowerBound False True = (FalseLTEAny, FalseLTEAny)
proofLowerBound True False = (FalseLTEAny, FalseLTEAny)
proofLowerBound True True = (TrueLTETrue, TrueLTETrue)
proofGreatestLowerBound False y z FalseLTEAny FalseLTEAny = FalseLTEAny
proofGreatestLowerBound True True True TrueLTETrue TrueLTETrue = TrueLTETrue
module Data.Boolean.Group
import Builtin
import Algebra.Group.Magma
import Algebra.Group.Semigroup
import Algebra.Group.Monoid
import public Data.Boolean.Basic
%default total
public export
[BooleanDisjMagma] Magma Boolean where
(<>) = disj
public export
[BooleanDisjCommutativeMagma] CommutativeMagma Boolean using BooleanDisjMagma where
proofCommutative = proofDisjCommutative
public export
[BooleanDisjSemigroup] Semigroup Boolean using BooleanDisjMagma where
proofAssociative False b c =
rewrite proofDisjLeftIdentity b in
rewrite proofDisjLeftIdentity (b `disj` c) in
Refl
proofAssociative True b c = Refl
public export
[BooleanDisjCommutativeSemigroup] CommutativeSemigroup Boolean using BooleanDisjCommutativeMagma BooleanDisjSemigroup where
public export
[BooleanDisjMonoid] Monoid Boolean using BooleanDisjSemigroup where
id = False
proofLeftIdentity = proofDisjLeftIdentity
proofRightIdentity = proofDisjRightIdentity
public export
[BooleanDisjCommutativeMonoid] CommutativeMonoid Boolean using BooleanDisjCommutativeSemigroup BooleanDisjMonoid where
public export
[BooleanConjMagma] Magma Boolean where
(<>) = conj
public export
[BooleanConjCommutativeMagma] CommutativeMagma Boolean using BooleanConjMagma where
proofCommutative = proofConjCommutative
public export
[BooleanConjSemigroup] Semigroup Boolean using BooleanConjMagma where
proofAssociative False b c = Refl
proofAssociative True b c =
rewrite proofConjLeftIdentity b in
rewrite proofConjLeftIdentity (b `conj` c) in
Refl
public export
[BooleanConjMonoid] Monoid Boolean using BooleanConjSemigroup where
id = True
proofLeftIdentity = proofConjLeftIdentity
proofRightIdentity = proofConjRightIdentity
module Data.Boolean.Equivalence
import Builtin
import Algebra.Relation.Equivalence
import public Data.Boolean.Basic
%default total
public export
data BooleanEquiv : (a, b : Boolean) -> Type where
BothFalse : BooleanEquiv False False
BothTrue : BooleanEquiv True True
public export
Uninhabited (BooleanEquiv False True) where
uninhabited BothFalse impossible
uninhabited BothTrue impossible
public export
Uninhabited (BooleanEquiv True False) where
uninhabited BothFalse impossible
uninhabited BothTrue impossible
public export
Equivalence Boolean where
Equiv = BooleanEquiv
decEquiv False False = Yes BothFalse
decEquiv True True = Yes BothTrue
decEquiv False True = No absurd
decEquiv True False = No absurd
module Data.Boolean.Basic
import Builtin
%default total
public export
data Boolean = False | True
--
-- Negation / Complement
--
public export
not : Boolean -> Boolean
not False = True
not True = False
export
proofNotInvolution : (a : Boolean) -> not (not a) = a
proofNotInvolution False = Refl
proofNotInvolution True = Refl
--
-- Disjunction / Inclusive OR
--
public export
disj : Boolean -> Boolean -> Boolean
disj False False = False
disj _ _ = True
export
proofDisjLeftIdentity : (a : Boolean) -> False `disj` a = a
proofDisjLeftIdentity False = Refl
proofDisjLeftIdentity True = Refl
export
proofDisjRightIdentity : (a : Boolean) -> a `disj` False = a
proofDisjRightIdentity False = Refl
proofDisjRightIdentity True = Refl
export
proofDisjLeftAnnihilation : (a : Boolean) -> True `disj` a = True
proofDisjLeftAnnihilation False = Refl
proofDisjLeftAnnihilation True = Refl
export
proofDisjRightAnnihilation : (a : Boolean) -> a `disj` True = True
proofDisjRightAnnihilation False = Refl
proofDisjRightAnnihilation True = Refl
export
proofDisjCommutative : (a, b : Boolean) -> a `disj` b = b `disj` a
proofDisjCommutative False b =
rewrite proofDisjLeftIdentity b in
rewrite proofDisjRightIdentity b in
Refl
proofDisjCommutative True b = rewrite proofDisjRightAnnihilation b in Refl
--
-- Conjunction / AND
--
public export
conj : Boolean -> Boolean -> Boolean
conj True True = True
conj _ _ = False
export
proofConjLeftIdentity : (a : Boolean) -> True `conj` a = a
proofConjLeftIdentity False = Refl
proofConjLeftIdentity True = Refl
export
proofConjRightIdentity : (a : Boolean) -> a `conj` True = a
proofConjRightIdentity False = Refl
proofConjRightIdentity True = Refl
export
proofConjLeftAnnihilation : (a : Boolean) -> False `conj` a = False
proofConjLeftAnnihilation False = Refl
proofConjLeftAnnihilation True = Refl
export
proofConjRightAnnihilation : (a : Boolean) -> a `conj` False = False
proofConjRightAnnihilation False = Refl
proofConjRightAnnihilation True = Refl
export
proofConjCommutative : (a, b : Boolean) -> a `conj` b = b `conj` a
proofConjCommutative False b = rewrite proofConjRightAnnihilation b in Refl
proofConjCommutative True b =
rewrite proofConjLeftIdentity b in
rewrite proofConjRightIdentity b in
Refl
--
-- Util
--
public export
decToBoolean : Dec t -> Boolean
decToBoolean (Yes _) = True
decToBoolean (No _) = False