Skip to content

Commit ee36a77

Browse files
authored
Add filter-↭ (#2589)
1 parent 9897c20 commit ee36a77

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,16 @@ Additions to existing modules
130130
quasiring : Quasiring c ℓ → Quasiring (a ⊔ c) (a ⊔ ℓ)
131131
commutativeRing : CommutativeRing c ℓ → CommutativeRing (a ⊔ c) (a ⊔ ℓ)
132132
```
133+
133134
* In `Data.List.Properties`:
134135
```agda
135136
map-applyUpTo : ∀ (f : ℕ → A) (g : A → B) n → map g (applyUpTo f n) ≡ applyUpTo (g ∘ f) n
136137
map-applyDownFrom : ∀ (f : ℕ → A) (g : A → B) n → map g (applyDownFrom f n) ≡ applyDownFrom (g ∘ f) n
137138
map-upTo : ∀ (f : ℕ → A) n → map f (upTo n) ≡ applyUpTo f n
138139
map-downFrom : ∀ (f : ℕ → A) n → map f (downFrom n) ≡ applyDownFrom f n
139140
```
141+
142+
* In `Data.List.Relation.Binary.Permutation.PropositionalProperties`:
143+
```agda
144+
filter-↭ : ∀ (P? : Pred.Decidable P) → xs ↭ ys → filter P? xs ↭ filter P? ys
145+
```

src/Data/List/Relation/Binary/Permutation/Propositional/Properties.agda

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ open import Data.Product.Base using (_,_; _×_; ∃; ∃₂)
2626
open import Data.Maybe.Base using (Maybe; just; nothing)
2727
open import Function.Base using (_∘_; _⟨_⟩_; _$_)
2828
open import Level using (Level)
29-
open import Relation.Unary using (Pred)
29+
open import Relation.Unary as Pred using (Pred)
3030
open import Relation.Binary.Core using (Rel; _Preserves_⟶_; _Preserves₂_⟶_⟶_)
3131
open import Relation.Binary.Definitions using (_Respects_; Decidable)
3232
open import Relation.Binary.PropositionalEquality.Core as ≡
@@ -372,6 +372,21 @@ module _ {ℓ} {R : Rel A ℓ} (R? : Decidable R) where
372372
x ∷ xs ++ y ∷ ys ∎
373373
where open PermutationReasoning
374374

375+
------------------------------------------------------------------------
376+
-- filter
377+
378+
filter-↭ : {p} {P : Pred A p} (P? : Pred.Decidable P) xs ↭ ys filter P? xs ↭ filter P? ys
379+
filter-↭ P? refl = refl
380+
filter-↭ P? (prep x xs↭ys) with P? x
381+
... | yes _ = prep x (filter-↭ P? xs↭ys)
382+
... | no _ = filter-↭ P? xs↭ys
383+
filter-↭ P? (swap x y xs↭ys) with P? x in eqˣ | P? y in eqʸ
384+
... | yes _ | yes _ rewrite eqˣ rewrite eqʸ = swap x y (filter-↭ P? xs↭ys)
385+
... | yes _ | no _ rewrite eqˣ rewrite eqʸ = prep x (filter-↭ P? xs↭ys)
386+
... | no _ | yes _ rewrite eqˣ rewrite eqʸ = prep y (filter-↭ P? xs↭ys)
387+
... | no _ | no _ rewrite eqˣ rewrite eqʸ = filter-↭ P? xs↭ys
388+
filter-↭ P? (trans xs↭ys ys↭zs) = ↭-trans (filter-↭ P? xs↭ys) (filter-↭ P? ys↭zs)
389+
375390
------------------------------------------------------------------------
376391
-- catMaybes
377392

0 commit comments

Comments
 (0)