Una función tiene inversa por la izquierda si y solo si es inyectiva
En Lean, que g es una inversa por la izquierda de f está definido por
1 2 |
left_inverse (g : β → α) (f : α → β) : Prop := ∀ x, g (f x) = x |
y que f tenga inversa por la izquierda está definido por
1 2 |
has_left_inverse (f : α → β) : Prop := ∃ finv : β → α, left_inverse finv f |
Finalmente, que f es inyectiva está definido por
1 2 |
injective (f : α → β) : Prop := ∀ ⦃x y⦄, f x = f y → x = y |
Demostrar que una función f, con dominio no vacío, tiene inversa por la izquierda si y solo si es inyectiva.
Para ello, completar la siguiente teoría de Lean:
1 2 3 4 5 6 7 8 9 10 |
import tactic open function variables {α : Type*} [nonempty α] variable {β : Type*} variable {f : α → β} example : has_left_inverse f ↔ injective f := sorry |
[expand title=»Soluciones con 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 |
import tactic open function variables {α : Type*} [nonempty α] variable {β : Type*} variable {f : α → β} -- 1ª demostración example : has_left_inverse f ↔ injective f := begin split, { intro hf, intros x y hxy, cases hf with g hg, calc x = g (f x) : (hg x).symm ... = g (f y) : congr_arg g hxy ... = y : hg y, }, { intro hf, use inv_fun f, intro x, apply hf, apply inv_fun_eq, use x, }, end -- 2ª demostración example : has_left_inverse f ↔ injective f := begin split, { intro hf, exact has_left_inverse.injective hf }, { intro hf, exact injective.has_left_inverse hf }, end -- 3ª demostración example : has_left_inverse f ↔ injective f := ⟨has_left_inverse.injective, injective.has_left_inverse⟩ -- 4ª demostración example : has_left_inverse f ↔ injective f := injective_iff_has_left_inverse.symm |
Se puede interactuar con la prueba anterior en esta sesión con Lean.
En los comentarios se pueden escribir otras soluciones, escribiendo el código entre una línea con <pre lang="lean"> y otra con </pre>
[/expand]
[expand title=»Soluciones con Isabelle/HOL»]
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 |
theory Una_funcion_tiene_inversa_por_la_izquierda_si_y_solo_si_es_inyectiva imports Main begin definition tiene_inversa_izq :: "('a ⇒ 'b) ⇒ bool" where "tiene_inversa_izq f ⟷ (∃g. ∀x. g (f x) = x)" (* 1ª demostración *) lemma "tiene_inversa_izq f ⟷ inj f" proof (rule iffI) assume "tiene_inversa_izq f" show "inj f" proof (unfold inj_def; intro allI impI) fix x y assume "f x = f y" obtain g where hg : "∀x. g (f x) = x" using ‹tiene_inversa_izq f› tiene_inversa_izq_def by auto have "x = g (f x)" by (simp only: hg) also have "… = g (f y)" by (simp only: ‹f x = f y›) also have "… = y" by (simp only: hg) finally show "x = y" . qed next assume "inj f" show "tiene_inversa_izq f" proof (unfold tiene_inversa_izq_def) have "∀x. inv f (f x) = x" proof (rule allI) fix x show "inv f (f x) = x" using ‹inj f› by (simp only: inv_f_f) qed then show "(∃g. ∀x. g (f x) = x)" by (simp only: exI) qed qed (* 2ª demostración *) lemma "tiene_inversa_izq f ⟷ inj f" proof (rule iffI) assume "tiene_inversa_izq f" then show "inj f" by (metis inj_def tiene_inversa_izq_def) next assume "inj f" then show "tiene_inversa_izq f" by (metis the_inv_f_f tiene_inversa_izq_def) qed (* 3ª demostración *) lemma "tiene_inversa_izq f ⟷ inj f" by (metis tiene_inversa_izq_def inj_def the_inv_f_f) end |
En los comentarios se pueden escribir otras soluciones, escribiendo el código entre una línea con <pre lang="isar"> y otra con </pre>
[/expand]