# Tally

Tally is a small programming language for counts, units, exact model arithmetic and measurement provenance. It was
built to make the D0RE / Theory of Reality physics work executable and auditable. The current version is **0.3.0**
(`VERSION` in `tally.py`; specification in [SYNTAX.md](SYNTAX.md)).

**Status:** a research prototype. It is well tested within its scope, but it is a single-file tree-walking interpreter
with no packaging and no hosted CI; all verification is run locally. The physics programs check stated models; they do
not establish new physics (see [Scope](#scope-of-the-checks)).

## What the language does

- **Every number is a count of a declared kind.** There are no bare numbers, decimals or negative literals: write
  `500 ms`, not `0.5 s`. Signed values are balances (`balance`, `flip`) and exact fractions (`fraction`, `share`).
- **Observations carry their context:** kind, window, resolution, procedure and bench. A bench is `apparatus`,
  `simulated` or `cited`. Settings (trials, loop counters, phase steps you perform yourself) are exact and kept apart
  from observations. A zero needs a positive control.
- **Provenance is propagated** through arithmetic, calls and control flow, so a result says whether it came from
  theory, simulated, cited or apparatus records. This is metadata tracking, not a security proof.
- **Exact arithmetic for decisions.** Amplitudes are exact sums of phase arrows on a 16-step (or finer) ratchet.
  Comparisons of real cyclotomic values are decided by certified interval refinement (`exact_order.py`), never by a
  float tolerance.
- **Frozen claims and accuracy contracts.** `claim`/`certify` freezes a prediction together with hashes of the program,
  its imports and the runtime (`certification.py`). `assess`/`require_accuracy` (new in 0.3) give exact discrepancy
  intervals against a declared reference ([ACCURACY.md](ACCURACY.md)).

**Implementation.** The interpreter is `tally.py`: 2,256 lines of standard-library Python, with a line-based parser,
a recursive-descent expression parser and a tree-walking evaluator. It has three helper modules: `accuracy.py`,
`exact_order.py` and `certification.py`. It is slow: training the 8-feature chess perceptron takes about 100 s (as
recorded in `research/chess-proof`). Python 3.12 or newer is required.

## Run it

```sh
python3 verify.py                        # unit tests, self-check, strict accuracy, physics programs, premise audit
python3 tally.py --check                 # the language's own rules
python3 tally.py --test                  # all physics programs; rewrites every physics/*.out
python3 tally.py --strict-accuracy examples/accuracy.tly # gate every executed accuracy contract
python3 operational_audit.py             # run the operational model comparison and report premise dependencies
python3 tally.py examples/numbers.tly    # a tour
python3 tally.py examples/units.tly      # SI units as counts (import "si")
python3 tally.py                         # interactive
```

A program with `claim` statements writes `<name>.ledger.json` beside itself on its first run. In this folder only
`examples/drips.tly` and `examples/malus_kitchen.tly` do, and their ledgers are not tracked.

## Verification

`python3 verify.py` runs, in order:
1. the unit tests in `tests/` (697 tests in 52 files) and `../operational-math/tests` (6 tests);
2. `tally.py --check`;
3. `tally.py --strict-accuracy examples/accuracy.tly`;
4. `tally.py --test`: all 131 physics programs, 1,581 checks (the `✓` lines in `physics/*.out`);
5. `operational_audit.py --check`: 493 finite checks behind 41 declared conclusions.

**Timing.** No full run with the current 131 programs has been timed. The last recorded full run, with 72 programs,
took 3,802 s ([DEVELOPMENT.md](DEVELOPMENT.md), "Complete frozen verification"). An earlier run of program 80 alone
took 2,596 s and program 89 about 480 s, so expect well over an hour.

**Transcripts.** `--test`, and therefore `verify.py`, rewrites every `physics/*.out` transcript. Check `git diff`
before committing, and regenerate transcripts by running the programs, never by hand.

**Not covered by `verify.py`:** the six chess programs, `bridge_audit.py` (which re-runs the 44 relativity programs
and compares their transcripts), the NumPy side scripts and the figure scripts. There is no hosted CI, by the owner's
choice, to avoid paid Actions minutes; run `verify.py` locally before committing.

**Last replay, 22–23 November 2026, on Python 3.13:** all unit tests passed; `--check`, the strict accuracy example,
the operational audit and `bridge_audit.py` passed; and every physics program except 80 (skipped for time) passed and
reproduced its stored transcript.

## Folder map

| Path | Contents |
|---|---|
| `tally.py`, `accuracy.py`, `exact_order.py`, `certification.py` | the interpreter and its helpers |
| `SYNTAX.md` | the language specification |
| `lib/` | the standard library (below) and six generated chess data files |
| `examples/` | short tours; several fail deliberately to show a refusal |
| `physics/` | 131 numbered programs and their transcripts; **[physics/README.md](physics/README.md) indexes them** |
| `chess/` | six chess programs used by `research/chess-proof` (below) |
| `tests/` | unit tests and fixtures |
| `verify.py` | the local verification command |
| `operational_audit.py`, `premise_ledger.py`, `operational_models.json` | the premise-ledger audit of the operational models ([OPERATIONAL_MODELS.md](OPERATIONAL_MODELS.md), [PREMISE_LEDGER.md](PREMISE_LEDGER.md)) |
| `bridge_audit.py`, `bridge_ledger.json` | the premise-ledger audit of the relativity programs ([RELATIVITY_QUANTUM.md](RELATIVITY_QUANTUM.md)) |
| nine NumPy scripts and their `*_results.json` | side computations for programs 129–143 ([below](#numpy-side-scripts)) |
| `*_figure.py`, `figure.py`, `*.svg` | figure scripts and the figures they draw |
| `*.md` (topic write-ups) | one per program family; listed in [physics/README.md](physics/README.md) |
| `COLLABORATION.md`, `DEVELOPMENT.md` | open tasks and the running development log |

## Physics programs

| Programs | Family | Write-up |
|---|---|---|
| 01–24 | Photons, light and first records | [PHYSICS.md](PHYSICS.md) |
| 25–27 | Particles and measured constants | [PARTICLES.md](PARTICLES.md) |
| 28–34, 80–84 | Atoms, hydrogen to radon | [ATOMS.md](ATOMS.md) |
| 35–42 | QED and photon–photon scattering | [QED.md](QED.md), [LIGHT_BY_LIGHT.md](LIGHT_BY_LIGHT.md) |
| 43–47 | Premise audits and counterexamples | [FOUNDATIONS.md](FOUNDATIONS.md), [RECONSTRUCTION_LEDGER.md](RECONSTRUCTION_LEDGER.md) |
| 48–52 | Operational quantum models | [OPERATIONAL_MODELS.md](OPERATIONAL_MODELS.md) and per-program write-ups |
| 53–57, 69 | The atom/walk interaction | one write-up per program, e.g. [ATOM_SCHEDULE.md](ATOM_SCHEDULE.md) |
| 58 | Photon-number records | [PHOTON_RECORD.md](PHOTON_RECORD.md) |
| 59, 70–75 | Gauss law, orbitals and measurement | one write-up per program, e.g. [GAUSS_COULOMB.md](GAUSS_COULOMB.md) |
| 60–63 | Field content | [QUANTUM_FIELDS.md](QUANTUM_FIELDS.md) |
| 64 | Accuracy contracts | [ACCURACY.md](ACCURACY.md) |
| 65–68 | D0RE proposals: black-hole shadow, coherent return | [BLACK_HOLE_SHADOW.md](BLACK_HOLE_SHADOW.md), [COHERENT_RETURN.md](COHERENT_RETURN.md) |
| 85–89 | ROIFT and the Theory of Reality | [ROIFT.md](ROIFT.md), [THEORY_CROSSREF.md](THEORY_CROSSREF.md) |
| 90–99, 110–143 | Walks, relativity and gravity | [RELATIVITY_QUANTUM.md](RELATIVITY_QUANTUM.md) |
| 100–101 | Minimum photon and explicit observation | [PHOTON_MINIMUM.md](PHOTON_MINIMUM.md) |

Numbers 76–79 and 102–109 are unused. [physics/README.md](physics/README.md) gives one line, the check count and the
write-up for every program.

**The relativity programs in one paragraph.** Programs 90–99 and 110–143 build a conditional route from a quantum walk
to gravity: walk kinematics, a spin-2 composite and its gauge structure, Jacobson's Clausius argument, and entanglement
geometry. [`bridge_ledger.json`](bridge_ledger.json) records the route's dependencies. Its top conclusion lists two
supplied ROIFT postulates as premises, and it also relies on seven cited human arguments and four observations that
are not machine-checked. Programs 124–128 execute the finite algebraic steps of Jacobson's argument; the Raychaudhuri
reduction and the nonlinear Bianchi identity are cited. Nothing here derives Einstein dynamics from the walk without
those premises and citations. Programs 129–132, 134–138 and 140–143 check values copied by hand from NumPy
floating-point runs. Programs 140–143 use a single buffer width, w = 16; at w = 8, program 140's diagonal ratio is
4.2% off the prediction ([details](RELATIVITY_QUANTUM.md#floating-point-inputs-for-programs-129143)).

## NumPy side scripts

The interpreter is standard library only; nine side scripts use NumPy floats: `area_law_anisotropy.py`,
`buffered_correlation.py`, `clausius_walk.py`, `curved_entanglement.py`, `entanglement_metric.py`,
`modular_hamiltonian.py`, `mutual_information_area.py`, `quench_alternating.py` and `quench_entanglement.py`. Each
writes a `*_results.json` file. Programs 129–132, 134–138 and 140–143 enter rounded digits from those files by hand, as
records on a `simulated` bench. Exactness stops there: the Tally checks on the copied digits are exact, but the
floating-point values have no error bound. These scripts are not run by `verify.py`; where their docstrings state a
run time, it is between about one and fifteen minutes.

## Chess programs (`chess/`)

These programs belong to [`research/chess-proof`](../chess-proof/README.md). Its Python scripts generate their data
and run five of the six by path; for the two perceptrons, the reduced rule and the counterplay choice, a Python replica
must reach the same result. Every feature and label is computed in Python (python-chess, exhaustive search or
Stockfish) and exported as integer lists into `lib/chess_*_data.tly`; Tally only scores, trains and counts. Features
and labels enter as plain `trial` settings, not as records on a bench, so Tally's provenance tracking does not apply
and the outputs are marked `(derived)`.

| Program | What it does |
|---|---|
| `chess_ranking_network.tly` | Averaged ranking perceptron: a single-layer linear score over 8 integer move features, 6 passes over 300 labelled mate-in-2 positions. Its check is on the training set: a winning move ranks first in 134 of the 300 positions, against 88 for the unaveraged weights and 13 for python-chess's move order (as recorded in `research/chess-proof`). Held-out results are computed in Python by `research/chess-proof`. |
| `chess_play_network.tly` | The same perceptron on the 16 move facts of Stockfish-labelled positions. Its check is also on the training positions. `lib/chess_play_data.tly` is rewritten by either `play_benchmark.py` or `reduce_logic.py`, so the program trains on whichever wrote it last. |
| `chess_play_logic.tly` | Re-counts, on held-out positions, how often a 7-weight linear rule tuned in Python (`reduce_logic.py`) has a good move in its top k. |
| `chess_forcing_logic.tly` | ORs six forcing-move classes from facts that Python computed (check, capture, promotion, threat, fork, replies left, king bound) and applies a squeeze threshold of 3 replies, which its header calls "a measured choice, not a theorem". Its checks are on the 300 training positions. |
| `chess_forced_advantage.tly` | Scores defender counterplay at each leaf with hand-chosen weights (4 per check, 2 per capture, 1 per attacked king-zone square) and picks the least-risk shortest line. |
| `chess_wheel.tly` | Re-checks numeric claims that `chess_wheel.py` wrote into `lib/chess_wheel_data.tly`; it compares the generated constants and adds no independent evidence. |

There are no neural networks with hidden layers, no backpropagation and no new architectures in this folder;
"network" here means a single-layer linear perceptron. The chess programs are not run by `verify.py` or by any test in `tests/`.

## Libraries (`lib/`)

`core` (loaded before every program), `walk`, `atom` (exact atomic integrals with native kernels checked against their
Tally definitions), `angular`, `shells`, `si`, `qed`, `operational`, `quantum`, `quantum_operations`, `intervals`, and
model libraries shared by particular programs: `atom_walk`, `atom_manybody`, `atom_ring`, `atom_scaling`,
`coupling_scaling`, `equilibrium`, `gauss_coulomb`, `gauss_continuum`, `gauss_fermion`, `gauss_orbital`,
`orbital_memory`, `recorded_projection` and `repeatable_energy`. The six `chess_*_data.tly` files (about 9 MB) are
generated by `research/chess-proof`; do not edit them by hand.

## Scope of the checks

A passing program establishes the assertions it actually checks, under its stated model inputs. It does not establish
a new law of nature or authenticate an apparatus. A cited record is "observed", never "certified". In the words of
[FOUNDATIONS.md](FOUNDATIONS.md): no contradiction inaccessible to conventional mathematics has been established here.
The QED, atomic and field programs reconstruct standard physics under explicit premises; the D0RE, ROIFT and
relativity programs test proposals conditionally. Each write-up separates supplied assumptions from what the code
checks.

## Working on Tally

Start with [COLLABORATION.md](COLLABORATION.md) for open tasks and trust boundaries. [DEVELOPMENT.md](DEVELOPMENT.md)
is the running log, with the newest entries at the end. Changes to the language should include a
failing-before/passing-after regression and keep exact arithmetic, finite searches, simulation, cited measurements and
prospective checks distinct. Give `tally.py` one writer at a time.
