36. Symmetric storage, derived domains, and domain iteration helpers (0.3, 2026-11-21)
- 36.1 Symmetric 2D tables are a storage dimension
Sym<V>, not a new container type.[Sym<V>]Tpacks an unordered pair(u, v) : (V, V)into a flat triangular array of sizen * (n + 1) / 2viasym_idx(a, b) = max(a, b) * (max(a, b) + 1) / 2 + min(a, b). Bothadj[u, v]andadj[(u, v)]index it, withadj[u, v]andadj[v, u]aliasing the same cell. Diagonal cells(u, u)are included soSym<V>works uniformly for both graphs with self-loops and reflexive relations (costsnextra cells over strictn*(n-1)/2, avoiding a trap onadj[u, u]). Reason: eliminates duplicated symmetric writes (cf2150f) and halves memory while keeping the exact[Dim]Tarray model, formatter, linter, and trace display. Reverse: removeDim::Sym/DimSpec::SymandBuiltin::SymIdx(cpl-check,cpl-ir,cpl-interp,cpl-codegen).
- 36.2 Domain-typed iteration helpers
V.after(i),V.before(i), andV.pairs.V.after(i)andV.before(i)returnRange<V>covering(i.to_idx + 1)..V.countand0..i.to_idxrespectively, and lower directly toIter::Rangeinforloops and comprehensions so they emit zerocpl::Rangeruntime overhead.V.pairsyields unordered distinct pairs(i, j) : (V, V)withi < j: infor (i, j) in V.pairs(withoutbreak) it lowers directly to two nestedStmt::Forloops with zero allocation; as a value or withbreakit materializesList<(V, V)>; anddomain P = V.pairsdeclares a derived domain of sizen * (n - 1) / 2. Reason: mined fromcf2150f,cf2147h,cf2129b, andproto/ports/ecnerwala/dream/where ports repeatedly wrotefor j in V if j > i:or0..i/i + 1..n. Reverse: remove the domain member arms incpl-check/src/check/expr.rsandcpl-ir/src/lower/{call,expr,stmt}.rs.
- 36.3 Derived product domains (
domain S = A * B,domain E = edges(V)) remain staged behindSym<V>and[A, B]T. Multi-dimensional tables[A, B]Tand[(A, B)]Talready cover dense product indexing, anddomain P = V.pairscovers unordered pair domains. General algebraic product domains (domain State = (V, K),research/frictions/cf2178h.md,dream/cf2178h.cp) and graph-edge domains (domain E = edges(V)) need bijective packing/unpacking (Pos<A * B> <-> (A, B)) and are queued as the next step inplan/DOMAINS.md. Reason: keep commits small and avoid shipping half-baked product destructuring. Reverse: implement product-domain packing incpl-irandcpl-check.