Skip to content

Commit 191acf2

Browse files
committed
feat(JtvEcho): stratify number systems by additive algebra (spec D6 groundwork)
Adds SECTION 6: the reversibility tier of `+` over a number system is not a per-system stipulation but is *forced* by the carrier's additive algebra. * `NumAlgebra` (abelianGroup / approxGroup / nonGroup) — one constructor per Echo tier; the algebra tower maps 1:1 onto the SECTION 1 Echo lattice, so three levels suffice (a finer Monoid ⊂ CancellativeMonoid ⊂ Group tower would collapse onto the same 3-valued codomain). * `NumSystem` (the seven addable JtvType carriers) + `NumSystem.algebra` + `NumAlgebra.echo` + `NumSystem.echo` — the stratification map. Headline theorems pin the two design facts: * `hex_binary_collapse` — hex/binary are *encodings of ℤ*, not new algebras, so they carry int's tier exactly (encoding ≠ algebra). * `exact_groups_safe` — int/rational/complex/symbolic are exact abelian groups, hence `safe`. * `float_not_safe` / `float_neutral` — IEEE-754 addition is non-associative, so its reversal is lossy; the stratification lifts float to `neutral`. This is the single place "addition-only ⇒ reversible" is qualified by the carrier (and does not threaten the abstract lattice laws — those grade, not compute). * `no_current_system_breaks` — `breaking` is presently empty, reserved for a future non-invertible (nonGroup) system. * `reversal_tier_by_algebra` — ties the tier back to the SECTION 1/2b reversal policies: `safe` ⇔ exact abelian group; non-`breaking` ⇔ not a nonGroup. This answers the design question "are number systems additive on proofs, or a rework, or stratified?" — they are *stratified*: the existing Int results become the ℤ (abelianGroup) instance, and each further carrier is classified by its additive algebra rather than reproving the spine. `lake build` green; zero sorry/admit/axiom. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BJmfoz1ZS1Pejy9LLMY742
1 parent 246a2e2 commit 191acf2

1 file changed

Lines changed: 110 additions & 0 deletions

File tree

jtv_proofs/JtvEcho.lean

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,4 +383,114 @@ theorem feffect_join_idem (a : FunctionEffect) : a.join a = a := by
383383
cases a
384384
simp [FunctionEffect.join, join_idem, epi_join_idem]
385385

