Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversHalloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run Scan×
FREEDOM251

Freedom251 › Blog › formal mathematics

How to Get Started Proving Theorems in Lean 4: A Beginner’s Guide

By Freedom251 Team · · 12 min read

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The most reliable beginner route is to install Lean through the official VS Code setup, then learn by editing small examples and reading Lean’s feedback. Start with the Natural Number Game if you have little or no theorem-proving experience; choose Theorem Proving in Lean 4 for proof fundamentals, or Mathematics in Lean if your goal is formal mathematics with Mathlib.

Keep the Lean toolchain used by your project aligned with the tutorial you are following. When you cannot remember a theorem that may already exist, search Lean and Mathlib with Loogle instead of rebuilding the result from scratch.

As an Amazon Associate I earn from qualifying purchases.

What Lean is and what you are learning

Lean 4 is both a proof assistant and a programming language. You write definitions, propositions and proofs in Lean’s language; Lean checks that each proof follows its rules. The result is not merely an informal explanation that appears convincing on a page. A Lean file must elaborate successfully, and the kernel checks the resulting proof term.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

That distinction changes how you study. Reading a chapter gives you vocabulary and strategies, but progress comes from putting the examples into an editor, changing them, and investigating the messages Lean displays. A failed proof is useful feedback: it tells you which expression Lean inferred, which goal remains, or which name is unavailable in the current environment.

#1 Best Overall
Elebase USB to USB C Adapter for iPhone 18 Pro Max,USBC Car Charger Adapter | 4Pack Type C Female to A Male Cable Converter for Apple Duo 17 16 15 14 Plus,iWatch Watch 12 11 10,iPad 9 8 Air,Airpods 5 4
  • Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
  • Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
  • Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
  • Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
  • 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.

The official installation guidance recommends VS Code with the official Lean 4 extension, which supplies syntax highlighting, completion and the interactive information panel. Follow the guided setup first; use the manual instructions only when you need an operating-system-specific or command-line arrangement.

Install a working Lean environment

Use the guided VS Code setup

  1. Install VS Code for your operating system if it is not already present.
  2. Open the official installation page at https://lean-lang.org/install/ and follow the recommended VS Code route.
  3. Install the official Lean 4 extension from the VS Code Extensions view. The extension is the integration that displays goals, diagnostics and completion while you edit.
  4. Let the setup flow finish its remaining steps. The guided process configures the Lean components needed by the extension. Do not begin by mixing unrelated binaries or an old project configuration into a new installation.
  5. Restart or reload VS Code if requested, then open a folder containing a Lean project or a Lean source file. The extension should recognize the file and show Lean information rather than treating it as plain text.

The Lean project describes this VS Code-and-extension route as the recommended installation method because it provides the development environment as well as the compiler integration. The installation page is the right place to check current platform details rather than relying on a remembered command from an older tutorial.

When manual installation makes sense

Use the manual instructions at https://lean-lang.org/install/manual/ when you need a command-line setup, are integrating Lean into a particular operating-system workflow, or are preparing a project that depends on Mathlib and has its own documented requirements. The manual page warns that its steps may need adaptation in some environments and still recommends the guided installer for most users.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

A manual setup is not a different kind of Lean. It is a different way of obtaining and selecting the same toolchain. If the editor cannot find Lean after a manual installation, check the project’s configured toolchain and the extension’s detected executable before changing proof code.

Prepare for a Mathlib project

Mathlib is a large community library used by Mathematics in Lean and many formalization projects. A Mathlib project has dependencies and a toolchain configuration, so follow that project’s own setup instructions rather than copying files into an arbitrary directory. The first setup can require downloading dependencies; allow it to complete before diagnosing proof errors.

Keep the project folder intact. Opening only an individual source file outside its project can deprive Lean of the imports, dependency versions and configuration that make the file compile.

Verify the installation with a tiny theorem

After VS Code recognizes a Lean file, create a small scratch file inside the project and type a theorem whose proof is deliberately obvious:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #2
Sale
Anker USB-C Hub, 5-in-1 USB Hub for Laptops, 4K HDMI Multiport Adapter | USB C Dongle with 90W Max Power Delivery, 3×5Gbps USB A Data Ports, for MacBook, Dell, and More (Charger Not Included)
  • 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
  • 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
  • Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
  • 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
  • What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.
