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

Antidifferentiation (primitive) #230

Merged
merged 4 commits into from
May 2, 2023
Merged

Antidifferentiation (primitive) #230

merged 4 commits into from
May 2, 2023

Conversation

bmxam
Copy link
Contributor

@bmxam bmxam commented Dec 5, 2022

With this PR, I propose to introduce a function to get the antiderivative of multivariate polynomial. Note that the word primitive, (more natural in my native language), is already used by the Julia language; hence the antiderivative name. An associated PR in TypedPolynomials is proposed.

I tried to copy what is currently done for differentiate. Except for RationalPoly, which are not always possible to antidifferentiate with polynoms. I provided some unit tests as well.

With this new function, it would then be easy to integrate a multivariate polynomial on (simple) geometries such as lines, quads, cubes etc.

Note : for personal reasons, I may be absent in the next few weeks. Don't hesitate to continue the PR process "without me".

src/antidifferentiation.jl Outdated Show resolved Hide resolved
@bmxam
Copy link
Contributor Author

bmxam commented Dec 13, 2022

I see that the no-reg is failing because (as I understand it) it tries to apply antidifferentiate with DynamicPolynomials, which is not implemented. How can I fix this problem?

@blegat
Copy link
Member

blegat commented Dec 26, 2022

We need to add the definition of antidifferentiate first, release MultivariatePolynomials, then add it to DynamicPolynomials, then release DynamicPolynomials and then add the tests in MultivariatePolynomials

@bmxam
Copy link
Contributor Author

bmxam commented Dec 30, 2022

We need to add the definition of antidifferentiate first, release MultivariatePolynomials, then add it to DynamicPolynomials, then release DynamicPolynomials and then add the tests in MultivariatePolynomials

Alright. I will propose a commit without any tests.


# Fallback for everything else
antidifferentiate(α::T, v::AbstractVariable) where {T} = α * v
antidifferentiate(v1::AbstractVariable, v2::AbstractVariable) = v1 == v2 ? 1 / 2 * v1 * v2 : v1 * v2
Copy link
Member

Choose a reason for hiding this comment

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

I am a bit concerned about defaulting to Float64, this might also be used with polynomials on Rational{BigInt} for instance, I would use Rational{Int} as it is more neutral so it will preserve the type of the polynomial it is used with

julia> typeof(1.0 * (1 // 2))
Float64

julia> typeof((big(1)) * (1 // 2))
Rational{BigInt}

julia> typeof((big(1) // big(2)) * (1 // 2))
Rational{BigInt}

Copy link
Contributor Author

@bmxam bmxam Jan 2, 2023

Choose a reason for hiding this comment

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

you're right, I fixed it in my last commit (c34bb38)

@blegat
Copy link
Member

blegat commented Jan 2, 2023

Note that the word primitive, (more natural in my native language), is already used by the Julia language; hence the antiderivative name. An associated PR in TypedPolynomials is proposed.

I am also french-speaking so primitive is more natural for me as well but let's follow wikipedia: https://en.wikipedia.org/wiki/Antiderivative which uses antidifferentiate

@bmxam
Copy link
Contributor Author

bmxam commented Jan 2, 2023

We need to add the definition of antidifferentiate first, release MultivariatePolynomials, then add it to DynamicPolynomials, then release DynamicPolynomials and then add the tests in MultivariatePolynomials

Alright. I will propose a commit without any tests.

(done in c34bb38)

docs/make.jl Outdated Show resolved Hide resolved
@blegat
Copy link
Member

blegat commented May 2, 2023

Could you add some tests ?

@bmxam
Copy link
Contributor Author

bmxam commented May 2, 2023

We need to add the definition of antidifferentiate first, release MultivariatePolynomials, then add it to DynamicPolynomials, then release DynamicPolynomials and then add the tests in MultivariatePolynomials

Hi Benoît, as I understand the tests will be added later. Or there is something I didn't understand?

@blegat
Copy link
Member

blegat commented May 2, 2023

Indeed, sorry, I forgot that part, let's merge then

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.

None yet

2 participants