File Lattice

From MatchingLogic.Utils Require Export stdpp_ext.

Class OrderedSet A : Type :=
  { leq : relation A;
    leq_order : order A leq;
  }.

Program Definition OrderedSet_dual {A : Type} (OS : OrderedSet A) : OrderedSet A :=
  {| leq := fun x y ⇒ @leq A OS y x;
     leq_order := {| ord_refl := _; ord_trans := _; ord_antisym := _; |};
  |}.


Definition upperBound {A : Type} {OS : OrderedSet A} (X: propset A) (ub: A) : Prop :=
   (x: A), xXleq x ub.

Definition leastUpperBound {A : Type} {OS : OrderedSet A} (X: propset A) (lub: A) : Prop :=
  upperBound X lub
   (ub : A), upperBound X ubleq lub ub.

Definition lowerBound {A : Type} {OS : OrderedSet A} (X: propset A) (lb: A) : Prop :=
   (x : A), xXleq lb x.

Definition greatestLowerBound {A : Type} {OS : OrderedSet A} (X : propset A) (glb : A) : Prop :=
  lowerBound X glb
   (lb : A), lowerBound X lbleq lb glb.

Definition upperBoundsOf {A : Type} {OS : OrderedSet A} (X : propset A) : propset A :=
  PropSet (fun xupperBound X x).

Definition lowerBoundsOf {A : Type} {OS : OrderedSet A} (X : propset A) : propset A :=
  PropSet (fun xlowerBound X x).

Definition isMeet {A : Type} {OS : OrderedSet A} (meet : propset AA) : Prop :=
   (X : propset A), greatestLowerBound X (meet X).

Definition isJoin {A : Type} {OS : OrderedSet A} (join : propset AA) : Prop :=
   (X : propset A), leastUpperBound X (join X).

Definition joinFromMeet {A : Type} {OS : OrderedSet A} (meet : propset AA)
  : propset AA :=
  fun Xmeet (upperBoundsOf X).

Lemma joinFromMeet_lub: (A : Type) (OS : OrderedSet A)
                                (meet : propset AA),
     isMeet meetisJoin (joinFromMeet meet).

Definition meetFromJoin {A : Type} {OS : OrderedSet A} (join : propset AA)
   : propset AA :=
  fun Xjoin (lowerBoundsOf X).

(* Exactly a dual of joinFromMeet_lub. But there should be some way to avoid duplication. *)
Lemma meetFromJoin_glb: (A : Type) (OS : OrderedSet A)
                                (join : propset AA),
     isJoin joinisMeet (meetFromJoin join).

