@@ -184,16 +184,16 @@ Problem: Given a list of numbers, compute the minimum.
## Monoid Identification
* Interpretation of input elements as actions:
*…
*An element `a` in the input is an instruction to "ensure that the result is at most `a`".
* Combination of two actions:
*…
*If we ensure that the result is at most `a` and then we ensure that the result is a most `b`, altogether we ensure that result is at most `min(a, b)`.
* Representation of actions:
*…
*We can represent any action by storing the cap on the result.
@@ -212,22 +212,22 @@ As another way to look at the problem, if we know the average of a left-hand sid
This is the same issue we saw in divide-and-conquer design: we must be asking the wrong question.
If we ask for …, deferring …, then we can find a monoid.
If we ask for a sum and a count, deferring the division until the end, then we can find a monoid.
## Monoid Identification
* Interpretation of input elements as actions:
*…
*An element `a` in the input is an instruction to "add `a` to the total and add `1` the count".
* Combination of two actions:
*…
*…
*If we add `a` to the total and `1` to the count and then we add `c` to the total and `1` to the count, altogether we add `a + c` to the total and `2` to the count.
*If we add `a` to the total and `b` to the count and then we add `c` to the total and `d` to the count, altogether we add `a + c` to the total and `b + d` to the count.
* Representation of actions:
*…
*We can represent any action by storing an amount to add to the total (a real number) and an amount to add to the count (a natural number).
* Identity element:
*…
*Solving `e∙x = x∙e = x`, where `(a, b) ∙ (c, d) = (a + c, b + d)`, give us `e = (0, 0)`.
* Monoid:
*`A = (…, ∙, …)` where `(a, b) ∙ (c, d) = (…, …)`
*`A = (𝐑 × 𝐍, ∙, (0, 0))` where `(a, b) ∙ (c, d) = (a + c, b + d)`