------------------------------------------------------------------------ -- The Agda standard library -- -- Lexicographic ordering of same-length vector ------------------------------------------------------------------------ -- The definitions of lexicographic orderings used here is suitable if -- the argument order is a (non-strict) partial order. {-# OPTIONS --cubical-compatible --safe #-} module Data.Vec.Relation.Binary.Lex.NonStrict where open import Data.Empty using (⊥; ⊥-elim) open import Data.Unit.Base using (⊤; tt) open import Data.Product.Base using (proj₁; proj₂) open import Data.Nat.Base using (ℕ) open import Data.Vec.Base using (Vec; []; _∷_) import Data.Vec.Relation.Binary.Lex.Strict as Strict open import Data.Vec.Relation.Binary.Pointwise.Inductive as Pointwise using (Pointwise; []; _∷_; head; tail) open import Function.Base using (id) open import Level using (Level; _⊔_) open import Relation.Binary.Core using (REL; Rel; _⇒_) open import Relation.Binary.Bundles using (Poset; StrictPartialOrder; DecPoset; DecStrictPartialOrder ; DecTotalOrder; StrictTotalOrder; Preorder; TotalOrder) open import Relation.Binary.Structures using (IsEquivalence; IsPartialOrder; IsStrictPartialOrder; IsDecPartialOrder ; IsDecStrictPartialOrder; IsDecTotalOrder; IsStrictTotalOrder ; IsPreorder; IsTotalOrder) open import Relation.Binary.Definitions using (Irreflexive; _Respects₂_; Antisymmetric; Asymmetric; Symmetric; Trans ; Decidable; Total; Trichotomous) import Relation.Binary.Construct.NonStrictToStrict as Conv open import Relation.Nullary.Decidable.Core using (yes; no) private variable a ℓ₁ ℓ₂ : Level A : Set a ------------------------------------------------------------------------ -- Publicly re-export definitions from Core ------------------------------------------------------------------------ open import Data.Vec.Relation.Binary.Lex.Core as Core public using (base; this; next; ≰-this; ≰-next) ------------------------------------------------------------------------ -- Definitions ------------------------------------------------------------------------ module _ {A : Set a} (_≈_ : Rel A ℓ₁) (_≼_ : Rel A ℓ₂) where Lex-< : ∀ {m n} → REL (Vec A m) (Vec A n) (a ⊔ ℓ₁ ⊔ ℓ₂) Lex-< = Core.Lex {A = A} ⊥ _≈_ (Conv._<_ _≈_ _≼_) Lex-≤ : ∀ {m n} → REL (Vec A m) (Vec A n) (a ⊔ ℓ₁ ⊔ ℓ₂) Lex-≤ = Core.Lex {A = A} ⊤ _≈_ (Conv._<_ _≈_ _≼_) ------------------------------------------------------------------------ -- Properties of Lex-< ------------------------------------------------------------------------ module _ {_≈_ : Rel A ℓ₁} {_≼_ : Rel A ℓ₂} where private _≋_ = Pointwise _≈_ _<_ = Lex-< _≈_ _≼_ <-irrefl : ∀ {m n} → Irreflexive (_≋_ {m} {n}) _<_ <-irrefl = Strict.<-irrefl (Conv.<-irrefl _≈_ _≼_) <-asym : IsEquivalence _≈_ → _≼_ Respects₂ _≈_ → Antisymmetric _≈_ _≼_ → ∀ {n} → Asymmetric (_<_ {n} {n}) <-asym ≈-equiv ≼-resp-≈ ≼-antisym = Strict.<-asym sym (Conv.<-resp-≈ _ _ ≈-equiv ≼-resp-≈) (Conv.<-asym _≈_ _ ≼-antisym) where open IsEquivalence ≈-equiv <-antisym : Symmetric _≈_ → Antisymmetric _≈_ _≼_ → ∀ {n} → Antisymmetric (_≋_ {n} {n}) _<_ <-antisym ≈-sym ≼-antisym = Core.antisym ≈-sym (Conv.<-irrefl _≈_ _≼_) (Conv.<-asym _≈_ _≼_ ≼-antisym) <-trans : IsPartialOrder _≈_ _≼_ → ∀ {m n o} → Trans (_<_ {m} {n}) (_<_ {n} {o}) _<_ <-trans ≼-isPartialOrder = Core.transitive Eq.isPartialEquivalence (Conv.<-resp-≈ _ _ isEquivalence ≤-resp-≈) (Conv.<-trans _ _ ≼-isPartialOrder) where open IsPartialOrder ≼-isPartialOrder <-resp₂ : IsEquivalence _≈_ → _≼_ Respects₂ _≈_ → ∀ {n} → _Respects₂_ (_<_ {n} {n}) _≋_ <-resp₂ ≈-equiv ≼-resp-≈ = Core.respects₂ (IsEquivalence.isPartialEquivalence ≈-equiv) (Conv.<-resp-≈ _ _ ≈-equiv ≼-resp-≈) <-cmp : Symmetric _≈_ → Decidable _≈_ → Antisymmetric _≈_ _≼_ → Total _≼_ → ∀ {n} → Trichotomous (_≋_ {n} {n}) _<_ <-cmp ≈-sym _≟_ ≼-antisym ≼-total = Strict.<-cmp ≈-sym (Conv.<-trichotomous _ _ ≈-sym _≟_ ≼-antisym ≼-total) <-dec : Decidable _≈_ → Decidable _≼_ → ∀ {m n} → Decidable (_<_ {m} {n}) <-dec _≟_ _≼?_ = Core.decidable (no id) _≟_ (Conv.<-decidable _ _ _≟_ _≼?_) ------------------------------------------------------------------------ -- Structures <-isStrictPartialOrder : IsPartialOrder _≈_ _≼_ → ∀ {n} → IsStrictPartialOrder (_≋_ {n} {n}) _<_ <-isStrictPartialOrder ≼-isPartialOrder {n} = Strict.<-isStrictPartialOrder (Conv.<-isStrictPartialOrder _ _ ≼-isPartialOrder) <-isDecStrictPartialOrder : IsDecPartialOrder _≈_ _≼_ → ∀ {n} → IsDecStrictPartialOrder (_≋_ {n} {n}) _<_ <-isDecStrictPartialOrder ≼-isDecPartialOrder {n} = Strict.<-isDecStrictPartialOrder (Conv.<-isDecStrictPartialOrder _ _ ≼-isDecPartialOrder) <-isStrictTotalOrder : IsDecTotalOrder _≈_ _≼_ → ∀ {n} → IsStrictTotalOrder (_≋_ {n} {n}) _<_ <-isStrictTotalOrder ≼-isDecTotalOrder {n} = Strict.<-isStrictTotalOrder (Conv.<-isStrictTotalOrder₂ _ _ ≼-isDecTotalOrder) ------------------------------------------------------------------------ -- Bundles <-strictPartialOrder : Poset a ℓ₁ ℓ₂ → ℕ → StrictPartialOrder _ _ _ <-strictPartialOrder ≼-po n = record { isStrictPartialOrder = <-isStrictPartialOrder isPartialOrder {n = n} } where open Poset ≼-po <-decStrictPartialOrder : DecPoset a ℓ₁ ℓ₂ → ℕ → DecStrictPartialOrder _ _ _ <-decStrictPartialOrder ≼-dpo n = record { isDecStrictPartialOrder = <-isDecStrictPartialOrder isDecPartialOrder {n = n} } where open DecPoset ≼-dpo <-strictTotalOrder : DecTotalOrder a ℓ₁ ℓ₂ → ℕ → StrictTotalOrder _ _ _ <-strictTotalOrder ≼-dto n = record { isStrictTotalOrder = <-isStrictTotalOrder isDecTotalOrder {n = n} } where open DecTotalOrder ≼-dto ------------------------------------------------------------------------ -- Properties of Lex-≤ ------------------------------------------------------------------------ module _ {_≈_ : Rel A ℓ₁} {_≼_ : Rel A ℓ₂} where private _≋_ = Pointwise _≈_ _<_ = Lex-< _≈_ _≼_ _≤_ = Lex-≤ _≈_ _≼_ <⇒≤ : ∀ {m n} {xs : Vec A m} {ys : Vec A n} → xs < ys → xs ≤ ys <⇒≤ = Core.map-P ⊥-elim ≤-refl : ∀ {m n} → (_≋_ {m} {n}) ⇒ _≤_ ≤-refl = Strict.≤-refl ≤-antisym : Symmetric _≈_ → Antisymmetric _≈_ _≼_ → ∀ {n} → Antisymmetric (_≋_ {n} {n}) _≤_ ≤-antisym ≈-sym ≼-antisym = Core.antisym ≈-sym (Conv.<-irrefl _≈_ _≼_) (Conv.<-asym _ _≼_ ≼-antisym) private trans : IsPartialOrder _≈_ _≼_ → ∀ {P₁ P₂} {m n o} → Trans (Core.Lex P₁ _≈_ (Conv._<_ _≈_ _≼_) {m} {n}) (Core.Lex P₂ _≈_ (Conv._<_ _≈_ _≼_) {n} {o}) _ trans ≼-po = Core.transitive′ (IsEquivalence.isPartialEquivalence isEquivalence) (Conv.<-resp-≈ _ _ isEquivalence ≤-resp-≈) (Conv.<-trans _ _≼_ ≼-po) where open IsPartialOrder ≼-po ≤-trans : IsPartialOrder _≈_ _≼_ → ∀ {m n o} → Trans (_≤_ {m} {n}) (_≤_ {n} {o}) _≤_ ≤-trans ≼-po xs≤ys ys≤zs = Core.map-P proj₁ (trans ≼-po xs≤ys ys≤zs) <-transʳ : IsPartialOrder _≈_ _≼_ → ∀ {m n o} → Trans (_≤_ {m} {n}) (_<_ {n} {o}) _<_ <-transʳ ≼-po xs≤ys ys