Documents as Programs: Running the Method Section of a Paper with Index-Checked Equations
A paper's method section reads data, sets initial values, iterates and reports; its equations are only part of the computation. We make such a section run as written. A document in the LyX math editor is turned into a C++ program: inline formulas such as Xn, f ← data.csv, η ← 0.1 and t = 1, …, 500 are conditions, indentation is the body of an iteration, and every display equation becomes a compile-time index-checked literal, so an index error stops the build at the formula's line in the document. Writing a variable under other indices renames its axes, which makes Gram matrices and grids evaluated at a second point expressible; because a rename by position cannot tell a renamed axis from a typo, a document declares which indices are of one kind (p, r ∈ radial), and a rename between indices of different kinds is an error. On a document whose features and classes have the same number of entries, a typo Xs, c for Xs, f ran silently with the unchecked rename and printed a wrong result; with kinds it is refused at its line. A built-in Kronecker delta takes the traces a rename cannot write, upper and lower indices are summed as in Einstein's convention, and an index declared independent runs in threads with bit-identical output. Six documents in the repository reproduce independent references, and adding the kind declarations to the nine documents that rename left their generated programs byte-identical. What a document does not check is its algorithm: which statement is in which iteration. This is one of three papers that split the preprint The Equation Is the Type, version 3 (10.5281/zenodo.24762562): The Equation Is the Type: Compile-Time Checking of Named-Tensor Equations Written in LaTeX (10.5281/zenodo.24786239), Documents as Programs (10.5281/zenodo.24786242) and Eight Papers That Run (10.5281/zenodo.24786244). Source, data and scripts: github.com/uyuutosa/tensor, tag paper-split-preprint; the manuscripts are in paper/split/.
Authors
- Yu Sato (ORCID: https://orcid.org/0009-0009-4453-3507)
Publication Details
- Journal
- Zenodo (CERN European Organization for Nuclear Research)
- Published
- 2026-12-03
- DOI
- https://doi.org/10.5281/zenodo.24786241
- Citations
- 2
- Primary Topic
- Logic, programming, and type systems
- Type
- preprint