Skip to content
This repository was archived by the owner on Jul 24, 2024. It is now read-only.

Conversation

@eric-wieser
Copy link
Member

@eric-wieser eric-wieser commented Oct 4, 2020

@eric-wieser eric-wieser added WIP Work in progress blocked-by-other-PR This PR depends on another PR which is still in the queue. A bot manages this label via PR comment. labels Oct 4, 2020
Comment on lines 579 to 581
-- At this point the pretty-printing of the goal is nonsense, containing `p + q` despite
-- the fact there is no obvious `has_add (multiplicative G)`.
Copy link
Member Author

Choose a reason for hiding this comment

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

@eric-wieser eric-wieser added the help-wanted The author needs attention to resolve issues label Oct 4, 2020
@bors bors bot closed this Oct 5, 2020
@eric-wieser eric-wieser reopened this Oct 5, 2020
@eric-wieser eric-wieser changed the base branch from eric-wieser/finsupp-add_equiv to master October 5, 2020 14:38
@eric-wieser eric-wieser force-pushed the eric-wieser/monoid_algebra-equiv branch from 7af22ac to 5489f33 Compare October 5, 2020 14:49
@eric-wieser eric-wieser added awaiting-review The author would like community review of the PR and removed WIP Work in progress blocked-by-other-PR This PR depends on another PR which is still in the queue. A bot manages this label via PR comment. labels Oct 5, 2020
…algebra` and `monoid_algebra` in terms of `multiplicative`

Note that this needs a new `exact` tactic for conv mode.
@eric-wieser eric-wieser force-pushed the eric-wieser/monoid_algebra-equiv branch from 5489f33 to 5500504 Compare October 11, 2020 13:57
add_monoid_algebra k G ≃+* monoid_algebra k (multiplicative G) :=
{ map_mul' := λ x y, by {
simp only [finsupp.dom_congr],
apply add_monoid_algebra.map_domain_mul',
Copy link
Member Author

@eric-wieser eric-wieser Oct 11, 2020

Choose a reason for hiding this comment

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

Note that this line is the only reason map_domain_mul' exists - I can't work out any way to invoke the bundled map_domain_mul version here (apply monoid_algebra.map_domain_mul times out!).

Copy link
Member

Choose a reason for hiding this comment

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

I believe that applying this mul' version is causing you problems. I think you are abusing type equality somewhere here. One of the inputs of add_monoid_algebra.map_domain_mul is supposed to be an add_hom, and you want to feed it to_add which is neither an add_hom nor a mul_hom. Your mul' hack has the same problem -- what can f be, if it is to satisfy the axioms of the proposition?

add_monoid_algebra k G ≃+* monoid_algebra k (multiplicative G) :=
{ map_mul' := λ x y, by {
simp only [finsupp.dom_congr],
apply add_monoid_algebra.map_domain_mul',
Copy link
Member

Choose a reason for hiding this comment

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

I believe that applying this mul' version is causing you problems. I think you are abusing type equality somewhere here. One of the inputs of add_monoid_algebra.map_domain_mul is supposed to be an add_hom, and you want to feed it to_add which is neither an add_hom nor a mul_hom. Your mul' hack has the same problem -- what can f be, if it is to satisfy the axioms of the proposition?

apply add_monoid_algebra.map_domain_mul',
intros p q,
-- At this point the pretty-printing of the goal is nonsense, containing `p + q` despite
-- the fact there is no obvious `has_add (multiplicative G)`.
Copy link
Member

Choose a reason for hiding this comment

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

This is because you abused type equality when you applied map_domain_mul' -- it was an act of desperation by the unifier. If multiplicative was irreducible, which it should be in my opinion, then people would find this much harder to do and they would be forced to write better (in the sense of type correct) code.

-- the fact there is no obvious `has_mul (additive G)`.
simp only [of_mul_mul],
refl, },
..finsupp.dom_congr additive.of_mul }
Copy link
Member

Choose a reason for hiding this comment

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

Aah! If you make multiplicative irreducible, we see that this line is also abusing type equality.

type mismatch at field 'to_fun'
  (finsupp.dom_congr multiplicative.to_add).to_fun
has type
  (multiplicative ?m_1 →₀ ?m_2) → ?m_1 →₀ ?m_2 : Type (max ? ?)
but is expected to have type
  add_monoid_algebra k G → monoid_algebra k (multiplicative G) : Type (max (max u₂ u₁) u₁ u₂)

This is the problem -- multiplicative is on the wrong side.

Copy link
Member

@kbuzzard kbuzzard Oct 13, 2020

Choose a reason for hiding this comment

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

protected def add_monoid_algebra.of_multiplicative [semiring k] [add_monoid G] :
  monoid_algebra k (multiplicative G) ≃+* add_monoid_algebra k G :=
{ map_mul' := λ x y, by {
    simp only [finsupp.dom_congr],
    sorry
  },
  ..finsupp.dom_congr multiplicative.to_add }

This typechecks even if multiplicative is irreducible. Note that I switched the order of the equiv! (and hence changed the name).

But now you need a result which applies to to_add so it can't have the hypotheses of your f in the mul' lemma.

Copy link
Member

Choose a reason for hiding this comment

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

BTW making multiplicative irreducible shows that there is also type abuse going on in lift (which is already in mathlib) -- for example

type mismatch at application
  ⇑F a
term
  a
has type
  G
but is expected to have type
  multiplicative G

error in definition of lift.to_fun. Type abuse like this creates problems down the line (e.g. the earlier problem about p*q=p+q) and I've found that making stuff like multiplicative irreducible stops this sort of thing happening.

Copy link
Member Author

Choose a reason for hiding this comment

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

This is the problem -- multiplicative is on the wrong side.

Thanks for catching this - but this was a mistake in just one of the two definitions.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think this is a case of two wrong make a right. After the simp only [finsupp.dom_congr], line, the goal is:

--                                 VVVVV add_monoid_algebra k G
map_domain ⇑multiplicative.of_add (x * y) =
-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ monoid_algebra k multiplicative(G)
  map_domain ⇑multiplicative.of_add x * map_domain ⇑multiplicative.of_add y

map_domain doesn't know about *_monoid_algebra, so has signature (G →₀ k) → (multiplicative G →₀ k). At this point, we've done our first sneaky step in type abuse - we're considering the input an add_monoid_algebra, and the output a monoid_algebra - even though map_domain_mul' implies that both input and output are of the same type.

The second wrong is the tricks we already see in (f).

This would all be a lot easier if we could do away with add_*, and have monoid_algebra k G (+) and monoid_algebra k G (*) as our two versions...

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 that sneaky steps in type abuse should be avoided if at all possible. Can't we also use to_add and of_add etc to work around this?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'd argue that type abuse is only a problem in definitions. In proofs, it shouldn't matter - as long as the theorem statement plays no tricks, then proof irrelevance means that abuse in the proof doesn't matter, right?

Copy link
Member Author

@eric-wieser eric-wieser Oct 20, 2020

Choose a reason for hiding this comment

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

Now, I could replace the proof

apply monoid_algebra.map_domain_mul',
intros p q,
simp only [of_mul_mul],
refl

with

    simp only [finsupp.dom_congr],
    rw monoid_algebra.mul_def,
    rw add_monoid_algebra.mul_def,
    simp_rw [map_domain_sum, map_domain_single, of_mul_mul],
    rw finsupp.sum_map_domain_index,
    { congr,
      ext a b,
      rw finsupp.sum_map_domain_index,
      { simp },
      { simp [mul_add] } },
    { simp },
    { simp [add_mul] },

but that amounts to a copy-paste of monoid_algebra.map_domain_mul, with:

  • One monoid_algebra.mul_def replaced with add_monoid_algebra.mul_def
  • f.map_mul replaced with of_mul_mul

Given the whole point of the multiplicative type tag is to avoid duplicate lemmas, is this really worth it?

@github-actions github-actions bot added the merge-conflict Please `git merge origin/master` then a bot will remove this label. label Oct 15, 2020
@github-actions github-actions bot removed the merge-conflict Please `git merge origin/master` then a bot will remove this label. label Oct 16, 2020
@kim-em
Copy link
Collaborator

kim-em commented Oct 19, 2020

Is there a summary somewhere of what help you want with this PR? Perhaps you could create a thread on zulip explaining what's going on.

@eric-wieser
Copy link
Member Author

At this point, @kbuzzard has provided most of the help I needed. All that remains is to decide if the weird intermediate goal state and dependence on unfolding multiplicative is ok.

@eric-wieser eric-wieser removed the help-wanted The author needs attention to resolve issues label Oct 19, 2020
@jcommelin jcommelin requested a review from kim-em October 19, 2020 07:17
Copy link
Member

@kbuzzard kbuzzard left a comment

Choose a reason for hiding this comment

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

My understanding from Eric's comment is that this should be awaiting-author?

-- the fact there is no obvious `has_mul (additive G)`.
simp only [of_mul_mul],
refl, },
..finsupp.dom_congr additive.of_mul }
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 that sneaky steps in type abuse should be avoided if at all possible. Can't we also use to_add and of_add etc to work around this?

@kbuzzard kbuzzard added the awaiting-author A reviewer has asked the author a question or requested changes label Oct 20, 2020
Co-authored-by: Kevin Buzzard <k.buzzard@imperial.ac.uk>
@eric-wieser eric-wieser added awaiting-review The author would like community review of the PR and removed awaiting-author A reviewer has asked the author a question or requested changes labels Oct 20, 2020
@eric-wieser
Copy link
Member Author

My understanding from Eric's comment is that this should be awaiting-author?

That wasn't what I meant by my comment. I'm looking for a reviewer to say "yes, there's no obvious way to avoid the type abuse" and/or "the type abuse is inevitable because this code operates on the boundary between type tags"

@jcommelin
Copy link
Member

@eric-wieser I pushed a golf. I didn't make similar changes in the rest of the file, but I hope you can use this.

@jcommelin jcommelin added awaiting-author A reviewer has asked the author a question or requested changes and removed awaiting-review The author would like community review of the PR labels Oct 23, 2020
@eric-wieser eric-wieser force-pushed the eric-wieser/monoid_algebra-equiv branch from 862c6f3 to e026b21 Compare October 23, 2020 12:41
@eric-wieser eric-wieser added awaiting-review The author would like community review of the PR and removed awaiting-author A reviewer has asked the author a question or requested changes labels Oct 23, 2020
@eric-wieser
Copy link
Member Author

Thanks for the golf @jcommelin, much simpler now. The nasty type abuse is now nicely hidden by convert

@jcommelin jcommelin added awaiting-author A reviewer has asked the author a question or requested changes and removed awaiting-review The author would like community review of the PR labels Oct 23, 2020
@eric-wieser eric-wieser added awaiting-review The author would like community review of the PR and removed awaiting-author A reviewer has asked the author a question or requested changes labels Oct 29, 2020
Copy link
Member

@jcommelin jcommelin left a comment

Choose a reason for hiding this comment

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

Thanks 🎉

bors merge

@github-actions github-actions bot added ready-to-merge All that is left is for bors to build and merge this PR. (Remember you need to say `bors r+`.) and removed awaiting-review The author would like community review of the PR labels Oct 29, 2020
bors bot pushed a commit that referenced this pull request Oct 29, 2020
…algebra` and `monoid_algebra` in terms of `multiplicative` (#4402)

Co-authored-by: Johan Commelin <johan@commelin.net>
@bors
Copy link

bors bot commented Oct 29, 2020

Pull request successfully merged into master.

Build succeeded:

@bors bors bot changed the title feat(algebra/monoid_algebra): Add an equivalence between add_monoid_algebra and monoid_algebra in terms of multiplicative [Merged by Bors] - feat(algebra/monoid_algebra): Add an equivalence between add_monoid_algebra and monoid_algebra in terms of multiplicative Oct 29, 2020
@bors bors bot closed this Oct 29, 2020
@bors bors bot deleted the eric-wieser/monoid_algebra-equiv branch October 29, 2020 21:58
lecopivo pushed a commit to lecopivo/mathlib that referenced this pull request Oct 31, 2020
…algebra` and `monoid_algebra` in terms of `multiplicative` (leanprover-community#4402)

Co-authored-by: Johan Commelin <johan@commelin.net>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

ready-to-merge All that is left is for bors to build and merge this PR. (Remember you need to say `bors r+`.)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants