Visual guide to the mathematical structures underlying architectural enforcement
A lattice is a partially ordered set where every pair of elements has a meet (greatest lower bound) and a join (least upper bound).
The Hasse diagram shows the ordering: lines go from lower to higher. Every pair has a unique meet (go down to where they converge) and join (go up to where they converge).
KindScript's CodeLoc forms a three-level containment lattice. Higher = more general (contains more). Lower = more specific (contained by more).
subsumes(dir('/src/domain'), declLoc('/src/domain/order.ts', 'Order')) = true — the directory transitively contains the declaration.
meet(a, b) returns the greatest lower bound — the most specific location contained by both. Returns null if the locations are incomparable (different branches of the tree).
Take a set S = {a, b, c}. The powerset is all possible subsets, ordered by ⊆. This forms a lattice where meet = ∩ and join = ∪.
P(Loans) — the powerset of all loans. Each loan {shrd x} or {uniq y.0} is an atom. No loan subsumes another, so the powerset is naturally canonical. KindScript's version is more complex because its atoms (CodeLocs) have internal structure.
Because CodeLocs have containment (a directory subsumes its files), sets of CodeLocs can contain redundancy. canonicalize() removes locations that are subsumed by coarser ones already in the set.
dir /src/domain
file /src/domain/order.ts
decl /src/domain/order.ts#Order
file /src/infra/db.ts
dir /src/domain
file /src/domain/order.ts
decl order.ts#Order
file /src/infra/db.ts
The directory /src/domain already claims everything under it —
the file and declaration are redundant, so they're removed.
[dir('/src')] vs [dir('/src'), file('/src/a.ts')]. Canonicalization gives a unique representative for each equivalence class. This is why KindScript's lattice is a quotient of a powerset, not a pure powerset.
file /src/domain/order.ts
file /src/domain/event.ts
dir /src/domain
dir /src/domain
file order.ts
file event.ts
The directory subsumes both files after merge, so canonicalization removes them.
dir /src/domain
decl domain/order.ts#Order
file /src/infra/db.ts
decl domain/order.ts#Order
meet(dir, decl) = decl (dir contains the decl's file) —
meet(dir, infra/db.ts) = null (different tree)
file /src/a.ts
file /src/b.ts
file /src/c.ts
file /src/b.ts
file /src/a.ts
file /src/b.ts
file /src/c.ts
Each base location is checked: is it subsumed by any excluded location? If yes, it's dropped.
A CarrierExpr is an algebraic expression that describes where code lives. The resolver evaluates it to a concrete CodeLoc[] set.
The structural difference: Oxide's atoms (loans) are flat — no loan subsumes another. KindScript's atoms (CodeLocs) are hierarchical — directories subsume files subsume declarations.
| Property | Oxide | KindScript |
|---|---|---|
| Atom structure | Flat (no loan subsumes another) | Hierarchical (dir ⊒ file ⊒ decl) |
| Set union | A ∪ B | canonicalize([...A, ...B]) |
| Set intersect | A ∩ B | pairwise meet + canonicalize |
| Canonical? | Always (flat atoms) | Requires canonicalize() |
| Boolean algebra? | Yes (complete) | No (canonicalization breaks complements) |
| Lattice type | Powerset lattice | Quotient of powerset |
How the algebraic structures flow through KindScript's five-stage pipeline.
KindScript Lattice Visualizations — Generated 2026-02-16
Source: src/domain/physical/code-loc.ts · src/application/pipeline/carrier/carrier-expr.ts · src/application/pipeline/carrier/loc-set-ops.ts