Skip to content
This repository was archived by the owner on Aug 28, 2025. It is now read-only.

Commit a965c48

Browse files
author
mia von steinkirch, phd
committed
add a bunch of conceptual examples to start this great monday (#3)
1 parent c0895fe commit a965c48

File tree

15 files changed

+271
-129
lines changed

15 files changed

+271
-129
lines changed

.github/.keep

Whitespace-only changes.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
name: Lean Action CI
2+
3+
on:
4+
push:
5+
pull_request:
6+
workflow_dispatch:
7+
8+
jobs:
9+
build:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- uses: actions/checkout@v4
14+
- uses: leanprover/lean-action@v1

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
/build/
33
/.lake/
44
/.elan/
5+
elan-init
56

67
# editor and os files
78
*.swp

Main.lean

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import src.Basics
2+
3+
def main : IO Unit :=
4+
IO.println s!"gm... testing... btw, double of 5 is {double 5}"

Makefile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,22 @@ serve: check-lean
2424
update: check-lean
2525
@lake update
2626

27+
.PHONY: run-main
28+
run-main: check-lean
29+
@lake run
30+
2731
.PHONY: run-basics
2832
run-basics: check-lean
2933
@lake env lean src/Basics.lean
3034

3135
.PHONY: run-simple_proofs_I
3236
run-simple_proofs_I: check-lean
3337
@lake env lean src/SimpleProofs_I.lean
38+
39+
.PHONY: run-bt
40+
run-bt: check-lean
41+
@lake env lean src/BinaryTree.lean
42+
43+
.PHONY: run-tc
44+
run-tc: check-lean
45+
@lake env lean src/TypeClasses.lean

README.md

Lines changed: 27 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<br>
44

5-
> *this repository contains examples and explanations as i learn lean 4 (a powerful theorem prover and programming language for the AI age)*
5+
> *this repository contains examples and explanations as i learn lean4 (a powerful theorem prover and programming language for the AI age)*
66
77
<br>
88

@@ -35,166 +35,78 @@ lean --version
3535
lake --version
3636
```
3737

38-
---
39-
40-
### project structure
41-
42-
<br>
43-
44-
- `lakefile.lean`: the lean package manager configuration file
45-
- `src.lean`: the main entry point for the source code
46-
- `src/Basics.lean`: basic examples and concepts
47-
- `src/SimpleProofs_*.lean`: more advanced concepts and examples for proofs
48-
- `Makefile`
49-
5038
<br>
5139

5240
---
5341

54-
### basic concepts
42+
### documentation
5543

5644
<br>
5745

58-
#### types and functions
59-
60-
lean has several basic types:
61-
- natural numbers (`Nat`): whole numbers starting from 0
62-
- booleans (`Bool`): true or false values
63-
- strings: text values
46+
- [basic concepts](docs/basic_concepts.md) - introduction to types, functions, and simple proofs in lean4
6447

6548
<br>
6649

67-
we start with simple examples to check types using `#check` and evaluate expressions using `#eval`:
50+
---
6851

69-
```lean
70-
#check 43 -- shows the type of 43
71-
#eval 43 + 1 -- evaluates to 44
72-
#check true -- shows the type of true
73-
#eval true && false -- evaluates to false
74-
```
52+
### running
7553

7654
<br>
7755

78-
#### function definitions
79-
80-
functions are defined using the `def` keyword. here's a simple example:
81-
82-
```lean
83-
def double (n : Nat) : Nat := n + n
84-
```
85-
86-
this defines a function that:
87-
- takes a natural number `n` as input
88-
- returns a natural number
89-
- doubles the input by adding it to itself
56+
#### project structure
9057

9158
<br>
9259

93-
#### simple proofs
94-
95-
lean is primarily a theorem prover. here's a simple proof:
96-
97-
```lean
98-
theorem double_add (n m : Nat) : double (n + m) = double n + double m := by
99-
-- unfold the definition of double to work with the raw addition
100-
unfold double
101-
102-
-- use Lean's simplifier with three key properties of natural number addition
103-
-- 1. Nat.add_assoc: (a + b) + c = a + (b + c) (associativity)
104-
-- 2. Nat.add_comm: a + b = b + a (commutativity)
105-
-- 3. Nat.add_left_comm: a + (b + c) = b + (a + c) (left commutativity)
106-
simp only [Nat.add_assoc, Nat.add_comm, Nat.add_left_comm]
107-
```
60+
- `src.lean`: the main entry point for the source code
61+
- `Main.lean`: the main module file
62+
- `src/`: source code for examples and concepts
63+
- `Makefile`
64+
- `lakefile.lean`: the lean package manager configuration file (TODO: replace with `toml`)
65+
- `lake-manifest.json`: automatically generated dependency lock file
66+
- `lean-toolchain`: specifies the Lean version for the project
10867

10968
<br>
11069

111-
---
112-
113-
### running
70+
#### `make build`
11471

11572
<br>
11673

117-
run all `*.lean` files with:
74+
run all `src/*.lean` files with:
11875

11976
```shell
12077
make build
121-
122-
info: src/Basics.lean:8:0: 43 :
123-
info: src/Basics.lean:9:0: 44
124-
info: src/Basics.lean:12:0: Bool.true : Bool
125-
info: src/Basics.lean:13:0: false
126-
info: src/Basics.lean:16:0: "gm, anon" : String
127-
info: src/Basics.lean:17:0: "gm, anon"
128-
info: src/Basics.lean:27:0: 666
129-
info: src/Basics.lean:32:0: true
130-
info: src/Basics.lean:33:0: false
131-
ℹ [2853/2855] Built src.SimpleProofs_I
132-
info: src/SimpleProofs_I.lean:21:0: 10
133-
info: src/SimpleProofs_I.lean:22:0: 0
134-
info: src/SimpleProofs_I.lean:23:0: 6
135-
info: src/SimpleProofs_I.lean:26:0: true
136-
info: src/SimpleProofs_I.lean:27:0: false
137-
info: src/SimpleProofs_I.lean:28:0: true
138-
info: src/SimpleProofs_I.lean:31:0: double_add (n m : ℕ) : double (n + m) = double n + double m
139-
info: src/SimpleProofs_I.lean:34:0: 14
140-
info: src/SimpleProofs_I.lean:35:0: 14
141-
Build completed successfully.
14278
```
14379

14480
<br>
14581

146-
#### basic types and functions
82+
#### basic types, theorems, type classes...
14783

14884
<br>
14985

150-
run `Basics.lean` with:
86+
run any other file inside `src/` following its command inside `Makefile`. for instance, run `src/Basics.lean` with:
15187

15288
```shell
15389
make run-basic
154-
155-
43 :
156-
44
157-
Bool.true : Bool
158-
false
159-
"gm, anon" : String
160-
"gm, anon"
161-
666
162-
true
163-
false
16490
```
16591

16692
<br>
16793

168-
---
169-
170-
#### theorem to prove that doubling the sum of two numbers is the same as adding their double
171-
172-
<br>
173-
174-
run `SimpleProofs_I.lean` with:
17594

176-
```shell
177-
make run-simple_proofs_I
178-
179-
10
180-
0
181-
6
182-
true
183-
false
184-
true
185-
double_add (n m : Nat) : double (n + m) = double n + double m
186-
14
187-
14
188-
```
95+
----
18996

97+
### study resources
19098

19199
<br>
192100

193-
----
101+
#### learning lean
194102

195-
### resources
103+
- [learn lean](https://lean-lang.org/documentation/0)
104+
- [lean4 documentation](https://leanprover.github.io/lean4/doc/)
105+
- [vscode/cursor plugin](https://marketplace.visualstudio.com/items?itemName=leanprover.lean4)
196106

197107
<br>
198108

199-
- [lean 4 documentation](https://leanprover.github.io/lean4/doc/)
200-
- [lean 4 manual](https://leanprover.github.io/lean4/doc/)
109+
#### applied examples
110+
111+
- [AI safety via debate, by g. irving et al (2018)](https://arxiv.org/pdf/1805.00899)
112+
- *"in the debate game, it is harder to lie than to refute a lie."*

docs/basic_concepts.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
## basic concepts
2+
3+
<br>
4+
5+
---
6+
7+
### types and functions
8+
9+
<br>
10+
11+
* there are two primary concepts in lean: functions and types
12+
* basic types examples are natural numbers (`Nat`, whole numbers starting from 0), booleans (`Bool`), true or false values, strings
13+
* check types using `#check`
14+
* evaluate expressions using `#eval`
15+
16+
<br>
17+
18+
---
19+
20+
### function definitions
21+
22+
<br>
23+
24+
* functions are defined using the `def` keyword:
25+
26+
```lean
27+
def double (n : Nat) : Nat := n + n
28+
```

elan-init

-5.92 MB
Binary file not shown.

lake-manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"type": "git",
66
"subDir": null,
77
"scope": "",
8-
"rev": "e6f52a442b52ac7fddcb4ae4818e1751c6efd3c9",
8+
"rev": "8744850cc139c0d23086fdabad638f970a983bce",
99
"name": "mathlib",
1010
"manifestFile": "lake-manifest.json",
1111
"inputRev": null,

lakefile.lean

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,8 @@ require mathlib from git
1111
@[default_target]
1212
lean_lib «src» {
1313
-- add library configuration options here
14+
}
15+
16+
lean_exe Main {
17+
root := `Main
1418
}

0 commit comments

Comments
 (0)