The counting semiring is an m-semiring
Lax392996.CountingSemiring · concepts/Lax392996/CountingSemiring.lean · lax-392996
No public endorsements yet.
Loading review…
Sign in with ORCIDNatural Language Statement
Definition
The counting semiring is an m-semiring: its natural order is the usual order on natural numbers, its monus is truncated subtraction, and its operator is the support indicator, on and elsewhere. Unlike most provenance semirings it is neither idempotent nor absorptive. Its usual order also serves as the alternative linear order that lets counts share a column with data values.
Concept map
In the paper
- page 4 of this submission's paper
Lean source view on GitHub
| 1 | import Mathlib.Algebra.Order.Ring.Defs |
| 2 | import Mathlib.Algebra.Order.Ring.Canonical |
| 3 | import Mathlib.Algebra.Order.Group.Nat |
| 4 | import Mathlib.Algebra.Order.Ring.Nat |
| 5 | import Lax392996.SemiringsWithMonus |
| 6 | |
| 7 | /-! |
| 8 | --- |
| 9 | title: The counting semiring is an m-semiring |
| 10 | type: definition |
| 11 | --- |
| 12 | The counting semiring is an m-semiring: its |
| 13 | natural order is the usual order on natural numbers, its monus is truncated |
| 14 | subtraction, and its operator is the support indicator, on |
| 15 | and elsewhere. Unlike most provenance semirings it is neither idempotent |
| 16 | nor absorptive. Its usual order also serves as the alternative linear order |
| 17 | that lets counts share a column with data values. |
| 18 | -/ |
| 19 | |
| 20 | namespace Lax392996.CountingSemiring |
| 21 | |
| 22 | open Lax392996.SemiringsWithMonus |
| 23 | |
| 24 | /-- The support indicator: `0 ↦ 0`, positive `↦ 1`. -/ |
| 25 | def Nat.deltaInd (n : ℕ) : ℕ := if n = 0 then 0 else 1 |
| 26 | |
| 27 | /-- `ℕ` is an m-semiring: the natural order is the usual one, the monus is |
| 28 | truncated subtraction, and `δ` is the support indicator. -/ |
| 29 | instance instSemiringWithMonusNat : SemiringWithMonus ℕ where |
| 30 | monus_spec := by |
| 31 | intro a b c |
| 32 | omega |
| 33 | delta := Nat.deltaInd |
| 34 | delta_zero := rfl |
| 35 | delta_natCast_pos := by |
| 36 | intro n hn |
| 37 | simp [Nat.deltaInd, Nat.pos_iff_ne_zero.mp hn] |
| 38 | delta_absorb := by |
| 39 | intro a b |
| 40 | by_cases ha : a = 0 |
| 41 | · simp [ha, Nat.deltaInd] |
| 42 | · simp [Nat.deltaInd, ha] |
| 43 | |
| 44 | instance instHasAltLinearOrderNat : HasAltLinearOrder ℕ where |
| 45 | altOrder := inferInstance |
| 46 | |
| 47 | end Lax392996.CountingSemiring |
| 48 |
Discussion
Ask a question or add context. Endorsements and structured flags are kept in the review panel above.
0 comments