Litex: Python of Formal Mathematics

6 min read Original article ↗

Python of Formal Mathematics

Litex branching tree logo
Litex: Lisp for logic, TeX for beauty.A branching tree of formal mathematics, growing from minimal axioms.

Pen sketch of Isaac Newton

“Truth is ever to be found in simplicity, and not in the multiplicity and confusion of things.”
— Isaac Newton

Litex is a high-level language for formal mathematics

Litex is a high-level language for formal mathematics. Instead of building proofs command by command, you write natural mathematical statements: Litex automatically checks domain conditions (such as nonzero denominators) and searches existing context for justifications.

Litex makes formal code feel natural

1 / 6

Everyday mathematical writing already has rigorous logical structure; Litex lets that structure become checkable formal code directly.

The way you would say it

. Then .

The same words in Litex

forall x R:
    x^2 >= 0

The same words in Lean

Extra proof commands

theorem nonneg_sq (x : ℝ) : x ^ 2 ≥ 0 := by
  exact sq_nonneg x

Lean requires a theorem name ('nonneg_sq'), ':= by', and a library lemma call ('exact sq_nonneg x') beyond the mathematical statement itself.

Select a colored phrase to follow it into code and into the reason it holds.

See why each proof step holds

Click a statement to locate its JSON record. Hover for proof details. Edit, then Check (⌘ / Ctrl + Enter).

Why √2 is irrational

(Secondary)

Loading the interactive reading…

Pen sketch of Donald Knuth

Litex automatically checks domains and finds justifications

Litex takes on routine deduction. Just as Python manages memory so programmers can focus on algorithms, Litex automatically checks domain conditions and verifies routine steps so authors can focus on the mathematical argument.

From a general rule to a particular fact.

Set syllogism in Litex and Lean: from every element of A belonging to B and a belonging to A, Litex instantiates x with a and checks the premise to establish a in B. The parallel Lean example shows elaboration, a proof term and kernel checking.

Every element of A belongs to B, and a belongs to A. Litex finds the universal fact, substitutes a for x, checks its premise, and obtains a ∈ B.

See the full checking process

What does Litex build on?

Litex provides basic mathematical objects and their relations, mathematical axioms, and reasoning mechanisms such as syllogisms, contradiction and case analysis: the bricks and mortar. Your definitions, assumptions and verified facts form the context in which it searches for evidence.

What about a complicated proof?

Finding a proof may require deep insight. Checking it can be broken down into basic steps: substitution, calculation and applying established results. Litex also automatically checks domain conditions, such as a denominator being nonzero, and retrieves known facts. It searches for evidence for each step and makes its conclusion available to later steps, without needing a dedicated builtin rule for every new theorem.

What about abstract concepts?

An abstract concept can be defined by combining existing objects, properties and conditions. Litex lets you define new mathematical concepts yourself. Your concepts can then be used in the next layer of definitions and proofs, building the edifice of mathematics step by step.

A finite set of basic mechanisms can be combined repeatedly. This does not mean Litex already covers all mathematics; support for particular constructions and proofs still needs to be tested in practice.

Measured: program length and checking time

The de Bruijn factor compares formal code length to ordinary mathematical text: 1.0 means equal length; lower is shorter.

22–23 Oct 2026 · warm medians · native checking, excluding startup, imports, output and Lean replay.

See what the same statement means in Litex and in Lean →

Pen sketch of Alfred V. Aho & Jeffrey D. Ullman

A High-Level Language & Universal Frontend

Litex: A universal mathematical frontend across proof systems.

In programming, developers moved from assembly to Python to focus on algorithms. In formal mathematics, Litex serves as a high-level language and universal frontend: write mathematics once with automatic domain checks, compile supported proofs directly to Lean 4 today for independent kernel verification, and extend toward Coq (Rocq) and Isabelle on the roadmap.

Litex as a universal mathematical frontend: an analogy with higher-level programming languages, bringing mathematical objects, facts, statements and automatic domain checking into a shared authoring language above Lean, Coq, and Isabelle.View full-size diagram ↗

