Wolfram Language Paclet Repository

Community-contributed installable additions to the Wolfram Language

Primary Navigation

    • Cloud & Deployment
    • Core Language & Structure
    • Data Manipulation & Analysis
    • Engineering Data & Computation
    • External Interfaces & Connections
    • Financial Data & Computation
    • Geographic Data & Computation
    • Geometry
    • Graphs & Networks
    • Higher Mathematical Computation
    • Images
    • Knowledge Representation & Natural Language
    • Machine Learning
    • Notebook Documents & Presentation
    • Scientific and Medical Data & Computation
    • Social, Cultural & Linguistic Data
    • Strings & Text
    • Symbolic & Numeric Computation
    • System Operation & Setup
    • Time-Related Computation
    • User Interface Construction
    • Visualization & Graphics
    • Random Paclet
    • Alphabetical List
  • Using Paclets
    • Get Started
    • Download Definition Notebook
  • Learn More about Wolfram Language

LeanLink

Guides

  • LeanLink

Tech Notes

  • Exploring Mathlib with LeanLink
  • An Import Graph for Mathlib
  • Getting Started with LeanLink

Symbols

  • ImportDOT
  • LeanApp
  • LeanBVar
  • LeanCallGraph
  • LeanCompile
  • LeanCompileTyped
  • LeanConstantInfo
  • LeanConstant
  • LeanConst
  • LeanEnvironment
  • LeanExport
  • LeanExportString
  • LeanExprGraph
  • LeanExpr
  • LeanExprToType
  • LeanForall
  • LeanFreeEnvironment
  • LeanFVar
  • LeanGoal
  • LeanImport
  • LeanImportString
  • LeanLam
  • LeanLet
  • LeanLevelIMax
  • LeanLevelMax
  • LeanLevelMVar
  • LeanLevelParam
  • LeanLevelSucc
  • LeanLevelZero
  • LeanListConstants
  • LeanListTheorems
  • LeanLitNat
  • LeanLitStr
  • LeanLoadEnvironment
  • LeanMVar
  • LeanNoValue
  • LeanProj
  • LeanSort
  • LeanState
  • LeanTactic
  • LeanTerm
  • LeanToFunction
  • LeanTruncated
  • LeanValue
  • ProofToLean
Getting Started with LeanLink
LeanLink embeds the
Lean 4
theorem prover in the Wolfram Language. This tutorial loads a small bundled environment, inspects Lean types and proof terms, runs interactive tactic proofs, and round-trips proofs between the two systems. One environment is imported up front and reused throughout.
Importing a Lean Environment
LeanImport
loads the constants of a compiled Lean module or
.lean
file into a
LeanEnvironment
. Here we load the example file bundled with the paclet:
In[1]:=
env=
LeanImport
[PacletObject["Wolfram/LeanLink"]["AssetLocation","Examples"]]
Out[1]=
LeanEnvironment
Constants: 25
Kinds: 6 def18 theorem1 inductive

It holds a handful of definitions and proofs:
In[2]:=
Keys[env]
Out[2]=
{Vec.head,id_proof,add_zero_term,fin_example,add_comm_proof,contrapositive,bor_false,eq_transport,add_succ_term,Vec.map,sigma_example,bnot_bnot,even_two,exists_succ,Vec.tail,and_comm_proof,add_assoc_proof,Vec,band_true,comp_proof,reverse_reverse,modus_ponens,nat_eq_decide,zero_add_proof,or_comm_proof}
Inspecting Types and Terms
Index the environment by name to get a
LeanTerm
. Its
"TypeForm"
is the proposition it proves (or the type it inhabits), pretty-printed as Lean source:
In[3]:=
env["id_proof"]["TypeForm"]
Out[3]=
∀ (P : Prop) (a : P), P
The
"TermForm"
is the proof term itself:
In[4]:=
env["id_proof"]["TermForm"]
Out[4]=
fun x hp => hp
Behind the pretty-print is a symbolic expression tree, built from the CIC heads
LeanForall
,
LeanApp
,
LeanConst
,
LeanSort
, and friends. The
"Type"
property returns it:
In[5]:=
env["id_proof"]["Type"]
Out[5]=
(P:Prop)(a:
#0
)
#1
A dependent type from the same file - the head of a length-indexed vector:
In[6]:=
env["Vec.head"]["TypeForm"]
Out[6]=
∀ {α : Type} {n : Nat} (a : Vec α n + 1), α
Expression Graphs
Every expression is a tree, and
"ExprGraph"
draws it as a
Graph
:
In[7]:=
env["modus_ponens"]["ExprGraph"]
Out[7]=
Constructing Expressions
You can build a Lean expression from the CIC heads and bind it to an environment for type-checking with
LeanTerm
[expr,env]
. Applying
Nat.succ
to a literal:
In[8]:=
t=
LeanTerm

