Skip to main content

FormulaTracer

English | 日本語

From scientific code to auditable mathematics.

Python 3.10+ Rust 1.85+ License: Apache-2.0

FormulaTracer reconstructs the mathematics actually implemented in scientific code, audits assumptions and approximations, compares implementations with declared theory, and generates auditable code from mathematical specifications.

It is designed for scientific software where mathematically similar-looking code may differ because of discretization, floating-point behavior, library semantics, domains, units, assumptions, or implementation details.

When FormulaTracer cannot justify an interpretation, it reports UNRESOLVED instead of guessing. Structural similarity is not proof, numerical similarity is not a certified bound, and provider retrieval is not verification.

python -m pip install formulatracer

What FormulaTracer does

  • Reconstructs mathematical expressions and structures from scientific source code.
  • Distinguishes exact equality from approximation, discretization, truncation, sampling, and algorithmic realization.
  • Tracks assumptions, proof obligations, numerical error and range, and provenance.
  • Compares independently reconstructed implementation mathematics with declared theory.
  • Localizes semantic mismatches back to source code.
  • Supports user-defined semantics for opaque or proprietary operations without treating declarations as verification.
  • Generates scientific code from mathematical specifications and independently re-audits the generated implementation.
  • Preserves unresolved semantics instead of guessing.
  • Integrates selected Lean-verified proof evidence where available.

Why FormulaTracer?

Scientific code is not just source syntax. An implementation may look mathematically equivalent to a theoretical formula while actually introducing:

  • finite-difference discretization;
  • floating-point reduction order;
  • truncation or approximate numerical integration;
  • hidden axis, dtype, domain, or unit assumptions;
  • library-specific semantics; or
  • unresolved callback behavior.

FormulaTracer keeps these distinctions explicit instead of collapsing them into one equivalent/not-equivalent answer. It connects them through one Rust-owned semantic model and returns a structured VerificationResult or ReconstructionResult; TeX, JSON, and explanations are derived views.

Typical uses include scientific implementation review, model-change review, pre-publication checks, reproducibility work, and inherited-code assessment.

Example: derivative versus finite difference

Theory:

dy/dx

Implementation:

(f(x + h) - f(x)) / h

FormulaTracer does not report these as exact equality. It can represent the implementation as a finite-difference realization of a derivative, together with its discretization relation and relevant assumptions.

Likewise, if an external callback has no source, provider contract, user declaration, or runtime evidence, FormulaTracer reports it as unresolved rather than inventing a mathematical interpretation.

Installation

Python 3.10 or newer is required. Published supported wheels are intended to include the native core, so end users do not need Rust, Cargo, or CMake.

python -m pip install formulatracer

Published wheels currently support Windows x86-64 and Linux x86-64 with a manylinux-compatible wheel. Python 3.10 through 3.13 is supported. macOS wheels are not currently published.

This repository is version 0.1.1. Source developers need Rust 1.85+, and the optional C++ frontend requires LLVM/Clang major 18 and a C++20 build toolchain.

Quick start: audit code without a theory

Clone the repository, install it, then run the synthetic example:

python -m pip install -e .
formulatracer python-audit examples/python_audit/weighted_sum.py --function calculate_weighted_score --output weighted_score --mode REPORT_ONLY --report output/python-audit/report.md --json-output output/python-audit/audit.json --no-lean

The report contains the independently reconstructed implementation expression, numeric backward slice, assumptions, provider contracts, provenance, and any unresolved boundary. No theory annotation is required.

Mathematics to code

FormulaTracer also works in the opposite direction. A mathematical specification can be used to retrieve implementation candidates, select one, generate source, and independently re-audit the result:

from formulatracer import FormulaTracer

formula = FormulaTracer.from_tex(r"\sum_{i=0}^{N-1} x_i")
plan = formula.plan_generation(language="python", search="broad")
print(plan.explain(limit=5))
generated = formula.generate(language="python", auto_select=True)
result = generated.verify()
print(result.status)
print(result.independent_audit)

Candidate similarity only starts an investigation. Selection still requires typed unification, constraints, authorized transformations, and independent re-analysis.

Theory comparison

