Algebra.slop.md (31208B)
1 # Long Discussion 2 3 ## Summary 4 5 ### 1. Initial objects 6 - **Ring → ℤ**, via n ↦ n·1. The initial object is always the free algebra on no generators. 7 - **Rng → 0**, the zero ring, which is also terminal. Rng maps ℤ → R correspond to idempotents of R. 8 - **Rig → ℕ.** Absorption doesn't matter here, since 0·0 = 0 is derivable in unital rigs. 9 - **Rg:** 0 with absorption. Without absorption the initial object is {0, 0², …} ≅ ({1, 2, …}, max, +). 10 - **Rig without 0 → ℕ₊**, and ∅ if 1 is dropped too. 11 - **Non-associative rings → ℤ** (0 if non-unital). **Near-rings → ℤ** if unital, else 0. 12 - **Commutative versions** have the same initial objects. 13 - **Derivable laws in rings:** additive commutativity (expand (1+1)(a+b) two ways) and absorption (by cancellation). 14 15 ### 2. Literals under RebindableSyntax 16 - **Integer literals:** 17 - `fromNatural :: Natural -> a` lives on `Semiring`, since ℕ is the initial rig. Its default uses binary splitting. 18 - `fromZ` lives on `Ring`. 19 - The hook is `fromInteger = fromNatural . P.fromInteger`, where `P.fromInteger` is base's `Num` method at `Natural`; instances are global. 20 - **Negative literals** go through `negate`, which needs `Ring`. 21 - Keep NegativeLiterals and LexicalNegation off; they would produce `fromInteger (-n)`. 22 - Detect them with Template Haskell's `isExtEnabled` in a splice, or with a GHC plugin, plus a runtime error as a safety net. 23 - **Laws:** these maps are homomorphisms, which makes them unique; overriding them is only for speed. 24 - **Caveat:** in idempotent semirings (Bool, min-plus, max-plus), every positive literal equals `one`. 25 - **Decimal literals:** 26 - `fromQ` lives on a ℚ-algebra class (every nonzero integer invertible; ℚ is initial). The condition is not "characteristic 0". 27 - `Double` overrides it with `P.fromRational` to avoid double rounding. 28 - A semiring version is possible via ℚ≥0. 29 - Skip a methodless `CharZero`. Positive characteristic, if needed, gets an associated type-level `Characteristic` with `KnownNat` (useful for Frobenius). 30 31 ### 3. Terminology 32 - There's no standard adjective for "is a ring". The nearest are rig or bimonoidal category; "ringoid" means an Ab-enriched category; "ringed" is already taken. 33 - Rename endofunctor algebras to F-algebras and F-coalgebras, freeing "algebra" for associative algebras. Avoid "R-ring". 34 35 ### 4. Scope of the hierarchy 36 - **Add:** 37 - division rings and fields; 38 - Euclidean (`quotRem`/`divMod`, `gcd`, `lcm`, over rigs); 39 - monus; 40 - signed/ordered classes (`abs`/`signum` kept out of `Ring`); 41 - `Module` over a rig, with an associated `Scalar`; 42 - associative algebras (methodless, with `fromScalar r = r *^ one`); 43 - `Action m x`; 44 - torsors/affine spaces with `Diff x`. 45 - **Maybe:** semifields, lattices/Boolean algebras, star semirings. 46 - **Skip:** rng, rg, near-rings, non-associative rings, magmas, quasigroups, PID/UFD (`GcdDomain` optional). Integral domain later came back as `Domain`. 47 - **Modules** have the same axioms over rigs, rings and fields. 48 - Over rigs, 0·m = 0 must be stated; over rings, negatives are forced. 49 - Vector space is a constraint synonym. Non-commutative scalars give left vs. right modules. 50 - **Algebras** need commutative scalars. Law: r*^(ab) = (r*^a)b = a(r*^b). 51 - Instances: complex numbers, polynomials, power series, matrices, quaternions, dual numbers, functions, monoid/group algebras. 52 - Skip Lie algebras, octonions, non-unital algebras. 53 - **Monoids and actions** in a monoidal category: 54 - (Set, ×): monoids and actions. 55 - (CMon, ⊗): rigs and semimodules. 56 - (Ab, ⊗): rings and modules. 57 - (Vect, ⊗): algebras and representations. 58 - (Endofunctors, ∘): monads and their algebras. 59 60 A monoid is a one-object category, and an action is a functor out of it. 61 62 ### 5. Division, `NonZero`, `Units` 63 - **`Divisive`** (`recip`, `/`, `^^`) is shared by `MulGroup` and `DivisionSemiring`, a group with zero. Laws are guarded. `recip zero` is unspecified; Lean's meadow convention `recip 0 = 0` is the alternative. 64 - **`NonZero a`** is a newtype with a hidden constructor, nominal role and smart constructor. Its accessor is not a record field, because record-update syntax would let clients forge a zero. 65 - It's a monoid iff `a` is a domain, a group iff `a` is a group with zero, and an additive semigroup iff `a` is zero-sum-free (`NonZero Natural` = ℕ₊). `negate` preserves it in rings. 66 - `Int`/`Word` aren't domains, and `Double` breaks the invariant. 67 - Use it for divisors, Euclidean norms, `leadingCoeff` and mixed division, with partial wrappers for literal divisors (there are no `NonZero` literals). 68 - **Units:** 69 - They're defined for any monoid: M^× is the largest submonoid that's a group. It's right adjoint to groups ↪ monoids; the -oid analogue is the core of a category. 70 - Examples: ℤ → ±1; ℕ → 1; k[x] → nonzero constants; invertible matrices; ℤ/n → coprime residues; `Int` → the odd numbers. `AddUnits` is the additive version. 71 - In a group with zero, `Units ≅ NonZero`; keep both types anyway. 72 - Model: a single-field `newtype Units a`, plus a class `HasUnits` with `toUnit` (returning an unboxed sum) and `invertUnit`. `Units a` is then an `IsMulGroup`, and instances compose (matrices via the determinant). 73 - Don't store the inverse; in your rep-polymorphic setting that would need an unlifted tuple. Name it `Units`, not `Unit`. 74 - **No class for testing equality with `one`.** 75 76 ### 6. Representation polymorphism 77 - **The rule:** no variable or argument may have a representation-polymorphic type. Function types are always lifted, so `coerce` between functions works generically. 78 - **`NonZero` under it:** 79 - It becomes `NonZero :: TYPE r -> TYPE r` via UnliftedNewtypes. 80 - `onNonZero = coerce`, and `getNonZero = onNonZero id` works over each fixed representation. 81 - Instances coerce function-typed methods. 82 - **What has to be per-instance:** 83 - Anything that inspects values, such as the zero test. 84 - Default method bodies, which can't bind values either. 85 - **Other consequences:** 86 - `Maybe` holds only lifted types, so decisions return unboxed sums. 87 - base's `Eq`/`Ord` get standalone instances at `a :: Type`. 88 89 ### 7. Equality and decidability 90 - **No `Eq` superclass** on algebraic classes. It would exclude function types, and structural `Eq` on symbolic types would falsify the laws; `Double` isn't lawful anyway. `Num` lost `Eq`/`Show` in GHC 7.4. 91 - Document each instance's intended equality. Skip `Setoid`; property tests carry their own constraints. 92 - **The zero test isn't algebraic** (ℚ and computable reals are both fields). 93 - It says zero is an *isolated point*, equivalently `a ≅ 1 + NonZero a`, which is `nonZero`'s type. 94 - It equals decidable equality given subtraction or monus, and is weaker otherwise (ℕ∞). 95 - A division semiring with a zero test is a *discrete division rig*, R = {0} ⊔ R^×. The alternative reads "nonzero" as apartness (Heyting). 96 - Mathlib's `withZeroUnitsEquiv` needs exactly a decidable zero. 97 - It lives in `IsZeroIsolated`, beside equality, with the splitting as its law. `IsDiscreteDivisionSemiring` is a synonym. 98 - The addition-free precondition for `NonZero a` being a group is `GroupWithZero`, which needs its own `zero` class, as Lean has `Zero`. 99 - **Lean's approach:** 100 - `Decidable p` is a proof-carrying Bool; `DecidableEq`/`Pred`/`Rel` are abbreviations for families of it. 101 - Lawless `BEq` and `Ord` get law mixins: `PartialEquivBEq`, `ReflBEq`, `EquivBEq`, `LawfulBEq`, `LawfulHashable`, `TransOrd`, `LawfulEqOrd`. 102 - Mathlib adds classical `DecidableEq` for ℝ and `Set`. 103 - **Recommendations:** 104 - Decisions return evidence, as splittings into refinement types (detachable subsets); `Bool` versions are secondary. 105 - Split equality into a lawless `==` plus an equivalence mixin and a lawful (substitutive) mixin. 106 - IEEE `==` is only a partial equivalence. 107 - For `Double` in containers, use a strict-equality newtype, like Scala's `StrictEquiv`. 108 - Treat ordering the same way. 109 - Give no instance where equality is undecidable; at most offer one-sided evidence tests. 110 - Precedents: base's `TestEquality`, singletons' `Decision`. 111 112 ### 8. Commutativity and operators 113 - **Non-commutative addition** is allowed, as in Lean, though Lean's main payoff (`to_additive`) has no Haskell analogue. 114 - **Commutativity** gets one class, `IsAddCommSemigroup`, plus synonyms `IsAddCommMonoid` and `IsAddCommGroup`. 115 - **Aliases:** an operator takes the constraint of the method it aliases, so `(+)` needs `IsAddSemigroup`. 116 - **Consequences:** 117 - Code that relies on commutativity must state it. 118 - `Semiring` and `Module` superclasses use the `Comm` versions. 119 120 ### 9. Ordered structures 121 - **Pattern:** an ordered X is an X-object in the ordered counterpart of the category X is presented in. 122 - (Set, ×) becomes (Pos, ×). 123 - (Ab, ⊗) becomes (OAb, ⊗), whose nonnegative cone is generated by products of nonnegatives. OAb is closed, its internal hom contains all homomorphisms with the monotone ones nonnegative, and preorders are used throughout. 124 - Properties, like having inverses, stay properties. 125 - **Resulting definitions:** 126 - Ordered monoid: a monoid in Pos. 127 - Ordered group: a monoid in Pos that's a group. A group object in Pos is discrete. 128 - Ordered ring: a monoid in OAb. A rig object in Pos that's a ring is discrete. 129 - Ordered modules and algebras: likewise, in OAb. 130 - Ordered rigs: use Mathlib's definition (monotone multiplication by nonnegatives, 0 ≤ 1), so ordered rings are ordered rigs. 131 - **Laws:** 132 - Structure maps are monotone, or positive bimorphisms. 133 - Antitone laws are theorems about derived operations (negation, `recip`, subtraction, division) and belong on the ordered-structure mixin. Field `recip` is antitone only within each sign. 134 - Strict and reflecting variants exist. Mathlib calls them `AddLeftMono`, `AddLeftStrictMono`, `AddLeftReflectLE`; its older "contravariant" means *reflecting*. 135 - **Mixins** are per operation (Mathlib's 2025 unbundling): additive monotonicity; multiplicative monotonicity (not for rings); ordered semiring, plus a strict version. An ordered ring's multiplicative monoid is not an ordered monoid. 136 - **Canonical orders** (ℕ, ℝ≥0, multisets) are where monus lives, as an adjoint (`OrderedSub`). 137 - **Trichotomy** needs only a linear order and a zero (`SignType.sign`). In ordered groups, sign and `compare` are interdefinable. 138 - `Positive a` is closed under + in ordered monoids and under * in strictly ordered semirings; in ℕ it equals `NonZero`. 139 - **Earlier drafts:** a fuzzy "variance recipe" and a polarity formulation came first. The pattern above supersedes them. 140 141 ### 10. "Is a group", categorically 142 - Being a group is a property, so groups form a full subcategory. 143 - **U-group:** an inverse exists in D after applying a product-preserving U: C → D. 144 - **Shear map:** an isomorphism gives a group object; mono plus epi (a bijection) gives an ordered group. 145 - **Units counit** of V ⊣ Inv: an isomorphism gives a group object (discrete); an epimorphism gives an ordered group. 146 - The gap exists because Pos isn't balanced. Top shows the same split: topological vs. paratopological groups (the Sorgenfrey line). Ordered groups are paratopological in the up-set topology. 147 - Group completion inside Pos collapses comparable elements: ordered ℤ completes to the trivial group. 148 - `negate` is the witness of the property, with no monotonicity law. 149 150 ### 11. Naming scheme (final version) 151 - **Constraints:** never contradict convention, and make monoid-like structures the unmarked default. 152 - **Roots:** `Monoid`; `Rig` (commutative additive monoid, multiplicative monoid, distributive, absorbing 0). 153 - **Removing a default:** `NonUnital`, `NonAssoc`. 154 - **Adding a feature:** `Comm`, `Idem`, `Inv` (division, so loops and quasigroups fit), `Neg` (additive inverses), `Div` (nonzero reciprocals), `WithZero`. 155 - **Constructors:** `…oid`, `…Action`, `…Algebra`. A leading `Add`/`Mul` names the operation. 156 - **Order:** `[Add|Mul][Comm][Idem][NonAssoc][NonUnital][Neg][Div][Inv]Root[WithZero][oid|Action|Algebra]`. 157 - **Translations:** 158 - group = `InvMonoid`; semigroup = `NonUnitalMonoid`; magma = `NonAssocNonUnitalMonoid`. 159 - loop = `NonAssocInvMonoid`; quasigroup = `NonAssocNonUnitalInvMonoid`. 160 - band and semilattice use `Idem`; group with zero = `DivMonoidWithZero`. 161 - category = `Monoidoid`; semicategory = `NonUnitalMonoidoid`; groupoid = `InvMonoidoid`. 162 - rg = `NonUnitalRig`; rng = `NonUnitalNegRig`; ring = `NegRig`. 163 - division semiring = `DivRig`; semifield = `CommDivRig`; division ring = `NegDivRig`; field = `CommNegDivRig`. 164 - ringoid = `NegRigoid`. 165 - semimodule, module, vector space = `RigAction`, `NegRigAction`, `CommNegDivRigAction`. 166 - semialgebra = `CommRigAlgebra`; algebra = `CommNegRigAlgebra`. 167 - **Notes:** 168 - Conventional names can stay as aliases. 169 - Collapsed combinations: `NonUnitalInvMonoid` needs no name, and a module's negatives are forced. 170 - The first draft (`Semi` = "no division", making `SemiGroup` mean monoid) was rejected. 171 172 ### 12. Structures with several operations 173 - **Absorption:** 174 - It's the empty-sum case of distributivity: monoid homomorphisms must be told to preserve 0. That's also why rng maps can send 1 to idempotents. 175 - Beck's distributive law: a product of sums is a sum of products, so an empty factor gives the empty sum. 176 - Near-rings have absorption on their distributive side only. 177 - Without it, the identity matrix and the polynomial 1 aren't units, and sparse representations are unsound. 178 - In `Rig`, state `mul a zero = zero = mul zero a`; in `NegRig` it's a theorem. 179 - **Cayley pattern:** rigs are subrigs of End(commutative monoid), and each axiom reflects that. 180 - Addition must be commutative for pointwise sums of endomorphisms to be endomorphisms. 181 - The same template: monoids = End(set), groups = Aut(set), rings = End(Ab), near-rings = functions on a group, modules = homomorphisms into End. 182 - **Kinds of compatibility:** 183 - distributivity (tensor); 184 - interchange, which by Eckmann–Hilton forces equal, commutative operations; 185 - lattice absorption (one order); 186 - compatibility with extra structure. 187 - **Why require compatibility:** 188 - normal forms (the free rig is ℕ⟨X⟩); 189 - homomorphic evaluation; 190 - generic algorithms, such as dynamic programming over semirings. 191 - **Non-commutative addition:** 192 - It's not a monoid in (Mon, ×), which gives commutative monoids. 193 - Two-sided distributivity works only without cancellation (example: {0, 1, t}); some literature says "additively commutative semiring" when assuming it. 194 - The natural notion is the one-sided near-semiring (seminearring). Its Cayley model is functions on a monoid; examples are ordinals and `Alternative`/`MonadPlus`. 195 - Keep additive commutativity in `Rig`. 196 197 ### 13. Monoids in monoidal categories, precisely 198 - **Notation:** base (V, ⊗, I, σ). Mon(V, ⊗) and CMon(V, ⊗) name the product explicitly: Mon(Ab, ×) ≃ Ab, but Mon(Ab, ⊗_ℤ) = rings. 199 - **Examples:** 200 - Mon(Set, ×): monoids. Mon(Pos, ×): ordered monoids. Mon(Top, ×): topological monoids. 201 - Mon(Ab, ⊗_ℤ): rings. Mon(CMon, ⊛): rigs. Mon(Vect, ⊗_k): algebras. 202 - Mon(End(C), ∘): monads. 203 - **Free objects:** lists ∐X^⊗n and bags ∐X^⊗n/Σₙ. 204 - **Products on C = Mon(V, ⊗) or CMon(V, ⊗):** 205 - ⊗ᶜ, componentwise (needs σ). It's × for cartesian V, and the coproduct on CMon. 206 - ⊔, the coproduct (free product), whose unit is the initial monoid. 207 - ⊛, bilinear. It needs a commutative theory over a cartesian closed V with colimits. It's a quotient of the free model on M × N, and its unit is the free model on one generator. 208 - On CMon: × = ⊗ᶜ = ⊔ (a biproduct), and ⊛ is the tensor of commutative monoids. On Ab, ⊛ = ⊗_ℤ. 209 - **Their monoids:** 210 - Mon(Mon(V, ⊗), ⊗ᶜ) ≃ CMon(V, ⊗) by Eckmann–Hilton. 211 - Mon(C, ⊔) ≃ C. 212 - Mon(Mod_T, ⊛) gives: 213 - sets → monoids; 214 - pointed sets → monoids with zero; 215 - commutative monoids → rigs; 216 - abelian groups → rings; 217 - join-semilattices with 0 → idempotent semirings; 218 - sup-lattices → quantales; 219 - R-modules → R-algebras. 220 - Commutative monoids for ⊛ give the commutative versions. Over Pos, ⊛ gives rig objects in Pos; ordered rings came from the cone tensor instead. 221 - **Why monoids get no ⊛:** it needs a commutative theory. For monoids, interchange is the same as commutativity; the list monad isn't commutative, while the bag monad is. 222 - **One-sided:** on End(C), composition ∘ distributes over the pointwise product ×. Near-semiring objects there are `MonadPlus`. 223 224 ## Algebraic structures mentioned 225 226 - **One operation:** magma, unital magma, quasigroup, loop, semigroup, monoid, group, abelian group, band, (bounded) semilattice, monoid with zero, group with zero, adjoined zero, units and additive units, zero-sum-free monoid, canonically ordered monoid, monus, semigroup/monoid/group actions, torsor, affine space. 227 - **Two operations:** 228 - Rings and rigs: ring, rng, rig/semiring, rg/hemiring, rig without zero, commutative ring/rig, non-associative ring, near-ring (zero-symmetric), near-semiring/seminearring, additively non-commutative semiring. 229 - Domains: domain/integral domain, GCD domain, PID, UFD, Euclidean domain. 230 - Division structures: division ring, field, division semiring, semifield/division rig, discrete and Heyting division rigs, meadow. 231 - Characteristic: ℚ-algebra, characteristic zero and positive characteristic, finite field, ℤ/n. 232 - Idempotent and order-like: idempotent, tropical (min-plus, max-plus) and Boolean semirings, star semiring, quantale, lattice, Boolean algebra, residuated lattice, join-semilattice with 0, sup-lattice. 233 - **Module-like:** left/right module, semimodule, vector space, representation, associative algebra, semialgebra, R-algebra, monoid/group algebra, Lie algebra, octonions. 234 - **Ordered and topological:** preordered, ordered, linearly ordered and strictly ordered versions of semigroups, monoids, groups (bi- and left-ordered), abelian groups, semirings, rings, fields, modules, vector spaces and algebras; positive cones; group objects in Pos; topological monoids; topological and paratopological groups. 235 - **Categorical:** monoid, commutative monoid and group objects; category (monoidoid); semicategory; groupoid; core; ringoid; rigoid; rig (bimonoidal) category; monads; near-semiring objects (`Alternative`, `MonadPlus`); F-algebras and coalgebras; algebras for a monad; commutative theories and monads (bag vs. list); pointed sets with smash product; ringed spaces. 236 - **Examples:** ℕ, ℕ₊, ℕ∞, ℤ, ℚ, ℚ≥0, ℝ, ℝ≥0, ℂ, ordinals, polynomials, power series, matrices, quaternions, dual numbers, pointwise functions, computable reals, `Int`/`Word` (ℤ/2ⁿ), `Double`, `Bool`, permutations, valuation targets, multisets, sets, End(M), the {0, 1, t} rig, the Sorgenfrey line. 237 238 # Algebraic Structures/Abstractions Useful in FP 239 240 **Rule of thumb:** algebra pays off in FP when it gives you one of three things: 241 - laws you can program against, which license folds, parallelism, incrementality, rewrites and property tests; 242 - homomorphisms and free/quotient constructions; 243 - order and fixpoint theory. 244 245 Classification theory almost never pays off. 246 247 **Cosets and ideals:** rarely used as such. What transfers is the general notion behind them: congruences and quotients (cosets are congruence classes; normal subgroups and ideals are kernels), plus orbits. Concrete cosets are elements of ℤ/n and syndrome decoding of linear codes. Ring ideals matter through quotient rings (§5). Order ideals (down-sets) matter in lattices and CRDTs (§7). Semigroup ideals show up as absorbing elements (§1). 248 249 ### 1. Extra laws on the basics 250 - **Commutativity** → order-independent reduction: `HashMap`/bag folds that respect equality, and parallel partial results combined in completion order. Commutative effects can be reordered or batched (Haxl), and give exchangeability in probabilistic programs (Staton). 251 - **Idempotence** (bands; plus commutativity = **semilattices**) → merging that tolerates duplicates and retries: state-based CRDTs, LVars, Datalog/Datafun, `Min`/`Max`, `First`/`Last`. 252 - **Absorbing elements** → early exit from folds (`Any True`, `All False`, `0`); `empty <*> x = empty` → pruning in search. 253 - **Cancellative, GCD and monus monoids** (`monoid-subclasses`) → `stripPrefix`/`isPrefixOf` for any monoid, parsers over any monoidal input (picoparsec), and multiset/`Natural` subtraction. 254 - **Involutions/anti-homomorphisms** → `Dual . reverse` is a monoid iso `[a] → Dual [a]`; dagger and inverse categories model reversible and quantum languages. 255 - **Near-semirings** → the actual laws of `Alternative`/`MonadPlus` (Rivas–Jaskelioff–Schrijvers). 256 - **Closed (star) semirings, Kleene algebra (with tests)** → one matrix-closure algorithm gives shortest/widest paths, reachability, path counting and automaton→regex, just by swapping the semiring (Dolan, *Fun with Semirings*). Also: regex derivatives, semiring parsing (Goodman), provenance semirings, KAT/NetKAT verification. 257 - **Graded monoids/rings** → `(++) :: Vec n a → Vec m a → Vec (n+m) a`; graded monads; units of measure (a ring graded by the dimension group). 258 - **Preordered monoids/semirings** → effect systems via graded monads with subeffecting (Katsumata); usage multiplicities in QTT/Idris 2 ({0,1,ω}), Linear Haskell and Granule. 259 - **Caveat:** IEEE `+`/`*` are only commutative magmas, so parallel float sums aren't reproducible and `Double` instances are only approximately lawful. 260 261 ### 2. Universal algebra (biggest payoff after the basics) 262 - **Homomorphisms** → `foldMap f` is the unique monoid hom out of the free monoid. Homs parallelize (third homomorphism theorem, Gibbons) and justify fusion and GHC `RULES`. Monad morphisms give the laws for `lift` and `hoist`. `Traversable`'s naturality law quantifies over applicative homs. 263 - **Free algebras** → the Boom hierarchy: free magma = leaf trees; add associativity = `NonEmpty`; add a unit = lists; add commutativity = bags; add idempotence = finite sets. 264 - Free group = reduced words. 265 - ℕ[X] = the universal provenance semiring. 266 - Free monads, applicatives and categories, with effect handlers = homs out of them (Plotkin–Pretnar). 267 - **Initial algebras / final coalgebras** → ADTs and folds (recursion schemes); codata, streams and bisimulation. 268 - **Presentations / equational theories** → algebraic effects = operations + equations (Plotkin–Power); Knuth–Bendix and rewriting; unification modulo AC/AG (F# units-of-measure inference, Maude, Tamarin). 269 - **Birkhoff's HSP theorem** → equational laws survive products, subalgebras and quotients. So tuple and pointwise (`a -> b`) instances are lawful for free, and invariant-preserving newtypes inherit laws. Non-equational axioms don't survive: 270 - Fields aren't a variety: there is no free field, and pointwise `Fractional (a,b)` is unlawful because `(1,0)` has no inverse. 271 - Cancellativity isn't preserved by quotients. 272 - This is why `Group` makes `invert` an operation. 273 - **Subalgebras** → a smart-constructor invariant is sound iff it is closed under every exported operation. 274 - **Congruences and quotients** → `Eq` on an abstract type must be a congruence for its API. Also: quotient types (Lean `Quot`, cubical HITs, setoids), and e-graphs, which are incremental congruence closure. The 1st isomorphism theorem says you can represent A/ker f by im f, which is how normal forms work (sorted lists or `Map a Int` for bags, reduced words for free groups). 275 - **Cayley's theorem** → difference lists (`Endo`), `Codensity` for monads (Rivas–Jaskelioff), CPS. All three reassociate for asymptotic speedups. 276 - **Semidirect products** → pair a value with the transformation acting on it: diagrams (Yorgey, *Monoids: Theme and Variations*); rolling hashes and CRCs combine as affine maps x ↦ x·Bⁿ + h. 277 278 ### 3. Actions, torsors, automata 279 - **Monoid actions** → update monads (Ahman–Uustalu); change actions/structures for incremental computation and semi-naïve Datalog (Alvarez-Picallo et al.; Cai et al.). 280 - **Actions by homomorphisms** → lazy-propagation segment trees. 281 - **Torsors / affine spaces** → points typed apart from differences: `UTCTime`/`NominalDiffTime`, pointer/offset (`vector-space`, `acts`). 282 - **Transition monoids** → running a DFA is a hom into endofunctions on its states, which gives parallel/incremental lexing (Hillis–Steele; finger-tree measures). 283 - **The bicyclic monoid** ⟨p,q ∣ pq=1⟩ → parallel bracket matching (Levien's "stack monoid"). 284 - **Orbits, stabilizers, Burnside** → quotient containers such as unordered pairs, bags and cycles (Abbott–Altenkirch–Ghani–McBride); species (Yorgey); symmetry reduction in search and model checking. 285 - **Actions of monoidal categories** → profunctor optics are Tambara modules. 286 287 ### 4. Groups and their "-oids" 288 - **Inverses** → range queries from prefix sums or Fenwick trees need inverses; segment trees need only a monoid. Also subtract-on-evict sliding windows, and undo. 289 - **(Free) abelian groups** → Z-sets in DBSP and differential dataflow (incremental view maintenance with ± weights); units of measure (Kennedy). 290 - **Cyclic groups** → wraparound indices, ring buffers (`Finite n`, `Mod m`). 291 - **Symmetric groups** → permutations as invertible first-class data, axis transposes, species. 292 - **Semigroupoids, categories, groupoids** (typed semigroups, monoids and groups) → the `semigroupoids` package; patches (Darcs; homotopical patch theory); HoTT identity types; isos. 293 - **Inverse semigroups** (partial bijections) → partial isomorphisms for invertible parser/printers (Rendel–Ostermann); reversible computing. 294 - **Trace (partially commutative) monoids** → Mazurkiewicz traces and partial-order reduction; scoped-label rows (Leijen; Koka effect rows). 295 296 ### 5. Rings and ideals 297 - **Quotient rings in daily use:** 298 - ℤ/2ⁿ is wrapping `Word`/`Int`: a lawful ring, unlike `Double`. Odd numbers are units, which gives bijective hash mixers (SplitMix) and exact division by constants. 299 - ℤ/n with CRT and Fermat/Euler (Lagrange in the unit group) → modular types, multi-modular/NTT arithmetic, hashing. 300 - 𝔽₂[x]/(p) = GF(2ⁿ) → CRC (reduction is a ring hom, which gives `crc32_combine` and parallel CRC), Rabin fingerprints, Reed–Solomon, AES. The quotient is a field iff (p) is maximal iff p is irreducible. 301 - ℝ[ε]/(ε²) = dual numbers → forward-mode AD; ℝ[ε]/(εᵏ⁺¹) → Taylor-mode AD. 302 - **Euclidean/GCD domains** → `semirings`' `GcdDomain`/`Euclidean`; generic extended gcd; canonical `Ratio`. 303 - **Fields of fractions** → `Ratio a`, rational functions. 304 - **Polynomial, power-series and monoid (semi)rings** → lazy power series (McIlroy). Convolution over a monoid unifies polynomials, languages and weighted automata (Elliott, *Generalized Convolution*). 305 - **Noetherianity / ACC** → termination arguments: Kleene iteration terminates under ACC (otherwise you need widening), and Dickson/Hilbert make Buchberger's algorithm terminate. 306 307 ### 6. Modules & linear algebra 308 - **Free semimodule monad** (finite S-weighted sums) → one monad with many semantics, depending on S: 309 - 𝔹 → nondeterminism 310 - ℕ → multisets 311 - ℝ≥0 → probability (distributions are free convex algebras) 312 - tropical → optimization 313 - ℂ → quantum amplitudes 314 - **Matrices over semirings** → graph algorithms as linear algebra (GraphBLAS); weighted automata. 315 - **Duals and transposes** → reverse-mode AD is transposed linearization (JAX, *You Only Linearize Once*; Elliott, *Simple Essence of AD*). 316 - **𝔽₂-linear algebra** → XOR bases, linear codes. 317 - **Tensor products, inner products, spectral theory, canonical forms, exterior/Clifford algebras** → numerics, ML and graphics only. Tensor products do serve as the model for monoidal products (§8). 318 319 ### 7. Order theory 320 - **Complete lattices + Knaster–Tarski/Kleene** → semantics of recursion, dataflow analysis, Datalog, grammar analyses (nullable/FIRST). 321 - **CPOs/domains** → semantics of laziness, ⊥ and general recursion. 322 - **Galois connections** → abstract interpretation; calculating `floor`, integer division and integer sqrt (Backhouse; Mu–Oliveira). 323 - **Distributive lattices, Birkhoff representation, down-sets** → causal histories and version vectors; join-irreducible decompositions for optimal delta-CRDT sync (Enes et al.). 324 - **Boolean algebras** → bitsets, predicates, BDDs; set-theoretic types (CDuce, Elixir). 325 - **Heyting algebras** → the intuitionistic logic of types. 326 - **Security lattices** → information-flow control (LIO, MAC). 327 - **Well-founded orders, WQOs, ordinals** → termination checking; homeomorphic embedding (Kruskal) as supercompilation's termination test. 328 - **Quantales** → quantitative/metric semantics (niche). 329 330 ### 8. Categorified algebra (where all of the above resurfaces) 331 - **Monoid objects:** 332 - `Monoid` under × 333 - `Applicative` under Day convolution 334 - `Monad` under composition 335 - `Category`/`Arrow` in profunctors 336 - `Alternative` as a monoid on `f a` 337 - `Divisible`/`Decidable` as the contravariant versions 338 - **Comonoids** → trivial in Hask, explicit under linearity (`linear-base`'s `Dupable`/`Consumable`). 339 - **Eilenberg–Moore algebras** → monoids are list-monad algebras, convex sets are distribution-monad algebras; effect handlers. 340 - **The rig of types up to iso** → "algebraic" data types, refactoring by algebra, zippers as derivatives and dissections (McBride); the reversible language Π as rig-groupoid isos (James–Sabry; Carette–Sabry). 341 - **Distributive laws** (Beck) → when monads compose; `traverse`. 342 - **Adjunctions** → free ⊣ forgetful underlies every "free X" above; `State` comes from currying. 343 344 ### 9. Little or no use 345 These have little or no use: 346 - Sylow theory, p-groups and the class equation 347 - simple, solvable and nilpotent groups; composition series 348 - the 2nd and 3rd isomorphism theorems 349 - structure theorems for abelian groups and PID-modules; Jordan and rational canonical forms 350 - field extensions and Galois theory 351 - representation theory and Lie theory 352 - homological algebra, most commutative algebra, algebraic geometry 353 - subdirect representation, quasigroups 354 - Green's relations and Krohn–Rhodes; Hopf algebras 355 356 **Why:** these classify or decompose structures rather than supplying laws to program against, so they license no generic algorithm, data structure or rewrite. 357 358 **Domain-specific exceptions:** 359 - characters of finite abelian groups → FFT, NTT, Walsh–Hadamard 360 - quaternions and SO(3) → graphics and robotics 361 - Schreier–Sims → symmetry breaking (nauty) 362 - Hermite and Smith normal forms → polyhedral compilation 363 - Gröbner bases → computer algebra, nonlinear SMT, invariant generation 364 365 I can turn this into a Doc if you want an editable catalogue.