aboutsummaryrefslogtreecommitdiff
path: root/Data/Permutation/Sort.agda
diff options
context:
space:
mode:
authorJacques Comeaux <jacquesrcomeaux@protonmail.com>2025-10-28 17:20:33 -0500
committerJacques Comeaux <jacquesrcomeaux@protonmail.com>2025-10-28 17:20:33 -0500
commit0bf55c23ad3bee621d0e7425f5a5e875254e3450 (patch)
treeea5dbac95aa1fa9449b785cb5be3078790a88aea /Data/Permutation/Sort.agda
parent2cd74f160389fe2ab2b30ab628fbb9b712f06faf (diff)
parent2439066ad6901ed1e083f48fb7ac4fd7a7840d27 (diff)
Merge branch 'hypergraph-conversion'
Diffstat (limited to 'Data/Permutation/Sort.agda')
-rw-r--r--Data/Permutation/Sort.agda29
1 files changed, 29 insertions, 0 deletions
diff --git a/Data/Permutation/Sort.agda b/Data/Permutation/Sort.agda
new file mode 100644
index 0000000..8d097f2
--- /dev/null
+++ b/Data/Permutation/Sort.agda
@@ -0,0 +1,29 @@
+{-# OPTIONS --without-K --safe #-}
+
+open import Relation.Binary.Bundles using (DecTotalOrder)
+
+module Data.Permutation.Sort {ℓ₁ ℓ₂ ℓ₃} (dto : DecTotalOrder ℓ₁ ℓ₂ ℓ₃) where
+
+open DecTotalOrder dto using (module Eq; totalOrder) renaming (Carrier to A)
+
+open import Data.List.Base using (List)
+open import Data.List.Relation.Binary.Equality.Setoid Eq.setoid using (_≋_)
+open import Data.List.Relation.Binary.Permutation.Setoid Eq.setoid using (_↭_; module PermutationReasoning)
+open import Data.List.Relation.Unary.Sorted.TotalOrder.Properties using (↗↭↗⇒≋)
+open import Data.List.Sort dto using (sortingAlgorithm)
+open import Data.List.Sort.Base totalOrder using (SortingAlgorithm)
+open SortingAlgorithm sortingAlgorithm using (sort; sort-↭ₛ; sort-↗)
+
+sorted-≋
+ : {xs ys : List A}
+ → xs ↭ ys
+ → sort xs ≋ sort ys
+sorted-≋ {xs} {ys} xs↭ys = ↗↭↗⇒≋ totalOrder (sort-↗ xs) (sort-↗ ys) sort-xs↭sort-ys
+ where
+ open PermutationReasoning
+ sort-xs↭sort-ys : sort xs ↭ sort ys
+ sort-xs↭sort-ys = begin
+ sort xs ↭⟨ sort-↭ₛ xs ⟩
+ xs ↭⟨ xs↭ys ⟩
+ ys ↭⟨ sort-↭ₛ ys ⟨
+ sort ys ∎