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

Add antidifferentiation #158

Merged
merged 7 commits into from
Apr 11, 2024

Conversation

chrhansk
Copy link
Contributor

@chrhansk chrhansk commented Apr 2, 2024

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
Copy link
Member

blegat commented Apr 5, 2024

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
Copy link
Contributor Author

chrhansk commented Apr 8, 2024

Done.

src/anti_diff.jl Outdated Show resolved Hide resolved
Co-authored-by: Benoît Legat <benoit.legat@gmail.com>
@chrhansk
Copy link
Contributor Author

chrhansk commented Apr 9, 2024

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

test/poly.jl Outdated
@polyvar x y

p = (x^2 + 4 * y^3)
(_, _, T) = typeof(p).parameters
Copy link
Member

Choose a reason for hiding this comment

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

Can you use coefficient_type instead ?

@chrhansk
Copy link
Contributor Author

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
Copy link
Member

blegat commented Apr 10, 2024

Yes, this should also be Rational{Int}

@chrhansk chrhansk force-pushed the feature-antidifferentiation branch from 66274d3 to 7ce8832 Compare April 10, 2024 12:25
@chrhansk
Copy link
Contributor Author

OK, I adjusted the implementation accordingly.

@blegat
Copy link
Member

blegat commented Apr 10, 2024

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

@blegat blegat merged commit c3e9a02 into JuliaAlgebra:master Apr 11, 2024
4 checks passed
@blegat blegat mentioned this pull request Apr 30, 2024
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.

2 participants