aboutsummaryrefslogtreecommitdiff
path: root/Util.agda
diff options
context:
space:
mode:
authorJacques Comeaux <jacquesrcomeaux@protonmail.com>2024-02-21 18:59:18 -0600
committerJacques Comeaux <jacquesrcomeaux@protonmail.com>2024-02-21 18:59:18 -0600
commit2207e9b0e3defe2a5b6250ff8a2a1132d8fd10ee (patch)
tree3bc564f7719cf37ecc9a344e74c8e9612d8ff82c /Util.agda
parent5e30f210d4d510649ca87a02b7e9a409ee74d13a (diff)
Add iterative version of glue
Diffstat (limited to 'Util.agda')
-rw-r--r--Util.agda17
1 files changed, 16 insertions, 1 deletions
diff --git a/Util.agda b/Util.agda
index 23da7cc..b30aeb5 100644
--- a/Util.agda
+++ b/Util.agda
@@ -2,7 +2,8 @@ module Util where
open import Data.Fin using (Fin; toℕ)
open import Data.Nat using (ℕ; _≤_; _<_ ; z<s; s≤s)
-open import Data.Product using (_×_)
+open import Data.Product using (_×_; _,_)
+open import Relation.Binary.PropositionalEquality using (_≡_; refl; cong)
_<_≤_ : ℕ → ℕ → ℕ → Set
@@ -14,3 +15,17 @@ _<_<_ i j k = (i < j) × (j < k)
toℕ< : {n : ℕ} → (i : Fin n) → toℕ i < n
toℕ< Fin.zero = z<s
toℕ< (Fin.suc i) = s≤s (toℕ< i)
+
+data Ordering {n : ℕ} : Fin n → Fin n → Set where
+ less : ∀ {i j} → toℕ i < toℕ j < n → Ordering i j
+ equal : ∀ {i j} → i ≡ j → Ordering i j
+ greater : ∀ {i j} → toℕ j < toℕ i < n → Ordering i j
+
+compare : ∀ {n : ℕ} (i j : Fin n) → Ordering i j
+compare Fin.zero Fin.zero = equal refl
+compare Fin.zero j@(Fin.suc _) = less (z<s , toℕ< j)
+compare i@(Fin.suc _) Fin.zero = greater (z<s , toℕ< i)
+compare (Fin.suc i) (Fin.suc j) with compare i j
+... | less (i<j , j<n) = less (_≤_.s≤s i<j , _≤_.s≤s j<n)
+... | equal i≡j = equal (cong Fin.suc i≡j)
+... | greater (j<i , i<n) = greater (_≤_.s≤s j<i , _≤_.s≤s i<n)