๐Ÿ“ Propositional Logic Proofs Using Lean 4: A Practical Guide ๐Ÿ”—

Propositional Logic Proofs Using Lean 4: A Practical GuidePropositional Logic Proofs Using Lean 4: A Practical Guide

This post provides a technical walkthrough of fundamental propositional logic concepts and their formal implementation using the Lean 4 programming language and theorem prover.

Whether you are a mathematician looking to formalize proofs or a programmer diving into type theory, this guide reconstructs logic from first principles. We will start with basic logical constants and explore how Lean 4 elegantly models logical constructs using the Curry-Howard Isomorphismโ€”the principle that propositions are types and proofs are programs.

๐Ÿ“‘ Table of Contents ๐Ÿ”—


โš™๏ธ The Preamble: Setting the Stage ๐Ÿ”—

Before defining our logical connectives, we need to set up a foundational environment. In Lean 4, this is typically done using two specific commands to control scope and computational behavior.

namespace Basic

noncomputable section

๐Ÿงฉ Core Logical Connectives ๐Ÿ”—

In this section, we will define the foundational elements of logic, mapping standard mathematical notation to Lean 4 code.

โœ… 1. True (โŠค) ๐Ÿ”—

The simplest proposition is one that is universally logically valid. In programming terms, โŠค\top behaves like a Unit typeโ€”it has exactly one state and carries no additional data.

Definition:

inductive True : Prop where
  | intro : True

Because it is defined with a single constructor (intro), the only way to “prove” True is to provide this exact constructor.

Examples:

-- Proving True unconditionally
example : True := True.intro

-- Any proposition 'a' trivially implies True
example {a : Prop} : a โ†’ True := fun _ => True.intro

โŒ 2. False (โŠฅ) ๐Ÿ”—

While True is defined by the trivial existence of a proof, False is defined by the total absence of one. It is an Empty type (or Void type).

Definition:

inductive False : Prop

Because False has no constructors, you can never instantiate it out of thin air. It represents a logical contradiction.

The Principle of Explosion (Ex Falso Quodlibet): If you ever find yourself holding a proof of False, logic breaks down, and you can prove anything. Lean handles this using the recursor False.elim.

-- From a falsehood, any proposition 'a' follows (โŠฅ โ†’ a)
def False.elim {a : Prop} (false_proof : False) : a := 
  false_proof.rec

๐Ÿ”„ 3. Negation (ยฌ) ๐Ÿ”—

In Lean 4, negation is not a primitive, built-in concept. Instead, it is defined functionally using implication and False. To prove that proposition aa is false (denoted ยฌa\neg a), you must demonstrate a function where assuming aa leads directly to a contradiction (โŠฅ\bot).

Definition:

def Not (a : Prop) : Prop := a โ†’ False

Key Theorems:

-- Proving Negation: If assuming 'a' proves False, then Not 'a' is true.
theorem Not.intro {a : Prop} (h : a โ†’ False) : Not a := 
  fun ha => h ha

-- Double Negation Introduction (a โ†’ ยฌยฌa)
theorem not_not_intro {a : Prop} (ha : a) : Not (Not a) := 
  fun na => na ha  -- 'na' has type (a โ†’ False), so passing 'ha' yields False.

-- Modus Tollens: If (a โ†’ b) and (ยฌb), then (ยฌa)
theorem Not.imp {a b : Prop} (nb : Not b) (ab : a โ†’ b) : Not a := 
  fun ha => 
    have hb : b := ab ha
    nb hb

โžก๏ธ 4. Implication (โ†’) ๐Ÿ”—

Because Lean relies on type theory, logical implication (aโ†’ba \to b) is treated literally as a function. To prove that aa implies bb, you must write a function that takes an arbitrary proof of aa and returns a proof of bb.

Chained Implication Example: If you can turn cc into aa, and turn bb into dd, you can transform a function from aโ†’ba \to b into one from cโ†’dc \to d.

theorem imp_imp_imp {a b c d : Prop} 
  (ca : c โ†’ a) (bd : b โ†’ d) : (a โ†’ b) โ†’ (c โ†’ d) := 
  fun ab => fun hc => 
    have ha : a := ca hc
    have hb : b := ab ha
    bd hb