A declared theory is optional. When one is supplied, FormulaTracer compares it with mathematics reconstructed independently from the implementation. The declaration is never substituted for the implementation-derived expression and does not become verified evidence merely because a user provided it.

Core workflow

Scientific source -> Implementation IR -> Mathematical reconstruction
  -> Exact/relational analysis -> Assumptions and obligations
  -> Error/range and provider evidence -> Provenance and localization
  -> Structured result -> AuditBundle / TeX / JSON / explanation

Main Python entry points are FormulaTracer.from_source, FormulaTracer.analyze, FormulaTracer.from_tex, plan_generation, reconstruct, and the native structured-result wrappers. See the Python API instead of relying on internal cpp_audit modules.

Supported languages

Language Implementation role Audit input Code generation End-user Python required?
Python Public facade and frontend Yes Yes Yes for Python API/CLI
Rust 2021 Semantic core and native CLI Yes, via current project frontend Yes No for native semantic-document API
C Stable ABI v1 Limited C/C++ frontend path No No
C++17/20 Clang 18 audited input Yes Yes No for C ABI/C++ wrapper
Lean 4.19 Independent proof layer No Proof obligations only No

The FormulaTracer C++ components build as C++20. The native CLI currently operates on semantic documents (canonicalize, tex, compare); it is not a complete Rust-source audit CLI. See language support.

Scientific libraries and providers

Provider contracts cover selected public APIs, not an entire upstream library. Most external library entries are currently REFERENCE_ONLY_VERSION_UNPINNED; therefore this release does not promise a broad NumPy/SciPy/xarray version range. Axis, dtype, missing-value, named- dimension, device, laziness, mutation, and default semantics remain explicit contract conditions. See the provider matrix.

No LLM required for core auditing

FormulaTracer's core semantic audit does not require an LLM or generative AI. Unknown semantics are preserved as unresolved rather than filled in by model-generated guesses.

User-defined semantics: a redundant evidence path

@cpp_audit.theory(output=..., expression=...) supplies a user declaration to the same Mathematical IR, relation, evidence, and provenance pipeline used by automatic reconstruction. It is useful for private callbacks, future libraries, hardware kernels, and source that is unavailable to the auditor. It is not a second evaluator and a declaration alone never becomes implementation-, reference-, or Lean-verified evidence.

When implementation-derived mathematics is available, FormulaTracer reports MATCH, MISMATCH, or NOT_EVALUABLE between the two independent paths. Callback value semantics and effects are separate: an expression may be retained while purity remains UNKNOWN_EFFECT. See user-defined semantics.

Physics foundation

The versioned physics foundation defines multivariable/vector calculus, geometric integral relations, dimensions and frames, SO(3)/quaternion representations, Fourier/Laplace relations, numerical realizations, and selected SciPy callback boundaries. Support levels are reported separately as DEFINED, THEOREM_REGISTERED, LEAN_KERNEL_VERIFIED, REALIZATION_AVAILABLE, CONDITIONAL, or PARTIAL.

FormulaTracer audits mathematical and implementation relations. It does not prove that a physical law is empirically true. General Noether, Gauss/Stokes, SE(3), finite-volume error, and AD claims remain conditional unless their listed obligations are discharged. See the physics support boundary.

Platform status

Platform Source/tests Native package Status
Windows x86-64 Locally tested Wheel build and clean-install tested Tested
Linux x86-64 Debian GNU/Linux 12 (bookworm), Python 3.11.2 Wheel/sdist build, clean install, native load, and release suite tested in a real x86-64 Linux container Tested on this recorded environment only
macOS Not validated No release wheel claim Untested

Evidence model

  • KERNEL_VERIFIED: checked by the Lean kernel.
  • KERNEL_VERIFIED_UNDER_ASSUMPTIONS: kernel-checked with listed assumptions.
  • FORMALLY_DERIVED: derived from versioned rules and evidence.
  • REFERENCE_CONTRACT: backed by an upstream public reference.
  • EMPIRICALLY_VALIDATED / RUNTIME_EVIDENCE: tests or a concrete run, not proof.
  • UNRESOLVED: ambiguity, unsupported behavior, missing contract, or open obligation.

Exact equality, approximation, discretization, truncation, sampling, and algorithmic realization are distinct relations. Read proof levels and the trust boundary.

