Skip to content

Commit a25efd5

Browse files
guilhermehasMatthewDaggitt
authored andcommitted
Added foldr of permutation of Commutative Monoid (#1944)
1 parent ff24b7c commit a25efd5

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

CHANGELOG.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -3361,6 +3361,11 @@ This is a full list of proofs that have changed form to use irrelevant instance
33613361
<-weakInduction-startingFrom : P i → (∀ j → P (inject₁ j) → P (suc j)) → ∀ {j} → j ≥ i → P j
33623362
```
33633363

3364+
* In `Data.List.Relation.Binary.Permutation.Setoid.Properties`:
3365+
```agda
3366+
foldr-commMonoid : xs ↭ ys → foldr _∙_ ε xs ≈ foldr _∙_ ε ys
3367+
```
3368+
33643369
* Added new module to `Data.Rational.Unnormalised.Properties`
33653370
```agda
33663371
module ≃-Reasoning = SetoidReasoning ≃-setoid
@@ -3442,4 +3447,4 @@ This is a full list of proofs that have changed form to use irrelevant instance
34423447
b #⟨ b#c ⟩
34433448
c ≈⟨ c≈d ⟩
34443449
d ∎
3445-
```
3450+
```

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

+29
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ module Data.List.Relation.Binary.Permutation.Setoid.Properties
1616
where
1717

1818
open import Algebra
19+
import Algebra.Properties.CommutativeMonoid as ACM
1920
open import Data.Bool.Base using (true; false)
2021
open import Data.List.Base as List hiding (head; tail)
2122
open import Data.List.Relation.Binary.Pointwise as Pointwise
@@ -36,6 +37,7 @@ open import Data.Product.Base using (_,_; _×_; ∃; ∃₂; proj₁; proj₂)
3637
open import Function.Base using (_∘_; _⟨_⟩_; flip)
3738
open import Level using (Level; _⊔_)
3839
open import Relation.Unary using (Pred; Decidable)
40+
import Relation.Binary.Reasoning.Setoid as RelSetoid
3941
open import Relation.Binary.Properties.Setoid S using (≉-resp₂)
4042
open import Relation.Binary.PropositionalEquality.Core as ≡
4143
using (_≡_ ; refl; sym; cong; cong₂; subst; _≢_)
@@ -474,3 +476,30 @@ module _ {ℓ} {R : Rel A ℓ} (R? : B.Decidable R) where
474476
++↭ʳ++ : (xs ys : List A) xs ++ ys ↭ xs ʳ++ ys
475477
++↭ʳ++ [] ys = ↭-refl
476478
++↭ʳ++ (x ∷ xs) ys = ↭-trans (↭-sym (↭-shift xs ys)) (++↭ʳ++ xs (x ∷ ys))
479+
480+
------------------------------------------------------------------------
481+
-- foldr of Commutative Monoid
482+
483+
module _ {_∙_ : Op₂ A} {ε : A} (isCmonoid : IsCommutativeMonoid _≈_ _∙_ ε) where
484+
open module CM = IsCommutativeMonoid isCmonoid
485+
486+
private
487+
module S = RelSetoid setoid
488+
489+
cmonoid : CommutativeMonoid _ _
490+
cmonoid = record { isCommutativeMonoid = isCmonoid }
491+
492+
open ACM cmonoid
493+
494+
foldr-commMonoid : {xs ys} xs ↭ ys foldr _∙_ ε xs ≈ foldr _∙_ ε ys
495+
foldr-commMonoid (refl []) = CM.refl
496+
foldr-commMonoid (refl (x≈y ∷ xs≈ys)) = ∙-cong x≈y (foldr-commMonoid (Permutation.refl xs≈ys))
497+
foldr-commMonoid (prep x≈y xs↭ys) = ∙-cong x≈y (foldr-commMonoid xs↭ys)
498+
foldr-commMonoid (swap {xs} {ys} {x} {y} {x′} {y′} x≈x′ y≈y′ xs↭ys) = S.begin
499+
x ∙ (y ∙ foldr _∙_ ε xs) S.≈⟨ ∙-congˡ (∙-congˡ (foldr-commMonoid xs↭ys)) ⟩
500+
x ∙ (y ∙ foldr _∙_ ε ys) S.≈˘⟨ assoc x y (foldr _∙_ ε ys) ⟩
501+
(x ∙ y) ∙ foldr _∙_ ε ys S.≈⟨ ∙-congʳ (comm x y) ⟩
502+
(y ∙ x) ∙ foldr _∙_ ε ys S.≈⟨ ∙-congʳ (∙-cong y≈y′ x≈x′) ⟩
503+
(y′ ∙ x′) ∙ foldr _∙_ ε ys S.≈⟨ assoc y′ x′ (foldr _∙_ ε ys) ⟩
504+
y′ ∙ (x′ ∙ foldr _∙_ ε ys) S.∎
505+
foldr-commMonoid (trans xs↭ys ys↭zs) = CM.trans (foldr-commMonoid xs↭ys) (foldr-commMonoid ys↭zs)

0 commit comments

Comments
 (0)