theorem self_equal (n : Nat) : n = n := by
  rfl

rfl proves reflexive equality. A successful result gives you three useful checks at once: the file is being parsed as Lean, the extension is communicating with Lean, and the editor can display a completed proof without an error marker.

Next, try a proposition that makes you inspect a hypothesis:

theorem take_left (p q : Prop) (h : p ∧ q) : p := by
  exact h.left

Here h has an “and” proposition, and h.left is its first component. If you make a deliberate change—such as replacing h.left with h.right—Lean’s feedback shows that the resulting type no longer matches the goal. These tiny experiments teach you to read types before reaching for a tactic.

Do not judge the setup by whether every example from a book compiles immediately. A different import, library revision or toolchain can change available names and elaboration behavior. First establish that a minimal local theorem works, then investigate differences in the learning project.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Choose a first learning resource

The official learning hub at https://lean-lang.org/lean4/doc presents different starting points because “learning Lean” can mean learning proof construction, formalizing mathematics, or learning Lean as a programming language. Choose according to the outcome you want, not according to the longest or most advanced-looking title.

Your starting point or goal Best first step Emphasis How to work through it
No theorem-proving experience Natural Number Game A gamified introduction to mathematical proof and Lean concepts Attempt each exercise in the game, then recreate representative proofs in your own file.
General interest in constructing proofs Theorem Proving in Lean 4 Propositions, equality, tactics, induction, type classes and interaction with Lean Copy examples into VS Code, alter them, and use the resulting goals and errors as part of the lesson.
Mathematics student or researcher Mathematics in Lean Interactive, tactic-based mathematical formalization using Mathlib Open the matching Lean file for each section, preserve the original exercise file, and work in a copy.
Programmer learning Lean as a language Functional Programming in Lean Lean programming, with programming experience assumed Study definitions and programs first, adding theorem exercises when the language material requires them.

The Natural Number Game is the most approachable first contact when neither mathematics nor programming is familiar. It is not a substitute for every later topic: after its guided exercises, move to a book or project that matches your intended use.

Theorem Proving in Lean 4 is the broad proof-development route. Its introduction explains the relationship between propositions, proofs and Lean’s checking process; later material develops the concepts that recur in larger proofs. Treat the examples as executable exercises, not text to read passively.

Rank #3
Sale
Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter | 85W Max PD, 2 USB 3.0 & 1 USBC Data Ports, SD/TF Card Reader, for Laptops/Mac and Other Type C Devices (Charger Not Included)
  • Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
  • Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
  • Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
  • Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
  • What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.

Mathematics in Lean assumes that you want to express actual mathematics with Mathlib. Its sections correspond to Lean files containing examples and exercises, so your study loop is especially concrete: read a short section, open its file, fill in or modify proofs, and compile before moving on.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use the editor as an interactive proof partner

Read the goal before choosing a tactic

When Lean places a goal in the information panel, identify its outer shape. An equality goal asks you to establish that two terms are equal. An implication gives you a premise when you introduce it. A conjunction can be split into two components, while an existential goal requires a witness and a proof about that witness. This classification is more dependable than memorizing a large list of tactic names.

Make one change at a time

Copy a working example, change a single term, and observe the new goal or diagnostic. Then change the hypothesis, import, or tactic separately. This isolates cause and effect and builds the habit of using Lean’s response as evidence. Keep successful fragments in a personal scratch file, but label what concept each fragment demonstrates so it remains useful later.

Separate experiments from source exercises

For textbook or Mathlib exercises, make a working copy rather than editing the original lesson file. You can freely try a failed approach, restore a previous version, and compare two proofs without losing the supplied exercise. Keep the file inside the project so it inherits the intended imports and toolchain.

Learn both explicit and automated proof styles

Start with explicit terms such as exact, projections like h.left, and short introductions. Once you understand the goal, try a suitable tactic or automation supplied by the project. Automation is valuable, but a beginner who cannot explain the goal’s structure will have difficulty repairing an automated proof when a definition or library version changes.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Build proof skills in a deliberate order

