Skip to content
This repository was archived by the owner on Apr 22, 2026. It is now read-only.

Commit e2bcb90

Browse files
author
mia von steinkirch, phd
committed
add definig even number proof, + notes, + refs (#7)
1 parent 3feaeca commit e2bcb90

6 files changed

Lines changed: 196 additions & 2 deletions

File tree

README.md

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,25 +85,38 @@ run any other file inside `src/example/` following its command inside `Makefile`
8585
#### my notes
8686

8787
- [basics](docs/basic_concepts.md)
88+
- [formal verification](docs/formal_verification.md)
8889

8990
<br>
9091

91-
#### learning lean
92+
#### learning lean and theorem proving
9293

93-
-[learn Lean from lean-lang.org](https://lean-lang.org/documentation/0)
94+
-[learn Lean from lean-lang.org](https://lean-lang.org/documentation/)
95+
-[Lean prover community](https://leanprover-community.github.io/)
9496
- 🟡 [Lean 4 documentation](https://leanprover.github.io/lean4/doc/)
9597
- 🟡 [mathematics in Lean](https://leanprover-community.github.io/mathematics_in_lean/C01_Introduction.html)
9698
- 🟡 [theorem proving in Lean 4](https://leanprover.github.io/theorem_proving_in_lean4/)
99+
- 🟡 [the matrix cookbook](https://www.math.uwaterloo.ca/~hwolkowi/matrixcookbook.pdf) with [code](https://github.com/eric-wieser/lean-matrix-cookbook)
100+
- 🟡 [the Lean 4 theorem prover and programming language](https://lean-lang.org/papers/lean4.pdf)
101+
- 🟡 [an extensible theorem proving frontend](https://lean-lang.org/papers/thesis-sebastian.pdf)
102+
- 🟡 [a metaprogramming framework for formal verification](https://lean-lang.org/papers/tactic.pdf)
97103

98104
<br>
99105

100106
#### useful
101107

102108
- [vscode/cursor plugin](https://marketplace.visualstudio.com/items?itemName=leanprover.lean4)
109+
- [mathlib algebra methods ref](https://leanprover-community.github.io/mathlib4_docs/Mathlib/Algebra/Group/Defs.html#Group)
110+
- [zulip Lean channel](https://leanprover.zulipchat.com/)
111+
- [moogle.ai (find theorems)](https://www.moogle.ai/)
103112

104113
<br>
105114

106115
#### applied examples
107116

117+
- [Lean prover community's blog](https://leanprover-community.github.io/blog/) and [projects](https://leanprover-community.github.io/lean_projects.html)
118+
- [social choice theory in Lean (code)](https://github.com/asouther4/lean-social-choice?tab=readme-ov-file)
119+
- [the deep link equating math proofs and computer programs](https://www.quantamagazine.org/the-deep-link-equating-math-proofs-and-computer-programs-20231011/)
120+
- *"types are fundamentally equivalent to logical propositions"*
108121
- [AI safety via debate, by g. irving et al (2018)](https://arxiv.org/pdf/1805.00899)
109122
- *"in the debate game, it is harder to lie than to refute a lie."*

docs/basic_concepts.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,10 @@ def twice (f : Nat → Nat) (a : Nat) := f (f a)
369369

370370
<br>
371371

372+
* for instance, `(· + 2)` is syntax sugar for `(fun x => x + 2)`
373+
374+
<br>
375+
372376
---
373377

374378
## namespaces

docs/formal_verification.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# formal verification
2+
3+
<br>
4+
5+
## tl; dr
6+
7+
<br>
8+
9+
* formal methods are a set of techniques and specialized tools used to specify, design, and verify
10+
complex systems with mathematical rigor
11+
- 1. specify: describe a system's desired behavior precisely
12+
- 2. design: develop system components with assurance they'll work as intended
13+
- 3. verify: prove or provide evidence that a system meets its specification
14+
15+
<br>
16+
17+
---
18+
19+
## proof assistant
20+
21+
<br>
22+
23+
* a piece of software that provides a language for defining objects, specifying properties of these objects, and proving that these specifications hold (i.e., the system checks that these proofs are correct down to their logical foundation)
24+
* in a formalization, all definitions are precisely specified and all proofs are virtually guaranteed to be correct.
25+
26+
<br>
27+
28+
<p align="center">
29+
<img src="images/proof_assistant.png" width=80%" align="center" style="padding:1px;border:1px solid black;"/>
30+
</p>
31+
32+
<br>
33+
34+
---
35+
36+
## proving methods
37+
38+
<br>
39+
40+
### rfl
41+
42+
<br>
43+
44+
* reflexivity of equality: anything is equal to itself
45+
* `rfl` stands for reflexivity, a fundamental concept and a very common tactic used in proofs
46+
* in Lean's type theory, equality is an inductive type, and `Eq.refl` a is the constructor for proving` a = a`

docs/images/proof_assistant.png

450 KB
Loading

src/proofs/DefiningEvenNumber.lean

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
import Mathlib.Data.Nat.Basic
2+
3+
/-
4+
##
5+
## I. defining what an "even" number is
6+
##
7+
-/
8+
9+
-- we define a new `inductive` type called `Even`
10+
-- an inductive type allows us to define a data type by specifying its constructors
11+
-- here, we say that a number `n` is `Even` if:
12+
-- 1. `Even.zero` : 0 is even
13+
-- 2. `Even.add_two` : if `k` is even, then `k + 2` is also even
14+
inductive Even : Nat → Prop
15+
| zero : Even 0
16+
| add_two {k : Nat} (hk : Even k) : Even (k + 2)
17+
18+
19+
/-
20+
##
21+
## II. proving a simple property about even numbers
22+
##
23+
-/
24+
25+
-- our goal is to prove the following theorem:
26+
-- if a number `n` is even, then `n + 2` is also even
27+
theorem even_add_two_is_even {n : Nat} (hn : Even n) : Even (n + 2) := by
28+
-- we have `hn : Even n` in our context
29+
-- our goal is `Even (n + 2)`
30+
-- since `Even` is an inductive type, we can use `induction` on `hn`.
31+
-- this means we'll prove the statement for each constructor of `Even`
32+
induction hn with
33+
| zero =>
34+
-- case 1: `n` is `0`.
35+
-- our goal is now `Even (0 + 2)`, which simplifies to `Even 2`
36+
-- we can prove this directly using the `Even.add_two` constructor
37+
-- we need to show that `Even 0` holds, which is true by `Even.zero`
38+
apply Even.add_two
39+
apply Even.zero
40+
| add_two k hk ih =>
41+
-- case 2: `n` is of the form `k + 2`, where `hk : Even k`
42+
-- and `ih` is our inductive hypothesis: `Even (k + 2)` implies `Even ((k + 2) + 2)`
43+
-- the inductive hypothesis `ih` is actually `Even (k + 2)` implies `Even (k + 2 + 2)`
44+
-- `ih` will be a proof of our goal for `k` so `ih : Even (k + 2)`
45+
-- our goal is `Even ((k + 2) + 2)`
46+
-- we can use `Even.add_two` again
47+
-- to apply `Even.add_two`, we need a proof that `Even (k + 2)` holds (our inductive hypothesis `ih`)
48+
apply Even.add_two
49+
assumption -- this tactic tries to find a proof of the current goal among the hypotheses
50+
-- in this case, `ih` is exactly `Even (k + 2)`
51+
52+
53+
/-
54+
##
55+
## III. using the theorem
56+
##
57+
-/
58+
59+
example : Even 4 := by
60+
-- we know 0 is even
61+
have h0 : Even 0 := Even.zero
62+
-- then 2 is even (0 + 2)
63+
have h2 : Even 2 := Even.add_two h0
64+
-- then 4 is even (2 + 2)
65+
exact Even.add_two h2
66+
67+
68+
-- another way to prove `Even 4` using our theorem `even_add_two_is_even`
69+
example : Even 4 := by
70+
-- we know `Even 0`.
71+
have h0 : Even 0 := Even.zero
72+
-- apply `even_add_two_is_even` to `h0` to get `Even (0 + 2)`, i.e., `Even 2`
73+
have h2 : Even 2 := even_add_two_is_even h0
74+
-- apply `even_add_two_is_even` to `h2` to get `Even (2 + 2)`, i.e., `Even 4`
75+
exact even_add_two_is_even h2
76+
77+
78+
/-
79+
##
80+
## IV. a slightly more complex definition and proof
81+
##
82+
-/
83+
84+
-- let's define addition for natural numbers
85+
-- let's assume `add_zero` and `add_succ` are axioms for now
86+
-- let's define what it means for a number to be "odd":
87+
-- a number `n` is `Odd` if `n = k + 1` for some even `k`
88+
def Odd (n : Nat) : Prop := ∃ k, Even k ∧ n = k + 1
89+
90+
-- prove that if `n` is odd, then `n + 2` is also odd
91+
theorem odd_add_two_is_odd {n : Nat} (hn : Odd n) : Odd (n + 2) := by
92+
-- our hypothesis `hn` is `Odd n`, which means `∃ k, wven k ∧ n = k + 1`
93+
-- we can `rcases` this hypothesis to get `k` and its properties
94+
rcases hn with ⟨k, hk_even, hk_n⟩
95+
-- `k : Nat`
96+
-- `hk_even : Even k`
97+
-- `hk_n : n = k + 1`
98+
99+
-- our goal is `Odd (n + 2)`
100+
-- by definition, this means `∃ m, Even m ∧ (n + 2) = m + 1`
101+
102+
-- let's substitute `n = k + 1` into the goal
103+
-- the goal becomes `Odd ((k + 1) + 2)`, which simplifies to `Odd (k + 3)`
104+
-- we need to find an `m` such that `Even m` and `k + 3 = m + 1`
105+
-- if we choose `m = k + 2`, then `k + 3 = (k + 2) + 1` is true
106+
-- so we need to show `Even (k + 2)`
107+
108+
-- we know `hk_even : Even k`
109+
-- we can use our previously proven theorem `even_add_two_is_even` to show `Even (k + 2)`
110+
have hk_plus_2_even : Even (k + 2) := even_add_two_is_even hk_even
111+
112+
-- now we have `hk_plus_2_even : Even (k + 2)`
113+
-- we want to show `∃ m, Even m ∧ (n + 2) = m + 1`
114+
-- let `m := k + 2`
115+
-- we use `exists.intro` to provide the witness `k + 2`
116+
exists (k + 2)
117+
-- now our goal is `Even (k + 2) ∧ (n + 2) = (k + 2) + 1`
118+
-- we can `split` the goal into two subgoals
119+
constructor
120+
-- subgoal 1: `Even (k + 2)`
121+
exact hk_plus_2_even
122+
-- subgoal 2: `(n + 2) = (k + 2) + 1`
123+
-- we know `n = k + 1`, lets rewrite:
124+
rw [hk_n]
125+
-- goal becomes `(k + 1) + 2 = (k + 2) + 1`
126+
-- this is true by associativity and commutativity of addition
127+
-- lean's simplifier `simp` can usually handle such arithmetic equalities
128+
simp

src/proofs/FermatLastTheorem.lean

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
/-
22
##
33
## for the lolz
4+
## https://leanprover-community.github.io/blog/posts/FLT-announcement/
5+
## https://github.com/leanprover-community/flt-regular
6+
## https://leanprover-community.github.io/flt-regular/blueprint/
47
##
58
-/
69

0 commit comments

Comments
 (0)