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.
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
namespace Basic: This command groups our definitions, preventing naming conflicts with Lean’s built-in library (the Prelude). It allows us to redefine fundamental structures like True, False, and And from scratch for educational purposes.noncomputable section: Lean 4 is both a theorem prover and a functional programming language. By default, it tries to generate executable bytecode for every definition. Marking a section as noncomputable tells the compiler to skip this step, which is common in formal logic where we care about mathematical properties rather than runtime execution.In this section, we will define the foundational elements of logic, mapping standard mathematical notation to Lean 4 code.
The simplest proposition is one that is universally logically valid. In programming terms, 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
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
In Lean 4, negation is not a primitive, built-in concept. Instead, it is defined functionally using implication and False. To prove that proposition is false (denoted ), you must demonstrate a function where assuming leads directly to a contradiction ().
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
Because Lean relies on type theory, logical implication () is treated literally as a function. To prove that implies , you must write a function that takes an arbitrary proof of and returns a proof of .
Chained Implication Example: If you can turn into , and turn into , you can transform a function from into one from .
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
Logical conjunction, requiring both and 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
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 , you wrap a proof of in the inl (inject-left) constructor, or a proof of 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
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)
By rebuilding propositional logic from scratch in Lean 4, we reveal the mechanical beauty of formal systems:
And is a struct, Or is an enum, True is a unit, and False is void.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.
Get the curated offline edition of Kaue's Way of Lifeβa practical field guide to optimizing π Health, π° Wealth, β€οΈ Love, and π§ Meaning.
Get notified when I publish new essays, book summaries, and practical guides on living well. No spamβunsubscribe anytime.
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.