Live compiler example: a Litex source and the Lean 4 proof generated from it.

Proof compilation

# The number one equals itself.

1 = 1
import Litex

set_option linter.unusedVariables false

namespace LitexCompiled.file_lean_x2f_examples_x2f_one_x5f_equals_x5f_itself_x2f_statement_x2e_lit

universe u
variable {M : Litex.Semantics.{u}}

theorem h_1 : Litex.Same (Litex.number (M := M) (1 : ℂ)) (Litex.number (M := M) (1 : ℂ)) :=
  (by
    litex_complete =>
      exact (
        (show @Eq M.Value _ _ from Eq.refl _)
      )
  )
end LitexCompiled.file_lean_x2f_examples_x2f_one_x5f_equals_x5f_itself_x2f_statement_x2e_lit

Definitions and proof rules: Litex.lean ↗

See what the compiler does today →

Pen sketch of G. H. Hardy

“A mathematician, like a painter or a poet, is a maker of patterns.”
— G. H. Hardy

One Litex source, beyond proof checking

From a single formal Litex source—without maintaining separate prose and proof files—generate a typeset interactive textbook (litex -reading -latex), inspect its dependency graph, export LaTeX, or compile supported numerical definitions to Python.

Interactive textbooks

litex -reading -latex

Conventional digital math notes either offer natural-language prose with no formal verification, or place prose and low-level proof scripts in two disconnected layers. In Litex, a single verified source is enough: litex -reading -latex compiles it directly into the typeset textbook below—click any sentence or symbol to inspect its cited reasons and domain conditions, switch to the Litex source, or click “Try editing” to modify and recheck in place.

Loading the interactive reading…

Open full interactive demo →

Knowledge graphs

Inspect the dependency graph of axioms, definitions, and theorems behind a proof, and click any node to read the statement.

Fns: 1 · Props: 0 · Theorems: 0 · Retained facts: 3 · Citations: 4 · Nodes: 4 · Edges: 4

(newton(x) - r) = (((x - r) ^ 2) / (2 * x))(newton(x) - r) =…facthave r R+ = sqrt (2)have r R+ = sqrt …factnewtonnewtondefinitionrelease thm newton_error((3 / 2))release thm newto…fact

See the graph →

LaTeX

Export clean, publication-ready LaTeX directly from your checked Litex definitions and proofs.

Litex

have fn newton(x R+) R = (x + 2 / x) / 2

newton(x)=x+2x2\mathit{newton}(x) = \frac{x + \frac{2}{x}}{2}

See the output →

Python

Compile supported numerical definitions directly into runnable Python functions.

Litex

algo newton_step(x R) R by cases:
    case x = 0: 1
    case x != 0: (x + 2 / x) / 2

Python

def newton_step(x):
    if x == 0.0:
        return 1.0
    elif x != 0.0:
        return ((x + (2.0 / x)) / 2.0)
    raise AssertionError("unreachable verified Litex cases")
See the Python →
Sessions and file reuse →

Pen sketch of Richard Feynman

Interactive sessions and AI exploration sandboxes

Litex provides an interactive Session environment for AI agents and human authors. Submit one proof step at a time: when a step fails, Litex reports the exact reason—such as a missing domain condition x != 0—without terminating the Session or discarding earlier accepted facts. The agent repairs that step in place and continues.

Run with -session and keep the process open while AI adds or repairs statements.

First accepted definition

One statement in the live Session

have fn reciprocal(x R: x != 0) R = 1 / x

Litex response

Selected fields from the actual interactive success response

{
  "kind": "run",
  "run_result": "success",
  "target": "repl",
  "session_terminated": false,
  "termination": null
}

The definition is accepted. Save it before moving on.

Start an interactive Session with: litex -strict -lang en -session

Read the Agent Guide: step-by-step proving in a live Session →Formalization experiments ↗Litex Skills ↗