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.

Litex interactive textbooks (litex -reading -latex)

Other interactive textbooks either have natural language without formal verification, or place prose and formal tactics side by side in two disconnected layers. Here, formal Litex code alone compiles directly into a unified mathematical textbook: click any sentence or symbol to inspect its verified grounds, switch to Litex source, or click “Try editing” to modify and recheck.

11 lines of pure formal Litex code—with zero hand-written prose—compiled directly into a unified interactive textbook via litex -reading -latex.

Loading the interactive reading…

A knowledge graph from the verification record

Follow the proof as a network of definitions and results. Links show recorded citations between top-level statements; select a node to read it. Check edited code to update the graph.

The graph will appear when the reading record is ready.

Turn Litex proofs into LaTeX.

The same source can go into notes, a handout, or a paper. Below, a proof of Newton's error formula is Litex on the left and generated LaTeX on the right.

Litex

Checked mathematical source

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

claim:
    ? forall x R+:
        newton(x) - r = (x - r)^2 / (2 * x)
    r^2 = 2
    (x - r)^2 = x^2 - 2 * x * r + r^2 = x^2 - 2 * x * r + 2
    newton(x) - r = (x^2 - 2 * x * r + 2) / (2 * x) = (x - r)^2 / (2 * x)

Let r∈R>0r\in \mathbb{R}_{>0} satisfy r=2r = \sqrt{2}.

Definition newton.

Let newton:R>0→R\mathit{newton} : \mathbb{R}_{>0}\to \mathbb{R}.

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

Claim.

For every x∈R>0x\in \mathbb{R}_{>0}, we have newton(x)−r=(x−r)22⋅x\mathit{newton}(x) - r = \frac{\left(x - r\right)^{2}}{2 \cdot x}.

Proof. We have r2=2r^{2} = 2. We also have (x−r)2=x2−2⋅x⋅r+r2=x2−2⋅x⋅r+2\left(x - r\right)^{2} = x^{2} - 2 \cdot x \cdot r + r^{2} = x^{2} - 2 \cdot x \cdot r + 2. We also have newton(x)−r=x2−2⋅x⋅r+22⋅x=(x−r)22⋅x\mathit{newton}(x) - r = \frac{x^{2} - 2 \cdot x \cdot r + 2}{2 \cdot x} = \frac{\left(x - r\right)^{2}}{2 \cdot x}. □\square

LaTeX conversion handles presentation; a separate verification step checks whether the proof is valid.

View LaTeX conversion on GitHub

Think, write, and check as you go.

Start a Session with -session and try steps without starting over. Here a = 3 is rejected, and a = 2 is still available for the next line.

Terminal REPL

Recorded terminal Session · selected JSON fields

litex -strict -lang en -session -e 'have a R = 2'

litex> a = 3
{"run_result": "failure", "session_terminated": false}
litex> a + 1 = 3
{"run_result": "success", "session_terminated": false}

Keep today's results for the next exploration.

Save a theorem once and use it in another file. newton.lit proves that a positive number whose square is 2 is unchanged by one Newton step; example.lit applies that result to √2.

example.lit

Use the theorem from newton.lit

release obj def newton::newton_sqrt_two
release thm newton::fixed_point(sqrt(2))
View the project files · definition, proof, and configuration

newton.lit

Newton step and fixed-point theorem

claim:
    ? forall x R+:
        (x + 2 / x) / 2 $in R+
    2 / x > 0
    x + 2 / x > 0
    (x + 2 / x) / 2 > 0

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

thm fixed_point:
    ? forall x R+:
        x^2 = 2
        =>:
            newton_sqrt_two(x) = x
    x = x * x / x = x^2 / x = 2 / x
    newton_sqrt_two(x) = (x + 2 / x) / 2 = (x + x) / 2 = x

litex.config

Load the library before the example

[export]
newton = "./newton.lit"
example = "./example.lit"

These files belong to one project. The prefix newton:: identifies a definition or theorem from newton.lit.

Your mathematical source can also connect to Python and Lean. See the supported examples below.

Explore code generation and Lean compilation

From a checked definition to running code.

The generated Python runs Newton's method toward √2. If the input is zero, the update restarts at 1.

Litex

Checked computational definition

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

Python

Generated by the current CLI

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")

Executed: 1.0 → 1.5 → 1.4166666667.

Experimental: extraction covers the numeric definitions Litex supports, with Python and C99 targets. The generated code uses floating point.

View Python / C extraction on GitHub