|
2 | 2 |
|
3 | 3 | <br> |
4 | 4 |
|
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)* |
6 | 6 |
|
7 | 7 | <br> |
8 | 8 |
|
@@ -35,166 +35,78 @@ lean --version |
35 | 35 | lake --version |
36 | 36 | ``` |
37 | 37 |
|
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 | | - |
50 | 38 | <br> |
51 | 39 |
|
52 | 40 | --- |
53 | 41 |
|
54 | | -### basic concepts |
| 42 | +### documentation |
55 | 43 |
|
56 | 44 | <br> |
57 | 45 |
|
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 |
64 | 47 |
|
65 | 48 | <br> |
66 | 49 |
|
67 | | -we start with simple examples to check types using `#check` and evaluate expressions using `#eval`: |
| 50 | +--- |
68 | 51 |
|
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 |
75 | 53 |
|
76 | 54 | <br> |
77 | 55 |
|
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 |
90 | 57 |
|
91 | 58 | <br> |
92 | 59 |
|
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 |
108 | 67 |
|
109 | 68 | <br> |
110 | 69 |
|
111 | | ---- |
112 | | - |
113 | | -### running |
| 70 | +#### `make build` |
114 | 71 |
|
115 | 72 | <br> |
116 | 73 |
|
117 | | -run all `*.lean` files with: |
| 74 | +run all `src/*.lean` files with: |
118 | 75 |
|
119 | 76 | ```shell |
120 | 77 | 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. |
142 | 78 | ``` |
143 | 79 |
|
144 | 80 | <br> |
145 | 81 |
|
146 | | -#### basic types and functions |
| 82 | +#### basic types, theorems, type classes... |
147 | 83 |
|
148 | 84 | <br> |
149 | 85 |
|
150 | | -run `Basics.lean` with: |
| 86 | +run any other file inside `src/` following its command inside `Makefile`. for instance, run `src/Basics.lean` with: |
151 | 87 |
|
152 | 88 | ```shell |
153 | 89 | 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 |
164 | 90 | ``` |
165 | 91 |
|
166 | 92 | <br> |
167 | 93 |
|
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: |
175 | 94 |
|
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 | +---- |
189 | 96 |
|
| 97 | +### study resources |
190 | 98 |
|
191 | 99 | <br> |
192 | 100 |
|
193 | | ----- |
| 101 | +#### learning lean |
194 | 102 |
|
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) |
196 | 106 |
|
197 | 107 | <br> |
198 | 108 |
|
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."* |
0 commit comments