
“A mathematician, like a painter or a poet, is a maker of patterns.”
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.
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…
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.
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 satisfy .
Definition newton.
Let .
Claim.
For every , we have .
Proof. We have . We also have . We also have .
LaTeX conversion handles presentation; a separate verification step checks whether the proof is valid.
View LaTeX conversion on GitHubStart 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}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))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 = xlitex.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 compilationThe 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) / 2Python
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