------------------------------------------------------------------------ -- 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 --without-K --safe #-} module Data.Product.Relation.Binary.Lex.Strict where open import Data.Product open import Data.Product.Relation.Binary.Pointwise.NonDependent as Pointwise using (Pointwise) open import Data.Sum.Base using (inj₁; inj₂; _-⊎-_; [_,_]) open import Data.Empty open import Function open import Induction.WellFounded open import Level open import Relation.Nullary open import Relation.Nullary.Product open import Relation.Nullary.Sum open import Relation.Binary open import Relation.Binary.Consequences open import Relation.Binary.PropositionalEquality using (_≡_; refl) 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 B ℓ₂} where -- Currently only proven for propositional equality -- (unsure how to satisfy the termination checker for arbitrary equalities) private _<ₗₑₓ_ = ×-Lex _≡_ _<₁_ _<₂_ ×-wellFounded : WellFounded _<₁_ → WellFounded _<₂_ → WellFounded _<ₗₑₓ_ ×-wellFounded 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₂ (u , v) (inj₁ u