1. Terms, types and propositions

Learn to distinguish an expression from its type and a proposition from a proof of that proposition. Practice reading declarations in the editor and predicting whether a term should inhabit the displayed type. This prevents a common early mistake: treating a proposition as though it were already evidence for itself.

2. Equality and basic logical structure

Use reflexivity for goals where both sides reduce to the same expression, then practice implication, conjunction and disjunction. The following compact example reinforces that a proof can be built by extracting a component from a hypothesis:

Rank #4
Sale
UGREEN USB to USB C Adapter Combo 4-Pack, 10Gbps USB C Converter Space Gray | Data transfer & Fast charging for MacBook, iPhone 17/16/15, iPad, Samsung Galaxy, Apple Watch
  • Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
  • Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
  • Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
  • Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
  • Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft
theorem take_right (p q : Prop) (h : p ∧ q) : q := by
  exact h.right

When a goal does not reduce to an obvious identity, inspect the available hypotheses and definitions before trying increasingly powerful tactics.

3. Functions and dependent types

Lean treats functions as values and types can depend on values. Work through examples that introduce arguments one at a time, then apply functions to explicit arguments. This is the bridge between ordinary programming practice and theorem statements whose types describe what a proof must do.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

4. Induction

Natural-number and list proofs often follow the data structure. An induction proof has a base case and an inductive step; Lean exposes the corresponding hypotheses and goals. Follow the induction examples in Theorem Proving in Lean 4 rather than attempting to memorize a universal script, because the useful induction hypothesis depends on the statement and the chosen variable.

5. Tactics and type classes

After the underlying terms make sense, learn the tactics used repeatedly in your chosen material. Type classes let a theorem use operations and laws supplied by an appropriate instance, which is why a declaration can work for several numeric structures without naming one concrete implementation. When type-class inference fails, read the complete diagnostic and check imports and expected types before adding annotations.

Formalize mathematics with Mathlib

If your goal is mathematical formalization, begin with the Mathlib-oriented material rather than trying to rebuild standard facts yourself. Mathematics in Lean is organized around editable examples and exercises and uses the library’s definitions, lemmas and tactics.

  1. Start the project exactly as its instructions specify. Use the project’s declared Lean toolchain and dependencies.
  2. Open the section’s corresponding Lean file in VS Code so the imports and options match the text.
  3. Read the statement before the prose explanation. Identify what is given, what must be shown, and which definitions are in scope.
  4. Attempt the exercise in a copy. Keep the original unchanged so you can compare your work with the supplied progression.
  5. Search Mathlib before proving a standard result. A library theorem may already express the needed fact with a different name or argument order.
  6. Record the smallest successful proof. Then, if useful, write a second version that makes the intermediate reasoning explicit.

Expect an initial dependency download in a new Mathlib project. A slow first build is not evidence that a theorem is wrong. If later files fail after an upgrade, compare the project’s toolchain and dependency declarations with the version expected by the lesson.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Find existing declarations with Loogle

Loogle searches Lean and Mathlib declarations by constant, text in a name, or a subexpression of a statement. It is useful when you know the shape of the result but not its exact identifier.

Best Value
Sale
Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display | 85W Max PD, 1 Powered USB-C 5Gbps & 2 Powered USB-A 3.0 5Gbps Data Ports, for MacBook Pro, MacBook Air, Dell and More (Black)
  • 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
  • Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
  • Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
  • HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
  • What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.

Search by the idea you need

Describe the relevant operation or proposition in the form Loogle accepts, then inspect the returned declarations and their namespaces. Compare the complete type with your goal: a theorem can be mathematically appropriate but require its arguments in another order or need an explicit type annotation.

Confirm the result in your project

Copy the candidate declaration name into your Lean file and let completion or the information panel show its type. If Lean cannot resolve it, check whether the required module is imported and whether the declaration belongs to a Mathlib revision different from yours. Loogle helps you locate possibilities; your project remains the authority on what is available in the file you are compiling.

Use search to learn library style

