From 02dba8020fd65a81b1fd8d636b394f259695f672 Mon Sep 17 00:00:00 2001 From: jamesmckinna Date: Fri, 23 Jan 2026 13:17:18 +0000 Subject: [PATCH 01/19] refactor: use `variable`s more systematically --- src/Data/List/Fresh.agda | 125 ++++++++++++++++++++------------------- 1 file changed, 65 insertions(+), 60 deletions(-) diff --git a/src/Data/List/Fresh.agda b/src/Data/List/Fresh.agda index c75d2edade..f8a49e018f 100644 --- a/src/Data/List/Fresh.agda +++ b/src/Data/List/Fresh.agda @@ -24,7 +24,7 @@ open import Data.Nat.Base using (ℕ; zero; suc) open import Function.Base using (_∘′_; flip; id; _on_) open import Relation.Nullary using (does) open import Relation.Unary as U using (Pred) -open import Relation.Binary.Core using (Rel) +open import Relation.Binary.Core using (Rel; REL) import Relation.Binary.Definitions as B using (Reflexive) open import Relation.Nary using (_⇒_; ∀[_]) @@ -34,6 +34,11 @@ private a b p r s : Level A : Set a B : Set b + P : Pred A p + R : Rel A r + S : Rel A s + x y : A + ------------------------------------------------------------------------ -- Basic type @@ -44,11 +49,11 @@ private module _ {a} (A : Set a) (R : Rel A r) where data List# : Set (a ⊔ r) - fresh : (a : A) (as : List#) → Set r + fresh : REL A List# r data List# where [] : List# - cons : (a : A) (as : List#) → fresh a as → List# + cons : (x : A) (xs : List#) → fresh x xs → List# -- Whenever R can be reconstructed by η-expansion (e.g. because it is -- the erasure ⌊_⌋ of a decidable predicate, cf. Relation.Nary) or we @@ -64,29 +69,29 @@ module _ {a} (A : Set a) (R : Rel A r) where -- Convenient notation for freshness making A and R implicit parameters infix 5 _#_ -_#_ : {R : Rel A r} (a : A) (as : List# A R) → Set r +_#_ : REL A (List# A R) _ _#_ = fresh _ _ ------------------------------------------------------------------------ -- Operations for modifying fresh lists -module _ {R : Rel A r} {S : Rel B s} (f : A → B) (R⇒S : ∀[ R ⇒ (S on f) ]) where +module _ (f : A → B) (R⇒S : ∀[ R ⇒ (S on f) ]) where map : List# A R → List# B S - map-# : ∀ {a} as → a # as → f a # map as + map-# : ∀ xs → x # xs → f x # map xs map [] = [] - map (cons a as ps) = cons (f a) (map as) (map-# as ps) + map (cons x xs ps) = cons (f x) (map xs) (map-# xs ps) map-# [] _ = _ - map-# (a ∷# as) (p , ps) = R⇒S p , map-# as ps + map-# (x ∷# xs) (p , ps) = R⇒S p , map-# xs ps -module _ {R : Rel B r} (f : A → B) where +module _ (f : A → B) where map₁ : List# A (R on f) → List# B R map₁ = map f id -module _ {R : Rel A r} {S : Rel A s} (R⇒S : ∀[ R ⇒ S ]) where +module _ {S : Rel A s} (R⇒S : ∀[ R ⇒ S ]) where map₂ : List# A R → List# A S map₂ = map id R⇒S @@ -94,115 +99,115 @@ module _ {R : Rel A r} {S : Rel A s} (R⇒S : ∀[ R ⇒ S ]) where ------------------------------------------------------------------------ -- Views -data Empty {A : Set a} {R : Rel A r} : List# A R → Set (a ⊔ r) where +data Empty {A : Set a} {R : Rel A r} : Pred (List# A R) (a ⊔ r) where [] : Empty [] -data NonEmpty {A : Set a} {R : Rel A r} : List# A R → Set (a ⊔ r) where +data NonEmpty {A : Set a} {R : Rel A r} : Pred (List# A R) (a ⊔ r) where cons : ∀ x xs pr → NonEmpty (cons x xs pr) ------------------------------------------------------------------------ -- Operations for reducing fresh lists -length : {R : Rel A r} → List# A R → ℕ +length : List# A R → ℕ length [] = 0 length (_ ∷# xs) = suc (length xs) ------------------------------------------------------------------------ -- Operations for constructing fresh lists -pattern [_] a = a ∷# [] +pattern [_] x = x ∷# [] -fromMaybe : {R : Rel A r} → Maybe A → List# A R +fromMaybe : Maybe A → List# A R fromMaybe nothing = [] -fromMaybe (just a) = [ a ] +fromMaybe (just x) = [ x ] -module _ {R : Rel A r} (R-refl : B.Reflexive R) where +module _ (R-refl : B.Reflexive {A = A} R) where replicate : ℕ → A → List# A R - replicate-# : (n : ℕ) (a : A) → a # replicate n a + replicate-# : (n : ℕ) (x : A) → x # replicate n x - replicate zero a = [] - replicate (suc n) a = cons a (replicate n a) (replicate-# n a) + replicate zero x = [] + replicate (suc n) x = cons x (replicate n x) (replicate-# n x) - replicate-# zero a = _ - replicate-# (suc n) a = R-refl , replicate-# n a + replicate-# zero x = _ + replicate-# (suc n) x = R-refl , replicate-# n x ------------------------------------------------------------------------ -- Operations for deconstructing fresh lists -uncons : {R : Rel A r} → List# A R → Maybe (A × List# A R) +uncons : List# A R → Maybe (A × List# A R) uncons [] = nothing -uncons (a ∷# as) = just (a , as) +uncons (x ∷# xs) = just (x , xs) -head : {R : Rel A r} → List# A R → Maybe A +head : List# A R → Maybe A head = Maybe.map proj₁ ∘′ uncons -tail : {R : Rel A r} → List# A R → Maybe (List# A R) +tail : List# A R → Maybe (List# A R) tail = Maybe.map proj₂ ∘′ uncons -take : {R : Rel A r} → ℕ → List# A R → List# A R -take-# : {R : Rel A r} → ∀ n a (as : List# A R) → a # as → a # take n as +take : ℕ → List# A R → List# A R +take-# : ∀ n y (xs : List# A R) → y # xs → y # take n xs take zero xs = [] take (suc n) [] = [] -take (suc n) (cons a as ps) = cons a (take n as) (take-# n a as ps) +take (suc n) (cons x xs ps) = cons x (take n xs) (take-# n x xs ps) -take-# zero a xs _ = _ -take-# (suc n) a [] ps = _ -take-# (suc n) a (x ∷# xs) (p , ps) = p , take-# n a xs ps +take-# zero y xs _ = _ +take-# (suc n) y [] ps = _ +take-# (suc n) y (x ∷# xs) (p , ps) = p , take-# n y xs ps -drop : {R : Rel A r} → ℕ → List# A R → List# A R -drop zero as = as +drop : ℕ → List# A R → List# A R +drop zero xs = xs drop (suc n) [] = [] -drop (suc n) (a ∷# as) = drop n as +drop (suc n) (x ∷# xs) = drop n xs -module _ {P : Pred A p} (P? : U.Decidable P) where +module _ (P? : U.Decidable {A = A} P) where - takeWhile : {R : Rel A r} → List# A R → List# A R - takeWhile-# : ∀ {R : Rel A r} a (as : List# A R) → a # as → a # takeWhile as + takeWhile : List# A R → List# A R + takeWhile-# : ∀ y (xs : List# A R) → y # xs → y # takeWhile xs takeWhile [] = [] - takeWhile (cons a as ps) = - if does (P? a) then cons a (takeWhile as) (takeWhile-# a as ps) else [] + takeWhile (cons x xs ps) = + if does (P? x) then cons x (takeWhile xs) (takeWhile-# x xs ps) else [] -- this 'with' is needed to cause reduction in the type of 'takeWhile (a ∷# as)' - takeWhile-# a [] _ = _ - takeWhile-# a (x ∷# xs) (p , ps) with does (P? x) - ... | true = p , takeWhile-# a xs ps + takeWhile-# y [] _ = _ + takeWhile-# y (x ∷# xs) (p , ps) with does (P? x) + ... | true = p , takeWhile-# y xs ps ... | false = _ - dropWhile : {R : Rel A r} → List# A R → List# A R + dropWhile : List# A R → List# A R dropWhile [] = [] - dropWhile aas@(a ∷# as) = if does (P? a) then dropWhile as else aas + dropWhile xxs@(x ∷# xs) = if does (P? x) then dropWhile xs else xxs - filter : {R : Rel A r} → List# A R → List# A R - filter-# : ∀ {R : Rel A r} a (as : List# A R) → a # as → a # filter as + filter : List# A R → List# A R + filter-# : ∀ y (xs : List# A R) → y # xs → y # filter xs filter [] = [] - filter (cons a as ps) = - let l = filter as in - if does (P? a) then cons a l (filter-# a as ps) else l + filter (cons x xs ps) = + let l = filter xs in + if does (P? x) then cons x l (filter-# x xs ps) else l - -- this 'with' is needed to cause reduction in the type of 'filter-# a (x ∷# xs)' - filter-# a [] _ = _ - filter-# a (x ∷# xs) (p , ps) with does (P? x) - ... | true = p , filter-# a xs ps - ... | false = filter-# a xs ps + -- this 'with' is needed to cause reduction in the type of 'filter-# y (x ∷# xs)' + filter-# y [] _ = _ + filter-# y (x ∷# xs) (p , ps) with does (P? x) + ... | true = p , filter-# y xs ps + ... | false = filter-# y xs ps ------------------------------------------------------------------------ -- Relationship to List and AllPairs -toList : {R : Rel A r} → List# A R → ∃ (AllPairs R) -toAll : ∀ {R : Rel A r} {a} as → fresh A R a as → All (R a) (proj₁ (toList as)) +toList : List# A R → ∃ (AllPairs R) +toAll : (xs : List# A R) → x # xs → All (R x) (proj₁ (toList xs)) toList [] = -, [] toList (cons x xs ps) = -, toAll xs ps ∷ proj₂ (toList xs) toAll [] ps = [] -toAll (a ∷# as) (p , ps) = p ∷ toAll as ps +toAll (x ∷# xs) (p , ps) = p ∷ toAll xs ps -fromList : ∀ {R : Rel A r} {xs} → AllPairs R xs → List# A R -fromList-# : ∀ {R : Rel A r} {x xs} (ps : AllPairs R xs) → +fromList : ∀ {xs} → AllPairs R xs → List# A R +fromList-# : ∀ {xs} (ps : AllPairs R xs) → All (R x) xs → x # fromList ps fromList [] = [] From 67ef7e19a0c83e5bfd0e760dc85858745db91725 Mon Sep 17 00:00:00 2001 From: jamesmckinna Date: Tue, 27 Jan 2026 11:57:40 +0000 Subject: [PATCH 02/19] refactor: remove `P` from `variable` block --- src/Data/List/Fresh.agda | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Data/List/Fresh.agda b/src/Data/List/Fresh.agda index f8a49e018f..29a1ae4d2e 100644 --- a/src/Data/List/Fresh.agda +++ b/src/Data/List/Fresh.agda @@ -34,7 +34,6 @@ private a b p r s : Level A : Set a B : Set b - P : Pred A p R : Rel A r S : Rel A s x y : A @@ -161,7 +160,7 @@ drop zero xs = xs drop (suc n) [] = [] drop (suc n) (x ∷# xs) = drop n xs -module _ (P? : U.Decidable {A = A} P) where +module _ {P : Pred A p} (P? : U.Decidable {A = A} P) where takeWhile : List# A R → List# A R takeWhile-# : ∀ y (xs : List# A R) → y # xs → y # takeWhile xs From 6af45e404a147870b0e7e5504cfa4c1aecd6ed16 Mon Sep 17 00:00:00 2001 From: jamesmckinna Date: Tue, 27 Jan 2026 18:08:07 +0000 Subject: [PATCH 03/19] refactor: `Properties` follow easily --- src/Data/List/Fresh/Properties.agda | 32 +++++++++++++++-------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/src/Data/List/Fresh/Properties.agda b/src/Data/List/Fresh/Properties.agda index 1f39b1d057..7d8ae09aec 100644 --- a/src/Data/List/Fresh/Properties.agda +++ b/src/Data/List/Fresh/Properties.agda @@ -11,42 +11,44 @@ module Data.List.Fresh.Properties where open import Data.List.Fresh using (List#; _∷#_; _#_; Empty; NonEmpty; cons; []) open import Data.Product.Base using (_,_) open import Level using (Level; _⊔_) +open import Relation.Binary.Definitions as Binary using (_Respects_; _Respectsˡ_) +open import Relation.Binary.Core using (Rel) open import Relation.Nullary.Decidable using (Dec; yes; no) open import Relation.Nullary.Negation using (¬_) -open import Relation.Unary as U using (Pred) -import Relation.Binary.Definitions as B using (_Respectsˡ_; Irrelevant) -open import Relation.Binary.Core using (Rel) - private variable - a b e p r : Level + a b ℓ p r : Level A : Set a B : Set b + R : Rel A r + x y : A + xs : List# A R + ------------------------------------------------------------------------ -- Fresh congruence -module _ {R : Rel A r} {_≈_ : Rel A e} (R≈ : R B.Respectsˡ _≈_) where +module _ {_≈_ : Rel A ℓ} (resp : R Respectsˡ _≈_) where - fresh-respectsˡ : ∀ {x y} {xs : List# A R} → x ≈ y → x # xs → y # xs - fresh-respectsˡ {xs = []} x≈y x#xs = _ + fresh-respectsˡ : ∀ {xs : List# A R} → (_# xs) Respects _≈_ + fresh-respectsˡ {xs = []} x≈y _ = _ fresh-respectsˡ {xs = x ∷# xs} x≈y (r , x#xs) = - R≈ x≈y r , fresh-respectsˡ x≈y x#xs + resp x≈y r , fresh-respectsˡ x≈y x#xs ------------------------------------------------------------------------ -- Empty and NotEmpty -Empty⇒¬NonEmpty : {R : Rel A r} {xs : List# A R} → Empty xs → ¬ (NonEmpty xs) +Empty⇒¬NonEmpty : Empty xs → ¬ (NonEmpty xs) Empty⇒¬NonEmpty [] () -NonEmpty⇒¬Empty : {R : Rel A r} {xs : List# A R} → NonEmpty xs → ¬ (Empty xs) +NonEmpty⇒¬Empty : NonEmpty xs → ¬ (Empty xs) NonEmpty⇒¬Empty () [] -empty? : {R : Rel A r} (xs : List# A R) → Dec (Empty xs) +empty? : (xs : List# A R) → Dec (Empty xs) empty? [] = yes [] -empty? (_ ∷# _) = no (λ ()) +empty? (_ ∷# _) = no λ() -nonEmpty? : {R : Rel A r} (xs : List# A R) → Dec (NonEmpty xs) -nonEmpty? [] = no (λ ()) +nonEmpty? : (xs : List# A R) → Dec (NonEmpty xs) +nonEmpty? [] = no λ() nonEmpty? (cons x xs pr) = yes (cons x xs pr) From de98e4ed907424ce667639af3e28b6ba596ba06b Mon Sep 17 00:00:00 2001 From: jamesmckinna Date: Wed, 28 Jan 2026 11:10:53 +0000 Subject: [PATCH 04/19] refactor: propagate the `variable` style throughout --- src/Data/List/Fresh/Membership/Setoid.agda | 18 ++-- .../Fresh/Membership/Setoid/Properties.agda | 89 +++++++++---------- src/Data/List/Fresh/Relation/Unary/All.agda | 67 +++++++------- .../Fresh/Relation/Unary/All/Properties.agda | 31 ++++--- src/Data/List/Fresh/Relation/Unary/Any.agda | 47 +++++----- 5 files changed, 125 insertions(+), 127 deletions(-) diff --git a/src/Data/List/Fresh/Membership/Setoid.agda b/src/Data/List/Fresh/Membership/Setoid.agda index 6be37629d7..b5d52b397c 100644 --- a/src/Data/List/Fresh/Membership/Setoid.agda +++ b/src/Data/List/Fresh/Membership/Setoid.agda @@ -10,22 +10,26 @@ open import Relation.Binary.Bundles using (Setoid) module Data.List.Fresh.Membership.Setoid {c ℓ} (S : Setoid c ℓ) where -open import Level using (Level; _⊔_) +open import Level using (Level) open import Data.List.Fresh using (List#) open import Data.List.Fresh.Relation.Unary.Any as Any using (Any) -open import Relation.Binary.Core using (Rel) +open import Relation.Binary.Core using (Rel; REL) open import Relation.Nullary.Negation.Core using (¬_) -open Setoid S renaming (Carrier to A) - -infix 4 _∈_ _∉_ +open Setoid S + using (_≈_) + renaming (Carrier to A) private variable r : Level + R : Rel A r + + +infix 4 _∈_ _∉_ -_∈_ : {R : Rel A r} → A → List# A R → Set _ +_∈_ : REL A (List# A R) _ x ∈ xs = Any (x ≈_) xs -_∉_ : {R : Rel A r} → A → List# A R → Set _ +_∉_ : REL A (List# A R) _ x ∉ xs = ¬ (x ∈ xs) diff --git a/src/Data/List/Fresh/Membership/Setoid/Properties.agda b/src/Data/List/Fresh/Membership/Setoid/Properties.agda index 819ee4a893..cf873d61d6 100644 --- a/src/Data/List/Fresh/Membership/Setoid/Properties.agda +++ b/src/Data/List/Fresh/Membership/Setoid/Properties.agda @@ -8,104 +8,99 @@ open import Relation.Binary.Bundles using (Setoid) -module Data.List.Fresh.Membership.Setoid.Properties {c ℓ} (S : Setoid c ℓ) +module Data.List.Fresh.Membership.Setoid.PropertiesJHM {c ℓ} (S : Setoid c ℓ) where -open import Level using (Level; _⊔_) +open import Level using (Level) open import Data.List.Fresh open import Data.List.Fresh.Properties using (fresh-respectsˡ) open import Data.List.Fresh.Membership.Setoid S using (_∈_; _∉_) open import Data.List.Fresh.Relation.Unary.Any using (Any; here; there; _─_) -import Data.List.Fresh.Relation.Unary.Any.Properties as List# +open import Data.List.Fresh.Relation.Unary.Any.Properties as List# using (length-remove) -open import Data.Empty using (⊥; ⊥-elim) open import Data.Nat.Base using (ℕ; suc; zero; _≤_; _<_; z≤n; s≤s; z Date: Wed, 28 Jan 2026 11:12:10 +0000 Subject: [PATCH 05/19] Update src/Data/List/Fresh.agda --- src/Data/List/Fresh.agda | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Data/List/Fresh.agda b/src/Data/List/Fresh.agda index 29a1ae4d2e..35a17fd045 100644 --- a/src/Data/List/Fresh.agda +++ b/src/Data/List/Fresh.agda @@ -23,7 +23,7 @@ open import Data.Maybe.Base as Maybe using (Maybe; just; nothing) open import Data.Nat.Base using (ℕ; zero; suc) open import Function.Base using (_∘′_; flip; id; _on_) open import Relation.Nullary using (does) -open import Relation.Unary as U using (Pred) +open import Relation.Unary as Unary using (Pred; Decidable) open import Relation.Binary.Core using (Rel; REL) import Relation.Binary.Definitions as B using (Reflexive) open import Relation.Nary using (_⇒_; ∀[_]) From 2d081b66316b7e426897822a51250d00beed25f5 Mon Sep 17 00:00:00 2001 From: jamesmckinna <31931406+jamesmckinna@users.noreply.github.com> Date: Wed, 28 Jan 2026 11:34:57 +0000 Subject: [PATCH 06/19] Update src/Data/List/Fresh.agda --- src/Data/List/Fresh.agda | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Data/List/Fresh.agda b/src/Data/List/Fresh.agda index 35a17fd045..6d2458c851 100644 --- a/src/Data/List/Fresh.agda +++ b/src/Data/List/Fresh.agda @@ -120,7 +120,7 @@ fromMaybe : Maybe A → List# A R fromMaybe nothing = [] fromMaybe (just x) = [ x ] -module _ (R-refl : B.Reflexive {A = A} R) where +module _ (refl : Reflexive {A = A} R) where replicate : ℕ → A → List# A R replicate-# : (n : ℕ) (x : A) → x # replicate n x From 09c8b5f5ef2bcfeff1f22bb4c22ba8c1b39c9134 Mon Sep 17 00:00:00 2001 From: jamesmckinna <31931406+jamesmckinna@users.noreply.github.com> Date: Wed, 28 Jan 2026 11:35:15 +0000 Subject: [PATCH 07/19] Update src/Data/List/Fresh.agda --- src/Data/List/Fresh.agda | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Data/List/Fresh.agda b/src/Data/List/Fresh.agda index 6d2458c851..5c351751ed 100644 --- a/src/Data/List/Fresh.agda +++ b/src/Data/List/Fresh.agda @@ -129,7 +129,7 @@ module _ (refl : Reflexive {A = A} R) where replicate (suc n) x = cons x (replicate n x) (replicate-# n x) replicate-# zero x = _ - replicate-# (suc n) x = R-refl , replicate-# n x + replicate-# (suc n) x = refl , replicate-# n x ------------------------------------------------------------------------ -- Operations for deconstructing fresh lists From 502c9033d0a787b038268bb47a62a5bd206ba756 Mon Sep 17 00:00:00 2001 From: jamesmckinna <31931406+jamesmckinna@users.noreply.github.com> Date: Wed, 28 Jan 2026 11:35:53 +0000 Subject: [PATCH 08/19] Update src/Data/List/Fresh.agda --- src/Data/List/Fresh.agda | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Data/List/Fresh.agda b/src/Data/List/Fresh.agda index 5c351751ed..4fdfa5659f 100644 --- a/src/Data/List/Fresh.agda +++ b/src/Data/List/Fresh.agda @@ -160,7 +160,7 @@ drop zero xs = xs drop (suc n) [] = [] drop (suc n) (x ∷# xs) = drop n xs -module _ {P : Pred A p} (P? : U.Decidable {A = A} P) where +module _ {P : Pred A p} (P? : Decidable P) where takeWhile : List# A R → List# A R takeWhile-# : ∀ y (xs : List# A R) → y # xs → y # takeWhile xs From 563ad4b7fefc70cac546c5227ac8ff3cdc846e26 Mon Sep 17 00:00:00 2001 From: jamesmckinna Date: Wed, 28 Jan 2026 11:38:18 +0000 Subject: [PATCH 09/19] fix: module name --- src/Data/List/Fresh/Membership/Setoid/Properties.agda | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Data/List/Fresh/Membership/Setoid/Properties.agda b/src/Data/List/Fresh/Membership/Setoid/Properties.agda index cf873d61d6..398bfdf6d5 100644 --- a/src/Data/List/Fresh/Membership/Setoid/Properties.agda +++ b/src/Data/List/Fresh/Membership/Setoid/Properties.agda @@ -8,7 +8,7 @@ open import Relation.Binary.Bundles using (Setoid) -module Data.List.Fresh.Membership.Setoid.PropertiesJHM {c ℓ} (S : Setoid c ℓ) +module Data.List.Fresh.Membership.Setoid.Properties {c ℓ} (S : Setoid c ℓ) where open import Level using (Level) From 0acb35e3f0d65b45847f0abce1aded3ef5a0d8ed Mon Sep 17 00:00:00 2001 From: jamesmckinna Date: Wed, 28 Jan 2026 11:48:58 +0000 Subject: [PATCH 10/19] fix: bug in `import`s --- src/Data/List/Fresh.agda | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Data/List/Fresh.agda b/src/Data/List/Fresh.agda index 4fdfa5659f..9d9d2bf594 100644 --- a/src/Data/List/Fresh.agda +++ b/src/Data/List/Fresh.agda @@ -25,7 +25,7 @@ open import Function.Base using (_∘′_; flip; id; _on_) open import Relation.Nullary using (does) open import Relation.Unary as Unary using (Pred; Decidable) open import Relation.Binary.Core using (Rel; REL) -import Relation.Binary.Definitions as B using (Reflexive) +open import Relation.Binary.Definitions as Binary using (Reflexive) open import Relation.Nary using (_⇒_; ∀[_]) From cfc60a62c75fced398d6679e24428ffbe3cbc6b7 Mon Sep 17 00:00:00 2001 From: jamesmckinna Date: Wed, 28 Jan 2026 12:22:02 +0000 Subject: [PATCH 11/19] refactor: `Any.Properties`s --- .../Fresh/Relation/Unary/Any/Properties.agda | 60 +++++++++---------- 1 file changed, 28 insertions(+), 32 deletions(-) diff --git a/src/Data/List/Fresh/Relation/Unary/Any/Properties.agda b/src/Data/List/Fresh/Relation/Unary/Any/Properties.agda index 1618295ece..d60073f426 100644 --- a/src/Data/List/Fresh/Relation/Unary/Any/Properties.agda +++ b/src/Data/List/Fresh/Relation/Unary/Any/Properties.agda @@ -19,7 +19,7 @@ open import Function.Base using (_∘′_) open import Level using (Level; _⊔_; Lift) open import Relation.Nullary.Reflects using (invert) open import Relation.Nullary.Decidable.Core -open import Relation.Unary as U using (Pred) +open import Relation.Unary as Unary using (Pred) open import Relation.Binary.Core using (Rel) open import Relation.Nary using (∀[_]; _⇒_; ∁; Decidable) open import Relation.Binary.PropositionalEquality.Core using (_≡_; refl; cong) @@ -30,37 +30,40 @@ private a b p q r s : Level A : Set a B : Set b + P : Pred A p + Q : Pred A q + R : Rel A r + xs ys : List# A R + ------------------------------------------------------------------------ -- NonEmpty -module _ {R : Rel A r} {P : Pred A p} where - - Any⇒NonEmpty : {xs : List# A R} → Any P xs → NonEmpty xs - Any⇒NonEmpty {xs = cons x xs pr} p = cons x xs pr +Any⇒NonEmpty : Any P xs → NonEmpty xs +Any⇒NonEmpty {xs = cons x xs pr} p = cons x xs pr ------------------------------------------------------------------------ -- Correspondence between Any and All -module _ {R : Rel A r} {P : Pred A p} {Q : Pred A q} (P⇒¬Q : ∀[ P ⇒ ∁ Q ]) where +module _ (P⇒¬Q : ∀[ P ⇒ ∁ Q ]) where - Any⇒¬All : {xs : List# A R} → Any P xs → ¬ (All Q xs) + Any⇒¬All : Any P xs → ¬ (All Q xs) Any⇒¬All (here p) (q ∷ _) = P⇒¬Q p q Any⇒¬All (there ps) (_ ∷ qs) = Any⇒¬All ps qs - All⇒¬Any : {xs : List# A R} → All P xs → ¬ (Any Q xs) + All⇒¬Any : All P xs → ¬ (Any Q xs) All⇒¬Any (p ∷ _) (here q) = P⇒¬Q p q All⇒¬Any (_ ∷ ps) (there qs) = All⇒¬Any ps qs -module _ {R : Rel A r} {P : Pred A p} (P? : Decidable P) where +module _ (P? : Decidable P) where - ¬All⇒Any : {xs : List# A R} → ¬ (All P xs) → Any (∁ P) xs + ¬All⇒Any : ¬ (All P xs) → Any (∁ P) xs ¬All⇒Any {xs = []} ¬ps = contradiction [] ¬ps ¬All⇒Any {xs = x ∷# xs} ¬ps with P? x ... | true because [p] = there (¬All⇒Any (¬ps ∘′ (invert [p] ∷_))) ... | false because [¬p] = here (invert [¬p]) - ¬Any⇒All : {xs : List# A R} → ¬ (Any P xs) → All (∁ P) xs + ¬Any⇒All : ¬ (Any P xs) → All (∁ P) xs ¬Any⇒All {xs = []} ¬ps = [] ¬Any⇒All {xs = x ∷# xs} ¬ps with P? x ... | true because [p] = contradiction (here (invert [p])) ¬ps @@ -69,30 +72,23 @@ module _ {R : Rel A r} {P : Pred A p} (P? : Decidable P) where ------------------------------------------------------------------------ -- remove -module _ {R : Rel A r} {P : Pred A p} where - - length-remove : {xs : List# A R} (k : Any P xs) → - length xs ≡ suc (length (xs ─ k)) - length-remove (here _) = refl - length-remove (there p) = cong suc (length-remove p) +length-remove : (k : Any P xs) → length xs ≡ suc (length (xs ─ k)) +length-remove (here _) = refl +length-remove (there p) = cong suc (length-remove p) ------------------------------------------------------------------------ -- append -module _ {R : Rel A r} {P : Pred A p} where - - append⁺ˡ : {xs ys : List# A R} {ps : All (_# ys) xs} → - Any P xs → Any P (append xs ys ps) - append⁺ˡ (here px) = here px - append⁺ˡ (there p) = there (append⁺ˡ p) +append⁺ˡ : {ps : All (_# ys) xs} → Any P xs → Any P (append xs ys ps) +append⁺ˡ (here px) = here px +append⁺ˡ (there p) = there (append⁺ˡ p) - append⁺ʳ : {xs ys : List# A R} {ps : All (_# ys) xs} → - Any P ys → Any P (append xs ys ps) - append⁺ʳ {xs = []} p = p - append⁺ʳ {xs = x ∷# xs} p = there (append⁺ʳ p) +append⁺ʳ : {ps : All (_# ys) xs} → Any P ys → Any P (append xs ys ps) +append⁺ʳ {xs = []} p = p +append⁺ʳ {xs = x ∷# xs} p = there (append⁺ʳ p) - append⁻ : ∀ xs {ys : List# A R} {ps : All (_# ys) xs} → - Any P (append xs ys ps) → Any P xs ⊎ Any P ys - append⁻ [] p = inj₂ p - append⁻ (x ∷# xs) (here px) = inj₁ (here px) - append⁻ (x ∷# xs) (there p) = Sum.map₁ there (append⁻ xs p) +append⁻ : ∀ xs {ps : All (_# ys) xs} → + Any P (append xs ys ps) → Any P xs ⊎ Any P ys +append⁻ [] p = inj₂ p +append⁻ (x ∷# xs) (here px) = inj₁ (here px) +append⁻ (x ∷# xs) (there p) = Sum.map₁ there (append⁻ xs p) From d1d7a7ccade1f32bf380dc995b904856f88c2418 Mon Sep 17 00:00:00 2001 From: jamesmckinna Date: Wed, 28 Jan 2026 12:24:37 +0000 Subject: [PATCH 12/19] fix: quantifier prefix --- src/Data/List/Fresh/Relation/Unary/Any/Properties.agda | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Data/List/Fresh/Relation/Unary/Any/Properties.agda b/src/Data/List/Fresh/Relation/Unary/Any/Properties.agda index d60073f426..c3c045f9a5 100644 --- a/src/Data/List/Fresh/Relation/Unary/Any/Properties.agda +++ b/src/Data/List/Fresh/Relation/Unary/Any/Properties.agda @@ -87,7 +87,7 @@ append⁺ʳ : {ps : All (_# ys) xs} → Any P ys → Any P (append xs ys ps) append⁺ʳ {xs = []} p = p append⁺ʳ {xs = x ∷# xs} p = there (append⁺ʳ p) -append⁻ : ∀ xs {ps : All (_# ys) xs} → +append⁻ : ∀ xs {ys} {ps : All {R = R} (_# ys) xs} → Any P (append xs ys ps) → Any P xs ⊎ Any P ys append⁻ [] p = inj₂ p append⁻ (x ∷# xs) (here px) = inj₁ (here px) From ab384a4b1038ad841766fc2eab24ded360379422 Mon Sep 17 00:00:00 2001 From: jamesmckinna Date: Wed, 28 Jan 2026 12:32:06 +0000 Subject: [PATCH 13/19] final tweaks --- src/Data/List/Fresh.agda | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Data/List/Fresh.agda b/src/Data/List/Fresh.agda index 9d9d2bf594..805b0daddd 100644 --- a/src/Data/List/Fresh.agda +++ b/src/Data/List/Fresh.agda @@ -23,10 +23,10 @@ open import Data.Maybe.Base as Maybe using (Maybe; just; nothing) open import Data.Nat.Base using (ℕ; zero; suc) open import Function.Base using (_∘′_; flip; id; _on_) open import Relation.Nullary using (does) -open import Relation.Unary as Unary using (Pred; Decidable) +open import Relation.Unary as Unary using (Pred) open import Relation.Binary.Core using (Rel; REL) open import Relation.Binary.Definitions as Binary using (Reflexive) -open import Relation.Nary using (_⇒_; ∀[_]) +open import Relation.Nary using (_⇒_; ∀[_]; Decidable) private @@ -45,7 +45,7 @@ private -- If we pick an R such that (R a b) means that a is different from b -- then we have a list of distinct values. -module _ {a} (A : Set a) (R : Rel A r) where +module _ (A : Set a) (R : Rel A r) where data List# : Set (a ⊔ r) fresh : REL A List# r @@ -123,7 +123,7 @@ fromMaybe (just x) = [ x ] module _ (refl : Reflexive {A = A} R) where replicate : ℕ → A → List# A R - replicate-# : (n : ℕ) (x : A) → x # replicate n x + replicate-# : ∀ n x → x # replicate n x replicate zero x = [] replicate (suc n) x = cons x (replicate n x) (replicate-# n x) From 18bf6f0b148063fe599d39578201bb12408ec42a Mon Sep 17 00:00:00 2001 From: jamesmckinna <31931406+jamesmckinna@users.noreply.github.com> Date: Tue, 3 Mar 2026 11:52:47 +0000 Subject: [PATCH 14/19] Update src/Data/List/Fresh/Relation/Unary/Any.agda Use a `Unary` definition, rather than spell it out explicitly. Co-authored-by: G. Allais --- src/Data/List/Fresh/Relation/Unary/Any.agda | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Data/List/Fresh/Relation/Unary/Any.agda b/src/Data/List/Fresh/Relation/Unary/Any.agda index ad5f654215..27042bd860 100644 --- a/src/Data/List/Fresh/Relation/Unary/Any.agda +++ b/src/Data/List/Fresh/Relation/Unary/Any.agda @@ -79,6 +79,6 @@ _─_ = remove module _ (P? : Decidable P) where - any? : ∀ xs → Dec (Any {R = R} P xs) + any? : Decidable (Any {R = R} P) any? [] = no λ() any? (x ∷# xs) = Dec.map ⊎⇔Any (P? x ⊎? any? xs) From 4abd7d06afeea01eb699c6d4658b761f5645704d Mon Sep 17 00:00:00 2001 From: jamesmckinna Date: Tue, 3 Mar 2026 13:18:34 +0000 Subject: [PATCH 15/19] refactor: further streamlining steps; plus one deprecation --- CHANGELOG.md | 5 +++ src/Data/List/Fresh.agda | 14 ++++---- src/Data/List/Fresh/Relation/Unary/All.agda | 4 +-- .../Fresh/Relation/Unary/All/Properties.agda | 12 +++---- src/Data/List/Fresh/Relation/Unary/Any.agda | 36 +++++++++++++------ .../Fresh/Relation/Unary/Any/Properties.agda | 12 +++---- 6 files changed, 50 insertions(+), 33 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1608f59701..cbb0b5d07e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -79,6 +79,11 @@ Deprecated names ¬∀⟶∃¬- ↦ ¬∀⇒∃¬ ``` +* In `Data.List.Fresh.Relation.Unary.Any`: + ```agda + witness ↦ satisfiable + ``` + * In `Data.Rational.Properties`: ```agda nonPos*nonPos⇒nonPos ↦ nonPos*nonPos⇒nonNeg diff --git a/src/Data/List/Fresh.agda b/src/Data/List/Fresh.agda index 805b0daddd..5f056cddb1 100644 --- a/src/Data/List/Fresh.agda +++ b/src/Data/List/Fresh.agda @@ -22,11 +22,11 @@ open import Data.List.Relation.Unary.AllPairs using (AllPairs; []; _∷_) open import Data.Maybe.Base as Maybe using (Maybe; just; nothing) open import Data.Nat.Base using (ℕ; zero; suc) open import Function.Base using (_∘′_; flip; id; _on_) -open import Relation.Nullary using (does) -open import Relation.Unary as Unary using (Pred) open import Relation.Binary.Core using (Rel; REL) open import Relation.Binary.Definitions as Binary using (Reflexive) -open import Relation.Nary using (_⇒_; ∀[_]; Decidable) +open import Relation.Nary using (_⇒_; ∀[_]) +open import Relation.Nullary using (does) +open import Relation.Unary as Unary using (Pred; Decidable) private @@ -145,7 +145,7 @@ tail : List# A R → Maybe (List# A R) tail = Maybe.map proj₂ ∘′ uncons take : ℕ → List# A R → List# A R -take-# : ∀ n y (xs : List# A R) → y # xs → y # take n xs +take-# : ∀ n y xs → y # xs → y # take {R = R} n xs take zero xs = [] take (suc n) [] = [] @@ -163,7 +163,7 @@ drop (suc n) (x ∷# xs) = drop n xs module _ {P : Pred A p} (P? : Decidable P) where takeWhile : List# A R → List# A R - takeWhile-# : ∀ y (xs : List# A R) → y # xs → y # takeWhile xs + takeWhile-# : ∀ y xs → y # xs → y # takeWhile {R = R} xs takeWhile [] = [] takeWhile (cons x xs ps) = @@ -180,7 +180,7 @@ module _ {P : Pred A p} (P? : Decidable P) where dropWhile xxs@(x ∷# xs) = if does (P? x) then dropWhile xs else xxs filter : List# A R → List# A R - filter-# : ∀ y (xs : List# A R) → y # xs → y # filter xs + filter-# : ∀ y xs → y # xs → y # filter {R = R} xs filter [] = [] filter (cons x xs ps) = @@ -197,7 +197,7 @@ module _ {P : Pred A p} (P? : Decidable P) where -- Relationship to List and AllPairs toList : List# A R → ∃ (AllPairs R) -toAll : (xs : List# A R) → x # xs → All (R x) (proj₁ (toList xs)) +toAll : ∀ xs → x # xs → All (R x) (proj₁ (toList {R = R} xs)) toList [] = -, [] toList (cons x xs ps) = -, toAll xs ps ∷ proj₂ (toList xs) diff --git a/src/Data/List/Fresh/Relation/Unary/All.agda b/src/Data/List/Fresh/Relation/Unary/All.agda index 03cfc59e58..769defadee 100644 --- a/src/Data/List/Fresh/Relation/Unary/All.agda +++ b/src/Data/List/Fresh/Relation/Unary/All.agda @@ -58,13 +58,13 @@ map : ∀[ P ⇒ Q ] → All P xs → All Q xs map p⇒q [] = [] map p⇒q (p ∷ ps) = p⇒q p ∷ map p⇒q ps -lookup : All Q xs → (ps : Any P xs) → Q (proj₁ (Any.witness ps)) +lookup : All Q xs → (ps : Any P xs) → Q (proj₁ (Any.satisfiable ps)) lookup (q ∷ _) (here _) = q lookup (_ ∷ qs) (there k) = lookup qs k module _ (P? : Decidable P) where - all? : ∀ xs → Dec (All {R = R} P xs) + all? : Decidable (All {R = R} P) all? [] = yes [] all? (x ∷# xs) = Dec.map′ (uncurry _∷_) uncons (P? x ×? all? xs) diff --git a/src/Data/List/Fresh/Relation/Unary/All/Properties.agda b/src/Data/List/Fresh/Relation/Unary/All/Properties.agda index 41b41cde68..25e1b921d7 100644 --- a/src/Data/List/Fresh/Relation/Unary/All/Properties.agda +++ b/src/Data/List/Fresh/Relation/Unary/All/Properties.agda @@ -8,15 +8,12 @@ module Data.List.Fresh.Relation.Unary.All.Properties where -open import Data.List.Fresh using (List#; []; cons; _∷#_; _#_) +open import Data.List.Fresh using (List#; []; _∷#_; _#_) open import Data.List.Fresh.Relation.Unary.All using (All; []; _∷_; append) -open import Data.Nat.Base using (ℕ; zero; suc) open import Data.Product.Base using (_,_) -open import Function.Base using (_∘′_) -open import Level using (Level; _⊔_; Lift) -open import Relation.Unary as Unary using (Pred) +open import Level using (Level) +open import Relation.Unary as Unary using (Pred) open import Relation.Binary.Core using (Rel) -open import Relation.Binary.PropositionalEquality.Core using (_≡_; refl; cong) private variable @@ -36,7 +33,6 @@ toAll : x # xs → All {R = R} (R x) xs toAll {xs = []} _ = [] toAll {xs = a ∷# as} (p , ps) = p ∷ toAll ps -append⁺ : {ps : All {R = R} (_# ys) xs} → - All P xs → All P ys → All P (append xs ys ps) +append⁺ : ∀ {ps} → All P xs → All P ys → All P (append {R = R} xs ys ps) append⁺ [] pys = pys append⁺ (px ∷ pxs) pys = px ∷ append⁺ pxs pys diff --git a/src/Data/List/Fresh/Relation/Unary/Any.agda b/src/Data/List/Fresh/Relation/Unary/Any.agda index 27042bd860..e884b42643 100644 --- a/src/Data/List/Fresh/Relation/Unary/Any.agda +++ b/src/Data/List/Fresh/Relation/Unary/Any.agda @@ -10,15 +10,15 @@ module Data.List.Fresh.Relation.Unary.Any where open import Level using (Level; _⊔_; Lift) open import Data.List.Fresh using (List#; []; cons; _∷#_; _#_; fresh) -open import Data.Product.Base using (∃; _,_; -,_) +open import Data.Product.Base using (_,_; -,_) open import Data.Sum.Base using (_⊎_; [_,_]′; inj₁; inj₂) open import Function.Bundles using (_⇔_; mk⇔) -open import Level using (Level; _⊔_; Lift) +open import Level using (Level; _⊔_) +open import Relation.Binary.Core using (Rel) open import Relation.Nullary.Negation using (¬_; contradiction) open import Relation.Nullary.Decidable as Dec using (Dec; no; _⊎?_) open import Relation.Unary as Unary - using (Pred; IUniversal; Universal; Decidable; _⇒_; _∪_; _∩_) -open import Relation.Binary.Core using (Rel) + using (Pred; Satisfiable; Decidable; _⊆_; _∪_; _∩_) private variable @@ -57,16 +57,16 @@ module _ {pr : fresh A R x xs} where ⊎⇔Any : (P x ⊎ Any P xs) ⇔ Any P (cons x xs pr) ⊎⇔Any = mk⇔ fromSum toSum -map : ∀[ P ⇒ Q ] → Any P xs → Any Q xs +map : P ⊆ Q → Any P xs → Any Q xs map p⇒q (here p) = here (p⇒q p) map p⇒q (there p) = there (map p⇒q p) -witness : Any P xs → ∃ P -witness (here p) = -, p -witness (there ps) = witness ps +satisfiable : Any P xs → Satisfiable P +satisfiable (here p) = -, p +satisfiable (there ps) = satisfiable ps -remove : (xs : List# A R) → Any P xs → List# A R -remove-# : (p : Any {R = R} P xs) → x # xs → x # (remove xs p) +remove : ∀ xs → Any {R = R} P xs → List# A R +remove-# : (p : Any {R = R} P xs) → x # xs → x # remove xs p remove (_ ∷# xs) (here _) = xs remove (cons x xs pr) (there k) = cons x (remove xs k) (remove-# k pr) @@ -82,3 +82,19 @@ module _ (P? : Decidable P) where any? : Decidable (Any {R = R} P) any? [] = no λ() any? (x ∷# xs) = Dec.map ⊎⇔Any (P? x ⊎? any? xs) + + +------------------------------------------------------------------------ +-- DEPRECATED NAMES +------------------------------------------------------------------------ +-- Please use the new names as continuing support for the old names is +-- not guaranteed. + +-- Version 2.4 + +witness = satisfiable +{-# WARNING_ON_USAGE witness +"Warning: witness was deprecated in v2.4. +Please use satisfiable instead." +#-} + diff --git a/src/Data/List/Fresh/Relation/Unary/Any/Properties.agda b/src/Data/List/Fresh/Relation/Unary/Any/Properties.agda index c3c045f9a5..6b07568d7b 100644 --- a/src/Data/List/Fresh/Relation/Unary/Any/Properties.agda +++ b/src/Data/List/Fresh/Relation/Unary/Any/Properties.agda @@ -16,14 +16,14 @@ open import Data.Nat.Base using (ℕ; zero; suc) open import Data.Product.Base using (_,_) open import Data.Sum.Base as Sum using (_⊎_; inj₁; inj₂) open import Function.Base using (_∘′_) -open import Level using (Level; _⊔_; Lift) -open import Relation.Nullary.Reflects using (invert) -open import Relation.Nullary.Decidable.Core -open import Relation.Unary as Unary using (Pred) +open import Level using (Level) open import Relation.Binary.Core using (Rel) -open import Relation.Nary using (∀[_]; _⇒_; ∁; Decidable) open import Relation.Binary.PropositionalEquality.Core using (_≡_; refl; cong) -open import Relation.Nullary.Negation.Core using (contradiction; ¬_) +open import Relation.Nary using (∀[_]; _⇒_; ∁; Decidable) +open import Relation.Nullary.Decidable.Core +open import Relation.Nullary.Negation.Core using (¬_; contradiction) +open import Relation.Nullary.Reflects using (invert) +open import Relation.Unary as Unary using (Pred) private variable From fcbf06635bf99e8cfbabf15ee9432943745614bc Mon Sep 17 00:00:00 2001 From: jamesmckinna Date: Tue, 3 Mar 2026 16:48:34 +0000 Subject: [PATCH 16/19] refactor: introduce new notation --- CHANGELOG.md | 5 +++ src/Data/List/Fresh.agda | 12 ++++--- .../Fresh/Membership/Setoid/Properties.agda | 6 ++-- src/Data/List/Fresh/Relation/Unary/All.agda | 5 +-- .../Fresh/Relation/Unary/All/Properties.agda | 6 ++-- src/Data/List/Fresh/Relation/Unary/Any.agda | 6 ++-- .../Fresh/Relation/Unary/Any/Properties.agda | 31 +++++++++---------- 7 files changed, 40 insertions(+), 31 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cbb0b5d07e..9055a5429e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -236,6 +236,11 @@ Additions to existing modules search-least⟨¬_⟩ : Decidable P → Π[ P ] ⊎ Least⟨ ∁ P ⟩ ``` +* In `Data.List.Fresh`: + ```agda + _#[_]_ : A → (R : Rel A r) → Pred (List# A R) _ + ``` + * In `Data.List.NonEmpty.Relation.Unary.All`: ``` map : P ⊆ Q → All P xs → All Q xs diff --git a/src/Data/List/Fresh.agda b/src/Data/List/Fresh.agda index 5f056cddb1..c225a4b6a1 100644 --- a/src/Data/List/Fresh.agda +++ b/src/Data/List/Fresh.agda @@ -66,10 +66,14 @@ module _ (A : Set a) (R : Rel A r) where fresh a [] = ⊤ fresh a (x ∷# xs) = R a x × fresh a xs --- Convenient notation for freshness making A and R implicit parameters -infix 5 _#_ +-- Convenient notation for freshness making A (and R) implicit +infix 5 _#[_]_ _#_ + +_#[_]_ : A → (R : Rel A r) → Pred (List# A R) _ +x #[ R ] xs = fresh _ R x xs + _#_ : REL A (List# A R) _ -_#_ = fresh _ _ +x # xs = x #[ _ ] xs ------------------------------------------------------------------------ -- Operations for modifying fresh lists @@ -197,7 +201,7 @@ module _ {P : Pred A p} (P? : Decidable P) where -- Relationship to List and AllPairs toList : List# A R → ∃ (AllPairs R) -toAll : ∀ xs → x # xs → All (R x) (proj₁ (toList {R = R} xs)) +toAll : ∀ xs → x #[ R ] xs → All (R x) (proj₁ (toList xs)) toList [] = -, [] toList (cons x xs ps) = -, toAll xs ps ∷ proj₂ (toList xs) diff --git a/src/Data/List/Fresh/Membership/Setoid/Properties.agda b/src/Data/List/Fresh/Membership/Setoid/Properties.agda index 398bfdf6d5..32a9658178 100644 --- a/src/Data/List/Fresh/Membership/Setoid/Properties.agda +++ b/src/Data/List/Fresh/Membership/Setoid/Properties.agda @@ -54,7 +54,7 @@ private module _ (R⇒≉ : ∀[ R ⇒ _≉_ ]) where - fresh⇒∉ : ∀ {xs : List# A R} → x # xs → x ∉ xs + fresh⇒∉ : x #[ R ] xs → x ∉ xs fresh⇒∉ (r , _) (here x≈y) = R⇒≉ r x≈y fresh⇒∉ (_ , x#xs) (there x∈xs) = fresh⇒∉ x#xs x∈xs @@ -82,12 +82,12 @@ module _ (R⇒≉ : ∀[ R ⇒ _≉_ ]) (≉⇒R : ∀[ _≉_ ⇒ R ]) where R≈ : R Binary.Respectsˡ _≈_ R≈ x≈y Rxz = ≉⇒R (R⇒≉ Rxz ∘′ trans x≈y) - fresh-remove : ∀ {xs : List# A R} (x∈xs : x ∈ xs) → x # (xs ─ x∈xs) + fresh-remove : ∀ (x∈xs : x ∈ xs) → x #[ R ] (xs ─ x∈xs) fresh-remove {xs = cons x xs pr} (here x≈y) = fresh-respectsˡ R≈ (sym x≈y) pr fresh-remove {xs = cons x xs pr} (there x∈xs) = ≉⇒R (distinct x∈xs (fresh⇒∉ R⇒≉ pr)) , fresh-remove x∈xs - ∉-remove : ∀ {xs : List# A R} (x∈xs : x ∈ xs) → x ∉ (xs ─ x∈xs) + ∉-remove : ∀ {xs} (x∈xs : x ∈ xs) → x ∉ (xs ─ x∈xs) ∉-remove x∈xs = fresh⇒∉ R⇒≉ (fresh-remove x∈xs) ------------------------------------------------------------------------ diff --git a/src/Data/List/Fresh/Relation/Unary/All.agda b/src/Data/List/Fresh/Relation/Unary/All.agda index 769defadee..0b831cec33 100644 --- a/src/Data/List/Fresh/Relation/Unary/All.agda +++ b/src/Data/List/Fresh/Relation/Unary/All.agda @@ -8,7 +8,7 @@ module Data.List.Fresh.Relation.Unary.All where -open import Data.List.Fresh using (List#; []; cons; _∷#_; _#_) +open import Data.List.Fresh using (List#; []; cons; _∷#_; _#[_]_; _#_) open import Data.List.Fresh.Relation.Unary.Any as Any using (Any; here; there) open import Data.Product.Base using (_×_; _,_; proj₁; uncurry) open import Data.Sum.Base as Sum using (inj₁; inj₂; [_,_]′) @@ -29,6 +29,7 @@ private Q : Pred A q x : A xs : List# A R + pr : x #[ R ] xs module _ {A : Set a} {R : Rel A r} (P : Pred A p) where @@ -37,7 +38,7 @@ module _ {A : Set a} {R : Rel A r} (P : Pred A p) where data All : List# A R → Set (p ⊔ a ⊔ r) where [] : All [] - _∷_ : ∀ {x xs pr} → P x → All xs → All (cons x xs pr) + _∷_ : P x → All xs → All (cons x xs pr) uncons : ∀ {pr} → All P (cons x xs pr) → P x × All P xs diff --git a/src/Data/List/Fresh/Relation/Unary/All/Properties.agda b/src/Data/List/Fresh/Relation/Unary/All/Properties.agda index 25e1b921d7..802a8d001c 100644 --- a/src/Data/List/Fresh/Relation/Unary/All/Properties.agda +++ b/src/Data/List/Fresh/Relation/Unary/All/Properties.agda @@ -8,7 +8,7 @@ module Data.List.Fresh.Relation.Unary.All.Properties where -open import Data.List.Fresh using (List#; []; _∷#_; _#_) +open import Data.List.Fresh using (List#; []; _∷#_; _#[_]_; _#_) open import Data.List.Fresh.Relation.Unary.All using (All; []; _∷_; append) open import Data.Product.Base using (_,_) open import Level using (Level) @@ -25,11 +25,11 @@ private xs ys : List# A R -fromAll : All {R = R} (R x) xs → x # xs +fromAll : All (R x) xs → x #[ R ] xs fromAll [] = _ fromAll (p ∷ ps) = p , fromAll ps -toAll : x # xs → All {R = R} (R x) xs +toAll : x #[ R ] xs → All (R x) xs toAll {xs = []} _ = [] toAll {xs = a ∷# as} (p , ps) = p ∷ toAll ps diff --git a/src/Data/List/Fresh/Relation/Unary/Any.agda b/src/Data/List/Fresh/Relation/Unary/Any.agda index e884b42643..ea7401ee4f 100644 --- a/src/Data/List/Fresh/Relation/Unary/Any.agda +++ b/src/Data/List/Fresh/Relation/Unary/Any.agda @@ -9,7 +9,7 @@ module Data.List.Fresh.Relation.Unary.Any where open import Level using (Level; _⊔_; Lift) -open import Data.List.Fresh using (List#; []; cons; _∷#_; _#_; fresh) +open import Data.List.Fresh using (List#; []; cons; _∷#_; _#[_]_; _#_) open import Data.Product.Base using (_,_; -,_) open import Data.Sum.Base using (_⊎_; [_,_]′; inj₁; inj₂) open import Function.Bundles using (_⇔_; mk⇔) @@ -18,7 +18,7 @@ open import Relation.Binary.Core using (Rel) open import Relation.Nullary.Negation using (¬_; contradiction) open import Relation.Nullary.Decidable as Dec using (Dec; no; _⊎?_) open import Relation.Unary as Unary - using (Pred; Satisfiable; Decidable; _⊆_; _∪_; _∩_) + using (Pred; Satisfiable; Decidable; _⊆_) private variable @@ -37,7 +37,7 @@ module _ {A : Set a} {R : Rel A r} (P : Pred A p) where here : ∀ {x xs pr} → P x → Any (cons x xs pr) there : ∀ {x xs pr} → Any xs → Any (cons x xs pr) -module _ {pr : fresh A R x xs} where +module _ {pr : x #[ R ] xs} where head : ¬ Any P xs → Any P (cons x xs pr) → P x head ¬tail (here p) = p diff --git a/src/Data/List/Fresh/Relation/Unary/Any/Properties.agda b/src/Data/List/Fresh/Relation/Unary/Any/Properties.agda index 6b07568d7b..0b8ddb4605 100644 --- a/src/Data/List/Fresh/Relation/Unary/Any/Properties.agda +++ b/src/Data/List/Fresh/Relation/Unary/Any/Properties.agda @@ -12,18 +12,17 @@ open import Data.Bool.Base using (true; false) open import Data.List.Fresh using (List#; _∷#_; _#_; NonEmpty; cons; length; []) open import Data.List.Fresh.Relation.Unary.All using (All; _∷_; append; []) open import Data.List.Fresh.Relation.Unary.Any using (Any; here; there; _─_) -open import Data.Nat.Base using (ℕ; zero; suc) +open import Data.Nat.Base using (suc) open import Data.Product.Base using (_,_) open import Data.Sum.Base as Sum using (_⊎_; inj₁; inj₂) open import Function.Base using (_∘′_) open import Level using (Level) open import Relation.Binary.Core using (Rel) open import Relation.Binary.PropositionalEquality.Core using (_≡_; refl; cong) -open import Relation.Nary using (∀[_]; _⇒_; ∁; Decidable) open import Relation.Nullary.Decidable.Core open import Relation.Nullary.Negation.Core using (¬_; contradiction) open import Relation.Nullary.Reflects using (invert) -open import Relation.Unary as Unary using (Pred) +open import Relation.Unary as Unary using (Pred; _⊆_; ∁; Decidable) private variable @@ -45,27 +44,27 @@ Any⇒NonEmpty {xs = cons x xs pr} p = cons x xs pr ------------------------------------------------------------------------ -- Correspondence between Any and All -module _ (P⇒¬Q : ∀[ P ⇒ ∁ Q ]) where +module _ (P⇒¬Q : P ⊆ ∁ Q) where - Any⇒¬All : Any P xs → ¬ (All Q xs) + Any⇒¬All : Any {R = R} P ⊆ ∁ (All Q) Any⇒¬All (here p) (q ∷ _) = P⇒¬Q p q Any⇒¬All (there ps) (_ ∷ qs) = Any⇒¬All ps qs - All⇒¬Any : All P xs → ¬ (Any Q xs) + All⇒¬Any : All {R = R} P ⊆ ∁ (Any Q) All⇒¬Any (p ∷ _) (here q) = P⇒¬Q p q All⇒¬Any (_ ∷ ps) (there qs) = All⇒¬Any ps qs module _ (P? : Decidable P) where - ¬All⇒Any : ¬ (All P xs) → Any (∁ P) xs - ¬All⇒Any {xs = []} ¬ps = contradiction [] ¬ps - ¬All⇒Any {xs = x ∷# xs} ¬ps with P? x + ¬All⇒Any : ∁ (All {R = R} P) ⊆ Any (∁ P) + ¬All⇒Any {x = []} ¬ps = contradiction [] ¬ps + ¬All⇒Any {x = x ∷# xs} ¬ps with P? x ... | true because [p] = there (¬All⇒Any (¬ps ∘′ (invert [p] ∷_))) ... | false because [¬p] = here (invert [¬p]) - ¬Any⇒All : ¬ (Any P xs) → All (∁ P) xs - ¬Any⇒All {xs = []} ¬ps = [] - ¬Any⇒All {xs = x ∷# xs} ¬ps with P? x + ¬Any⇒All : ∁ (Any {R = R} P) ⊆ All (∁ P) + ¬Any⇒All {x = []} ¬ps = [] + ¬Any⇒All {x = x ∷# xs} ¬ps with P? x ... | true because [p] = contradiction (here (invert [p])) ¬ps ... | false because [¬p] = invert [¬p] ∷ ¬Any⇒All (¬ps ∘′ there) @@ -79,16 +78,16 @@ length-remove (there p) = cong suc (length-remove p) ------------------------------------------------------------------------ -- append -append⁺ˡ : {ps : All (_# ys) xs} → Any P xs → Any P (append xs ys ps) +append⁺ˡ : ∀ {ps} → Any P xs → Any P (append {R = R} xs ys ps) append⁺ˡ (here px) = here px append⁺ˡ (there p) = there (append⁺ˡ p) -append⁺ʳ : {ps : All (_# ys) xs} → Any P ys → Any P (append xs ys ps) +append⁺ʳ : ∀ {ps} → Any P ys → Any P (append {R = R} xs ys ps) append⁺ʳ {xs = []} p = p append⁺ʳ {xs = x ∷# xs} p = there (append⁺ʳ p) -append⁻ : ∀ xs {ys} {ps : All {R = R} (_# ys) xs} → - Any P (append xs ys ps) → Any P xs ⊎ Any P ys +append⁻ : ∀ xs {ys} {ps} → + Any P (append {R = R} xs ys ps) → Any P xs ⊎ Any P ys append⁻ [] p = inj₂ p append⁻ (x ∷# xs) (here px) = inj₁ (here px) append⁻ (x ∷# xs) (there p) = Sum.map₁ there (append⁻ xs p) From 8dd0e3cd49170724dee133a60a99b328eb3b0117 Mon Sep 17 00:00:00 2001 From: jamesmckinna Date: Tue, 3 Mar 2026 17:40:50 +0000 Subject: [PATCH 17/19] final tweaks --- src/Data/List/Fresh/Relation/Unary/All.agda | 8 ++++---- src/Data/List/Fresh/Relation/Unary/Any.agda | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Data/List/Fresh/Relation/Unary/All.agda b/src/Data/List/Fresh/Relation/Unary/All.agda index 0b831cec33..5fc14ca1a4 100644 --- a/src/Data/List/Fresh/Relation/Unary/All.agda +++ b/src/Data/List/Fresh/Relation/Unary/All.agda @@ -14,10 +14,10 @@ open import Data.Product.Base using (_×_; _,_; proj₁; uncurry) open import Data.Sum.Base as Sum using (inj₁; inj₂; [_,_]′) open import Function.Base using (_∘_; _$_) open import Level using (Level; _⊔_; Lift) +open import Relation.Binary.Core using (Rel) open import Relation.Nullary.Decidable.Core as Dec using (Dec; yes; no; _×?_) open import Relation.Unary as Unary - using (Pred; IUniversal; Universal; Decidable; _⇒_; _∪_; _∩_) -open import Relation.Binary.Core using (Rel) + using (Pred; _⊆_; Universal; _∪_; Decidable) private @@ -44,7 +44,7 @@ module _ {A : Set a} {R : Rel A r} (P : Pred A p) where uncons : ∀ {pr} → All P (cons x xs pr) → P x × All P xs uncons (p ∷ ps) = p , ps -append : (xs ys : List# A R) → All (_# ys) xs → List# A R +append : ∀ xs ys → All (_#[ R ] ys) xs → List# A R append-# : ∀ xs ys {ps} → x # xs → x # ys → x # append {R = R} xs ys ps append [] ys _ = ys @@ -55,7 +55,7 @@ append (cons x xs pr) ys ps = append-# [] ys x#xs x#ys = x#ys append-# (cons x xs pr) ys (r , x#xs) x#ys = r , append-# xs ys x#xs x#ys -map : ∀[ P ⇒ Q ] → All P xs → All Q xs +map : P ⊆ Q → All P xs → All Q xs map p⇒q [] = [] map p⇒q (p ∷ ps) = p⇒q p ∷ map p⇒q ps diff --git a/src/Data/List/Fresh/Relation/Unary/Any.agda b/src/Data/List/Fresh/Relation/Unary/Any.agda index ea7401ee4f..1508fdb708 100644 --- a/src/Data/List/Fresh/Relation/Unary/Any.agda +++ b/src/Data/List/Fresh/Relation/Unary/Any.agda @@ -8,7 +8,6 @@ module Data.List.Fresh.Relation.Unary.Any where -open import Level using (Level; _⊔_; Lift) open import Data.List.Fresh using (List#; []; cons; _∷#_; _#[_]_; _#_) open import Data.Product.Base using (_,_; -,_) open import Data.Sum.Base using (_⊎_; [_,_]′; inj₁; inj₂) @@ -29,13 +28,14 @@ private Q : Pred A q x : A xs : List# A R + pr : x #[ R ] xs module _ {A : Set a} {R : Rel A r} (P : Pred A p) where data Any : List# A R → Set (p ⊔ a ⊔ r) where - here : ∀ {x xs pr} → P x → Any (cons x xs pr) - there : ∀ {x xs pr} → Any xs → Any (cons x xs pr) + here : P x → Any (cons x xs pr) + there : Any xs → Any (cons x xs pr) module _ {pr : x #[ R ] xs} where From d0ca96d4e1817fa0c10ba74905194cb6d41b8956 Mon Sep 17 00:00:00 2001 From: jamesmckinna Date: Tue, 3 Mar 2026 18:22:27 +0000 Subject: [PATCH 18/19] add Guillaume's characterisation, plus one deprecation --- CHANGELOG.md | 13 ++++- .../Fresh/Membership/Setoid/Properties.agda | 53 ++++++++++++++----- 2 files changed, 52 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1252ed0014..744c273212 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -89,6 +89,11 @@ Deprecated names ¬∀⟶∃¬- ↦ ¬∀⇒∃¬ ``` +* In `Data.List.Fresh.Membership.Setoid.Properties`: + ```agda + ≈-subst-∈ ↦ ∈-resp-≈ + ``` + * In `Data.List.Fresh.Relation.Unary.Any`: ```agda witness ↦ satisfiable @@ -284,7 +289,13 @@ Additions to existing modules * In `Data.List.Fresh`: ```agda _#[_]_ : A → (R : Rel A r) → Pred (List# A R) _ - ``` + ``` + +* In `Data.List.Fresh.Membership.Setoid.Properties`: + ```agda + ∉-All[x≉] : x ∉ xs → All (x ≉_) xs + All[x≉]-∉ : All (x ≉_) xs → x ∉ xs + ``` * In `Data.List.NonEmpty.Relation.Unary.All`: ``` diff --git a/src/Data/List/Fresh/Membership/Setoid/Properties.agda b/src/Data/List/Fresh/Membership/Setoid/Properties.agda index 32a9658178..96cbb50b79 100644 --- a/src/Data/List/Fresh/Membership/Setoid/Properties.agda +++ b/src/Data/List/Fresh/Membership/Setoid/Properties.agda @@ -15,7 +15,8 @@ open import Level using (Level) open import Data.List.Fresh open import Data.List.Fresh.Properties using (fresh-respectsˡ) open import Data.List.Fresh.Membership.Setoid S using (_∈_; _∉_) -open import Data.List.Fresh.Relation.Unary.Any using (Any; here; there; _─_) +open import Data.List.Fresh.Relation.Unary.All as All using (All; []; _∷_) +open import Data.List.Fresh.Relation.Unary.Any using (Any; here; there; remove; _─_) open import Data.List.Fresh.Relation.Unary.Any.Properties as List# using (length-remove) open import Data.Nat.Base using (ℕ; suc; zero; _≤_; _<_; z≤n; s≤s; z Date: Tue, 3 Mar 2026 18:24:23 +0000 Subject: [PATCH 19/19] fix: whitespace --- src/Data/List/Fresh/Membership/Setoid/Properties.agda | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Data/List/Fresh/Membership/Setoid/Properties.agda b/src/Data/List/Fresh/Membership/Setoid/Properties.agda index 96cbb50b79..5fdc702104 100644 --- a/src/Data/List/Fresh/Membership/Setoid/Properties.agda +++ b/src/Data/List/Fresh/Membership/Setoid/Properties.agda @@ -83,7 +83,7 @@ module _ (R⇒≉ : ∀[ R ⇒ _≉_ ]) (≉⇒R : ∀[ _≉_ ⇒ R ]) where fresh-remove {xs = cons x xs pr} (here x≈y) = fresh-respectsˡ resp (sym x≈y) pr where resp : R Respectsˡ _≈_ - resp x≈y Rxz = ≉⇒R (R⇒≉ Rxz ∘′ trans x≈y) + resp x≈y Rxz = ≉⇒R (R⇒≉ Rxz ∘′ trans x≈y) fresh-remove {xs = cons x xs pr} (there x∈xs) = ≉⇒R (distinct x∈xs (fresh⇒∉ R⇒≉ pr)) , fresh-remove x∈xs