Skip to content

Commit fa14ce3

Browse files
jverzaniiojea
andauthored
Iojea master (#616)
* Include a method for derivative of constant `ImmutableDensePolynomial` (N=1). The method returns the zero `ImmutableDensePolynomial. This is a possible fix of a bug, since previously derivative of an `ImmutablePolynomial` returned an unusable polynomial of type `ImmutablePolynomial{Union{},:x,0}`. * Improved derivative for constant `ImmutablePolynomial`. `derivative(p)` now returns `zero(p)`. * subtract, not add; add simple tests * test display --------- Co-authored-by: Ignacio Ojea <[email protected]>
1 parent cf94695 commit fa14ce3

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/polynomials/standard-basis/immutable-polynomial.jl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,6 @@ derivative(p::ImmutableDensePolynomial{B,T,X,0}) where {B<:StandardBasis,T,X} =
145145
derivative(p::ImmutableDensePolynomial{B,T,X,1}) where {B<:StandardBasis,T,X} = zero(p)
146146

147147
function derivative(p::ImmutableDensePolynomial{B,T,X,N}) where {B<:StandardBasis,T,X,N}
148-
N == 0 && return p
149-
N == 1 && return zero(p)
150148
hasnan(p) && return ImmutableDensePolynomial{B,T,X,1}(zero(T)/zero(T)) # NaN{T}
151149
cs = ntuple(i -> i*p.coeffs[i+1], Val(N-1))
152150
R = eltype(cs)

test/StandardBasis.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1094,6 +1094,15 @@ end
10941094
@test_throws ArgumentError derivative(pR, -1)
10951095
@test integrate(P([1,1,0,0]), 0, 2) == 4.0
10961096

1097+
p₀, p₁, p₂ = zero(P), one(P), variable(P)
1098+
@test derivative(p₂) == p₁
1099+
@test derivative(p₁) == p₀
1100+
@test integrate(p₀, 1) == p₁
1101+
@test integrate(p₁) == p₂
1102+
if P != Polynomials.MutableSparseVectorPolynomial{Polynomials.StandardBasis}
1103+
@test repr(derivative(p₁)) == string(P)*"(0.0)" # #615 display issue
1104+
end
1105+
10971106
P <: FactoredPolynomial && continue
10981107

10991108
@testset for i in 1:10

0 commit comments

Comments
 (0)