# Discovery cycle 2: compositions, exact relations and vocabulary reuse

The saved geometry vocabulary now participates in the search. The previous coordinate learner tested single transformation families. The new search can assemble stored operators, validate the resulting composition, save it, and recognize it on fresh coordinate pairs. A separate exact polynomial normalizer exposes cancellations that the previous local compiler could not see.

This is release 0.8 inside the continuing Geometry Lab package. The original sequence engine is unchanged. No neural-network weights were trained.

## What improved

| Experiment | Previous/baseline result | This cycle |
|---|---:|---:|
| Recognize 60 sampled compositions of 2–4 saved operators | Single-family learner: 7/60 | Composition search: 60/60 |
| Recheck those maps on additional curved point sets | — | 60/60 |
| Fit new affine coefficients after saved nonlinear features | — | 20/20, including 3D → 2D and 3D → 4D |
| Reject shuffled correspondences | — | 40/40 |
| Reject corrupted holdouts | — | 10/10 |
| Reject nonlinear parameters outside this fixed search dictionary | — | 10/10 |
| Reject random affine-readout targets | — | 12/12 |
| Recognize a saved composition on fresh point sets | — | 20/20 |

The positive composition targets are new combinations of **six existing fitted operators with their saved parameter values**: translation, twist, bend, taper, sine shear and polynomial shear. They are not unseen nonlinear parameters. Separate affine-readout tests fit fresh matrix coefficients and offsets. Coordinates are synthetic, and target transformations use the runtime kernels. Extra point sets check transfer; exact coefficient reasoning is a separate test.

Each query uses 96 paired points: 72 for candidate selection and 24 held out. The first four training pairs are only a search prefilter. A candidate must then fit every training row before its holdout is examined. A failing holdout cannot select a replacement candidate. Matching finite samples does not prove a unique transformation history.

## Finding combinations faster

For a four-step program, forward enumeration tries complete prefixes up to length four. The new method grows a short path forward from the inputs and another backward from the outputs using registered inverses, then looks for a meeting point. It preserves execution order.

For the representative four-step chain:

| Method | State evaluations | Median query time |
|---|---:|---:|
| Forward enumeration | 1,554 | 39.13 ms |
| Meet-in-the-middle | 84 | 4.75 ms |
| Previously saved composition, small cache | No search expansion | 0.337 ms |

That is about **8.2× faster search** and **14.1× faster reuse than search**, or about **116× faster reuse than forward enumeration** on this case. Preparing the small bank took another 0.706 ms and is measured separately. These are one-machine timings, not universal speed guarantees. Both search methods used the same six atoms, prepared evaluators, depth bound, training data and holdout rule.

The saved bank now includes 74 validated discovery entries alongside the earlier fitted operators. Some entries are aliases or related compositions, not 74 independent laws. Sixty-one entries are eligible for the 3D-to-3D memory lookup. A cold lookup in that larger bank took 4.30 ms. Prioritizing the most recently validated composition reduced recurring-transform lookup to 0.350 ms on fresh coordinates. All coordinates were still re-evaluated and checked.

**Accumulation alone does not guarantee speed.** More entries can increase lookup cost. The last-success ordering helps repeated transformations; varied or unrelated queries may not benefit. The search still has a finite depth/state budget, excludes atoms without registered inverses, and may miss matches when inverse evaluation is ill-conditioned. It reports unresolved or budget-exhausted cases instead of claiming completeness.

## What the exact relation miner found

The miner enumerated all words through length four over six declared atoms: positive/negative source translations, the earlier learned quadratic shear and its inverse, and mirrors of its source and target coordinates.

- **1,555 words examined**, including identity.
- **392 distinct polynomial endpoint maps** for the represented rational coefficients.
- **788 words with a shorter word in the same finite alphabet.**
- **1,024 word instances reduced to fewer top-level operations than the 0.7 compiler produced.**
- Within those, **96 instances became affine maps or identity**, representing 55 distinct exact endpoint maps.

These counts overlap and include many related instances of established identities. They are not counts of new mathematical theorems. A single polynomial-map instruction can contain many arithmetic operations, so fewer top-level instructions need not mean faster execution.

The equality mechanism is exact rational polynomial composition. It retains coefficients and monomial exponents, and compares normal forms. `results/exact-relations.json` records the alphabet, words, reductions and certificate hashes; recomputing the normal forms checks them. Forty selected reductions also passed a separate direct rational point interpreter on 27 points each. That point check guards implementation errors; it is not what establishes polynomial equality.

The reducer also rejected false commutation, retained a coefficient as small as `1/10^30`, refused to treat sphere inversion as a total polynomial map, and stopped a degree-explosion example at the configured budget. No sampled coincidence is promoted into a symbolic rewrite theorem.

