-
Notifications
You must be signed in to change notification settings - Fork 1
/
Ejercicio_Suma_por_diferencia.lean
113 lines (100 loc) · 3.83 KB
/
Ejercicio_Suma_por_diferencia.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
-- ---------------------------------------------------------------------
-- Ejercicio. Demostrar que si a y b son números reales, entonces
-- (a + b) * (a - b) = a^2 - b^2
-- ---------------------------------------------------------------------
import data.real.basic
variables a b c d : ℝ
-- 1ª demostración (con calc)
-- ==========================
example : (a + b) * (a - b) = a^2 - b^2 :=
calc
(a + b) * (a - b)
= a * (a - b) + b * (a - b) : by rw add_mul
... = (a * a - a * b) + b * (a - b) : by rw mul_sub
... = (a^2 - a * b) + b * (a - b) : by rw ← pow_two
... = (a^2 - a * b) + (b * a - b * b) : by rw mul_sub
... = (a^2 - a * b) + (b * a - b^2) : by rw ← pow_two
... = (a^2 + -(a * b)) + (b * a - b^2) : by ring
... = a^2 + (-(a * b) + (b * a - b^2)) : by rw add_assoc
... = a^2 + (-(a * b) + (b * a + -b^2)) : by ring
... = a^2 + ((-(a * b) + b * a) + -b^2) : by rw ← add_assoc
(-(a * b)) (b * a) (-b^2)
... = a^2 + ((-(a * b) + a * b) + -b^2) : by rw mul_comm
... = a^2 + (0 + -b^2) : by rw neg_add_self (a * b)
... = (a^2 + 0) + -b^2 : by rw ← add_assoc
... = a^2 + -b^2 : by rw add_zero
... = a^2 - b^2 : by linarith
-- Comentario. Se han usado los siguientes lemas:
-- + pow_two a : a ^ 2 = a * a
-- + mul_sub a b c : a * (b - c) = a * b - a * c
-- + add_mul a b c : (a + b) * c = a * c + b * c
-- + add_sub a b c : a + (b - c) = a + b - c
-- + sub_sub a b c : a - b - c = a - (b + c)
-- + add_zero a : a + 0 = a
-- 2ª demostración (con calc)
-- ==========================
example : (a + b) * (a - b) = a^2 - b^2 :=
calc
(a + b) * (a - b)
= a * (a - b) + b * (a - b) : by ring
... = (a * a - a * b) + b * (a - b) : by ring
... = (a^2 - a * b) + b * (a - b) : by ring
... = (a^2 - a * b) + (b * a - b * b) : by ring
... = (a^2 - a * b) + (b * a - b^2) : by ring
... = (a^2 + -(a * b)) + (b * a - b^2) : by ring
... = a^2 + (-(a * b) + (b * a - b^2)) : by ring
... = a^2 + (-(a * b) + (b * a + -b^2)) : by ring
... = a^2 + ((-(a * b) + b * a) + -b^2) : by ring
... = a^2 + ((-(a * b) + a * b) + -b^2) : by ring
... = a^2 + (0 + -b^2) : by ring
... = (a^2 + 0) + -b^2 : by ring
... = a^2 + -b^2 : by ring
... = a^2 - b^2 : by ring
-- 3ª demostración
-- ===============
example : (a + b) * (a - b) = a^2 - b^2 :=
by ring
-- 4ª demostración (por reescritura usando el lema anterior)
-- =========================================================
-- El lema anterior es
lemma aux : (a + b) * (c + d) = a * c + a * d + b * c + b * d :=
by ring
-- La demostración es
example : (a + b) * (a - b) = a^2 - b^2 :=
begin
rw sub_eq_add_neg,
rw aux,
rw mul_neg,
rw add_assoc (a * a),
rw mul_comm b a,
rw neg_add_self,
rw add_zero,
rw ← pow_two,
rw mul_neg,
rw ← pow_two,
rw ← sub_eq_add_neg,
end
-- El desarrollo de la demostración es
-- ⊢ (a + b) * (a - b) = a ^ 2 - b ^ 2
-- rw sub_eq_add_neg,
-- ⊢ (a + b) * (a + -b) = a ^ 2 - b ^ 2
-- rw aux,
-- ⊢ a * a + a * -b + b * a + b * -b = a ^ 2 - b ^ 2
-- rw mul_neg_eq_neg_mul_symm,
-- ⊢ a * a + -(a * b) + b * a + b * -b = a ^ 2 - b ^ 2
-- rw add_assoc (a * a),
-- ⊢ a * a + (-(a * b) + b * a) + b * -b = a ^ 2 - b ^ 2
-- rw mul_comm b a,
-- ⊢ a * a + (-(a * b) + a * b) + b * -b = a ^ 2 - b ^ 2
-- rw neg_add_self,
-- ⊢ a * a + 0 + b * -b = a ^ 2 - b ^ 2
-- rw add_zero,
-- ⊢ a * a + b * -b = a ^ 2 - b ^ 2
-- rw ← pow_two,
-- ⊢ a ^ 2 + b * -b = a ^ 2 - b ^ 2
-- rw mul_neg_eq_neg_mul_symm,
-- ⊢ a ^ 2 + -(b * b) = a ^ 2 - b ^ 2
-- rw ← pow_two,
-- ⊢ a ^ 2 + -b ^ 2 = a ^ 2 - b ^ 2
-- rw ← sub_eq_add_neg,
-- no goals