------------------------------------------------------------------------ -- The Agda standard library -- -- Lexicographic products of binary relations ------------------------------------------------------------------------ -- The definition of lexicographic product used here is suitable if -- the left-hand relation is a strict partial order. {-# OPTIONS --cubical-compatible --safe #-} module Data.Product.Relation.Binary.Lex.Strict where open import Data.Product.Base open import Data.Product.Relation.Binary.Pointwise.NonDependent as Pointwise using (Pointwise) open import Data.Sum.Base using (inj₁; inj₂; _-⊎-_; [_,_]) open import Function.Base using (flip; _on_; _$_; _∘_) open import Induction.WellFounded using (Acc; acc; WfRec; WellFounded; Acc-resp-flip-≈) open import Level using (Level) open import Relation.Binary.Core using (Rel; _⇒_) open import Relation.Binary.Bundles using (Preorder; StrictPartialOrder; StrictTotalOrder) open import Relation.Binary.Structures using (IsEquivalence; IsPreorder; IsStrictPartialOrder; IsStrictTotalOrder) open import Relation.Binary.Definitions using (Transitive; Symmetric; Irreflexive; Asymmetric; Total; Decidable ; Antisymmetric; Trichotomous; _Respects₂_; _Respectsʳ_; _Respectsˡ_ ; tri<; tri>; tri≈) open import Relation.Binary.Consequences using (asym⇒irr) open import Relation.Binary.PropositionalEquality.Core as ≡ using (_≡_) open import Relation.Nullary.Decidable.Core using (yes; no; _⊎-dec_; _×-dec_) open import Relation.Nullary.Negation.Core using (contradiction) private variable a b ℓ₁ ℓ₂ ℓ₃ ℓ₄ : Level A : Set a B : Set b ------------------------------------------------------------------------ -- A lexicographic ordering over products ×-Lex : (_≈₁_ : Rel A ℓ₁) (_<₁_ : Rel A ℓ₂) (_≤₂_ : Rel B ℓ₃) → Rel (A × B) _ ×-Lex _≈₁_ _<₁_ _≤₂_ = (_<₁_ on proj₁) -⊎- (_≈₁_ on proj₁) -×- (_≤₂_ on proj₂) ------------------------------------------------------------------------ -- Some properties which are preserved by ×-Lex (under certain -- assumptions). ×-reflexive : (_≈₁_ : Rel A ℓ₁) (_∼₁_ : Rel A ℓ₂) {_≈₂_ : Rel B ℓ₃} (_≤₂_ : Rel B ℓ₄) → _≈₂_ ⇒ _≤₂_ → (Pointwise _≈₁_ _≈₂_) ⇒ (×-Lex _≈₁_ _∼₁_ _≤₂_) ×-reflexive _ _ _ refl₂ = λ x≈y → inj₂ (proj₁ x≈y , refl₂ (proj₂ x≈y)) module _ {_≈₁_ : Rel A ℓ₁} {_<₁_ : Rel A ℓ₂} {_<₂_ : Rel B ℓ₃} where private _<ₗₑₓ_ = ×-Lex _≈₁_ _<₁_ _<₂_ ×-transitive : IsEquivalence _≈₁_ → _<₁_ Respects₂ _≈₁_ → Transitive _<₁_ → Transitive _<₂_ → Transitive _<ₗₑₓ_ ×-transitive eq₁ resp₁ trans₁ trans₂ = trans where module Eq₁ = IsEquivalence eq₁ trans : Transitive _<ₗₑₓ_ trans (inj₁ x₁y₁ = inj₂ (inj₁ x₁>y₁) ×-total₂ : Symmetric _≈₁_ → Trichotomous _≈₁_ _<₁_ → Total _<₂_ → Total _<ₗₑₓ_ ×-total₂ sym tri₁ total₂ x y with tri₁ (proj₁ x) (proj₁ y) ... | tri< x₁ _ _ y₁ x₁≮y₁ x₁≉y₁ x₁>y₁) = tri> [ x₁≮y₁ , x₁≉y₁ ∘ proj₁ ] (x₁≉y₁ ∘ proj₁) (inj₁ x₁>y₁) ... | (tri≈ x₁≮y₁ x₁≈y₁ x₁≯y₁) with cmp₂ x₂ y₂ ... | (tri< x₂ x₂≮y₂ x₂≉y₂ x₂>y₂) = tri> [ x₁≮y₁ , x₂≮y₂ ∘ proj₂ ] (x₂≉y₂ ∘ proj₂) (inj₂ (sym₁ x₁≈y₁ , x₂>y₂)) ... | (tri≈ x₂≮y₂ x₂≈y₂ x₂≯y₂) = tri≈ [ x₁≮y₁ , x₂≮y₂ ∘ proj₂ ] (x₁≈y₁ , x₂≈y₂) [ x₁≯y₁ , x₂≯y₂ ∘ proj₂ ] module _ {_≈₁_ : Rel A ℓ₁} {_<₁_ : Rel A ℓ₂} {_<₂_ : Rel B ℓ₃} where private _<ₗₑₓ_ = ×-Lex _≈₁_ _<₁_ _<₂_ ×-wellFounded' : Transitive _≈₁_ → _<₁_ Respectsʳ _≈₁_ → WellFounded _<₁_ → WellFounded _<₂_ → WellFounded _<ₗₑₓ_ ×-wellFounded' trans resp wf₁ wf₂ (x , y) = acc (×-acc (wf₁ x) (wf₂ y)) where ×-acc : ∀ {x y} → Acc _<₁_ x → Acc _<₂_ y → WfRec _<ₗₑₓ_ (Acc _<ₗₑₓ_) (x , y) ×-acc (acc rec₁) acc₂ (inj₁ u