Litex: A Formal Language as Easy to Learn as Python and LaTeX
Litex is a personal project exploring a formal language for mathematics. Started in 2024, it remains experimental.
以下正文同步自 Hacker News 最新,版权归原站所有,已转换为易读排版。
Litex is a personal project exploring a formal language for mathematics. Started in 2024, it remains experimental.
Blueprint · 中文GitHubMotivation
Pronounced /ˈliːtɛk/ (LEE-tek), not LIE-tek.Litex takes its name from Lisp and TeX. The logo is a Python-generated binary tree, symbolizing mathematics taking root in axioms and growing branches, leaves, and blossoms.
“Truth is ever to be found in simplicity, and not in the multiplicity and confusion of things.”
— Isaac Newton
Maybe just write the math?
Litex is an experimental formal language for mathematics, started in 2024.
Writing a formal proof often means reshaping an argument around the prover’s goals and commands.
Ideally, you write what you want to prove, and let the language find the proof. Litex aims to be that kind of tool.
Litex ManualSet up Litex
01
Elementary · Word problemAn age problem becomes equations
02
Secondary · Number theoryWhy √2 is irrational
03
Foundations · SetsUnion and intersection, one fact at a time
04
Secondary · Coordinate geometryAn ellipse as a set of points
05
Secondary · StatisticsWhy the average is the best fit
06
University · Set theoryCantor's diagonal argument
07
Abstract · AlgebraA theorem from the group axioms
University
Set theory
Cantor's diagonal argument
Can a function f from S to its power set produce every subset of S? Construct the set of x for which x is not in f(x). If this set were f(a), then a would belong to it exactly when a did not—a contradiction. The proof is checked without using trust to skip any steps.
State the conclusion you want to prove. Litex tries to verify it using available definitions, facts, and builtin rules.
Start with familiar mathematical concepts.
Express objects through sets, elements, and functions, with the conditions for using them written explicitly.
During one interactive session (Session), an ordinary rejected statement leaves earlier accepted definitions and facts available.
For a rejected statement, inspect the reported failure. For an accepted one, see the grounds used to verify it.
When writing Lean with tactics, you use proof commands to guide the proof. In Litex, you state mathematical facts and let the checker look for reasons in the available definitions and conclusions. Compare Litex and Lean →
You can start learning Litex with mathematics you already know. Learn a few basic ways to define objects and state facts, then build your understanding of the language by writing proofs. We want to lower the barrier to formal proof so more people can use it in their studies and research.
With Litex, you can define mathematical objects, write proofs, and have the computer check each step. Results you have proved can support later calculations and proofs.
The Newton example below approximates √2. Edit the code, run the check, and inspect the verification record for each conclusion and the graph linking definitions and results.
Describe the objects, their properties, and the conditions under which they can be used.
Write a statement or proof, run the check, and revise it using the feedback.
Use earlier accepted definitions and facts in later steps, wherever they remain in scope.
Save definitions and theorems in files so other files in the project can use them.
Define a reciprocal function whose input must be nonzero. A call with zero fails, but you can still call it with another value in the same session.
litex> have fn f(x R: x != 0) R = 1 / x success litex> f(2) = 1 / 2 success litex> f(0) = 0 Failed: input 0 does not satisfy x != 0. litex> f(4) = 1 / 4 success
Keep today's results for the next exploration.
Prove in newton.lit that a positive number whose square is 2 stays unchanged by a Newton step. Then use that theorem for √2 in example.lit.
release obj def newton::newton_sqrt_two release thm newton::fixed_point(sqrt(2))
View the project files · definition, proof, and configurationnewton.litNewton 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.configLoad 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.
Turn Litex proofs into LaTeX.
Litex emphasizes readable mathematical writing. It can turn definitions, statements, and proof steps into LaTeX for notes, teaching materials, and papers. Here, a short proof shows how the Newton step for √2 turns the old error into its square divided by 2x. Compare the checked source with the generated mathematical text.
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)
PreviewLaTeX source
Let r∈R>0r\in \mathbb{R}_{>0}r∈R>0 satisfy r=2r = \sqrt{2}r=2.
Let newton:R>0→R\mathit{newton} : \mathbb{R}_{>0}\to \mathbb{R}newton:R>0→R.
For every x∈R>0x\in \mathbb{R}_{>0}x∈R>0, we have newton(x)−r=(x−r)22⋅x\mathit{newton}(x) - r = \frac{\left(x - r\right)^{2}}{2 \cdot x}newton(x)−r=2⋅x(x−r)2.
Further down, see examples of generating executable code and translating Litex proofs for Lean to check.
See how the checker works
To understand is to see connections.
— Ludwig WittgensteinAdapted from Philosophical Investigations, §122.
How Litex works
Litex checks whether your mathematical expressions make sense and whether your conclusions follow from the available definitions and facts. Here is how it represents objects and checks reasoning.
Sets, elements, functions, and relations let you express familiar mathematical concepts. Litex aims to describe them with a small set of basic forms that you can learn as you go.
You choose the proof method; Litex checks the justification for each step. Its verification record lists the result, the rules used, and the facts cited so you can review the reasoning.
To check a statement, Litex first checks that its expressions are meaningful, then looks for justification in the available definitions, facts, and rules. A statement that passes can be used in later steps. If it fails, Litex reports where the check stopped and keeps earlier accepted results available.
You develop the proof: establish intermediate results or split it into cases. Litex checks each step using the available definitions, premises, and supported rules. Checked conclusions can then support the next part of the argument.
For each supported builtin rule used, the verification record lists its name, arguments, and premise proofs, helping you see the justification for that step.
The recorded evidence also supports Lean compilation. This integration is ongoing: each kind of check must be translated faithfully into proof steps that Lean can verify.
“What I cannot create, I do not understand.”
— Richard Feynman
Math for AI
AI can draft definitions and proofs in Litex. Litex checks them, returns feedback for revision, and keeps accepted results available for later steps.
You set the mathematical task. AI writes one complete statement at a time, and Litex checks it against the available definitions and facts. The example below follows a reciprocal function from a missing condition to a checked proof.
The diagram follows AI-written code for a reciprocal function through a failed check, a correction, and a checked proof. The outputs at the end illustrate possible uses of the checked source.
Code written by AI
Litex feedback
YOUR MATHEMATICAL TASKDefine the reciprocal on nonzero real numbers and prove that multiplying it by its argument gives one.
A Session is an interactive terminal session that keeps accepted definitions and facts available for later input. An ordinary rejected statement does not erase them. Start by defining a reciprocal function on nonzero real numbers.
litex -strict -lang en -session
First accepted definitionOne statement in the live Session
have fn reciprocal(x R: x != 0) R = 1 / x
Litex responseActual interactive success response
success
The reciprocal definition has passed the check and can be used in this session. The AI saves the code, then writes the next statement.
Beyond checking proofs, Litex is exploring Python and C code generation and translation to Lean proofs. The examples below show current capabilities and work still in progress.
This example generates Python for a Newton step toward √2. When x is nonzero, it computes (x + 2/x)/2; when x is zero, it returns 1 to avoid division by zero.
algo newton_step(x R) R by cases: case x = 0: 1 case x != 0: (x + 2 / x) / 2
PythonGenerated 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.
Let Lean recheck a Litex proof.
Litex to Lean is partially implemented and already runnable. The detailed design is complete, with implementation targeted for completion by the end of 2026.
Litex can translate some proofs into Lean code for Lean’s kernel to check independently. This compilation remains experimental, and support is expanding.
Litex’s Rust core already spans more than 200,000 lines. Lean’s original core kernel was about 6,000—small enough for focused human review. Reviewing all of Litex at that depth is not realistic; independent checking offers another way to build confidence.
Litex records the rules, premises, and intermediate conclusions used in verification. For supported proofs, the compiler turns that evidence into Lean proof steps for Lean’s kernel to check.
The aim is to write proofs in Litex and have Lean check them again. The compiler must preserve the meaning of objects, statements, and assumptions and supply the proof steps Lean needs.
You write the mathematical facts used in the proof; Litex handles the routine checks it supports. The compiler guide explains how the recorded reasons can become Lean proofs.
The Litex count covers tracked Rust files under src/ as of 15 October 2026, including tests, comments, and blank lines. The roughly 6,000-line figure describes the first kernel layer in Lean’s 2015 system paper, not the size of today’s Lean 4 or its entire codebase. A smaller kernel helps review; it does not guarantee the absence of bugs.
1 = 1
Ordinary LeanTypical handwritten style
example : (1 : ℂ) = 1 := by rfl
Lean from LitexCompiler output · excerpt
import Litex
theorem __fact0 : Litex.Same (1 : ℂ) (1 : ℂ) := by exact Litex.Same.refl (1 : ℂ)
Left to right: the Litex fact, a typical ordinary Lean spelling of the same equality, and Lean generated from Litex for independent kernel checking. Litex can write 1 = 1; ordinary Lean usually needs an explicit type such as (1 : ℂ). The verification record below is a selected excerpt; compilation uses the full structured execution results. Lean integration is ongoing; the generated excerpt comes from an earlier compiler experiment.
How compilation uses the verification recordLitexChecked mathematical source
1 = 1
Execute
Verification recordExecution feedback · excerpt
{ "statement": "1 = 1", "statement_result": "accepted", "proof_method": { "type": "they_are_the_same", "rule_name": "Same object" } }
Compile evidence
Lean from LitexEarlier compiler output · excerpt
import Litex
theorem __fact0 : Litex.Same (1 : ℂ) (1 : ℂ) := by exact Litex.Same.refl (1 : ℂ)
Read the Litex-to-Lean design in DocumentsSee checked Lean examplesView the Lean compiler project on GitHub
Mathematics textbooks, from school to university.
We plan to build a complete Litex mathematics curriculum
正文由 探How 从来源站点 RSS 同步,内容未经改写;遇到排版缺失或需要图片、视频时请以原文为准。