Skip to content

Commit bc9c1b6

Browse files
authored
Add Algebra.Properties.Semiring.Sum showing mulitplication distributes over sums (#1462)
1 parent da6b864 commit bc9c1b6

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,11 @@ New modules
147147
Algebra.Construct.LexProduct.Inner
148148
```
149149

150+
* Properties of sums over semirings
151+
```
152+
Algebra.Properties.Semiring.Sum
153+
```
154+
150155
* Sorting algorithms over lists:
151156
```
152157
Data.List.Sort
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
------------------------------------------------------------------------
2+
-- The Agda standard library
3+
--
4+
-- Finite summations over a semiring
5+
------------------------------------------------------------------------
6+
7+
{-# OPTIONS --without-K --safe #-}
8+
9+
open import Algebra.Bundles using (Semiring)
10+
11+
module Algebra.Properties.Semiring.Sum {c} {ℓ} (R : Semiring c ℓ) where
12+
13+
open import Data.Nat.Base using (zero; suc)
14+
open import Data.Vec.Functional
15+
open Semiring R
16+
17+
------------------------------------------------------------------------
18+
-- Re-export summation over monoids
19+
20+
open import Algebra.Properties.CommutativeMonoid.Sum +-commutativeMonoid public
21+
22+
------------------------------------------------------------------------
23+
-- Properties
24+
25+
*-distribˡ-sum : {n} x (ys : Vector Carrier n) x * sum ys ≈ sum (map (x *_) ys)
26+
*-distribˡ-sum {zero} x ys = zeroʳ x
27+
*-distribˡ-sum {suc n} x ys = trans (distribˡ x (head ys) (sum (tail ys))) (+-congˡ (*-distribˡ-sum x (tail ys)))
28+
29+
*-distribʳ-sum : {n} x (ys : Vector Carrier n) sum ys * x ≈ sum (map (_* x) ys)
30+
*-distribʳ-sum {zero} x ys = zeroˡ x
31+
*-distribʳ-sum {suc n} x ys = trans (distribʳ x (head ys) (sum (tail ys))) (+-congˡ (*-distribʳ-sum x (tail ys)))

0 commit comments

Comments
 (0)