-
Notifications
You must be signed in to change notification settings - Fork 1
/
Prueba_por_induccion_2.lean
150 lines (127 loc) · 3.49 KB
/
Prueba_por_induccion_2.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
-- Prueba por inducción 2: ∀ m n k : ℕ, (m + n) + k = m + (n + k)
-- ==============================================================
-- ----------------------------------------------------
-- Ej. 1. Sean m, n y k números naturales. Demostrar que
-- (m + n) + k = m + (n + k)
-- ----------------------------------------------------
import tactic
open nat
variables (m n k : ℕ)
-- 1ª demostración
example : (m + n) + k = m + (n + k) :=
begin
induction k with k' HI,
{ rw nat.add_zero,
rw nat.add_zero, },
{ rw add_succ,
rw HI,
rw add_succ, },
end
-- 2ª demostración
example : (m + n) + k = m + (n + k) :=
begin
induction k with k' HI,
{ rw [nat.add_zero, nat.add_zero], },
{ rw [add_succ, HI, add_succ], },
end
-- 3ª demostración
example : (m + n) + k = m + (n + k) :=
begin
induction k with k HI,
{ simp, },
{ simp [add_succ, HI], },
end
-- 4ª demostración
example : (m + n) + k = m + (n + k) :=
begin
induction k with k HI,
{ simp only [add_zero], },
{ simp only [add_succ, HI], },
end
-- 5ª demostración
example : (m + n) + k = m + (n + k) :=
by induction k;
simp only [*, add_zero, add_succ]
-- 6ª demostración
example : (m + n) + k = m + (n + k) :=
by induction k;
simp [*, add_succ]
-- 7ª demostración
example : (m + n) + k = m + (n + k) :=
begin
induction k with k HI,
{ calc
(m + n) + 0
= m + n : by rw nat.add_zero
... = m + (n + 0) : by rw nat.add_zero, },
{ calc
(m + n) + succ k
= succ ((m + n) + k) : by rw add_succ
... = succ (m + (n + k)) : by rw HI
... = m + succ (n + k) : by rw add_succ
... = m + (n + succ k) : by rw add_succ, },
end
-- 8ª demostración
example : (m + n) + k = m + (n + k) :=
begin
induction k with k HI,
{ calc
(m + n) + 0 = m + (n + 0) : rfl, },
{ calc
(m + n) + succ k
= succ ((m + n) + k) : rfl
... = succ (m + (n + k)) : by rw HI
... = m + succ (n + k) : rfl
... = m + (n + succ k) : rfl, },
end
-- 9ª demostración
example : (m + n) + k = m + (n + k) :=
nat.rec_on k
( show (m + n) + 0 = m + (n + 0), from rfl )
( assume k,
assume HI : (m + n) + k = m + (n + k),
show (m + n) + succ k = m + (n + succ k), from
calc
(m + n) + succ k
= succ ((m + n) + k) : rfl
... = succ (m + (n + k)) : by rw HI
... = m + succ (n + k) : rfl
... = m + (n + succ k) : rfl )
-- 10ª demostración
example : (m + n) + k = m + (n + k) :=
nat.rec_on k rfl (λ k HI, by simp only [add_succ, HI])
-- 11ª demostración
example : (m + n) + k = m + (n + k) :=
-- by library_search
add_assoc m n k
-- 12ª demostración
example : (m + n) + k = m + (n + k) :=
-- by hint
by finish
-- 13ª demostración
example : (m + n) + k = m + (n + k) :=
by linarith
-- 14ª demostración
example : (m + n) + k = m + (n + k) :=
by nlinarith
-- 15ª demostración
example : (m + n) + k = m + (n + k) :=
by omega
-- 16ª demostración
example : (m + n) + k = m + (n + k) :=
by ring
-- 17ª demostración
lemma asociativa_suma :
∀ k : ℕ, (m + n) + k = m + (n + k)
| 0 := rfl
| (k + 1) := congr_arg succ (asociativa_suma k)
-- 18ª demostración
lemma asociativa_suma2 :
∀ k : ℕ, (m + n) + k = m + (n + k)
| 0 := by simp
| (k + 1) := by simp [add_succ, asociativa_suma2 k]
-- 19ª demostración
lemma asociativa_suma3 :
∀ k : ℕ, (m + n) + k = m + (n + k)
| 0 := by simp only [nat.add_zero]
| (k + 1) := by simp only [nat.add_zero, add_succ, asociativa_suma3 k]