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

Commit e9dbe95

Browse files
author
mia von steinkirch, phd
committed
add inductive predicate ex and reorg (#5)
1 parent a965c48 commit e9dbe95

15 files changed

+407
-237
lines changed

Main.lean

Lines changed: 0 additions & 4 deletions
This file was deleted.

Makefile

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,34 +12,19 @@ clean: check-lean
1212
@lake clean
1313
@rm -rf build
1414

15-
.PHONY: test
16-
test: check-lean
17-
@lake test
18-
19-
.PHONY: serve
20-
serve: check-lean
21-
@lake serve
22-
2315
.PHONY: update
2416
update: check-lean
2517
@lake update
2618

27-
.PHONY: run-main
28-
run-main: check-lean
29-
@lake run
30-
31-
.PHONY: run-basics
32-
run-basics: check-lean
33-
@lake env lean src/Basics.lean
34-
35-
.PHONY: run-simple_proofs_I
36-
run-simple_proofs_I: check-lean
37-
@lake env lean src/SimpleProofs_I.lean
19+
.PHONY: definitions
20+
definitions: check-lean
21+
@lake env lean src/examples/TypeClassesExamples.lean
3822

39-
.PHONY: run-bt
40-
run-bt: check-lean
41-
@lake env lean src/BinaryTree.lean
23+
.PHONY: classics
24+
classics: check-lean
25+
@lake env lean src/examples/PalindromeExamples.lean
26+
@lake env lean src/examples/BinaryTreeExamples.lean
4227

43-
.PHONY: run-tc
44-
run-tc: check-lean
45-
@lake env lean src/TypeClasses.lean
28+
.PHONY: proofs
29+
proofs: check-lean
30+
@lake env lean src/examples/SumsAndMultiExamples.lean

README.md

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,6 @@ lake --version
3939

4040
---
4141

42-
### documentation
43-
44-
<br>
45-
46-
- [basic concepts](docs/basic_concepts.md) - introduction to types, functions, and simple proofs in lean4
47-
48-
<br>
49-
50-
---
51-
5242
### running
5343

5444
<br>
@@ -58,12 +48,10 @@ lake --version
5848
<br>
5949

6050
- `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`
51+
- `src/`: source code for concepts and `examples/`
6452
- `lakefile.lean`: the lean package manager configuration file (TODO: replace with `toml`)
65-
- `lake-manifest.json`: automatically generated dependency lock file
6653
- `lean-toolchain`: specifies the Lean version for the project
54+
- `Makefile`: speficify all available commands
6755

6856
<br>
6957

@@ -83,11 +71,7 @@ make build
8371

8472
<br>
8573

86-
run any other file inside `src/` following its command inside `Makefile`. for instance, run `src/Basics.lean` with:
87-
88-
```shell
89-
make run-basic
90-
```
74+
run any other file inside `src/example/` following its command inside `Makefile`.
9175

9276
<br>
9377

@@ -98,6 +82,14 @@ make run-basic
9882

9983
<br>
10084

85+
#### my notes
86+
87+
<br>
88+
89+
- [basics](docs/basic_concepts.md)
90+
91+
<br>
92+
10193
#### learning lean
10294

10395
- [learn lean](https://lean-lang.org/documentation/0)

docs/basic_concepts.md

Lines changed: 77 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,98 @@
22

33
<br>
44

5-
---
6-
7-
### types and functions
5+
### tl; dr
86

97
<br>
108

119
* there are two primary concepts in lean: functions and types
1210
* basic types examples are natural numbers (`Nat`, whole numbers starting from 0), booleans (`Bool`), true or false values, strings
11+
* functions are defined using the `def` keyword (`def double (n : Nat) : Nat := n + n`)
1312
* check types using `#check`
1413
* evaluate expressions using `#eval`
1514

1615
<br>
1716

1817
---
1918

20-
### function definitions
19+
### universes
20+
21+
<br>
22+
23+
* the two primary kinds of universes are `Prop` and `Type`
24+
25+
<br>
26+
27+
#### predicative
28+
29+
<br>
30+
31+
* a function that returns a proposition (a statement that can be true or false), or, of type `Prop`
32+
* for example, defining a predicate `is_empty` for lists:
33+
34+
```lean
35+
def is_empty {α : Type} (l : List α) : Prop :=
36+
l = []
37+
```
38+
39+
* `...` represents whatever input the predicate takes
40+
* one can also define propositions inductively (i.e., instead of defining the property with a simple boolean check or an equality, one defines it by giving rules/constructors for when the proposition is true)
41+
42+
<br>
43+
44+
#### `Types`
45+
46+
<br>
47+
48+
* lean4's type theory is built upon a hierarchy of universes, which are types that contain other types (predicative)
49+
* this is a hierarchy of universes (Type 0, Type 1, Type 2, ...), where Type is an abbreviation for Type 0
50+
* these universes contain "data" or computational types.
51+
* for instance, for a function type `(a : A) → B`, where `A : Type u` and `B : Type v`, the resulting function type itself resides in `Type (max u v)`
52+
53+
<br>
54+
55+
##### inductive types
56+
57+
<br>
58+
59+
* one of the predicative `Type`
60+
* a way of defining a new type by specifying its constructors.
61+
* used to define fundamental data structures like natural numbers (Nat), lists (List), and booleans (Bool), user-defined types
62+
* example for natural numbers, where `succ` is successor (takes a natural number and produces the next one)
63+
64+
```lean
65+
inductive Nat where
66+
| zero : Nat
67+
| succ : Nat → Nat
68+
```
69+
70+
<br>
71+
72+
##### inductive predicative types
2173

2274
<br>
2375

24-
* functions are defined using the `def` keyword:
76+
* inductive type defined to live in one of the Type universes (must adhere to the predicativity rules of the Type hierarchy)
77+
* for example, the definition of a polymorphic list, `MyList` lives in the same universe `u` as the type of its elements `α`
2578

2679
```lean
27-
def double (n : Nat) : Nat := n + n
80+
inductive MyList (α : Type u) : Type u where
81+
| nil : MyList α
82+
| cons : α → MyList α → MyList α
2883
```
84+
85+
<br>
86+
87+
- universe polymorphism: same definition can be instantiated at different universe levels
88+
- large elimination: while one can freely define functions that pattern match on a Type-level inductive type to produce a value in any other Type, doing the same with a Prop-level inductive to produce a Type-level value is restricted (proofs in Prop are meant to be logically relevant but computationally erased, while data in Type has computational content)
89+
90+
<br>
91+
92+
---
93+
94+
#### `Prop` (propositions)
95+
96+
<br>
97+
98+
* impredicative (can quantify over any type, including types in higher universes and even Prop itself)
99+
* one can define a proposition that makes a statement about all types (for logical connectives -like `And`, `Or` - and quantifiers - `forall`, `exists`)

0 commit comments

Comments
 (0)