Skip to content

[Merged by Bors] - feat(Algebra/Polynomial/Derivation): coefficient-wise derivation on a polynomial#14702

Closed
Command-Master wants to merge 31 commits intomasterfrom
CommandMaster_coeffwise
Closed

[Merged by Bors] - feat(Algebra/Polynomial/Derivation): coefficient-wise derivation on a polynomial#14702
Command-Master wants to merge 31 commits intomasterfrom
CommandMaster_coeffwise

Conversation

@Command-Master
Copy link
Copy Markdown
Collaborator

@Command-Master Command-Master commented Jul 13, 2024

Define Derivation.coeffwise, which applies the derivation to the a polynomial coefficient-wise.


Open in Gitpod

@Command-Master Command-Master added the t-algebra Algebra (groups, rings, fields, etc) label Jul 13, 2024
@github-actions github-actions bot added the new-contributor This PR was made by a contributor with at most 5 merged PRs. Welcome to the community! label Jul 13, 2024
@github-actions
Copy link
Copy Markdown

github-actions bot commented Jul 13, 2024

PR summary 9deed4ebc9

Import changes for modified files

No significant changes to the import graph

Import changes for all files
Files Import difference
Mathlib.RingTheory.Derivation.MapCoeffs 987

Declarations diff

+ apply_aeval_eq
+ apply_aeval_eq'
+ apply_eval_eq
+ mapCoeffs
+ mapCoeffs_C
+ mapCoeffs_X
+ mapCoeffs_apply
+ mapCoeffs_monomial

You can run this locally as follows
## summary with just the declaration names:
./scripts/declarations_diff.sh <optional_commit>

## more verbose report:
./scripts/declarations_diff.sh long <optional_commit>

The doc-module for script/declarations_diff.sh contains some details about this script.

@ghost ghost added the blocked-by-other-PR This PR depends on another PR (this label is automatically managed by a bot) label Jul 13, 2024
Copy link
Copy Markdown
Member

@erdOne erdOne left a comment

Choose a reason for hiding this comment

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

/--
The `R`-derivation from `A[X]` to `M[X]` which applies the derivative to each
of the coefficients.
-/
def coeffwise : Derivation R A[X] (PolynomialModule A M) where
  __ := (PolynomialModule.map A d.toLinearMap).comp
    PolynomialModule.equivPolynomial.symm.toLinearMap
  map_one_eq_zero' := show (Finsupp.single 0 1).mapRange (d : A → M) d.map_zero = 0 by simp
  leibniz' p q := by
    dsimp 
    induction p using Polynomial.induction_on' with
    | h_add => simp only [add_mul, map_add, add_smul, smul_add, add_add_add_comm, *]
    | h_monomial n a =>
      induction q using Polynomial.induction_on' with
      | h_add => simp only [mul_add, map_add, add_smul, smul_add, add_add_add_comm, *]
      | h_monomial m b =>
        refine Finsupp.ext fun i ↦ ?_
        dsimp [PolynomialModule.equivPolynomial, PolynomialModule.map]
        simp only [toFinsupp_mul, toFinsupp_monomial, AddMonoidAlgebra.single_mul_single]
        show d _ = _ + _
        erw [Finsupp.mapRange.linearMap_apply, Finsupp.mapRange.linearMap_apply]
        rw [Finsupp.mapRange_single, Finsupp.mapRange_single]
        erw [PolynomialModule.monomial_smul_single, PolynomialModule.monomial_smul_single]
        simp only [AddMonoidAlgebra.single_apply, apply_ite d, leibniz, map_zero, coeFn_coe,
          PolynomialModule.single_apply, ite_add_zero, add_comm m n]

@[simp]
lemma coeffwise_apply (p : A[X]) (i) :
    d.coeffwise p i = d (coeff p i) := rfl

@[simp]
lemma coeffwise_monomial (n) (x : A) :
    d.coeffwise (monomial n x) = .single A n (d x) := Finsupp.ext fun _ ↦ by
  simp [coeff_monomial, apply_ite d, PolynomialModule.single_apply]

@[simp]
lemma coeffwise_X :
    d.coeffwise (X : A[X]) = 0 := Finsupp.ext fun _ ↦ by
  simp [← monomial_one_one_eq_X]

theorem apply_eval_eq (x : A) (p : A[X]) :
    d (eval x p) = PolynomialModule.eval x (d.coeffwise p) + eval x (derivative p) • d x := by
  induction p using Polynomial.induction_on' with
  | h_add => simp_all only [eval_add, map_add, add_smul]; abel
  | h_monomial n a =>
    simp only [eval_monomial, leibniz, leibniz_pow, coeffwise_monomial,
      PolynomialModule.eval_single, derivative_monomial, ← mul_smul, nsmul_eq_smul_cast A]
    rw [add_comm]
    congr 2
    ring

This seems like a better approach. Note that you would need to relax the typeclass arguments on PolynomialModule.map to make this work.
By the way it would be nice if you can identify the missing lemmas and remove those erws.

@Command-Master
Copy link
Copy Markdown
Collaborator Author

How could the typeclass parameters of PolynomialModule.map be relaxed? Its domain is PolynomialModule R M, which requires CommRing R. You'd have to relax all of PolynomialModule.

@erdOne
Copy link
Copy Markdown
Member

erdOne commented Jul 14, 2024

You're right. Then that's the thing to do if you really care about semirings.

