JuliaAlgebra / DynamicPolynomials.jl

Multivariate polynomials implementation of commutative and non-commutative variables
Other
60 stars 20 forks source link

Add antidifferentiation #158

Closed chrhansk closed 3 months ago

chrhansk commented 3 months ago

This patch adds an implementation of the antidifferentiate function for both monomials and polynomials (fixing #157).

The function antidifferentiate(p, x) works by either returning the product p*x if p has no term with variable x, or by incrementing the powers and adjusting the coefficients to match (thereby always ensuring that the antiderivative evaluates to zero whenever x is zero).

I included some basic unit tests as well. I did not run JuliaFormatter.jl over the codebase, since numerous other files are not formatted according to those formatting rules...

Let me know if anything is missing. If this lands, I would appreciated a new version to be used in my own project.

blegat commented 3 months ago

Looks very good thanks. Maybe we should go for Rational{Int} if the current coefficient type is Int ? So create some custom _div that uses / if AbstractFloat and // otherwise. Note that 1 // 2 is used here https://github.com/JuliaAlgebra/MultivariatePolynomials.jl/blob/master/src/antidifferentiation.jl#L30 so it's consistent with that

chrhansk commented 3 months ago

Done.

chrhansk commented 3 months ago

Is there anything else needed or is this ready to merge?

chrhansk commented 3 months ago

I was indeed unaware of the existence of that particular function. The problem should be fixed by now.

I also noticed another aspect regarding the monomials: The antidifferentiation of a monomial yields a term with a Float64 type. We could make this a Rational{Int} instead (similarly to the polynomial case). What is your opinion on this?

blegat commented 3 months ago

Yes, this should also be Rational{Int}

chrhansk commented 3 months ago

OK, I adjusted the implementation accordingly.

blegat commented 3 months ago

Thanks, let's wait to see the CI results but looks good to me