|
| 1 | +# Roadmap — v2: symbolic stack with Poincaré-style presentation |
| 2 | + |
| 3 | +v1.0.0 is a numeric RPN calculator: the stack holds *numbers* (exact rationals |
| 4 | +or doubles) and every operator computes eagerly. v2 changes the nature of the |
| 5 | +stack. |
| 6 | + |
| 7 | +## Vision |
| 8 | + |
| 9 | +The stack holds **expression terms**, not just numbers — a bit like lambda |
| 10 | +calculus: operators **build a term**, and a **reduction** step normalizes it on |
| 11 | +demand rather than computing eagerly. Results are then **presented like |
| 12 | +Poincaré**: real 2D math layout (stacked fractions, radicals, raised exponents) |
| 13 | +with the **exact form and its decimal approximation** shown together, exactly |
| 14 | +the feel of the standard NumWorks app. |
| 15 | + |
| 16 | +``` |
| 17 | + 2 ENTER 8 √ × level 1: 2·√8 ── exact, unreduced term |
| 18 | + reduce level 1: 4·√2 ── normalized |
| 19 | + →Num level 1: 5.656854 |
| 20 | +``` |
| 21 | + |
| 22 | +## The core constraint (unchanged from v1) |
| 23 | + |
| 24 | +An external app cannot call Poincaré (EADK sandbox). Two routes to the vision: |
| 25 | + |
| 26 | +| | Route A — native fork | Route B — self-contained engine | |
| 27 | +|---|---|---| |
| 28 | +| Where | RPL mode inside Epsilon (the `epsilon` fork) | still a portable `.nwa` | |
| 29 | +| Math | reuse Poincaré `Expression` + simplification + `Layout` | build a small term engine + 2D renderer ourselves | |
| 30 | +| Fidelity | full (real Poincaré look & CAS) | good, bounded | |
| 31 | +| Cost | fork maintenance, upstream sync, bigger build | more app code, but stays portable | |
| 32 | + |
| 33 | +**Recommendation:** prototype **Route B, Phase 1** first — it extends the |
| 34 | +existing host-tested pure core and keeps the app a single `.nwa`. Keep Route A |
| 35 | +as the escape hatch if you later want true Poincaré fidelity. |
| 36 | + |
| 37 | +## Architecture |
| 38 | + |
| 39 | +### 1. Term model (`expr`) |
| 40 | +Replace the flat `Value` on the stack with an expression tree: |
| 41 | + |
| 42 | +- Leaves: `Integer`, `Rational`, `Constant` (π, e, i), `Symbol` (future). |
| 43 | +- Nodes: n-ary `Add`, n-ary `Mul`, `Pow`, `Neg`, `Func` (sin, ln, …). |
| 44 | +- N-ary `Add`/`Mul` with **sorted, canonicalized** operands so equal terms |
| 45 | + collapse (`√2 + √2 → 2·√2`). |
| 46 | + |
| 47 | +The stack becomes a stack of `Expr` (kept small: arena/pool allocation, no heap |
| 48 | +churn — important on the device). |
| 49 | + |
| 50 | +### 2. Reduction (the "lambda" step) |
| 51 | +Operators are **constructors**: `×` just builds `Mul(a, b)`. A `reduce()` pass |
| 52 | +normalizes to a canonical form: |
| 53 | + |
| 54 | +- rational arithmetic (reuse v1's overflow-checked `Value`), |
| 55 | +- constant folding, like-term collection, `√` extraction of square factors, |
| 56 | + power rules (`xᵃ·xᵇ → xᵃ⁺ᵇ`), sign normalization. |
| 57 | + |
| 58 | +Two outputs from any term: **exact** (the normalized tree) and **approximate** |
| 59 | +(numeric eval to double). Reduction runs on `ENTER` / on demand — building a |
| 60 | +term then reducing it mirrors *build → β-reduce → normal form*. |
| 61 | + |
| 62 | +### 3. 2D layout renderer (`layout`) — the Poincaré look |
| 63 | +The biggest new piece in Route B. A layout tree of boxes with a **measure** |
| 64 | +(width, height, baseline) then **draw** pass over the EADK framebuffer: |
| 65 | + |
| 66 | +- `HBox` / `VBox`, `FractionLayout` (numerator over bar over denominator), |
| 67 | +- `RadicalLayout` (√ with vinculum), `SuperscriptLayout` (raised exponent). |
| 68 | + |
| 69 | +Reuses the two EADK font sizes; measurement drives right-alignment on the stack. |
| 70 | + |
| 71 | +### 4. Presentation |
| 72 | +Each stack level renders its **exact 2D layout**; a secondary line (or a |
| 73 | +per-level toggle) shows the **decimal approximation**, like the standard app's |
| 74 | +exact/approx duality. `→Num` forces the approximate view. |
| 75 | + |
| 76 | +## Phasing |
| 77 | + |
| 78 | +1. **Term engine + reducer** for rationals, `√`, π, basic simplification — pure |
| 79 | + C++, unit-tested on host (extends the current `make test` harness). 1D text |
| 80 | + output first (`4·√2`). |
| 81 | +2. **2D layout renderer**: fractions, powers, radicals over the framebuffer. |
| 82 | +3. **Exact / approximate dual presentation** + `→Num`. |
| 83 | +4. *(optional)* evaluate a **Route A** native-fork port if fidelity or scope |
| 84 | + demands the real Poincaré engine. |
| 85 | + |
| 86 | +## Risks & bounds |
| 87 | + |
| 88 | +- **Binary size** — v1 is already ~500 KB; a layout engine adds more. Budget it; |
| 89 | + consider dropping `_printf_float` via a hand-rolled number formatter. |
| 90 | +- **Mini-CAS scope creep** — explicitly *not* a general algebra system. Bound it |
| 91 | + to: exact rationals, `√`, π/e, like-term collection, power/product rules. |
| 92 | +- **Device memory** — pool-allocate terms; cap expression depth/size and report |
| 93 | + when a level exceeds it rather than failing silently. |
| 94 | + |
| 95 | +## What carries over from v1 |
| 96 | + |
| 97 | +The pure, host-tested core (`value`, `stack`, `input_field`, `rpn`) is the |
| 98 | +foundation: `Value` becomes the numeric leaf of the term model, `Stack` becomes |
| 99 | +a stack of `Expr`, and the `make test` harness extends to cover reduction rules. |
0 commit comments