forked from ImperialCollegeLondon/M40001_lean
-
Notifications
You must be signed in to change notification settings - Fork 0
/
logic_video.lean
118 lines (93 loc) · 2.05 KB
/
logic_video.lean
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import tactic
-- Definition: a Proposition is a type `P`, where `P : Prop`.
variables (P Q R : Prop)
-- In Lean, `P → Q` means `P ⇒ Q`
example : P → P :=
begin
intro hP, -- let hP be the hypothesis that P is true
exact hP, -- our goal is exactly our hypothesis
end
example : P → (Q → P) :=
begin
intro hP, -- let hP be the hypothesis that P is true
intro hQ,
exact hP,
end
-- is → associative? i.e. Does (P → Q) → R equal P → (Q → R) ?
-- (A+B)+C = A+(B+C)
-- (A-B)-C ≠ A-(B-C)
-- (A-B)-C
-- 2^(1^3) -- this is the convention for powers
-- CONVENTION: P → Q → R with no brackets MEANS P → (Q → R)
example : P → Q → P :=
begin
intro hP,
intro hQ,
exact hP,
end
/-- Modus Ponens : if P is true, and P → Q, then Q is true -/
theorem modus_ponens : P → (P → Q) → Q :=
begin
intro hP,
intro hPQ, -- hPQ is the hypothesis that P → Q
apply hPQ, -- apply the hypothesis that P → Q
exact hP,
end
-- If `a<b` and `b<c` then `a<c` -- that's called "transitivity of <"
-- theorem transitivity : (P → Q) → (Q → R) → (P → R) :=
-- begin
-- sorry
-- end
example : (P → Q → R) → (P → Q) → (P → R) :=
begin
intro hPQR,
intro hPQ,
intro hP,
apply hPQR,
assumption,
apply hPQ,
assumption,
end
-- in Lean, the definition of ¬ P is `P → false`
-- if P is true, ¬ P is false, and P → false is false
-- if P is false, then ¬ P is true, and P → false is true
example : P → ¬ (¬ P) :=
begin
intro hP,
change (¬ P → false),
intro hnP,
change P → false at hnP,
apply hnP,
assumption,
end
example : ¬ (¬ P) → P :=
begin
finish,
end
example : P → ¬ (¬ P) :=
begin
apply modus_ponens,
end
-- and
example : P ∧ Q → P :=
begin
intro hPaQ,
cases hPaQ with hP hQ,
assumption,
end
theorem and.elim' : P ∧ Q → (P → Q → R) → R :=
begin
intro hPaQ,
intro hPQR,
cases hPaQ with hP hQ,
apply hPQR;
assumption,
end
theorem and.intro' : P → Q → P ∧ Q :=
begin
intro hP,
intro hQ,
split,
assumption,
assumption,
end