๐Ÿ”— 5. Conjunction (โˆง) ๐Ÿ”—

Logical conjunction, requiring both aa and bb to be true, is modeled as a structure. In programming terms, this is a Product type (a struct or tuple) that holds two separate pieces of evidence.

Definition:

structure And (a b : Prop) : Prop where
  intro ::
  left : a
  right : b

Key Proof Patterns:

-- Introduction: Creating an And
example {a b : Prop} (ha : a) (hb : b) : And a b := 
  And.intro ha hb

-- Symmetry: a โˆง b โ†’ b โˆง a
theorem And.symm {a b : Prop} (h : And a b) : And b a := 
  And.intro h.right h.left

๐Ÿ”€ 6. Disjunction (โˆจ) ๐Ÿ”—

Logical disjunction requires at least one of the propositions to be true. Unlike And, Or is an inductive Sum type (a tagged union), because there are two distinct, alternative ways to construct a proof.

Definition:

inductive Or (a b : Prop) : Prop where
  | inl (h : a) : Or a b
  | inr (h : b) : Or a b

To prove aโˆจba \lor b, you wrap a proof of aa in the inl (inject-left) constructor, or a proof of bb in the inr (inject-right) constructor.

Example:

-- Symmetry: a โˆจ b โ†’ b โˆจ a
theorem Or.symm {a b : Prop} (h : Or a b) : Or b a :=
  match h with
  | Or.inl ha => Or.inr ha
  | Or.inr hb => Or.inl hb

โ†”๏ธ 7. Logical Equivalence (โ†”) ๐Ÿ”—

Bi-implication, or “if and only if” (Iff), represents that two propositions are logically equivalent. It is defined as a structure holding implications in both directions.

Definition:

structure Iff (a b : Prop) : Prop where
  intro ::
  mp : a โ†’ b
  mpr : b โ†’ a

Reflexivity Example:

-- Every proposition is equivalent to itself (a โ†” a)
theorem Iff.refl {a : Prop} : Iff a a :=
  Iff.intro (fun ha => ha) (fun ha => ha)

๐ŸŽฏ Conclusion and Key Takeaways ๐Ÿ”—

By rebuilding propositional logic from scratch in Lean 4, we reveal the mechanical beauty of formal systems:

  1. Constructive by Default: We define what it means to hold evidence of a truth, rather than merely stating something is true.
  2. Propositions as Types: Through the Curry-Howard mapping, logical connectives directly correspond to standard programming structures: Implication is a function, And is a struct, Or is an enum, True is a unit, and False is void.
  3. Proofs as Programs: Writing a mathematical proof in Lean is identical to writing a type-safe function that satisfies a specific signature.

Mastering these foundational building blocks provides the crucial stepping stones necessary to tackle more complex mathematical theorems, predicate logic, and the verification of complex software systems.


๐Ÿ“š Download My Free Ebook ๐Ÿ”—

Get the curated offline edition of Kaue's Way of Lifeโ€”a practical field guide to optimizing ๐Ÿ Health, ๐Ÿ’ฐ Wealth, โค๏ธ Love, and ๐Ÿง˜ Meaning.

Kaue's Way of Life

Kaue's Way of Life

๐Ÿ’ฌ Comments & Discussion ๐Ÿ”—

Have a question, perspective, or suggestion? Share your thoughts below. Comments are powered by GitHub Discussions (ad-free and spam-free)โ€”click Sign in with GitHub below to comment or react (creating a free GitHub account takes less than a minute).



Updated on Oct 11, 2026.

DISCLAIMER: The content on this site is for informational and educational purposes only and does not constitute medical, psychological, financial, investment, tax, or legal advice. The ideas, curation, and opinions presented here are my own and do not represent those of my employer. Book, lecture, and article summaries are independent educational commentary and remain the intellectual property of their respective authors. AI tools may be used to assist with editing, formatting, and synthesis; while every effort is made to ensure accuracy, errors may occur. PRIVACY: This site uses third-party services for comments (giscus / GitHub Discussions) and embedded media (YouTube), which may process visitor IP addresses and cookies in accordance with their respective privacy policies.