Zulip Chat Archive
Stream: new members
Topic: Improving injectivity proof
Danila Kurganov (Mar 05 2020 at 16:20):
Hi, I've proved that the composition of two injective functions is itself injective, but I'd like to see if I can improve on my proof; the paper version is much more slick IMO and I want to know if I can make my Lean more paper-like. Here is the code:
def injective {X : Type} {Y : Type} (f : X → Y) : Prop := ∀ a b : X, f a = f b → a = b theorem injective_comp2 {X Y Z : Type} (f : X → Y) (g : Y → Z) : injective f → injective g → injective (g ∘ f) := begin intros injf injg, unfold injective at *, intros c d, intro lefty, unfold function.comp at *, have intermediary : f c = f d, apply injg, exact lefty, apply injf, exact intermediary, end
Now usually (after some explaining) I'd just do g ∘ f a = g ∘ f b → g(f(a)) = g(f(b)) → f(a) = f(b) → a = b
, thinking in terms of injectivity in one-direction instead of bouncing back-and-forth with have statements. Is there anyway I can do this for the above theorem?
Johan Commelin (Mar 05 2020 at 16:22):
I don't know if this is what you want, but you can remove all the unfold
statements
Johan Commelin (Mar 05 2020 at 16:24):
Once you've done that, the have
statement becomes redundant...
Danila Kurganov (Mar 05 2020 at 16:31):
How does have
become redundant here?
(I do see though that the unfold isn't of use in the backend)
Johan Commelin (Mar 05 2020 at 16:32):
Because your have
is equal to the goal. So you might as well prove it directly.
Danila Kurganov (Mar 05 2020 at 16:37):
Oh wow that's neat!
theorem injective_comp3 {X Y Z : Type} (f : X → Y) (g : Y → Z) : injective f → injective g → injective (g ∘ f) := begin intros injf injg, intros c d, intro lefty, apply injf, apply injg, exact lefty, end
For some reason some time ago I figured it wouldn't work so nicely...
Kevin Buzzard (Mar 05 2020 at 17:03):
If you're at Xena this evening I'll show you some other proofs :-)
Danila Kurganov (Mar 05 2020 at 17:09):
Yes please :)
Yury G. Kudryashov (Mar 05 2020 at 17:16):
Please use "lean" after triple backticks, then your code will be highlighted.
Scott Morrison (Mar 05 2020 at 17:59):
Now that you've got down to a tactic proof that only usees intro
, apply
and exact
, you should practice turning this into a term-mode proof.
Scott Morrison (Mar 05 2020 at 18:00):
(Hint, you can do it step by step, pulling things "out the front" of the begin ... end block.)
Yury G. Kudryashov (Mar 05 2020 at 18:13):
Also try #print injective_comp3
Chris Hughes (Mar 05 2020 at 18:29):
Here's a really short proof λ hf hg _ _, (hf _ _ ∘ hg _ _)
Danila Kurganov (Mar 05 2020 at 18:33):
λ a b c d e, a c d (b _ _ e)
How's this? (Thanks Kevin)
Scott Morrison (Mar 05 2020 at 18:34):
at some point the idea that variable names should be single letters becomes a bad one. :-)
Marc Huisinga (Mar 05 2020 at 18:38):
we should stick to de brujin indices instead
Danila Kurganov (Mar 05 2020 at 18:43):
What's a term-mode proof?
Danila Kurganov (Mar 05 2020 at 18:49):
Also, #print injective_comp3
gives me a messy thing to read about, but it does help with not needing to unfold everything all the time
Johan Commelin (Mar 05 2020 at 19:02):
Danila Kurganov said:
What's a term-mode proof?
A proof that doesn't use begin ... end
Last updated: Dec 20 2023 at 11:08 UTC