@Command-Master
Copy link
Copy Markdown
Collaborator Author

I added the lemmas. I'm not sure about changing the definition - it makes coeffwise_apply definitional, and is a bit cleaner, but loses R being a semiring.

@erdOne
Copy link
Copy Markdown
Member

erdOne commented Jul 14, 2024

I don't think that matters much, unless you absolutely need semirings. Someone else who needs semirings may generalise PolynomialModule altogether.

Command-Master and others added 3 commits July 14, 2024 05:41
Co-authored-by: erdOne <36414270+erdOne@users.noreply.github.com>
@ghost ghost removed the blocked-by-other-PR This PR depends on another PR (this label is automatically managed by a bot) label Jul 14, 2024
@ghost
Copy link
Copy Markdown

ghost commented Jul 14, 2024

@YaelDillies YaelDillies changed the title feat(Algebra/Polynomial/Derivation): define coeffient-wise derivation on a polynomial feat(Algebra/Polynomial/Derivation): coefficient-wise derivation on a polynomial Sep 1, 2024
The `R`-derivation from `A[X]` to `M[X]` which applies the derivative to each
of the coefficients.
-/
def mapCoeffs : Derivation R A[X] (PolynomialModule A M) where
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This name is ambiguous in that one could also derive the a multivariate polynomial coefficient-wise. What about something like this?

Suggested change
def mapCoeffs : Derivation R A[X] (PolynomialModule A M) where
def polynomialCoeffs : Derivation R A[X] (PolynomialModule A M) where

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Should I also change the file name, or is it ok?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Thinking about it a bit more, I don't love polynomialCoeffs - it feels weird to write D.polynomialCoeffs p

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I would personally just call it Derivation.Polynomial, but I don't know 🤷

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Perhaps just Derivation.poly? Or is that too confusing?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Oh I see. I guess it can go back there

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@semorrison @erdOne could we get your opinions on this?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

In #14967 I also import RingTheory.Derivation.DifferentialRing to this file, so I think it's good to keep as a separate file

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

How bad do you think this name is? I'm unable to think of any alternative I like

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I guess it's fine, but let's not resolve this conversation in case someone thinks of a better name

@YaelDillies YaelDillies added the awaiting-author A reviewer has asked the author a question or requested changes. label Sep 1, 2024
@Command-Master Command-Master removed the awaiting-author A reviewer has asked the author a question or requested changes. label Sep 10, 2024
Copy link
Copy Markdown
Contributor

@YaelDillies YaelDillies left a comment

Choose a reason for hiding this comment

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

maintainer merge

@github-actions
Copy link
Copy Markdown

🚀 Pull request has been placed on the maintainer queue by YaelDillies.

@github-actions github-actions bot added the maintainer-merge A reviewer has approved the changed; awaiting maintainer approval. label Sep 11, 2024
@riccardobrasca
Copy link
Copy Markdown
Member

Thanks!

bors merge

@github-actions github-actions bot added the ready-to-merge This PR has been sent to bors. label Sep 11, 2024
mathlib-bors bot pushed a commit that referenced this pull request Sep 11, 2024
… polynomial (#14702)

Define `Derivation.coeffwise`, which applies the derivation to the a polynomial coefficient-wise.
@mathlib-bors
Copy link
Copy Markdown
Contributor

mathlib-bors bot commented Sep 11, 2024

Build failed:

  • Build

@Command-Master
Copy link
Copy Markdown
Collaborator Author

bors merge

@mathlib-bors
Copy link
Copy Markdown
Contributor

mathlib-bors bot commented Sep 11, 2024

🔒 Permission denied

Existing reviewers: click here to make Command-Master a reviewer

@Ruben-VandeVelde Ruben-VandeVelde removed ready-to-merge This PR has been sent to bors. maintainer-merge A reviewer has approved the changed; awaiting maintainer approval. labels Sep 11, 2024
@Ruben-VandeVelde
Copy link
Copy Markdown
Contributor

maintainer merge

@github-actions
Copy link
Copy Markdown

🚀 Pull request has been placed on the maintainer queue by Ruben-VandeVelde.

@github-actions github-actions bot added the maintainer-merge A reviewer has approved the changed; awaiting maintainer approval. label Sep 11, 2024
@riccardobrasca
Copy link
Copy Markdown
Member

bors merge

@github-actions github-actions bot added the ready-to-merge This PR has been sent to bors. label Sep 11, 2024
mathlib-bors bot pushed a commit that referenced this pull request Sep 11, 2024
… polynomial (#14702)

Define `Derivation.coeffwise`, which applies the derivation to the a polynomial coefficient-wise.
@mathlib-bors
Copy link
Copy Markdown
Contributor

mathlib-bors bot commented Sep 11, 2024

Pull request successfully merged into master.

Build succeeded:

@mathlib-bors mathlib-bors bot changed the title feat(Algebra/Polynomial/Derivation): coefficient-wise derivation on a polynomial [Merged by Bors] - feat(Algebra/Polynomial/Derivation): coefficient-wise derivation on a polynomial Sep 11, 2024
@mathlib-bors mathlib-bors bot closed this Sep 11, 2024
@mathlib-bors mathlib-bors bot deleted the CommandMaster_coeffwise branch September 11, 2024 12:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintainer-merge A reviewer has approved the changed; awaiting maintainer approval. new-contributor This PR was made by a contributor with at most 5 merged PRs. Welcome to the community! 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.

7 participants