| 1 |
------------------------------------------------------------------------ |
| 2 |
-- The Agda standard library |
| 3 |
-- |
| 4 |
-- Lexicographic ordering of lists |
| 5 |
------------------------------------------------------------------------ |
| 6 |
|
| 7 |
{-# OPTIONS --cubical-compatible --safe #-} |
| 8 |
|
| 9 |
module Data.List.Relation.Binary.Lex.Core where |
| 10 |
|
| 11 |
open import Data.Empty using (⊥) |
| 12 |
open import Data.Unit.Base using (⊤) |
| 13 |
open import Data.Product.Base using (_×_; _,_; proj₁; proj₂; uncurry) |
| 14 |
open import Data.List.Base using (List; []; _∷_) |
| 15 |
open import Function.Base using (_∘_; flip; id) |
| 16 |
open import Level using (Level; _⊔_) |
| 17 |
open import Relation.Nullary.Negation.Core using (¬_) |
| 18 |
open import Relation.Binary.Core using (Rel) |
| 19 |
open import Data.List.Relation.Binary.Pointwise.Base |
| 20 |
using (Pointwise; []; _∷_; head; tail) |
| 21 |
|
| 22 |
private |
| 23 |
variable |
| 24 |
a ℓ₁ ℓ₂ : Level |
| 25 |
|
| 26 |
-- The lexicographic ordering itself can be either strict or non-strict, |
| 27 |
-- depending on whether type P is inhabited. |
| 28 |
|
| 29 |
data Lex {A : Set a} (P : Set) |
| 30 |
(_≈_ : Rel A ℓ₁) (_≺_ : Rel A ℓ₂) : |
| 31 |
Rel (List A) (a ⊔ ℓ₁ ⊔ ℓ₂) where |
| 32 |
base : P → Lex P _≈_ _≺_ [] [] |
| 33 |
halt : ∀ {y ys} → Lex P _≈_ _≺_ [] (y ∷ ys) |
| 34 |
this : ∀ {x xs y ys} (x≺y : x ≺ y) → Lex P _≈_ _≺_ (x ∷ xs) (y ∷ ys) |
| 35 |
next : ∀ {x xs y ys} (x≈y : x ≈ y) |
| 36 |
(xs<ys : Lex P _≈_ _≺_ xs ys) → Lex P _≈_ _≺_ (x ∷ xs) (y ∷ ys) |
| 37 |
|
| 38 |
------------------------------------------------------------------------ |
| 39 |
-- Lexicographic orderings, using a strict ordering as the base |
| 40 |
|
| 41 |
Lex-< : {A : Set a} (_≈_ : Rel A ℓ₁) (_≺_ : Rel A ℓ₂) → |
| 42 |
Rel (List A) (a ⊔ ℓ₁ ⊔ ℓ₂) |
| 43 |
Lex-< = Lex ⊥ |
| 44 |
|
| 45 |
Lex-≤ : {A : Set a} (_≈_ : Rel A ℓ₁) (_≺_ : Rel A ℓ₂) → |
| 46 |
Rel (List A) (a ⊔ ℓ₁ ⊔ ℓ₂) |
| 47 |
Lex-≤ = Lex ⊤ |