Timings for lattices.v
Require Import
HoTT.Classes.interfaces.abstract_algebra
HoTT.Classes.interfaces.orders
HoTT.Classes.orders.semirings
HoTT.Classes.theory.lattices.
Generalizable Variables K L f.
(*
We prove that the algebraic definition of a lattice corresponds to the
order theoretic one. Note that we do not make any of these instances global,
because that would cause loops.
*)
Section join_semilattice_order.
Context `{JoinSemiLatticeOrder L}.
Lemma join_ub_3_r x y z : z ≤ x ⊔ y ⊔ z.
Lemma join_ub_3_m x y z : y ≤ x ⊔ y ⊔ z.
Lemma join_ub_3_l x y z : x ≤ x ⊔ y ⊔ z.
transitivity (x ⊔ y); apply join_ub_l.
Lemma join_ub_3_assoc_l x y z : x ≤ x ⊔ (y ⊔ z).
Lemma join_ub_3_assoc_m x y z : y ≤ x ⊔ (y ⊔ z).
Lemma join_ub_3_assoc_r x y z : z ≤ x ⊔ (y ⊔ z).
transitivity (y ⊔ z); apply join_ub_r.
Instance join_sl_order_join_sl: IsJoinSemiLattice L.
apply (antisymmetry (≤)).
apply (antisymmetry (≤)); apply join_lub;
first [apply join_ub_l | apply join_ub_r].
apply (antisymmetry (≤)).
apply join_lub; apply reflexivity.
Lemma join_le_compat_r x y z : z ≤ x -> z ≤ x ⊔ y.
Lemma join_le_compat_l x y z : z ≤ y -> z ≤ x ⊔ y.
rewrite (commutativity (f:=join)).
Lemma join_l x y : y ≤ x -> x ⊔ y = x.
apply (antisymmetry (≤)).
Lemma join_r x y : x ≤ y -> x ⊔ y = y.
rewrite (commutativity (f:=join)).
Lemma join_sl_le_spec x y : x ≤ y <-> x ⊔ y = y.
#[export] Instance join_le_preserving_l : forall z, OrderPreserving (z ⊔).
#[export] Instance join_le_preserving_r : forall z, OrderPreserving (⊔ z).
exact maps.order_preserving_flip.
Lemma join_le_compat x₁ x₂ y₁ y₂ : x₁ ≤ x₂ -> y₁ ≤ y₂ -> x₁ ⊔ y₁ ≤ x₂ ⊔ y₂.
apply (order_preserving (x₁ ⊔)).
apply (order_preserving (⊔ y₂));trivial.
Lemma join_le x y z : x ≤ z -> y ≤ z -> x ⊔ y ≤ z.
Context `{!TotalRelation le}.
Lemma total_join_either `{!TotalRelation le} x y : join x y = x |_| join x y = y.
destruct (total le x y) as [E|E].
Definition max x y :=
match total le x y with
| inl _ => y
| inr _ => x
end.
Lemma total_join_max x y : join x y = max x y.
unfold max;destruct (total le x y) as [E|E].
Lemma join_idempotent x : x ⊔ x = x.
assert (le1 : x ⊔ x ≤ x).
refine (join_lub _ _ _ _ _); apply reflexivity.
assert (le2 : x ≤ x ⊔ x).
exact (antisymmetry _ _ _ le1 le2).
End join_semilattice_order.
Section bounded_join_semilattice.
Context `{JoinSemiLatticeOrder L} `{Bottom L} `{!IsBoundedJoinSemiLattice L}.
Lemma above_bottom x : ⊥ ≤ x.
Lemma below_bottom x : x ≤ ⊥ -> x = ⊥.
apply join_sl_le_spec in E.
rewrite right_identity in E.
End bounded_join_semilattice.
Section meet_semilattice_order.
Context `{MeetSemiLatticeOrder L}.
Lemma meet_lb_3_r x y z : x ⊓ y ⊓ z ≤ z.
Lemma meet_lb_3_m x y z : x ⊓ y ⊓ z ≤ y.
Lemma meet_lb_3_l x y z : x ⊓ y ⊓ z ≤ x.
transitivity (x ⊓ y); apply meet_lb_l.
Lemma meet_lb_3_assoc_l x y z : x ⊓ (y ⊓ z) ≤ x.
Lemma meet_lb_3_assoc_m x y z : x ⊓ (y ⊓ z) ≤ y.
Lemma meet_lb_3_assoc_r x y z : x ⊓ (y ⊓ z) ≤ z.
transitivity (y ⊓ z); apply meet_lb_r.
Instance meet_sl_order_meet_sl: IsMeetSemiLattice L.
apply (antisymmetry (≤)).
apply (antisymmetry (≤)); apply meet_glb;
first [apply meet_lb_l | try apply meet_lb_r].
apply (antisymmetry (≤)).
apply meet_glb;apply reflexivity.
Lemma meet_le_compat_r x y z : x ≤ z -> x ⊓ y ≤ z.
Lemma meet_le_compat_l x y z : y ≤ z -> x ⊓ y ≤ z.
rewrite (commutativity (f:=meet)).
Lemma meet_l x y : x ≤ y -> x ⊓ y = x.
apply (antisymmetry (≤)).
Lemma meet_r x y : y ≤ x -> x ⊓ y = y.
rewrite (commutativity (f:=meet)).
Lemma meet_sl_le_spec x y : x ≤ y <-> x ⊓ y = x.
#[export] Instance orderpreserving_left_meet : forall z, OrderPreserving (z ⊓).
#[export] Instance orderpreserving_right_meet: forall z, OrderPreserving (⊓ z).
exact maps.order_preserving_flip.
Lemma meet_le_compat x₁ x₂ y₁ y₂ : x₁ ≤ x₂ -> y₁ ≤ y₂ -> x₁ ⊓ y₁ ≤ x₂ ⊓ y₂.
apply (order_preserving (x₁ ⊓)).
apply (order_preserving (⊓ y₂)).
Lemma meet_le x y z : z ≤ x -> z ≤ y -> z ≤ x ⊓ y.
Context `{!TotalRelation le}.
Lemma total_meet_either x y : meet x y = x |_| meet x y = y.
destruct (total le x y) as [E|E].
Definition min x y :=
match total le x y with
| inr _ => y
| inl _ => x
end.
Lemma total_meet_min x y : meet x y = min x y.
destruct (total le x y) as [E|E].
Lemma meet_idempotent x : x ⊓ x = x.
assert (le1 : x ⊓ x ≤ x).
assert (le2 : x ≤ x ⊓ x).
refine (meet_glb _ _ _ _ _); apply reflexivity.
exact (antisymmetry _ _ _ le1 le2).
End meet_semilattice_order.
Context `{LatticeOrder L}.
Instance isjoinsemilattice_latticeorder : IsJoinSemiLattice L := join_sl_order_join_sl.
Instance ismeetsemilattice_latticeorder : IsMeetSemiLattice L := meet_sl_order_meet_sl.
Instance absorption_join_meet : Absorption (⊓) (⊔).
apply (antisymmetry (≤)).
Instance absorption_meet_join : Absorption (⊔) (⊓).
apply (antisymmetry (≤)).
Instance lattice_order_lattice: IsLattice L := {}.
Lemma meet_join_distr_l_le x y z : (x ⊓ y) ⊔ (x ⊓ z) ≤ x ⊓ (y ⊔ z).
apply join_le; apply meet_lb_l.
Lemma join_meet_distr_l_le x y z : x ⊔ (y ⊓ z) ≤ (x ⊔ y) ⊓ (x ⊔ z).
Definition default_join_sl_le `{IsJoinSemiLattice L} : Le L := fun x y => x ⊔ y = y.
Section join_sl_order_alt.
Context `{IsJoinSemiLattice L} `{Le L} `{is_mere_relation L le}
(le_correct : forall x y, x ≤ y <-> x ⊔ y = y).
Lemma alt_Build_JoinSemiLatticeOrder : JoinSemiLatticeOrder (≤).
apply le_correct in E1;apply le_correct in E2;apply le_correct.
rewrite <-E2, simple_associativity, E1.
apply le_correct in E1;apply le_correct in E2.
rewrite <-E1, (commutativity (f:=join)).
rewrite simple_associativity,binary_idempotent.
rewrite (commutativity (f:=join)).
rewrite <-simple_associativity.
rewrite (idempotency _ _).
apply le_correct in E1;apply le_correct in E2;apply le_correct.
rewrite <-simple_associativity, E2.
Definition default_meet_sl_le `{IsMeetSemiLattice L} : Le L := fun x y => x ⊓ y = x.
Section meet_sl_order_alt.
Context `{IsMeetSemiLattice L} `{Le L} `{is_mere_relation L le}
(le_correct : forall x y, x ≤ y <-> x ⊓ y = x).
Lemma alt_Build_MeetSemiLatticeOrder : MeetSemiLatticeOrder (≤).
apply le_correct in E1;apply le_correct in E2;apply le_correct.
rewrite <-E1, <-simple_associativity, E2.
apply le_correct in E1;apply le_correct in E2.
rewrite <-E2, (commutativity (f:=meet)).
rewrite (commutativity (f:=meet)), simple_associativity, (idempotency _ _).
rewrite <-simple_associativity, (idempotency _ _).
apply le_correct in E1;apply le_correct in E2;apply le_correct.
rewrite associativity, E1.
Section join_order_preserving.
Context `{JoinSemiLatticeOrder L} `{JoinSemiLatticeOrder K} (f : L -> K)
`{!IsJoinPreserving f}.
Lemma join_sl_mor_preserving: OrderPreserving f.
apply join_sl_le_spec in E.
rewrite <-preserves_join.
Lemma join_sl_mor_reflecting `{!IsInjective f}: OrderReflecting f.
apply join_sl_le_spec in E.
rewrite <-preserves_join in E.
End join_order_preserving.
Section meet_order_preserving.
Context `{MeetSemiLatticeOrder L} `{MeetSemiLatticeOrder K} (f : L -> K)
`{!IsMeetPreserving f}.
Lemma meet_sl_mor_preserving: OrderPreserving f.
apply meet_sl_le_spec in E.
rewrite <-preserves_meet.
Lemma meet_sl_mor_reflecting `{!IsInjective f}: OrderReflecting f.
apply meet_sl_le_spec in E.
rewrite <-preserves_meet in E.
End meet_order_preserving.
Section order_preserving_join_sl_mor.
Context `{JoinSemiLatticeOrder L} `{JoinSemiLatticeOrder K}
`{!TotalOrder (_ : Le L)} `{!TotalOrder (_ : Le K)}
`{!OrderPreserving (f : L -> K)}.
Lemma order_preserving_join_sl_mor: IsJoinPreserving f.
case (total (≤) x y); intros E.
change (f (join x y) = join (f x) (f y)).
rewrite (join_r _ _ E),join_r;trivial.
apply (order_preserving _).
change (f (join x y) = join (f x) (f y)).
rewrite 2!join_l; trivial.
apply (order_preserving _).
End order_preserving_join_sl_mor.
Section order_preserving_meet_sl_mor.
Context `{MeetSemiLatticeOrder L} `{MeetSemiLatticeOrder K}
`{!TotalOrder (_ : Le L)} `{!TotalOrder (_ : Le K)}
`{!OrderPreserving (f : L -> K)}.
Lemma order_preserving_meet_sl_mor: IsSemiGroupPreserving f.
case (total (≤) x y); intros E.
change (f (meet x y) = meet (f x) (f y)).
rewrite 2!meet_l;trivial.
apply (order_preserving _).
change (f (meet x y) = meet (f x) (f y)).
rewrite 2!meet_r; trivial.
apply (order_preserving _).
End order_preserving_meet_sl_mor.
Section strict_ordered_field.
Generalizable Variables Lle Llt Lmeet Ljoin Lapart.
Context `{@LatticeOrder L Lle Lmeet Ljoin}.
Context `{@FullPseudoOrder L Lapart Lle Llt}.
Lemma join_lt_l_l x y z : z < x -> z < x ⊔ y.
refine (lt_le_trans z x _ _ _); try assumption.
Lemma join_lt_l_r x y z : z < y -> z < x ⊔ y.
refine (lt_le_trans z y _ _ _); try assumption.
Lemma join_lt_r x y z : x < z -> y < z -> x ⊔ y < z.
set (disj := cotransitive ltxz (x ⊔ y)).
refine (Trunc_rec _ disj); intros [ltxxy|ltxyz].
set (disj' := cotransitive ltyz (x ⊔ y)).
refine (Trunc_rec _ disj'); intros [ltyxy|ltxyz].
assert (ineqx : x ⊔ y <> x).
apply lt_ne_flip; assumption.
assert (nleyx : ~ (y ≤ x))
by exact (not_contrapositive (join_l x y) ineqx).
apply le_iff_not_lt_flip.
exact (nleyx (lt_le _ _ _)).
assert (ineqy : x ⊔ y <> y).
apply lt_ne_flip; assumption.
assert (nlexy : ~ (x ≤ y))
by exact (not_contrapositive (join_r x y) ineqy).
apply le_iff_not_lt_flip.
exact (nlexy (lt_le _ _ _)).
assert (eqxy : x = y)
by exact (antisymmetry _ _ _ lexy leyx).
rewrite <- eqxy in ineqx.
destruct (ineqx (join_idempotent x)).
Lemma meet_lt_r_l x y z : x < z -> x ⊓ y < z.
refine (le_lt_trans _ x _ _ _); try assumption.
Lemma meet_lt_r_r x y z : y < z -> x ⊓ y < z.
refine (le_lt_trans _ y _ _ _); try assumption.
Lemma meet_lt_l x y z : x < y -> x < z -> x < y ⊓ z.
set (disj := cotransitive ltxy (y ⊓ z)).
refine (Trunc_rec _ disj); intros [ltxyy|ltyzy].
set (disj' := cotransitive ltxz (y ⊓ z)).
refine (Trunc_rec _ disj'); intros [ltxyz|ltyzz].
assert (ineqy : y ⊓ z <> y).
assert (nleyz : ~ (y ≤ z))
by exact (not_contrapositive (meet_l y z) ineqy).
apply le_iff_not_lt_flip.
exact (nleyz (lt_le _ _ _)).
assert (ineqz : y ⊓ z <> z).
assert (nlezy : ~ (z ≤ y))
by exact (not_contrapositive (meet_r y z) ineqz).
apply le_iff_not_lt_flip.
exact (nlezy (lt_le _ _ _)).
assert (eqyz : y = z)
by exact (antisymmetry _ _ _ leyz lezy).
rewrite <- eqyz in ineqy.
destruct (ineqy (meet_idempotent y)).
End strict_ordered_field.