πŸ“ Propositional 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
Minimum price
Free!
Suggested price
$0.00

πŸ“¬ Join My Mailing List πŸ”—

Get notified when I publish new essays, book summaries, and practical guides on living well. No spamβ€”unsubscribe anytime.


πŸ’¬ Comments & Discussion πŸ”—

Have a question, perspective, or suggestion? Share your thoughts below.



Updated on 2026 Oct 11.

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 cookieless analytics (Google Analytics), optional newsletter subscriptions (Mailchimp), comments (Disqus), live chat (Tawk.to), and embedded media (YouTube), which may process visitor IP addresses and cookies in accordance with their respective privacy policies.