Skip to content

Commit

Permalink
Mkae monomial antidifferentiation coefficient types rationals
Browse files Browse the repository at this point in the history
  • Loading branch information
chrhansk committed Apr 10, 2024
1 parent b76a367 commit 66274d3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/anti_diff.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function MP.antidifferentiate(m::Monomial{V,M}, x::Variable{V,M}) where {V,M}
Monomial(MP.variables(m), z) * x
else
z[i] += 1
Monomial(MP.variables(m), z) / (m.z[i] + 1)
(1 // (m.z[i] + 1)) * Monomial(MP.variables(m), z)
end
end

Expand Down
6 changes: 6 additions & 0 deletions test/mono.jl
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,19 @@ import MultivariatePolynomials as MP
mi = DynamicPolynomials.MP.antidifferentiate(m, y)
@test mi == x * y

# Antidifferentiation is product => Integral coefficients
@test MP.coefficient_type(mi) == Int

# General antidifferentiation => Rational coefficients
m = x^3
mi = DynamicPolynomials.MP.antidifferentiate(m, x)
@test mi == (x^4 / 4)
@test MP.coefficient_type(mi) == Rational{Int}

m = Monomial([x, y, z], [1, 2, 3])
mi = DynamicPolynomials.MP.antidifferentiate(m, z)
@test mi == (x*y^2*z^4) / 4
@test MP.coefficient_type(mi) == Rational{Int}
end

@testset "Evaluation" begin
Expand Down

0 comments on commit 66274d3

Please sign in to comment.