Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Merged by Bors] - feat(data/option/basic): lemmas on map of none and congr #5424

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/data/option/basic.lean
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,18 @@ by cases x; simp
x.map f = some b ↔ ∃ a, x = some a ∧ f a = b :=
by cases x; simp

lemma map_eq_none {α β} {x : option α} {f : α → β} :
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
lemma map_eq_none {α β} {x : option α} {f : α → β} :
@[simp] lemma map_eq_none {α β} {x : option α} {f : α → β} :

like below? Or is there a reason not to?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

simp linter complains if both are simp afair.

f <$> x = none ↔ x = none :=
by { cases x; simp only [map_none, map_some, eq_self_iff_true] }

@[simp] lemma map_eq_none' {x : option α} {f : α → β} :
x.map f = none ↔ x = none :=
by { cases x; simp only [map_none', map_some', eq_self_iff_true] }

lemma map_congr {f g : α → β} {x : option α} (h : ∀ a ∈ x, f a = g a) :
option.map f x = option.map g x :=
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this lemma would be better if you left it without the x in the result (and maybe also the hypothesis. If you do that, then you can claim that map is injective

Copy link
Collaborator Author

@pechersky pechersky Dec 19, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How would you phrase the hypothesis then? I've found this lemma useful for the cases when x is some complex expression, and f a = g a for all some a for that complex x, but not in the general case.

There's already an option.map_injective lemma.

by { cases x; simp only [map_none', map_some', h, mem_def] }

@[simp] theorem map_id' : option.map (@id α) = id := map_id

@[simp] lemma map_map (h : β → γ) (g : α → β) (x : option α) :
Expand Down