-
Notifications
You must be signed in to change notification settings - Fork 297
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/sym2): add the universal property, and make sym2.is_diag ⟦(x, y)⟧ ↔ x = y
true definitionally
#8358
Conversation
eric-wieser
commented
Jul 18, 2021
…(x, y)⟧ ↔ x = y` true definitionally
2000e6b
to
2afd995
Compare
prod.rec_on z $ λ _ _, is_diag_iff_eq | ||
|
||
@[simp] | ||
lemma diag_is_diag (a : α) : is_diag (diag a) := |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lemma diag_is_diag (a : α) : is_diag (diag a) := | |
lemma is_diag_diag (a : α) : is_diag (diag a) := |
And the appropriate edits below
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This name is the same as it was before this PR, but I suppose I could creep the scope to fix the name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I get confused about the name to give compositions like this, and I get even more confused when dot notation is involved. If the conclusion were written as (diag a).is_diag
(which it could be), would it still be is_diag_diag
?
I think I'm guilty putting is_foo
predicates at the ends of lemmas elsewhere, too, which is why I ask.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made a Zulip thread.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've also reverted the change - if it's contentious, then renaming it is outside the scope of this PR.
src/data/sym2.lean
Outdated
`sym2.from_rel` is a more convenient spelling when working with `Prop`. -/ | ||
def lift {β : Sort*} : | ||
{f : α → α → β // ∀ a₁ a₂, f a₁ a₂ = f a₂ a₁} ≃ (sym2 α → β) := | ||
{ to_fun := λ f, quotient.lift (λ a : α × α, (f : α → α → β) a.1 a.2) $ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please make that to_fun
a separate definition? We needed that generalisation of sym2.from_rel
some time ago.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What would be the point of the separate definition? If you use lift
it unfolds to this anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well I guess it's easier to have a definition without mentioning a subtype.
def from_fun {β : Sort*} {f : α → α → β} (comm : ∀ ⦃x y⦄, f x y = f y x) :
sym2 α → β :=
quotient.lift (uncurry f) (by { rintro ⟨x, y⟩ _ ⟨_, _⟩, {refl }, unfold uncurry, rw comm })
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That def results in {β : Type*}
since uncurry
isn't defined on sorts:
#check @from_fun
-- Π {α : Type u_1} {β : Type u_2} {f : α → α → β}, (∀ ⦃x y : α⦄, f x y = f y x) → sym2 α → β
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh that's annoying... There's no real reason for it, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wait, what? The original definition of from_rel
uses function.uncurry r
. What is this witchcraft?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking again, it looks like there's no point in letting lift
work on Sort
anyway, no one every needs a subtype of a proof, and quotient.induction
works just fine for the cases when Sort would apply.
src/data/sym2.lean
Outdated
`sym2.from_rel` instead. -/ | ||
def lift {β : Type*} : {f : α → α → β // ∀ a₁ a₂, f a₁ a₂ = f a₂ a₁} ≃ (sym2 α → β) := | ||
{ to_fun := λ f, quotient.lift (uncurry ↑f) $ by { rintro _ _ ⟨⟩, exacts [rfl, f.prop _ _] }, | ||
inv_fun := λ F, ⟨λ a₁ a₂, F ⟦(a₁, a₂)⟧, λ a₁ a₂, congr_arg F eq_swap⟩, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we want to maintain the point-free style of to_fun
, then inv_fun
could be
inv_fun := λ F, ⟨curry (F ∘ quotient.mk), λ a₁ a₂, congr_arg F eq_swap⟩,
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, why not. I added a lemma that unfolds it to my version, but it's nice to see the composition in lift.inv_fun
, since there almost always is one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sym2.lift
should have existed long ago -- thanks!
Since there's no consensus, lets leave renaming this for another time. Also adds a docstring and a lemma
1a2ff4b
to
4dd20f2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me! I don't have a strong opinion on the is_diag_diag
naming choice, so I'll let @eric-wieser decide what to do there.
bors d+
✌️ eric-wieser can now approve this pull request. To approve and merge a pull request, simply reply with |
bors r+ I've left the name untouched, someone else can do a wider rename in a separate PR. |
…(x, y)⟧ ↔ x = y` true definitionally (#8358)
Build failed: |
bors r+ |
…(x, y)⟧ ↔ x = y` true definitionally (#8358)
Pull request successfully merged into master. Build succeeded: |
sym2.is_diag ⟦(x, y)⟧ ↔ x = y
true definitionallysym2.is_diag ⟦(x, y)⟧ ↔ x = y
true definitionally