2017-08-01 15:12:59 +02:00
|
|
|
(* Typeclass for lattices *)
|
2017-06-19 17:08:56 +02:00
|
|
|
Require Import HoTT.
|
|
|
|
|
|
|
|
Definition operation (A : Type) := A -> A -> A.
|
|
|
|
|
|
|
|
Section Defs.
|
|
|
|
Variable A : Type.
|
|
|
|
Variable f : A -> A -> A.
|
|
|
|
|
|
|
|
Class Commutative :=
|
|
|
|
commutative : forall x y, f x y = f y x.
|
|
|
|
|
|
|
|
Class Associative :=
|
|
|
|
associativity : forall x y z, f (f x y) z = f x (f y z).
|
|
|
|
|
|
|
|
Class Idempotent :=
|
|
|
|
idempotency : forall x, f x x = x.
|
|
|
|
|
|
|
|
Variable g : operation A.
|
|
|
|
|
|
|
|
Class Absorption :=
|
|
|
|
absrob : forall x y, f x (g x y) = x.
|
|
|
|
|
|
|
|
Variable n : A.
|
|
|
|
|
|
|
|
Class NeutralL :=
|
2017-08-01 17:25:57 +02:00
|
|
|
neutralityL : forall x, f n x = x.
|
2017-06-19 17:08:56 +02:00
|
|
|
|
|
|
|
Class NeutralR :=
|
2017-08-01 17:25:57 +02:00
|
|
|
neutralityR : forall x, f x n = x.
|
2017-06-19 17:08:56 +02:00
|
|
|
|
|
|
|
End Defs.
|
|
|
|
|
|
|
|
Arguments Commutative {_} _.
|
|
|
|
Arguments Associative {_} _.
|
|
|
|
Arguments Idempotent {_} _.
|
|
|
|
Arguments NeutralL {_} _ _.
|
|
|
|
Arguments NeutralR {_} _ _.
|
|
|
|
Arguments Absorption {_} _ _.
|
|
|
|
|
|
|
|
Section Lattice.
|
|
|
|
Variable A : Type.
|
|
|
|
Variable min max : operation A.
|
|
|
|
Variable empty : A.
|
|
|
|
|
|
|
|
Class Lattice :=
|
|
|
|
{
|
|
|
|
commutative_min :> Commutative min ;
|
|
|
|
commutative_max :> Commutative max ;
|
|
|
|
associative_min :> Associative min ;
|
|
|
|
associative_max :> Associative max ;
|
|
|
|
idempotent_min :> Idempotent min ;
|
|
|
|
idempotent_max :> Idempotent max ;
|
2017-08-01 15:12:59 +02:00
|
|
|
neutralL_min :> NeutralL max empty ;
|
|
|
|
neutralR_min :> NeutralR max empty ;
|
2017-06-19 17:08:56 +02:00
|
|
|
absorption_min_max :> Absorption min max ;
|
|
|
|
absorption_max_min :> Absorption max min
|
|
|
|
}.
|
|
|
|
|
|
|
|
End Lattice.
|
|
|
|
|
|
|
|
Arguments Lattice {_} _ _ _.
|
|
|
|
|
|
|
|
|
|
|
|
Section BoolLattice.
|
|
|
|
|
2017-08-01 15:12:59 +02:00
|
|
|
Ltac solve :=
|
2017-06-19 21:32:55 +02:00
|
|
|
let x := fresh in
|
|
|
|
repeat (intro x ; destruct x)
|
|
|
|
; compute
|
|
|
|
; auto
|
|
|
|
; try contradiction.
|
|
|
|
|
2017-08-01 15:12:59 +02:00
|
|
|
Instance orb_com : Commutative orb.
|
2017-06-19 17:08:56 +02:00
|
|
|
Proof.
|
|
|
|
solve.
|
|
|
|
Defined.
|
|
|
|
|
2017-08-01 15:12:59 +02:00
|
|
|
Instance andb_com : Commutative andb.
|
2017-06-19 17:08:56 +02:00
|
|
|
Proof.
|
|
|
|
solve.
|
|
|
|
Defined.
|
|
|
|
|
2017-08-01 15:12:59 +02:00
|
|
|
Instance orb_assoc : Associative orb.
|
2017-06-19 17:08:56 +02:00
|
|
|
Proof.
|
|
|
|
solve.
|
|
|
|
Defined.
|
|
|
|
|
2017-08-01 15:12:59 +02:00
|
|
|
Instance andb_assoc : Associative andb.
|
2017-06-19 17:08:56 +02:00
|
|
|
Proof.
|
|
|
|
solve.
|
|
|
|
Defined.
|
|
|
|
|
2017-08-01 15:12:59 +02:00
|
|
|
Instance orb_idem : Idempotent orb.
|
2017-06-19 17:08:56 +02:00
|
|
|
Proof.
|
|
|
|
solve.
|
|
|
|
Defined.
|
|
|
|
|
2017-08-01 15:12:59 +02:00
|
|
|
Instance andb_idem : Idempotent andb.
|
2017-06-19 17:08:56 +02:00
|
|
|
Proof.
|
|
|
|
solve.
|
|
|
|
Defined.
|
|
|
|
|
2017-08-01 15:12:59 +02:00
|
|
|
Instance orb_nl : NeutralL orb false.
|
2017-06-19 17:08:56 +02:00
|
|
|
Proof.
|
|
|
|
solve.
|
|
|
|
Defined.
|
|
|
|
|
2017-08-01 15:12:59 +02:00
|
|
|
Instance orb_nr : NeutralR orb false.
|
2017-06-19 17:08:56 +02:00
|
|
|
Proof.
|
|
|
|
solve.
|
|
|
|
Defined.
|
|
|
|
|
2017-08-01 15:12:59 +02:00
|
|
|
Instance bool_absorption_orb_andb : Absorption orb andb.
|
2017-06-19 17:08:56 +02:00
|
|
|
Proof.
|
|
|
|
solve.
|
|
|
|
Defined.
|
|
|
|
|
2017-08-01 15:12:59 +02:00
|
|
|
Instance bool_absorption_andb_orb : Absorption andb orb.
|
2017-06-19 17:08:56 +02:00
|
|
|
Proof.
|
|
|
|
solve.
|
|
|
|
Defined.
|
|
|
|
|
2017-08-01 15:12:59 +02:00
|
|
|
Global Instance lattice_bool : Lattice andb orb false :=
|
|
|
|
{ commutative_min := _ ;
|
2017-06-19 17:08:56 +02:00
|
|
|
commutative_max := _ ;
|
|
|
|
associative_min := _ ;
|
|
|
|
associative_max := _ ;
|
|
|
|
idempotent_min := _ ;
|
|
|
|
idempotent_max := _ ;
|
|
|
|
neutralL_min := _ ;
|
|
|
|
neutralR_min := _ ;
|
|
|
|
absorption_min_max := _ ;
|
|
|
|
absorption_max_min := _
|
|
|
|
}.
|
|
|
|
|
2017-08-01 15:12:59 +02:00
|
|
|
Definition and_true : forall b, andb b true = b.
|
|
|
|
Proof.
|
|
|
|
solve.
|
|
|
|
Defined.
|
|
|
|
|
|
|
|
Definition and_false : forall b, andb b false = false.
|
|
|
|
Proof.
|
|
|
|
solve.
|
|
|
|
Defined.
|
|
|
|
|
|
|
|
Definition dist₁ : forall b₁ b₂ b₃,
|
|
|
|
andb b₁ (orb b₂ b₃) = orb (andb b₁ b₂) (andb b₁ b₃).
|
|
|
|
Proof.
|
|
|
|
solve.
|
|
|
|
Defined.
|
|
|
|
|
|
|
|
Definition dist₂ : forall b₁ b₂ b₃,
|
|
|
|
orb b₁ (andb b₂ b₃) = andb (orb b₁ b₂) (orb b₁ b₃).
|
|
|
|
Proof.
|
|
|
|
solve.
|
|
|
|
Defined.
|
|
|
|
|
|
|
|
Definition max_min : forall b₁ b₂,
|
|
|
|
orb (andb b₁ b₂) b₁ = b₁.
|
|
|
|
Proof.
|
|
|
|
solve.
|
|
|
|
Defined.
|
|
|
|
|
2017-06-19 17:08:56 +02:00
|
|
|
End BoolLattice.
|
|
|
|
|
2017-06-19 17:54:44 +02:00
|
|
|
Hint Resolve
|
2017-08-01 15:12:59 +02:00
|
|
|
orb_com andb_com orb_assoc andb_assoc orb_idem andb_idem orb_nl orb_nr
|
|
|
|
bool_absorption_orb_andb bool_absorption_andb_orb and_true and_false
|
|
|
|
dist₁ dist₂ max_min
|
2017-06-19 17:54:44 +02:00
|
|
|
: bool_lattice_hints.
|