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

Tutorials

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

Guides

  • Lean 4 from the Wolfram Language

Symbols

  • ImportDOT
  • LeanApp
  • LeanBuild
  • LeanBVar
  • LeanCallGraph
  • LeanCompile
  • LeanConstantInfo
  • LeanConstant
  • LeanConst
  • LeanEnvironment
  • LeanEvaluate
  • LeanExport
  • LeanExportString
  • LeanExprGraph
  • LeanExpr
  • 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
  • LeanToTypeTheory
  • LeanTruncated
  • LeanValue
  • ProofToLean
  • TypeTheoryToLean

Getting Started with LeanLink

Importing a Lean Environment
The Environment
Inspecting Types and Terms
Exporting to Lean Source
Expression Graphs
Importing from a Source String
Constructing Expressions
Transpiling a Wolfram Proof
Interactive Tactic Proofs
Importing from Mathlib
Goal Properties
Structured Tactics
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: 32
Kinds: 18 theorem11 def2 constructor1 inductive

It holds a handful of definitions and proofs:
In[2]:=
Keys[env]
Out[2]=
{id_proof,Vec.head,band_true,add_assoc_proof,comp_proof,even_two,Vec.ctorElimType,bor_false,zero_add_proof,bnot_bnot,Vec.cons,Vec,eq_transport,add_comm_proof,nat_eq_decide,contrapositive,Vec.nil,reverse_reverse,Vec.cons.elim,Vec.map,or_comm_proof,fin_example,exists_succ,sigma_example,add_zero_term,add_succ_term,Vec.nil.elim,modus_ponens,and_comm_proof,Vec.ctorElim,Vec.tail,Vec.ctorIdx}

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), 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} → 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
Out[8]=
LeanTerm
Kind: expr
Name: user_expr

Its type, as Lean writes it:
In[9]:=
t["TypeForm"]
Out[9]=
Nat
A
LeanForall
builds a function type; as a term, its own type is a universe:
In[10]:=
LeanTerm

LeanForall
"n",
LeanConst
["Nat"],
LeanConst
["Nat"],"default",env["TypeForm"]
Out[10]=
Type

Interactive Tactic Proofs

LeanState
opens a theorem as a goal; a
LeanTactic
advances it. Take the identity
∀P:Prop,PP
:
In[11]:=
s0=
LeanState
[env["id_proof"]]
Out[11]=
1 goal
————————————
⊳ ∀ (P : Prop), P → P
Introduce the proposition:
In[12]:=
s1=
LeanTactic
["intro P"][s0]
Out[12]=
1 goal
P : Prop
————————————
⊳ P → P
Then the hypothesis:
In[13]:=
s2=
LeanTactic
["intro h"][s1]
Out[13]=
1 goal
P : Prop
h : P
————————————
⊳ P
And close the goal with the hypothesis:
In[14]:=
s3=
LeanTactic
["exact h"][s2]
Out[14]=
✓ No goals
The proof is complete:
In[15]:=
s3["Complete"]
Out[15]=
True

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

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

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

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

And commutativity:
P∧QQ∧P

In[18]:=
andComm=
LeanState
[env["and_comm_proof"]]
Out[18]=
1 goal
————————————
⊳ ∀ (P Q : Prop), P ∧ Q → Q ∧ P
constructor
splits the conjunction goal into two:
In[19]:=
LeanTactic
["constructor"]
LeanTactic
["intro P Q h"][andComm]
Out[19]=
2 goals
P : Prop
Q : Prop
h : P ∧ Q
————————————
⊳ Q
P : Prop
Q : Prop
h : P ∧ Q
————————————
⊳ P

Goal Properties

Whether the proof is complete:

The Environment

Exporting to Lean Source

Importing from a Source String

The theorem's statement:

Transpiling a Wolfram Proof

Its constants:
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, here to the identity's goal again:
Then the hypothesis:
And close the goal with it:

© 2026 Wolfram. All rights reserved.

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