Examples

Non-goals and limitations

FormulaTracer does not prove compilers, CPUs, every external implementation, or a researcher's scientific intent, and is not a general compiler, numerical solver, CAS, Lean replacement, or arbitrary-software verifier. It does not silently infer unknown semantics and does not replace scientific judgement. Complete Rust-source native audit orchestration is not yet exposed by formulatracer-native. Performance is secondary to semantic correctness and fail-closed behavior.

Runtime-only call targets, non-exhaustive dynamic keys, unknown backends, impure/opaque callbacks, and unproved conditional theorems remain partial or unresolved. “Currently unresolved” does not mean “fundamentally impossible”; user contracts, runtime evidence, or provider evidence may close some cases, but those evidence classes are never relabelled as static proof.

Documentation and support

Start with the class and function usage guide (日本語) or the documentation index. Use GitHub Issues for bugs and GitHub Discussions for usage questions. Report vulnerabilities privately as described in SECURITY.md. See SUPPORT.md for the reporting and support policy. External pull requests are not currently accepted; propose changes through an Issue or Discussion.

Public references: Python functions · Rust · C ABI · C++ · result/status/evidence · providers · physics · user-defined semantics

Citation, license, and contributing

Citation metadata is in CITATION.cff. FormulaTracer is licensed under Apache-2.0; third-party categories and redistribution notes are in THIRD_PARTY_NOTICES.md. Generated-code licensing depends on user input, selected templates, and upstream provenance; generation does not automatically impose the FormulaTracer project license on all output.

FormulaTracer's external participation model is documented in CONTRIBUTING.md. External pull requests are not currently accepted.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

formulatracer-0.1.1.tar.gz (2.0 MB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

formulatracer-0.1.1-py3-none-win_amd64.whl (2.0 MB view details)

Uploaded Python 3Windows x86-64

formulatracer-0.1.1-py3-none-manylinux_2_34_x86_64.whl (2.1 MB view details)

Uploaded Python 3manylinux: glibc 2.34+ x86-64

File details

Details for the file formulatracer-0.1.1.tar.gz.

File metadata

  • Download URL: formulatracer-0.1.1.tar.gz
  • Upload date:
  • Size: 2.0 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for formulatracer-0.1.1.tar.gz
Algorithm Hash digest
SHA256 95aeaa7ff868da886a9a83b4107ea0bd03bb0a63cb13fd7251f17c6774fa9e44
MD5 1079e0ae98362c9dfeb0026b0e92b90e
BLAKE2b-256 7009452b0cb0f7bb237161d1bbebfa783d95053b1586c63c4020ccc322ed20e1

See more details on using hashes here.

Provenance

The following attestation bundles were made for formulatracer-0.1.1.tar.gz:

Publisher: publish-pypi.yml on 3e456/FormulaTracer

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file formulatracer-0.1.1-py3-none-win_amd64.whl.

File metadata

File hashes

Hashes for formulatracer-0.1.1-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 21f5fc8baf344bd2f594b0a62aa579b64cec4092b93bb0973eae7067eff8932b
MD5 120f11a87401d9fed9df7b1b4e64d252
BLAKE2b-256 cee9e6e41ced302e8d08825b3bf6a389f957206174d3d383cac53e2a9839781e

See more details on using hashes here.

Provenance

The following attestation bundles were made for formulatracer-0.1.1-py3-none-win_amd64.whl:

Publisher: publish-pypi.yml on 3e456/FormulaTracer

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file formulatracer-0.1.1-py3-none-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for formulatracer-0.1.1-py3-none-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 ba777ab784fdb97cb07d2ed53eb81989f3db6d5a0d4ff1b451d78f78f2d19366
MD5 70d8b34b8c40bad7e1f477c7282331c5
BLAKE2b-256 ce0943855e826278961ce0c3db3932b54e25e8633f04d6886d551f09cfc8c656

See more details on using hashes here.

Provenance

The following attestation bundles were made for formulatracer-0.1.1-py3-none-manylinux_2_34_x86_64.whl:

Publisher: publish-pypi.yml on 3e456/FormulaTracer

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.1.1 This release

3 files

0.1.0

3 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page