https://github.com/robrix/semirings-modules
Semirings, with and without additive/multiplicative identities, and R-modules.
https://github.com/robrix/semirings-modules
Last synced: 10 months ago
JSON representation
Semirings, with and without additive/multiplicative identities, and R-modules.
- Host: GitHub
- URL: https://github.com/robrix/semirings-modules
- Owner: robrix
- License: bsd-3-clause
- Created: 2018-05-18T01:12:18.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2018-05-19T20:14:51.000Z (about 8 years ago)
- Last Synced: 2025-05-08T04:01:50.255Z (about 1 year ago)
- Language: Haskell
- Size: 268 KB
- Stars: 7
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# Semirings & (left) R-modules
This package provides Haskell typeclasses for semirings (with & without additive & multiplicative identities) & (left) R-modules, plus a variety of useful instances.
## Semirings
`Semiring`s extend the notion of a `Semigroup` with a second binary operator, `><`. Intuitively, `<>` is to addition as `><` is to multiplication, and several of the useful properties of `+` and `*` apply:
- `><` has higher precedence than `<>`: `a >< b <> c` is the same as `(a >< b) <> c`, not `a >< (b <> c)`.
- `<>` and `><` are both associative: `a <> b <> c` is the same as `a <> (b <> c)` is the same as `(a <> b) <> c`. Associative operators are trivially parallelizable, making this quite a useful property.
- Unlike in ordinary semigroups, `<>` is expected to be commutative: `a <> b` is the same as `b <> a`.
- `><` distributes over `<>`: `a >< (b <> c)` is the same as `a >< b <> a >< c`.
In this presentation, `Semiring`s are not required to have additive or multiplicative identities. They _can_ have them, however, by defining `Monoid` and `Unital` instances, respectively. If they do, there are some extra properties:
- `zero` (a synonym for the `Monoid` method `mempty`) is the additive identity: `zero <> a` is the same as `a <> zero` is the same as `a`.
- `zero` is the multiplicative absorbing element, or annihilator: `zero >< a` is the same as `a >< zero` is the same as `zero`.
- `one` is the multiplicative identity: `one >< a` is the same as `a >< one` is the same as `a`.
The relationship between `zero` and `><` can be useful for expressing values representing the success/failure of some set of operations, where failure of one operation implies failure of the overall set. This can be seen in the `Semiring` instance for `Maybe`, for which a `Nothing` value on either side results in a `Nothing`.
## Modules
R-modules over some semiring R generalize the notion of vector spaces over a field. As such, they are well suited to describe collections of or functions producing values in a semiring. A module’s operator, pronounced “scalar multiplication” and written here as `><<`, generalizes scaling a vector.
----
- [Read the docs][docs].
[docs]: https://antitypical.com/semirings-modules/