@@ -16,6 +16,7 @@ module Data.List.Relation.Binary.Permutation.Setoid.Properties
16
16
where
17
17
18
18
open import Algebra
19
+ import Algebra.Properties.CommutativeMonoid as ACM
19
20
open import Data.Bool.Base using (true; false)
20
21
open import Data.List.Base as List hiding (head; tail)
21
22
open import Data.List.Relation.Binary.Pointwise as Pointwise
@@ -36,6 +37,7 @@ open import Data.Product.Base using (_,_; _×_; ∃; ∃₂; proj₁; proj₂)
36
37
open import Function.Base using (_∘_; _⟨_⟩_; flip)
37
38
open import Level using (Level; _⊔_)
38
39
open import Relation.Unary using (Pred; Decidable)
40
+ import Relation.Binary.Reasoning.Setoid as RelSetoid
39
41
open import Relation.Binary.Properties.Setoid S using (≉-resp₂)
40
42
open import Relation.Binary.PropositionalEquality.Core as ≡
41
43
using (_≡_ ; refl; sym; cong; cong₂; subst; _≢_)
@@ -474,3 +476,30 @@ module _ {ℓ} {R : Rel A ℓ} (R? : B.Decidable R) where
474
476
++↭ʳ++ : ∀ (xs ys : List A) → xs ++ ys ↭ xs ʳ++ ys
475
477
++↭ʳ++ [] ys = ↭-refl
476
478
++↭ʳ++ (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