Class CompleteLattice A `{OrderedSet A} :=
  {
    meet : propset AA;
    join : propset AA;
    meet_isMeet : isMeet meet;
    join_isJoin : isJoin join;
  }.

Program Definition CompleteLattice_dual {A : Type} {OS : OrderedSet A} (CL : CompleteLattice A)
  : @CompleteLattice A (@OrderedSet_dual A OS) :=
  {| meet := join;
     join := meet;
     meet_isMeet := _;
     join_isJoin := _
  |}.

Definition MonotonicFunction {A : Type} {OS : OrderedSet A}
           (f : AA) :=
   (x y : A), leq x yleq (f x) (f y).

Definition AntiMonotonicFunction {A : Type} {OS : OrderedSet A}
           (f : AA) :=
   (x y : A), leq x yleq (f y) (f x).

Lemma MonotonicFunction_dual {A : Type} :
   (OS : OrderedSet A) (f : AA),
    @MonotonicFunction A OS f → @MonotonicFunction A (OrderedSet_dual OS) f.

Definition PrefixpointsOf {A : Type} {OS : OrderedSet A} (f : AA) : propset A :=
  PropSet (fun xleq (f x) x).

Definition LeastFixpointOf {A : Type} {OS : OrderedSet A} {L : CompleteLattice A}
           (f : AA) : A :=
  meet (PrefixpointsOf f).

Arguments LeastFixpointOf : simpl never.

Definition PostfixpointsOf {A : Type} {OS : OrderedSet A} (f : AA) : propset A :=
  PropSet (fun xleq x (f x)).

Definition GreatestFixpointOf {A : Type} {OS : OrderedSet A} {L : CompleteLattice A}
           (f : AA) : A :=
  join (PostfixpointsOf f).

Arguments GreatestFixpointOf : simpl never.

Lemma PrefixpointsOfDualArePostfixpoints {A : Type} :
   (OS : OrderedSet A) (f : AA),
    @PrefixpointsOf A (@OrderedSet_dual A OS) = @PostfixpointsOf A OS.

Lemma PostfixpointsOfDualArePrefixpoints {A : Type} :
   (OS : OrderedSet A) (f : AA),
    @PostfixpointsOf A (@OrderedSet_dual A OS) = @PrefixpointsOf A OS.

Lemma GreatestFixpointOnDualIsLeastFixpoint {A : Type} :
   (OS : OrderedSet A) (L : CompleteLattice A) (f : AA),
    @GreatestFixpointOf A (@OrderedSet_dual A OS) (@CompleteLattice_dual A OS L) f = LeastFixpointOf f.

Proposition GreatestFixpoint_greaterThanPostfixpoint:
   (A : Type) (OS : OrderedSet A) (L : CompleteLattice A) (f : AA) (x : A),
    leq x (f x) → leq x (GreatestFixpointOf f).

Proposition GreatestFixpoint_GreaterThanFixpoint :
   (A : Type) (OS : OrderedSet A) (L : CompleteLattice A) (f : AA) (x : A),
    x = (f x) → leq x (GreatestFixpointOf f).

Definition isFixpoint {A : Type} (f : AA) (p : A) : Prop :=
  f p = p.

Theorem GreatestFixpoint_fixpoint:
   (A : Type) (OS : OrderedSet A) (L : CompleteLattice A) (f : AA),
    MonotonicFunction fisFixpoint f (@GreatestFixpointOf A OS L f).

Theorem LeastFixpoint_fixpoint:
   (A : Type) (OS : OrderedSet A) (L : CompleteLattice A) (f : AA),
    MonotonicFunction fisFixpoint f (@LeastFixpointOf A OS L f).

Proposition LeastFixpoint_LesserThanPrefixpoint:
   (A : Type) (OS : OrderedSet A) (L : CompleteLattice A) (f : AA) (x : A),
    leq (f x) xleq (LeastFixpointOf f) x.

Proposition LeastFixpoint_LesserThanFixpoint :
   (A : Type) (OS : OrderedSet A) (L : CompleteLattice A) (f : AA) (x : A),
    x = (f x) → leq (LeastFixpointOf f) x.

Proposition LeastFixpoint_unique :
   (A : Type) (OS : OrderedSet A) (L : CompleteLattice A) (f : AA) (Sfix : A),
    leq (f Sfix) Sfix
    ( x, leq (f x) xleq Sfix x) →
    Sfix = LeastFixpointOf f.

Proposition LeastFixpoint_unique_2 :
   (A : Type) (OS : OrderedSet A) (L : CompleteLattice A)
    (f : AA)
    (Sfix : A),
    (MonotonicFunction f) →
    (f Sfix) = Sfix
    ( x, (f x) = xleq Sfix x) →
    Sfix = LeastFixpointOf f.

Lemma lfp_preserves_order {A : Type} (OS : OrderedSet A) (L : CompleteLattice A) (f g : AA) :
  MonotonicFunction fMonotonicFunction g
  ( (x : A), leq (f x) (g x)) →
  leq (LeastFixpointOf f) (LeastFixpointOf g).

From Coq Require Import Logic.FunctionalExtensionality Logic.PropExtensionality.

Section propset_lattice.
  Variable U : Type.

  Program Definition PropsetOrderedSet : OrderedSet (propset U) :=
  {| leq := subseteq;
  |}.


  Definition propset_Meet (ee : propset (propset U)) : propset U :=
    PropSet (fun m e : propset U,
        eeeme).

  Lemma propset_Meet_is_meet : @isMeet (propset U) PropsetOrderedSet propset_Meet.

  Definition PowersetLattice : CompleteLattice (propset U) :=
    {| meet := propset_Meet;
       join := joinFromMeet propset_Meet;
       meet_isMeet := propset_Meet_is_meet;
       join_isJoin := joinFromMeet_lub (propset U) PropsetOrderedSet propset_Meet propset_Meet_is_meet;
    |}.

End propset_lattice.


This page has been generated by coqdoc