Repeated searches reveal naming conventions, namespaces and common theorem patterns. Keep a short note of useful declarations with the statement that matched your problem, not just the name. This makes the note resilient when several similarly named lemmas exist.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Keep Lean and tutorial versions aligned

Lean projects specify a toolchain, and learning materials can be updated independently of your local installation. The indexed Theorem Proving in Lean 4 page currently labels its version as Lean 4.33.0. Treat that label as a time-specific reference, not a permanent promise that every future project uses the same version.

When an example does not compile, check these items in order:

  • Read the book or project’s stated Lean version and setup instructions.
  • Inspect the project’s toolchain declaration rather than assuming the editor is using the version you intended.
  • Confirm that the file is opened inside the project directory and has the imports shown by the lesson.
  • Compare the declaration names and theorem statements with the version of Mathlib installed by that project.
  • Only after those checks, investigate whether your proof differs from the example.

The installation pages and the current theorem-proving index are the appropriate places to verify changes: installation guidance and the theorem-proving text index. Avoid “fixing” a version mismatch by editing a library file or copying compiled artifacts from another project.

Troubleshoot the first common failures

Symptom Likely cause What to check
The file has no Lean goals or diagnostics VS Code is treating it as plain text, or the extension is not active Confirm the official Lean 4 extension is installed, reload VS Code, and open the file inside a recognized Lean project.
Imports cannot be found in a Mathlib exercise The file is outside its project or dependencies have not finished downloading Open the project folder, follow its setup instructions, and wait for the initial dependency process to complete.
A tutorial example worked elsewhere but not locally The toolchain, Lean version or Mathlib revision differs Compare the lesson’s version information with the project toolchain and use the project’s declared dependencies.
Lean reports that a theorem name is unknown The declaration is not imported, is in a namespace, or has changed between versions Use completion and Loogle, inspect the full declaration name, and verify the relevant import.
A tactic leaves an unexpected goal The statement’s type is not what you assumed, or the tactic solved only part of it Read the remaining goal and local hypotheses, then try a smaller explicit step before adding more automation.
Manual installation behaves differently from the guide Operating-system details or environment variables need adaptation Return to the guided installer where possible; otherwise use the caveats and platform-specific notes on the manual installation page.

A practical first month

Days 1–3: make the feedback loop work

  • Complete the guided VS Code installation.
  • Compile the reflexivity and conjunction examples above.
  • Change each proof intentionally and read the resulting diagnostic.

Days 4–10: finish a beginner sequence

  • Work through the opening Natural Number Game levels, or the introductory chapters of Theorem Proving in Lean 4.
  • Rewrite several examples without looking at the solution, then compare the declarations and goals.
  • Keep a glossary of terms such as proposition, hypothesis, goal, equality and induction.

Days 11–20: follow your intended track

  • Choose the proof-development book, the Mathlib mathematics text, or the programming text according to your goal.
  • Complete exercises in editable files rather than only reading the prose.
  • After each exercise, write one sentence explaining why the proof’s first step matches the goal’s shape.

Days 21–30: search and maintain

  • Use Loogle for at least one standard result instead of proving it from first principles.
  • Practice checking namespaces, imports and theorem types in the editor.
  • Reopen the project after a clean build and record the exact toolchain and dependency information it uses.

This schedule is a practice framework, not a deadline. Spend longer on a concept when you can follow a successful script but cannot yet predict the next goal; that prediction is the skill that transfers to unfamiliar theorems.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Beginner checklist

  • VS Code and the official Lean 4 extension are installed through the recommended setup.
  • A Lean file inside a project compiles a minimal theorem.
  • You can read the goal and local hypotheses before selecting a tactic.
  • You have chosen a first resource that matches your background and intended outcome.
  • You edit examples and exercises rather than reading them passively.
  • Your project’s Lean toolchain agrees with the material you are following.
  • You know how to search declarations with Loogle and verify a result inside your project.
  • You preserve original exercise files and keep experiments in a separate working copy.

With those pieces in place, proving theorems in Lean becomes an iterative activity: state a precise proposition, inspect the goal, try a small proof step, and let the checker tell you exactly what remains.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

formal mathematicsLean 4Mathlibproof assistantstheorem provingVS Code

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.