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

Exploring Mathlib with LeanLink

Prerequisites: Building Mathlib
Typeclasses
Loading a Module
Propositional Logic
Reading a Theorem's Type
Expression Graphs
Binder Annotations
Interactive Proofs
Mathlib
is Lean's community mathematics library. LeanLink imports any built Mathlib module and lets you read theorem statements, dissect their binder structure, and inspect the typeclass machinery behind them - all from the Wolfram Language. Every example below is guarded so the page still builds where Mathlib is absent.

Prerequisites: Building Mathlib

Install
elan
(the Lean version manager), then create a project with Mathlib as a dependency and build the modules used here:
(* Terminal:
curl https://elan.lean-lang.org/install.sh | sh
mkdir -p ~/src/mathlib4 && cd ~/src/mathlib4
lake init MathlibTest math
lake exe cache get
lake build Mathlib.Algebra.Group.Basic
lake build Mathlib.Basic.Logic.Basic
*)
Point a variable at the checkout and record whether it is built:
In[1]:=
mathlibDir=FileNameJoin[{$HomeDirectory,"src","mathlib4"}];​​mathlibReady=DirectoryQ[FileNameJoin[{mathlibDir,".lake","build"}]]
Out[1]=
True

Loading a Module

LeanImport
reads a module from the project. A
"Filter"
keeps the result small - here, the constants whose names contain
"mul"
:
In[2]:=
algEnv=IfmathlibReady,​​
LeanImport
["Mathlib.Algebra.Group.Basic","ProjectDir"mathlibDir,"Filter""mul"],​​"Mathlib not built"
Out[2]=
LeanEnvironment
Constants: 2502
Kinds: 2293 theorem198 def7 constructor4 opaque
This object cannot be used as input.


Reading a Theorem's Type

A theorem's
"TypeForm"
is the proposition it proves.
mul_comm
states commutativity of multiplication:
In[3]:=
If[mathlibReady,algEnv["mul_comm"]["TypeForm"],"Mathlib not built"]
Out[3]=
∀ {G : Type u_1} [inst : CommMagma G] (a b : G), a * b = b * a
And
one_mul
- one is a left identity:
In[4]:=
If[mathlibReady,algEnv["one_mul"]["TypeForm"],"Mathlib not built"]
Out[4]=
∀ {M : Type u_2} [inst : MulOneClass M] (a : M), 1 * a = a

Binder Annotations

Lean has three kinds of argument brackets:
◼
  • (x:T)
    - explicit: the caller supplies it
  • ◼
  • {x:T}
    - implicit: Lean infers it from context
  • ◼
  • [inst:T]
    - instance: Lean resolves it by typeclass search
  • The
    "Parameters"
    property unfolds the binder chain and tags each one. As a
    Dataset
    :
    In[5]:=
    If[mathlibReady,algEnv["mul_comm"]["Parameters"]//Dataset,"Mathlib not built"]
    Out[5]=
    Name
    Type
    TypeForm
    Binder
    G
    Sort
    u_1
    +1
    Type u_1
    implicit
    inst._@.Mathlib.Algebra.Group.Semigroup.544328808._hygCtx._hyg.3
    CommMagma
    #0
    CommMagma #0
    instance
    a
    #1
    #1
    explicit
    b
    #2
    #2
    explicit
    Reading it: to use
    mul_comm
    you supply two explicit values
    a
    and
    b
    ; Lean infers the type
    G
    and finds the
    CommMagma
    instance automatically.

    Typeclasses

    Typeclasses express algebraic structure. Selecting just the instance binders shows what
    mul_comm
    demands of its type:
    In[6]:=
    If[mathlibReady,​​Select[algEnv["mul_comm"]["Parameters"],#Binder"instance"&]//Dataset,​​"Mathlib not built"]
    Out[6]=
    Name
    Type
    TypeForm
    Binder
    inst._@.Mathlib.Algebra.Group.Semigroup.544328808._hygCtx._hyg.3
    CommMagma
    #0
    CommMagma #0
    instance

    Propositional Logic

    A different module, the same workflow. Load the logic basics, filtered to the commutativity lemmas:
    In[7]:=
    logicEnv=IfmathlibReady,​​
    LeanImport
    ["Mathlib.Basic.Logic.Basic","ProjectDir"mathlibDir,"Filter""comm"],​​"Mathlib not built"
    Out[7]=
    LeanEnvironment
    Constants: 463
    Kinds: 6 constructor286 theorem168 def1 inductive2 opaque
    
    And.comm
    , commutativity of conjunction:
    In[8]:=
    If[mathlibReady,logicEnv["And.comm"]["TypeForm"],"Mathlib not built"]
    Out[8]=
    ∀ {a b : Prop}, a ∧ b ↔ b ∧ a
    And of disjunction,
    Or.comm
    :
    In[9]:=
    If[mathlibReady,logicEnv["Or.comm"]["TypeForm"],"Mathlib not built"]
    Out[9]=
    ∀ {a b : Prop}, a ∨ b ↔ b ∨ a

    Expression Graphs

    The full type of a theorem, drawn as its expression tree:
    In[10]:=
    If[mathlibReady,algEnv["mul_comm"]["ExprGraph"],"Mathlib not built"]
    Out[10]=

    Interactive Proofs

    Any imported theorem can be opened as a goal with
    LeanState
    and stepped with
    LeanTactic
    . Open
    one_mul
    and confirm it presents a single goal:
    In[11]:=
    IfmathlibReady,
    LeanState
    [algEnv,"one_mul"]["GoalCount"],"Mathlib not built"
    Out[11]=
    1
    The
    Getting Started
    tutorial walks a full tactic proof end to end.
    RelatedGuides
    ▪
    Lean 4 from the Wolfram Language
    RelatedTechNotes
    ▪
    LeanLinkIntro
    ▪
    ImportGraph
    ▪
    CheckingMathlib
    ""

    © 2026 Wolfram. All rights reserved.

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