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(Data/Matrix/Basic): use a defeq for scalar that matches its docstring #8115

Closed
wants to merge 10 commits into from

Conversation

eric-wieser
Copy link
Member

@eric-wieser eric-wieser commented Nov 2, 2023

This changes the defeq from scalar a = a • 1 to scalar a = diagonal fun _ => a, which has the nice bonus of making algebraMap_eq_diagonal true by rfl.

As a result, we need a new smul_one_eq_diagonal lemma to rewrite diagonal fun _ => a back into a • 1, along with some variants for convenience.

In the long term we could generalize this to non-unital rings, now that it needs no 1.


Open in Gitpod

…ast`

This also gives the `intCast` instance a nicer defeq.
This remains unopinionated about which side of `diagonal 37 = 37` is the simp-normal form.
@eric-wieser eric-wieser added blocked-by-other-PR This PR depends on another PR which is still in the queue. awaiting-review The author would like community review of the PR awaiting-CI t-algebra Algebra (groups, rings, fields etc) labels Nov 2, 2023
@eric-wieser eric-wieser changed the title Eric wieser/change scalar defeq refactor(Data/Matrix/Basic): use a defeq for scalar that matches its docstring Nov 2, 2023
@leanprover-community-mathlib4-bot leanprover-community-mathlib4-bot added the merge-conflict The PR has a merge conflict with master, and needs manual merging. label Nov 2, 2023
@leanprover-community-mathlib4-bot leanprover-community-mathlib4-bot removed the blocked-by-other-PR This PR depends on another PR which is still in the queue. label Nov 5, 2023
@leanprover-community-mathlib4-bot leanprover-community-mathlib4-bot added blocked-by-other-PR This PR depends on another PR which is still in the queue. and removed merge-conflict The PR has a merge conflict with master, and needs manual merging. blocked-by-other-PR This PR depends on another PR which is still in the queue. labels Nov 6, 2023
Mathlib/Data/Matrix/Basic.lean Show resolved Hide resolved
Comment on lines +1279 to +1280
#noalign matrix.scalar_apply_eq
#noalign matrix.scalar_apply_ne
Copy link
Contributor

Choose a reason for hiding this comment

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

I would prefer to keep these two specialized apply lemmas (they don't need to be @[simp]), it seems to save a bit of work down the line. Also because many of the specializations of diagonal also have this apply_eq and apply_ne variation.

Copy link
Member Author

Choose a reason for hiding this comment

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

Also because many of the specializations of diagonal also have this apply_eq and apply_ne variation.

What lemmas are you thinking of?

Copy link
Contributor

Choose a reason for hiding this comment

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

A quick search for apply_(of_)?ne gives the following @[simp] lemmas about on/off diagonal entries of matrices: one_apply_{eq,ne}, charmatrix_apply_{eq,ne}, stdBasisMatrix.apply_{same,of_ne}, stdBasisMatrix.mul_{left,right}_apply_of_ne, transvection_mul_apply_of_ne.

More generally, we have AffineBasis.coord_apply_{eq,ne}, CategoryTheory.Mat.id_apply_of_ne, Finset.affineCombinationSingleWeights_apply_of_ne, Finset.weightedVSubVSubWeights_apply_of_ne, Finset.affineCombinationLineMapWeights_apply_of_ne, Finsupp.single_eq_of_ne.

I haven't counted but these apply lemmas are more commonly marked as @[simp] than not.

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 it's better to just force the user to unfold scalar (using scalar_apply) if they want any lemmas about it; its primary purpose is to exist as a bundled morphism. The alternative feels like a path to duplicating all the diagonal API for scalar, which seems like a lot of work to save using a dsimp lemma.

Copy link
Contributor

Choose a reason for hiding this comment

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

Alright! I haven't been entirely convinced but it's not worth holding up this PR on that.

Mathlib/Data/Matrix/Basic.lean Show resolved Hide resolved
@Vierkantor Vierkantor 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 Nov 10, 2023
@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 Nov 11, 2023
Copy link
Contributor

@Vierkantor Vierkantor left a comment

Choose a reason for hiding this comment

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

Only the question about keeping the apply lemmas, LGTM otherwise!

Comment on lines +1279 to +1280
#noalign matrix.scalar_apply_eq
#noalign matrix.scalar_apply_ne
Copy link
Contributor

Choose a reason for hiding this comment

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

A quick search for apply_(of_)?ne gives the following @[simp] lemmas about on/off diagonal entries of matrices: one_apply_{eq,ne}, charmatrix_apply_{eq,ne}, stdBasisMatrix.apply_{same,of_ne}, stdBasisMatrix.mul_{left,right}_apply_of_ne, transvection_mul_apply_of_ne.

More generally, we have AffineBasis.coord_apply_{eq,ne}, CategoryTheory.Mat.id_apply_of_ne, Finset.affineCombinationSingleWeights_apply_of_ne, Finset.weightedVSubVSubWeights_apply_of_ne, Finset.affineCombinationLineMapWeights_apply_of_ne, Finsupp.single_eq_of_ne.

I haven't counted but these apply lemmas are more commonly marked as @[simp] than not.

@Vierkantor
Copy link
Contributor

bors merge

@github-actions github-actions bot added the ready-to-merge This PR has been sent to bors. label Nov 27, 2023
@github-actions github-actions bot removed the awaiting-review The author would like community review of the PR label Nov 27, 2023
mathlib-bors bot pushed a commit that referenced this pull request Nov 27, 2023
…docstring (#8115)

This changes the defeq from `scalar a = a • 1` to `scalar a = diagonal fun _ => a`, which has the nice bonus of making `algebraMap_eq_diagonal` true by `rfl`.

As a result, we need a new `smul_one_eq_diagonal` lemma to rewrite `diagonal fun _ => a` back into `a • 1`, along with some variants for convenience.

In the long term we could generalize this to non-unital rings, now that it needs no `1`.
@mathlib-bors
Copy link

mathlib-bors bot commented Nov 27, 2023

Pull request successfully merged into master.

Build succeeded:

@mathlib-bors mathlib-bors bot changed the title refactor(Data/Matrix/Basic): use a defeq for scalar that matches its docstring [Merged by Bors] - refactor(Data/Matrix/Basic): use a defeq for scalar that matches its docstring Nov 27, 2023
@mathlib-bors mathlib-bors bot closed this Nov 27, 2023
@mathlib-bors mathlib-bors bot deleted the eric-wieser/change-scalar-defeq branch November 27, 2023 11:06
awueth pushed a commit that referenced this pull request Dec 19, 2023
…docstring (#8115)

This changes the defeq from `scalar a = a • 1` to `scalar a = diagonal fun _ => a`, which has the nice bonus of making `algebraMap_eq_diagonal` true by `rfl`.

As a result, we need a new `smul_one_eq_diagonal` lemma to rewrite `diagonal fun _ => a` back into `a • 1`, along with some variants for convenience.

In the long term we could generalize this to non-unital rings, now that it needs no `1`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready-to-merge This PR has been sent to bors. t-algebra Algebra (groups, rings, fields etc)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants