Definition of a lattice, loosely based on ideas from "A
reflection-based proof tactic for lattices in Coq" and
http://www.pps.univ-paris-diderot.fr/~sozeau/repos/coq/order/
Require Import RelationClasses.
Require Import Morphisms.
Require Import Equivalence.
Require Import EquivDec.
Section Lattice.
Definition part_le {
A} {
eqA} {
R} `{
part:
PartialOrder A eqA R} :
_ :=
R.
Infix "≤" :=
part_le (
at level 70,
no associativity).
Definition associative {
A}
eqA `{
equivA :
Equivalence A eqA} (
op :
A->
A->
A)
:=
forall x₁
x₂
x₃,
equiv (
op (
op x₁
x₂)
x₃) (
op x₁ (
op x₂
x₃)).
Definition commutative {
A}
eqA `{
equivA :
Equivalence A eqA} (
op :
A->
A->
A)
:=
forall x₁
x₂,
equiv (
op x₁
x₂) (
op x₂
x₁).
Definition idempotent {
A}
eqA `{
equivA :
Equivalence A eqA} (
op :
A->
A->
A)
:=
forall x,
equiv (
op x x)
x.
Definition absorptive {
A}
eqA `{
equivA :
Equivalence A eqA}
(
op1 op2 :
A->
A->
A)
:=
forall x y,
op1 x (
op2 x y) ===
x.
Definition is_unit_r {
A}
eqA `{
equivA :
Equivalence A eqA}
(
op :
A->
A->
A) (
unit:
A)
:=
forall a,
op a unit ===
a.
Definition is_unit_l {
A}
eqA `{
equivA :
Equivalence A eqA}
(
op :
A->
A->
A) (
unit:
A)
:=
forall a,
op unit a ===
a.
Class Lattice (
A:
Type) (
eqA:
A->
A->
Prop) {
equivA:
Equivalence eqA}
:= {
meet :
A ->
A ->
A;
join :
A ->
A ->
A;
meet_morphism :>
Proper (
eqA ==>
eqA ==>
eqA)
meet ;
join_morphism :>
Proper (
eqA ==>
eqA ==>
eqA)
join ;
meet_commutative :
commutative eqA meet;
meet_associative :
associative eqA meet;
meet_idempotent :
idempotent eqA meet;
join_commutative :
commutative eqA join;
join_associative :
associative eqA join;
join_idempotent :
idempotent eqA join;
meet_absorptive :
absorptive eqA meet join;
join_absorptive :
absorptive eqA join meet
}.
Infix "⊓" :=
meet (
at level 70).
Infix "⊔" :=
join (
at level 70).
A lattice that is consistent with a specified partial order.
Class OLattice {
A:
Type}
(
eqA:
A->
A->
Prop)
(
ordA:
A->
A->
Prop)
{
equivA:
Equivalence eqA}
{
lattice:
Lattice A eqA}
{
pre:
PreOrder ordA}
{
po:
PartialOrder eqA ordA}
:= {
consistent_meet:
forall a b,
a ≤
b <->
a ⊓
b ===
a
}.
Section oprops.
Context {
A eqA ordA} `{
olattice:
OLattice A eqA ordA}.
Lemma consistent_join
:
forall a b,
a ≤
b <->
a ⊔
b ===
b.
Proof.
Lemma meet_leq_l a b: (
a ⊓
b) ≤
a.
Proof.
Lemma meet_leq_r a b: (
a ⊓
b) ≤
b.
Proof.
Theorem meet_most {
a b c} :
a ≤
b ->
a ≤
c ->
a ≤ (
b ⊓
c).
Proof.
Lemma join_leq_l a b:
a ≤ (
a ⊔
b).
Proof.
Lemma join_leq_r a b:
b ≤ (
a ⊔
b).
Proof.
Theorem join_least {
a b c} :
a ≤
c ->
b ≤
c -> (
a ⊔
b) ≤
c.
Proof.
Global Instance meet_leq_proper :
Proper (
part_le ==>
part_le ==>
part_le)
meet.
Proof.
Global Instance join_leq_proper :
Proper (
part_le ==>
part_le ==>
part_le)
join.
Proof.
If the equivalence relation is decidable,
then we can decide the leq relation using either meet or join
Lemma leq_dec_meet `{
dec:
EqDec A eqA}
a b : {
a ≤
b} + {~
a ≤
b}.
Proof.
Lemma leq_dec_join `{
dec:
EqDec A eqA}
a b : {
a ≤
b} + {~
a ≤
b}.
Proof.
End oprops.
Class BLattice {
A:
Type}
(
eqA:
A->
A->
Prop)
{
equivA:
Equivalence eqA}
{
lattice:
Lattice A eqA}
:= {
top:
A;
bottom:
A;
join_bottom_r:
is_unit_r eqA join bottom;
meet_top_r:
is_unit_r eqA meet top
}.
Section bprops.
Lemma is_unit_l_r {
A}
eqA `{
equivA :
Equivalence A eqA}
(
op :
A->
A->
A) :
commutative eqA op ->
(
forall unit,
is_unit_l eqA op unit <->
is_unit_r eqA op unit).
Proof.
Context {
A eqA} `{
blattice:
BLattice A eqA}.
Lemma join_bottom_l:
is_unit_l eqA join bottom.
Proof.
Lemma meet_top_l:
is_unit_l eqA meet top.
Proof.
Lemma meet_bottom_r :
forall a,
a ⊓
bottom ===
bottom.
Proof.
Lemma meet_bottom_l :
forall a,
bottom ⊓
a ===
bottom.
Proof.
Lemma join_top_r :
forall a,
a ⊔
top ===
top.
Proof.
Lemma join_top_l :
forall a,
top ⊔
a ===
top.
Proof.
End bprops.
Section boprops.
Context {
A eqA ordA equiv}
{
lattice:@
Lattice A eqA equiv}
{
pre part}
{
blattice:@
BLattice A eqA equiv lattice}
{
olattice:@
OLattice A eqA ordA equiv lattice pre part}.
Lemma le_top :
forall a,
a ≤
top.
Proof.
Lemma bottom_le :
forall a,
bottom ≤
a.
Proof.
Lemma bottom_le_top :
bottom ≤
top.
Proof.
End boprops.
End Lattice.
Infix "≤" :=
part_le (
at level 70,
no associativity).
Infix "⊓" :=
meet (
at level 70).
Infix "⊔" :=
join (
at level 70).