Differentiation

Given a polynomial, say $p(x, y) = 3x^2y + x + 2y + 1$, we can differentiate it by a variable, say $x$ and get $\partial p(x, y) / \partial x = 6xy + 1$. We can also differentiate it by both of its variable and get the vector $[6xy+1, 3x^2+1]$.

MultivariatePolynomials.differentiateFunction
differentiate(p::AbstractPolynomialLike, v::AbstractVariable, deg::Union{Int, Val}=1)

Differentiate deg times the polynomial p by the variable v.

differentiate(p::AbstractPolynomialLike, vs, deg::Union{Int, Val}=1)

Differentiate deg times the polynomial p by the variables of the vector or tuple of variable vs and return an array of dimension deg. It is recommended to pass deg as a Val instance when the degree is known at compile time, e.g. differentiate(p, v, Val{2}()) instead of differentiate(p, x, 2), as this will help the compiler infer the return type.

differentiate(p::AbstractArray{<:AbstractPolynomialLike, N}, vs, deg::Union{Int, Val}=1) where N

Differentiate the polynomials in p by the variables of the vector or tuple of variable vs and return an array of dimension N+deg. If p is an AbstractVector this returns the Jacobian of p where the i-th row containts the partial derivaties of p[i].

Examples

p = 3x^2*y + x + 2y + 1
differentiate(p, x) # should return 6xy + 1
differentiate(p, x, Val{1}()) # equivalent to the above
differentiate(p, (x, y)) # should return [6xy+1, 3x^2+1]
differentiate( [x^2+y, z^2+4x], [x, y, z]) # should return [2x 1 0; 4 0 2z]
source

Antidifferentiation

Given a polynomial, say p(x, y) = 3x^2y + x + 2y + 1, we can antidifferentiate it by a variable, say x and get $\int_0^x p(X, y)\mathrm{d}X = x^3y + 1/2x^2 + 2xy + x$. We can also antidifferentiate it by both of its variable and get the vector [x^3y + 1/2x^2 + 2xy + x, 3/2x^2y^2 + xy + y^2 + y].

MultivariatePolynomials.antidifferentiateFunction
antidifferentiate(p::AbstractPolynomialLike, v::AbstractVariable, deg::Union{Int, Val}=1)

Antidifferentiate deg times the polynomial p by the variable v. The free constant involved by the antidifferentiation is set to 0.

antidifferentiate(p::AbstractPolynomialLike, vs, deg::Union{Int, Val}=1)

Antidifferentiate deg times the polynomial p by the variables of the vector or tuple of variable vs and return an array of dimension deg. It is recommended to pass deg as a Val instance when the degree is known at compile time, e.g. antidifferentiate(p, v, Val{2}()) instead of antidifferentiate(p, x, 2), as this will help the compiler infer the return type.

Examples

p = 3x^2*y + x + 2y + 1
antidifferentiate(p, x) # should return 3x^3* + 1/2*x + 2xy + x
antidifferentiate(p, x, Val{1}()) # equivalent to the above
antidifferentiate(p, (x, y)) # should return [3x^3* + 1/2*x + 2xy + x, 3/2x^2*y^2 + xy + y^2 + y]
source