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
Wolfram`LeanLink`
LeanCompile
​
LeanCompile
[term]
compiles a
LeanTerm
to native code via
FunctionCompile
, returning a
CompiledCodeFunction
.
​
​
LeanCompile
[env]
compiles every eligible term in a
LeanEnvironment
, returning an
Association
from name to compiled function.
​
Details and Options
▪
The Lean definition's argument and result types are mapped to Wolfram compiler types -
Nat
and
Int
to
"MachineInteger"
,
Bool
to
"Boolean"
,
Float
to
"Real64"
,
String
to
"String"
- and the body is lowered through
FunctionCompile
.
▪
Arithmetic (
+
,
-
,
*
,
/
,
%
,
^
), comparisons,

and
≠
, the connectives
&&
,
||
,
!
and
xor
,
if
and
bif
,
max
and
min
, decimal literals, and the conversions from
Nat
to
Int
and to
Float
become their Wolfram Language counterparts, and compute as Lean's do on
Nat
and
Int
:
a-b
stops at 0 on
Nat
, dividing by 0 gives 0, and
0^0
is 1.
▪
A call to any other function, another definition included, stays in the body as it is, and the definition does not compile.
▪
Only computational definitions compile; propositions and theorems are skipped by the environment form.
▪
A dependent type, such as
VectorIntn
, where the size
n
appears in the type, has no compiler type, so a definition of that type does not compile.
​
Examples  
(3)
Basic Examples  
(1)
A Lean definition, compiled from source:
In[1]:=
addEnv=
LeanImportString
["def myAdd (x y : Nat) : Nat := x + y"]
Out[1]=
LeanEnvironment
Constants: 1
Kinds: 1 def

Compile a Lean definition to a native function:
In[2]:=
cf=
LeanCompile
[addEnv["myAdd"]]
Out[2]=
CompiledCodeFunction
Type:
{Integer64,Integer64}Integer64

Run it:
In[3]:=
cf[3,4]
Out[3]=
7
Scope  
(2)

SeeAlso
LeanToFunction
 
▪
LeanImportString
 
▪
LeanTerm
RelatedGuides
▪
Lean 4 from the Wolfram Language
""

© 2026 Wolfram. All rights reserved.

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