Logic: Curry-Howard Correspondence and Natural numbers #
The foundations of Lean represent "all" of Mathematics. This means:
- The Curry-Howard correspondence: proofs are programs, propositions are types; allows logical connectives to be represented and rules of deduction to be implemented.
- The basic objects of Mathematics are constructed in terms of inductive types.
- The basic relations of Mathematics are constructed in terms of inductive types.
We will illustrate the latter two points in the context of Natural numbers.
Classical logic: example Natural Numbers #
- A language is a set of constants, (n-ary) functions, (n-ary) predicates (relations).
- For natural numbers:
- Constant:
0 - Functions:
succ,+,× - Predicates:
=,≤
- Constant:
- For natural numbers:
- Mathematical objects: Terms, are built from
- Constants
- Variables: fixed (countably infinite) set of variables
x₀,x₁, ... - Functions applied to terms
- Properties, i.e., Formulas are built from
- Predicates applied to terms
- Logical connectives:
∧,∨,¬,→,↔ - Quantifiers:
∀,∃
- Theory: Axioms are formulas that are assumed to be true.
- For natural numbers: Peano axioms
- We also include logical axioms, example excluded middle.
- Deduction rules: Proofs are constructed from
- Rules of inference: Modus ponens, i.e.,
A → B,AimpliesB., Generalization, i.e.,Aimplies∀ x, A.
- Rules of inference: Modus ponens, i.e.,
Logic in Lean #
Quantifiers #
∀ x : α, P xis(x : α) → P x.∃ x : α, P xis∃ x, P xorExists (fun x => P x).- A proof of existence is a pair consisting of
x : αfor whichP xholds.- A proof (witness) that
P xholds.
- A proof of existence is a pair consisting of
Constructing the Language of Natural Numbers #
- Our rules should allow us to constuct the "set" of natural numbers.
- We should be able to define the operations on natural numbers.
- We should be able to define the relations on natural numbers.
- We should be able to represent the axioms of Peano arithmetic, including the induction axiom schema.
- Our constructions should be such that all the axioms are theorems.
Equations
- MyNat.zero.mul n = MyNat.zero
- m'.succ.mul n = n #+# m'.mul n
Instances For
The subtle point is to define relations such as ≤ and =. These are indexed inductive types.
The induction principle encodes not only that refl and step are constructors of le, but also that they are the only ways to prove le.
Transitivity of ≤ is a theorem.