LeanApp

LeanConst
["Nat.succ"],
LeanLitNat
[42],env;​​t["TypeForm"]
Out[8]=
Nat
A
LeanForall
builds a function type; as a term, its own type is a universe:
In[9]:=
LeanTerm

LeanForall
"n",
LeanConst
["Nat"],
LeanConst
["Nat"],"default",env["TypeForm"]
Out[9]=
Type
Interactive Tactic Proofs
LeanState
opens a theorem as a goal; a
LeanTactic
advances it. Take the identity
∀P:Prop,PP
:
In[10]:=
s0=
LeanState
[env["id_proof"]]
Out[10]=
1 goal
————————————
⊳ ∀ (P : Prop) (a : P), P
Introduce the proposition and hypothesis, then close with the hypothesis:
In[11]:=
s1=
LeanTactic
["intro P"][s0];​​s2=
LeanTactic
["intro h"][s1];​​s3=
LeanTactic
["exact h"][s2];​​s3["Complete"]
Out[11]=
True

Modus ponens:
P(PQ)Q

A whole proof as one tactic sequence:
In[12]:=
LeanTactic
[{"intro P Q hP hPQ","exact hPQ hP"}]
LeanState
[env["modus_ponens"]]["Complete"]
Out[12]=
True

Contrapositive:
(PQ)(¬Q¬P)

In[13]:=
LeanTactic
[{"intro P Q hPQ hnQ hP","apply hnQ","exact hPQ hP"}]
LeanState
[env["contrapositive"]]["Complete"]
Out[13]=
True

And commutativity:
P⋀QQ⋀P

constructor
splits the conjunction goal into two:
In[14]:=
s0=
LeanState
[env["and_comm_proof"]];​​
LeanTactic
["constructor"]
LeanTactic
["intro P Q h"][s0]["GoalCount"]
Out[14]=
2
Goal Properties
A
LeanState
exposes its goal stack. Each goal is a
LeanGoal
with a
"Target"
and a
"Context"
:
In[15]:=
s0=
LeanState
[env["id_proof"]];​​s0["Goals"]〚1〛["Target"]
Out[15]=
∀ (P : Prop), P → P
In[16]:=
s0["Complete"]
Out[16]=
False
The Environment
A
LeanEnvironment
supports
Keys
,
Length
, and
Information
. The kind breakdown of our example file:
In[17]:=
Information[env,"Kinds"]
Out[17]=
def6,theorem18,inductive1
Exporting to Lean Source
LeanExportString
renders a constant's type back as Lean source (bound variables in a bare type print as de Bruijn indices
#0
,
#1
):
In[18]:=
LeanExportString
[env["id_proof"]]
Out[18]=
∀ (P : Prop) (a : #0), #1
Importing from a Source String
LeanImportString
compiles Lean source on the fly:
In[19]:=
imported=
LeanImportString
["theorem myT : Nat.succ 0 = 1 := rfl"];​​imported["myT"]["TypeForm"]
Out[19]=
Nat.succ 0 = 1
Transpiling a Wolfram Proof
The whole thing as Lean source:
Importing from Mathlib
Structured Tactics
Tactics can also be built structurally, with Lean-native names and Wolfram-valued arguments:
Applied the same way as string tactics:

© 2026 Wolfram. All rights reserved.

  • Legal & Privacy Policy
  • Contact Us
  • WolframAlpha.com
  • WolframCloud.com