## A concrete hidden shortcut

Take two coordinates x and z, leaving the others unchanged:

1. Shift z by 1.
2. Add z² to x.
3. Undo the shift.
4. Subtract z² from x.

The net change is:

```text
x' = x + (z+1)^2 - z^2 = x + 2*z + 1
z' = z
```

Four steps, including nonlinear steps, have become one affine map. The same construction applied to the saved learned quadratic coefficients produced an exact affine endpoint. On 12,000 points, that case took 0.507 ms before reduction and 0.179 ms afterward, about **2.84× faster once reduced**. Exact normalization itself took 0.399 ms; reuse is needed to amortize it. Maximum float difference was `3.34e-16`.

## Repeating the construction exposes a degree ladder

Starting with `x <- x + z^5`, the engine repeatedly constructed the shift/shear/undo chain and normalized it. It found:

| Repetition order | Degree of the added function | Original action count | Reduced result |
|---:|---:|---:|---|
| 0 | 5 | 1 | Quintic shear |
| 1 | 4 | 4 | Quartic shear |
| 2 | 3 | 10 | Cubic shear |
| 3 | 2 | 22 | Quadratic shear |
| 4 | 1 | 46 | One affine map |
| 5 | 0 | 94 | Constant translation by 120 |
| 6 | Zero function | 190 | Identity, zero remaining actions |

This is the established finite-difference pattern: taking a difference lowers a nonconstant polynomial's degree by one. The engine exposed it by composing the actions and reducing their exact coefficients. The 190-action identity is an algebraic result for this construction, not a claim that arbitrary long programs simplify to identity.

For degrees 1–5, the experiment then varied the shift size, gave the first 24 exact resulting translation amounts to the original RRLS sequence engine, and checked eight unseen shift sizes per degree. **All 40 future values matched.** The observed relation is `degree! * step_size^degree` after that many differences. The sequence engine's inference was drawn from the generated values; the exact normalizer supplied those values. This is not a newly discovered theorem or proof about physical dimensions.

Direct float64 evaluation of the long exact identity differed from its input by up to `7.18e-12` in the included run. Exact mathematical equality does not mean identical intermediate rounding, overflow behavior, or bit patterns.

## Run the new tools

The existing desktop lab now has **Discover combo** and **Exact polynomial** buttons. Choose **Saved-vocabulary composition** for discovery or **Hidden affine cancellation** for exact reduction. Desktop interaction remains untested here because the environment has no display; the core and CLI workflows were exercised.

```text
python geometry_cli.py discover examples/composition-pairs.json --bank results/discovery-vocabulary.json
python geometry_cli.py discover your-pairs.json --bank results/discovery-vocabulary.json --name my-new-composition
python geometry_cli.py discover your-pairs.json --bank results/discovery-vocabulary.json --readout --name my-feature-readout
python geometry_cli.py exact examples/hidden-affine.json --dim 3
python geometry_cli.py exact examples/nested-difference.json --dim 3
python geometry_cli.py use results/discovery-vocabulary.json twist_move_wave_taper examples/points-3d.json
```

`discover` defaults to depth four. `--atoms` restricts the fixed vocabulary by saved fit names. `--method flat` selects forward enumeration for comparison. `--readout` searches one stored feature map followed by a newly fitted affine map; it can change the output dimension. `--name` saves only a held-out-validated result. `exact` accepts the supported total polynomial operations and stops at explicit term/degree/work limits.

Reproduce the run:

```text
python benchmark_discovery.py
python check_discovery_interfaces.py
```

`benchmark_discovery.py` rebuilds the experimental discovery bank from the earlier fitted bank before accumulating the seeded results. Keep personal additions in a separate copy if rerunning that benchmark. Ordinary `discover --name` adds to the bank you specify.

## Files and evidence

- `rrls_composition.py`: bounded search, held-out validation, storage and affine readouts.
- `rrls_polynomial.py`: exact polynomial normalization, equality checks and finite relation mining.
- `results/discovery-benchmark.json`: full test rows, controls, timings and limitations.
- `results/discovery-vocabulary.json`: earlier fitted operators plus accepted discovery entries.
- `results/exact-relations.json`: enumerated words and exact reductions.
- `results/difference-ladder.json`: successive polynomial reductions.
- `results/difference-schedules.json`: original RRLS predictions and unseen expected values.
- `check_discovery_interfaces.py`: CLI persistence, reuse and rejection checks.

The gains demonstrated here are bounded program search, recognition reuse, and algebraic reduction. They do not establish arbitrary nonlinear inverse discovery, global minimality, universal compression, or automatic improvement on every domain.
