-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLas_funciones_inyectivas_tienen_inversa_por_la_izquierda.lean
171 lines (150 loc) · 4.53 KB
/
Las_funciones_inyectivas_tienen_inversa_por_la_izquierda.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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
-- Las_funciones_inyectivas_tienen_inversa_por_la_izquierda.lean
-- Las funciones inyectivas tienen inversa por la izquierda.
-- José A. Alonso Jiménez <https://jaalonso.github.io>
-- Sevilla, 11-junio-2024
-- ---------------------------------------------------------------------
-- ---------------------------------------------------------------------
-- En Lean4, que g es una inversa por la izquierda de f está definido por
-- LeftInverse (g : β → α) (f : α → β) : Prop :=
-- ∀ x, g (f x) = x
-- y que f tenga inversa por la izquierda está definido por
-- HasLeftInverse (f : α → β) : Prop :=
-- ∃ finv : β → α, LeftInverse finv f
-- Finalmente, que f es inyectiva está definido por
-- Injective (f : α → β) : Prop :=
-- ∀ ⦃x y⦄, f x = f y → x = y
--
-- Demostrar que si f es una función inyectiva con dominio no vacío,
-- entonces f tiene inversa por la izquierda.
-- ---------------------------------------------------------------------
-- Demostración en lenguaje natural
-- ================================
-- Sea f: A → B inyectiva con A ≠ ∅. Entonces, existe un a ∈ A. Sea
-- g: B → A definida por
-- g(y) = + un x tal que f(x) = y, si (∃x)[f(x) = y]
-- + a, en caso contrario.
-- Vamos a demostrar que g es una inversa por la izquierda de f; es
-- decir,
-- (∀x)[g(f(x)) = x]
-- Para ello, sea x ∈ A. Entonces,
-- (∃x)[f(x) = f(x)]
-- Por la definición de g,
-- g(f(x)) = z (1)
-- donde
-- f(z) = f(x).
-- Como f es inyectiva,
-- z = x
-- Y, por (1),
-- g(f(x)) = x
-- Demostraciones con Lean4
-- ========================
import Mathlib.Tactic
open Function Classical
variable {α β: Type _}
variable {f : α → β}
-- 1ª demostración
-- ===============
example
[hα : Nonempty α]
(hf : Injective f)
: HasLeftInverse f :=
by
unfold HasLeftInverse
-- ⊢ ∃ finv, LeftInverse finv f
set g := fun y ↦ if h : ∃ x, f x = y then h.choose else Classical.arbitrary α
use g
unfold LeftInverse
-- ⊢ ∀ (x : α), g (f x) = x
intro a
-- ⊢ g (f a) = a
have h1 : ∃ x : α, f x = f a := Exists.intro a rfl
simp only [g] at *
-- ⊢ (if h : ∃ x, f x = f a then Exists.choose h else Classical.arbitrary α) = a
simp [h1]
-- ⊢ Exists.choose (_ : ∃ x, f x = f a) = a
apply hf
-- ⊢ f (Exists.choose (_ : ∃ x, f x = f a)) = f a
exact Classical.choose_spec h1
-- 2ª demostración
-- ===============
example
[hα : Nonempty α]
(hf : Injective f)
: HasLeftInverse f :=
by
set g := fun y ↦ if h : ∃ x, f x = y then h.choose else Classical.arbitrary α
use g
-- ⊢ LeftInverse g f
intro a
-- a : α
-- ⊢ g (f a) = a
have h1 : ∃ x : α, f x = f a := Exists.intro a rfl
simp only [g] at *
-- ⊢ (if h : ∃ x, f x = f a then Exists.choose h else Classical.arbitrary α) = a
simp [h1]
-- ⊢ Exists.choose (_ : ∃ x, f x = f a) = a
exact hf (Classical.choose_spec h1)
-- 3ª demostración
-- ===============
example
[hα : Nonempty α]
(hf : Injective f)
: HasLeftInverse f :=
by
unfold HasLeftInverse
-- ⊢ ∃ finv, LeftInverse finv f
use invFun f
-- ⊢ LeftInverse (invFun f) f
unfold LeftInverse
-- ⊢ ∀ (x : α), invFun f (f x) = x
intro x
-- x : α
-- ⊢ invFun f (f x) = x
apply hf
-- ⊢ f (invFun f (f x)) = f x
apply invFun_eq
-- ⊢ ∃ a, f a = f x
use x
-- 4ª demostración
-- ===============
example
[hα : Nonempty α]
(hf : Injective f)
: HasLeftInverse f :=
by
use invFun f
-- ⊢ LeftInverse (invFun f) f
intro x
-- x : α
-- ⊢ invFun f (f x) = x
apply hf
-- ⊢ f (invFun f (f x)) = f x
apply invFun_eq
-- ⊢ ∃ a, f a = f x
use x
-- 5ª demostración
-- ===============
example
[_hα : Nonempty α]
(hf : Injective f)
: HasLeftInverse f :=
⟨invFun f, leftInverse_invFun hf⟩
-- 6ª demostración
-- ===============
example
[_hα : Nonempty α]
(hf : Injective f)
: HasLeftInverse f :=
Injective.hasLeftInverse hf
-- Lemas usados
-- ============
-- variable (p : α → Prop)
-- variable (x : α)
-- variable (b : β)
-- variable (γ : Type _) [Nonempty γ]
-- variable (f1 : γ → β)
-- #check (Classical.choose_spec : (h : ∃ x, p x) → p (Classical.choose h))
-- #check (Exists.intro x: p x → ∃ y, p y)
-- #check (Injective.hasLeftInverse : Injective f1 → HasLeftInverse f1)
-- #check (invFun_eq : (∃ a, f1 a = b) → f1 (invFun f1 b) = b)
-- #check (leftInverse_invFun : Function.Injective f1 → LeftInverse (Function.invFun f1) f1)