Equivalence-Preserving Rewriting¶
Core Idea¶
Equivalence-preserving rewriting transforms an object into a behaviourally equivalent but operationally different form under an explicit equivalence relation, then selects among the admissible rewrites by a cost criterion the equivalence itself does not adjudicate — the discipline lies in keeping the two factored: the equivalence carves a space of safe moves, the cost picks one point in it.
How would you explain it like I'm…
Same Thing, Easier Way
Swap Without Changing Meaning
Meaning-Safe Rewrites
Broad Use¶
- Database query optimisation: relational-algebra rewrites (selection push-down, join reordering) transform a query into result-equivalent plans, and the optimiser picks the lowest estimated cost.
- Compiler optimisation: loop unrolling, dead-code elimination, and peephole rewrites, each program-equivalence-preserving and scored by an execution-cost model.
- Theorem proving: normal-form rewriting and proof restructuring under preserved logical content.
- Symbolic computation: factoring, expanding, and simplifying under symbolic equivalence, scored by length or depth.
- Natural-language paraphrase: meaning-preserving rewordings scored by clarity, register, or length.
- Legal drafting: restating a clause to clarify or consolidate without changing its legal effect.
- Hardware synthesis: equivalent-circuit rewrites under logical equivalence, scored by gate count or power.
Clarity¶
Forces two questions ordinary language conflates — under what equivalence relation are these rewrites admissible? and what cost are we minimising? — exposing the grain problem: a too-coarse equivalence admits behaviour-changing rewrites ("correct by the spec, wrong by the user"); a too-fine one forbids safe ones.
Manages Complexity¶
Separates safe-space construction from cost minimisation — generating a good rewrite is hard, checking one preserves meaning is mechanisable, and choosing by cost is separate — so the equivalence relation, once written down, is reusable across many swappable cost models.
Abstract Reasoning¶
Licenses equivalence-as-design-choice, verification asymmetry (checking beats generating, so generate-then-verify architectures dominate), cost-equivalence orthogonality (re-tune by swapping cost models), and the non-obvious move of treating the equivalence relation — not the visible cost work — as the primary object of scrutiny, since correctness lives there.
Knowledge Transfer¶
- Compiler to legal drafting: declare the "preserved legal effects" relation up front and screen rewrites against it, rather than ad-hoc redrafting.
- Database optimiser to paraphrase: the search-then-verify architecture ports to controlled-language and assisted-editing tooling.
- Term rewriting to product design: the normal-form idea underwrites style guides, code formatters, and design-system standardisation.
Example¶
A database query optimiser generates candidate plans, each provably inside relational-algebra equivalence so correctness is never at issue, then ranks them by an orthogonal cost model — so re-tuning to new hardware swaps the cost model over a fixed, declared equivalence rather than rebuilding the safe space.
Relationships to Other Primes¶
Parents (1) — more general patterns this builds on
- Equivalence-Preserving Rewriting is a kind of Transformation — The MEANING-PRESERVING subclass of transformation: an explicit equivalence relation carves a space of safe moves, plus an orthogonal cost criterion that selects within it. The file: 'this prime is the disciplined subclass... preserved under what relation?' Generic transformation may change meaning freely; this constrains it by a named equivalence.
Path to root: Equivalence-Preserving Rewriting → Transformation
Not to Be Confused With¶
- Equivalence-Preserving Rewriting is not Transformation in general because a transformation may change meaning freely, whereas this prime is the meaning-preserving subclass constrained by an explicit equivalence relation.
- Equivalence-Preserving Rewriting is not Optimization generically because this prime factors the search into safe-space construction (the equivalence) and within-space selection (the cost), which generic optimisation fuses.
- Equivalence-Preserving Rewriting is not Canonical Form because a canonical form is a single distinguished representative, whereas this prime is cost-driven navigation among many admissible forms that need not converge on any one.