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] - refactor(ring_theory/algebra): use bundled homs, allow semirings #2303

Closed
wants to merge 9 commits into from

Conversation

urkud
Copy link
Member

@urkud urkud commented Mar 31, 2020

Fixes #2297

Build fails because of some class instance problems, asked on Zulip, no answer yet.

TO CONTRIBUTORS:

Make sure you have:

If this PR is related to a discussion on Zulip, please include a link in the discussion.

For reviewers: code review check list

@urkud urkud added the WIP Work in progress label Mar 31, 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.

LGTM

@urkud
Copy link
Member Author

urkud commented Apr 1, 2020

@jcommelin It fails to build, and I don't know how to fix this. I mean, I can supply arguments explicitly but this is a workaround, not a fix.

@urkud urkud added the help-wanted The author needs attention to resolve issues label Apr 1, 2020
@jcommelin
Copy link
Member

I see some type class resolution trace in the build logs, but I couldn't extract what failed exactly. Are you having trouble with coercing bundled homs to the underlying function?

@urkud
Copy link
Member Author

urkud commented Apr 1, 2020

The last line in lie_algebra.lean fails to find matrix_algebra instance, probably because of some semiring vs ring or semimodule vs module issues.

@sgouezel
Copy link
Collaborator

sgouezel commented Apr 2, 2020

One thing I wanted to do is to get rid of modules, and replace them by semimodules everywhere. It used to fail in Lean 3.4 because of type class issues, but now that some problems have been solved in Lean 3.7 it might be the right time to try again. Would you mind if I tried to do this starting from your branch, and see if it fixes your problem?

@urkud
Copy link
Member Author

urkud commented Apr 2, 2020

One thing I wanted to do is to get rid of modules, and replace them by semimodules everywhere. It used to fail in Lean 3.4 because of type class issues, but now that some problems have been solved in Lean 3.7 it might be the right time to try again. Would you mind if I tried to do this starting from your branch, and see if it fixes your problem?

This would be awesome. Unfortunately I won't have time to participate in this for a couple of days.

@sgouezel
Copy link
Collaborator

sgouezel commented Apr 3, 2020

I failed, again. The reason is that I am asking more from typeclass inference in usual situations (it should find a semiringinstance from a ring, and an add_comm_monoid from an add_comm_group), and it is simply not up to the task because there are way too many instances around. So, it becomes unbearably slow (and times out in some situations). Still, my time was not totally wasted as it uncovered a bug, see #2319.

@urkud
Copy link
Member Author

urkud commented Apr 3, 2020

@sgouezel Is your failed attempt somewhere on github?

@sgouezel
Copy link
Collaborator

sgouezel commented Apr 4, 2020

I have put it in a branch remove_module. It already fails in linear_algebra/basic. There is also something fishy going on in dfinsupp, that I will investigate further. You are welcome to play with the branch (and push whatever you want to it) if you like.

@sgouezel
Copy link
Collaborator

sgouezel commented Apr 4, 2020

In fact the dfinsupp is fixed by #2319, so I have merged #2319 and now the issue has disappeared.

@sgouezel
Copy link
Collaborator

sgouezel commented Apr 4, 2020

It seems that your problem with lie_ring is also solved by #2319. I have merged the relevant bits in your branch, and now the instance is found. I have just pushed this to your branch.

@urkud
Copy link
Member Author

urkud commented Apr 7, 2020

merge master failed, so I rebased.

Some functions and lemmas in `polynomial` now take bundled
homomorphisms as arguments.
@urkud urkud added awaiting-review The author would like community review of the PR and removed WIP Work in progress help-wanted The author needs attention to resolve issues labels Apr 8, 2020
@sgouezel sgouezel marked this pull request as ready for review April 8, 2020 18:49
@sgouezel
Copy link
Collaborator

sgouezel commented Apr 8, 2020

I had done a mess when picking the relevant bits of #2319. Hopefully fixed.

@urkud
Copy link
Member Author

urkud commented Apr 8, 2020

Merge conflict was because of #2348

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 a lot for this major effort!!!
If you would rather ignore my comments and merge this before it breaks, that's fine with me.

src/ring_theory/algebra.lean Outdated Show resolved Hide resolved
@@ -26,55 +26,37 @@ ring is the under category R ↓ CRing. In the categorical
setting we have a forgetful functor R-Alg ⥤ R-Mod.
However here it extends module in order to preserve
definitional equality in certain cases. -/
class algebra (R : Type u) (A : Type v) [comm_ring R] [ring A] extends has_scalar R A :=
(to_fun : R → A) [hom : is_ring_hom to_fun]
@[nolint has_inhabited_instance]
Copy link
Member

Choose a reason for hiding this comment

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

If you want, you can mark the identity as default algebra (i.e. inhabited instance).

Copy link
Member Author

Choose a reason for hiding this comment

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

Probably a better choice is of_ring_hom 0 _ because it works for all R, A.

Copy link
Member

Choose a reason for hiding this comment

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

All ring homs are unital, so that won't work.

Copy link
Member Author

Choose a reason for hiding this comment

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

You're right. That's why I didn't add an inhabited instance in the first place. I don't want to add an inhabited sequence just to make the linter happy. For me this nolint says "there is no universal construction that turns a semiring into an algebra over a given comm_semiring".

Copy link
Member

Choose a reason for hiding this comment

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

Ok, I guess there's not really a consensus on what to do with this linter (-;
I like your point of view, but I also like @semorrison 's idea of using these instances to sprinkle examples into mathlib...

src/ring_theory/algebra.lean Outdated Show resolved Hide resolved
src/ring_theory/algebra.lean Outdated Show resolved Hide resolved
@sgouezel
Copy link
Collaborator

Did I understand the new workflow? And is it working?
bors r+

@gebner
Copy link
Member

gebner commented Apr 10, 2020

bors r+

bors bot pushed a commit that referenced this pull request Apr 10, 2020
@bors
Copy link

bors bot commented Apr 10, 2020

Build succeeded

@bors
Copy link

bors bot commented Apr 10, 2020

Pull request successfully merged into master.

@bors bors bot changed the title refactor(ring_theory/algebra): use bundled homs, allow semirings [Merged by Bors] - refactor(ring_theory/algebra): use bundled homs, allow semirings Apr 10, 2020
@bors bors bot closed this Apr 10, 2020
@ChrisHughes24 ChrisHughes24 deleted the algebra-bundled branch April 10, 2020 12:30
@YaelDillies YaelDillies removed the awaiting-review The author would like community review of the PR label Nov 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use bundled homs in algebra, allow semirings
5 participants