Zulip Chat Archive

Stream: general

Topic: new writing technique


Patrick Massot (Jul 04 2018 at 20:03):

I've found a nice new trick to write obfuscated^W concise code:

lemma chart_chart_inv {φ : chart X} {x : φ.target} : x  φ.range  φ (φ.inv x) = x
| y, y_in, φ_y⟩⟩ := inv_fun_on_eq y, y_in, φ_y⟩⟩

Patrick Massot (Jul 04 2018 at 20:05):

Why not writing assume H, inv_fun_on_eq H? Well, the sequences of pointy brackets in the pattern matching and body don't represent the same (anonymized) constructor.

Simon Hudon (Jul 04 2018 at 20:08):

Would it make you happy if Lean gave you a warning about using the anonymous constructors in disjoint expressions to build expressions of different types?

Patrick Massot (Jul 04 2018 at 20:09):

I don't know.

Patrick Massot (Jul 04 2018 at 20:09):

I'm not complaining about anything.

Patrick Massot (Jul 04 2018 at 20:10):

I do think that if I read this code later than a few days away from now, I'll be thinking WTF?

Simon Hudon (Jul 04 2018 at 20:10):

Sorry, I'm highjacking your conversation. I've been saying for a while that we need a linter tool to find dubious code

Simon Hudon (Jul 04 2018 at 20:10):

And I'm wondering how to define "dubious code"

Chris Hughes (Jul 04 2018 at 20:12):

Maybe the type of the two ⟨y, ⟨y_in, φ_y⟩⟩s is different.

Simon Hudon (Jul 04 2018 at 20:18):

Yes, that's what Patrick was pointing out

Patrick Massot (Jul 04 2018 at 20:28):

Here is a minimized example for the curious readers:

import data.set.basic
open set

example (α β : Type) (s : set α) (f : α  β) (b) (h : as, f a = b) : b  f '' s  :=
begin
  -- rw mem_image, exact h,
  -- rw mem_image_eq, exact h,
  rw mem_image,
  rcases h with a, b, c⟩⟩,
  exact a, b, c⟩⟩
end

The two commented out lines are nice tries that don't work.

Patrick Massot (Jul 04 2018 at 20:28):

And it's in tactic mode so you can see everything

Patrick Massot (Jul 04 2018 at 20:30):

@Mario Carneiro Is there a variation on mem_image that I'm missing here?

Mario Carneiro (Jul 04 2018 at 20:55):

I see nothing wrong with chart_inv_inv

Mario Carneiro (Jul 04 2018 at 20:58):

example (α β : Type) (s : set α) (f : α → β) (b) (h : ∃a∈s, f a = b) : b ∈ f '' s  :=
by simpa using h

Patrick Massot (Jul 04 2018 at 21:00):

How does this work? What is simpa magically doing here? I know mem_image is a simp lemma. And then?

Chris Hughes (Jul 04 2018 at 21:02):

∃ (H : a ∈ s), f a = b ==> a ∈ s ∧ f a = b exists_prop


Last updated: Dec 20 2023 at 11:08 UTC