386+
-- ============================================================================
387+
-- SECTION 6: NUMBER-SYSTEM STRATIFICATION BY ADDITIVE ALGEBRA
388+
-- ============================================================================
389+
390+
/-
391+
The reversibility tier of `+` — and hence of `reverse { x += v }` — over a
392+
given number system is NOT a per-system stipulation. It is *forced* by the
393+
additive algebra of the carrier. This section stratifies JtV's numeric
394+
systems by where they sit in the additive-algebra tower and reads off the
395+
Echo tier mechanically.
396+
397+
Additive-algebra tower (only the levels reversal can distinguish):
398+
399+
abelianGroup associative + commutative + EXACT inverses
400+
→ reverse-add is total and exact → safe
401+
approxGroup commutative with identity, but NON-associative
402+
and inverses only approximate (rounding)
403+
→ reverse-add recoverable but lossy → neutral
404+
nonGroup `+` not invertible at all (e.g. tropical
405+
min-plus): no reverse exists → breaking
406+
407+
This tower maps 1:1 onto the Echo lattice of SECTION 1 (safe/neutral/breaking)
408+
— which is why three levels suffice: a finer carrier tower
409+
(Monoid ⊂ CancellativeMonoid ⊂ Group) would collapse onto the same 3-valued
410+
Echo codomain.
411+
412+
Headline collapse: `hex` and `binary` are NOT distinct algebras — they are
413+
*encodings of ℤ* (cf. the `JtvType` constructor comments "represented as
414+
int"), so they share `int`'s `abelianGroup` instance. The seven surface
415+
systems thus reduce to TWO inhabited algebra classes here; `nonGroup` is
416+
reserved for future non-invertible systems (spec D6).
417+
418+
Mirrors `crates/jtv-core/src/number.rs` (the runtime carriers) and the
419+
numeric constructors of `Jtv.JtvType`.
420+
-/
421+
422+
/-- The additive-algebra class of a carrier, at the granularity reversal cares
423+
about. One constructor per Echo tier. -/
424+
inductive NumAlgebra where
425+
| abelianGroup -- exact inverses; reverse-add total & exact
426+
| approxGroup -- non-associative / rounding; reverse-add lossy
427+
| nonGroup -- `+` not invertible; no reverse
428+
deriving Repr, DecidableEq
429+
430+
/-- JtV's addable number systems (the numeric constructors of `JtvType`). -/
431+
inductive NumSystem where
432+
| int | rational | complex | symbolic | hex | binary | float
433+
deriving Repr, DecidableEq
434+
435+
/-- Where each system sits in the additive-algebra tower. `hex`/`binary` map to
436+
the SAME class as `int` because they are encodings of ℤ, not new algebras. -/
437+
def NumSystem.algebra : NumSystem → NumAlgebra
438+
| .int => .abelianGroup
439+
| .rational => .abelianGroup
440+
| .complex => .abelianGroup
441+
| .symbolic => .abelianGroup
442+
| .hex => .abelianGroup -- ℤ in hex clothing
443+
| .binary => .abelianGroup -- ℤ in binary clothing
444+
| .float => .approxGroup -- IEEE-754: non-associative, rounding
445+
446+
/-- The Echo tier *forced* by an additive algebra. This is the stratification
447+
law: the reversal tier is a function of the algebra, never a free choice. -/
448+
def NumAlgebra.echo : NumAlgebra → Echo
449+
| .abelianGroup => .safe
450+
| .approxGroup => .neutral
451+
| .nonGroup => .breaking
452+
453+
/-- A number system's reversal tier = the Echo of its additive algebra. -/
454+
def NumSystem.echo (s : NumSystem) : Echo := s.algebra.echo
455+
456+
-- The stratification is total and the map is a genuine function of the algebra,
457+
-- so every result below is closed by definitional reduction / finite decision.
458+
459+
/-- **The hex/binary collapse**: the integer *encodings* carry int's tier
460+
exactly — encoding is not algebra. -/
461+
theorem hex_binary_collapse :
462+
NumSystem.echo .hex = NumSystem.echo .int
463+
∧ NumSystem.echo .binary = NumSystem.echo .int := ⟨rfl, rfl⟩
464+
465+
/-- The exact abelian groups are all `safe` (`+` is fully reversible). -/
466+
theorem exact_groups_safe :
467+
NumSystem.echo .int = .safe
468+
∧ NumSystem.echo .rational = .safe
469+
∧ NumSystem.echo .complex = .safe
470+
∧ NumSystem.echo .symbolic = .safe := ⟨rfl, rfl, rfl, rfl⟩
471+
472+
/-- **Float is not `safe`.** IEEE-754 addition is non-associative, so its
473+
reversal is lossy; the stratification lifts it to `neutral`. This is the one
474+
place the surface "addition-only ⇒ reversible" slogan is *qualified* by the
475+
carrier — and exactly why float's Echo grade sits above `safe`. -/
476+
theorem float_not_safe : NumSystem.echo .float ≠ .safe := by decide
477+
478+
theorem float_neutral : NumSystem.echo .float = .neutral := rfl
479+
480+
/-- **No current system is `breaking`.** Every inhabited carrier is at least an
481+
approximate group, so the `breaking` tier is presently empty — it is held in
482+
reserve for a future non-invertible (`nonGroup`) system. -/
483+
theorem no_current_system_breaks (s : NumSystem) : NumSystem.echo s ≠ .breaking := by
484+
cases s <;> decide
485+
486+
/-- **Stratification meets the reversal policies.** Reading the algebra off the
487+
carrier decides admissibility under both policies of SECTION 1/2b:
488+
`safe` (Safe-only reversal) holds iff the carrier is an exact abelian group;
489+
non-`breaking` (the `reversible { } -> tok` token policy, which also admits
490+
`neutral`) holds iff the carrier is not a `nonGroup`. -/
491+
theorem reversal_tier_by_algebra (s : NumSystem) :
492+
(NumSystem.echo s = .safe ↔ s.algebra = .abelianGroup)
493+
∧ (NumSystem.echo s ≠ .breaking ↔ s.algebra ≠ .nonGroup) := by
494+
cases s <;> decide
495+
386496
end Jtv.Echo

0 commit comments

Comments
 (0)