@@ -8,7 +8,7 @@ A [Laurent](https://en.wikipedia.org/wiki/Laurent_polynomial) polynomial is of t
8
8
The `coeffs` specify `a_{m}, a_{m-1}, ..., a_{n}`. The range specified is of the form `m:n`, if left empty, `0:length(coeffs)-1` is used (i.e., the coefficients refer to the standard basis). Alternatively, the coefficients can be specified using an `OffsetVector` from the `OffsetArrays` package.
9
9
10
10
Laurent polynomials and standard basis polynomials promote to Laurent polynomials. Laurent polynomials may be converted to a standard basis polynomial when `m >= 0`
11
- .
11
+ .
12
12
13
13
Integration will fail if there is a `x⁻¹` term in the polynomial.
14
14
@@ -203,7 +203,7 @@ function Base.setindex!(p::LaurentPolynomial{T}, value::Number, idx::Int) where
203
203
p. coeffs[i] = value
204
204
205
205
return p
206
-
206
+
207
207
end
208
208
209
209
Base. firstindex (p:: LaurentPolynomial ) = p. m[]
@@ -215,7 +215,7 @@ Base.eachindex(p::LaurentPolynomial) = range(p)
215
215
function chop! (p:: P ;
216
216
rtol:: Real = Base. rtoldefault (real (T)),
217
217
atol:: Real = 0 ,) where {T, P <: LaurentPolynomial{T} }
218
-
218
+
219
219
m0,n0 = m,n = extrema (p)
220
220
for k in n: - 1 : m
221
221
if isapprox (p[k], zero (T); rtol = rtol, atol = atol)
246
246
function truncate! (p:: LaurentPolynomial{T} ;
247
247
rtol:: Real = Base. rtoldefault (real (T)),
248
248
atol:: Real = 0 ,) where {T}
249
-
249
+
250
250
max_coeff = maximum (abs, coeffs (p))
251
251
thresh = max_coeff * rtol + atol
252
252
@@ -259,7 +259,7 @@ function truncate!(p::LaurentPolynomial{T};
259
259
chop! (p)
260
260
261
261
return p
262
-
262
+
263
263
end
264
264
265
265
# use unicode exponents. XXX modify printexponent to always use these?
314
314
315
315
[cf.](https://ccrma.stanford.edu/~jos/filters/Paraunitary_FiltersC_3.html)
316
316
317
- Call `p̂ = paraconj(p)` and `p̄` = conj(p)`, then this satisfies
317
+ Call `p̂ = paraconj(p)` and `p̄` = conj(p)`, then this satisfies
318
318
`conj(p(z)) = p̂(1/conj(z))` or `p̂(z) = p̄(1/z) = (conj ∘ p ∘ conj ∘ inf)(z)`.
319
319
320
320
Examples:
@@ -364,7 +364,7 @@ julia> s = 2im
364
364
julia> p = LaurentPolynomial([im,-1, -im, 1], 1:2, :s)
365
365
LaurentPolynomial(im*s - s² - im*s³ + s⁴)
366
366
367
- julia> Polynomials.cconj(p)(s) ≈ conj(p(s))
367
+ julia> Polynomials.cconj(p)(s) ≈ conj(p(s))
368
368
true
369
369
370
370
julia> a = LaurentPolynomial([-0.12, -0.29, 1],:s)
@@ -415,8 +415,8 @@ function (p::LaurentPolynomial{T})(x::S) where {T,S}
415
415
l + r - mid
416
416
end
417
417
end
418
-
419
-
418
+
419
+
420
420
421
421
# scalar operattoinis
422
422
Base.:- (p:: P ) where {P <: LaurentPolynomial } = P (- coeffs (p), range (p), p. var)
@@ -447,7 +447,7 @@ function Base.:+(p1::P1, p2::P2) where {T,P1<:LaurentPolynomial{T}, S, P2<:Laure
447
447
elseif isconstant (p2)
448
448
p2 = P2 (p2. coeffs, range (p2), p1. var)
449
449
end
450
-
450
+
451
451
p1. var != p2. var && error (" LaurentPolynomials must have same variable" )
452
452
453
453
R = promote_type (T,S)
@@ -465,7 +465,7 @@ function Base.:+(p1::P1, p2::P2) where {T,P1<:LaurentPolynomial{T}, S, P2<:Laure
465
465
chop! (q)
466
466
467
467
return q
468
-
468
+
469
469
end
470
470
471
471
function Base.:* (p1:: LaurentPolynomial{T} , p2:: LaurentPolynomial{S} ) where {T,S}
@@ -495,11 +495,34 @@ function Base.:*(p1::LaurentPolynomial{T}, p2::LaurentPolynomial{S}) where {T,S}
495
495
return p
496
496
end
497
497
498
+ # #
499
+ # # roots
500
+ # #
501
+ """
502
+ roots(p)
503
+
504
+ Compute the roots of the Laurent polynomial `p`.
505
+
506
+ # Example
507
+
508
+ ```julia
509
+ julia> p = LaurentPolynomial([24,10,-15,0,1],-2:1,:z)
510
+ LaurentPolynomial(24*z⁻² + 10*z⁻¹ - 15 + z²)
511
+
512
+
513
+ ```
514
+ """
515
+ function roots (p:: P ; kwargs... ) where {T, P <: LaurentPolynomial{T} }
516
+ c = coeffs (p)
517
+ a = Polynomial (c,p. var)
518
+ return roots (p; kwargs... )
519
+ end
520
+
498
521
# #
499
522
# # d/dx, ∫
500
523
# #
501
524
function derivative (p:: P , order:: Integer = 1 ) where {T, P<: LaurentPolynomial{T} }
502
-
525
+
503
526
order < 0 && error (" Order of derivative must be non-negative" )
504
527
order == 0 && return p
505
528
@@ -518,9 +541,9 @@ function derivative(p::P, order::Integer = 1) where {T, P<:LaurentPolynomial{T}}
518
541
as[idx] = reduce (* , (k - order + 1 ): k, init = p[k])
519
542
end
520
543
end
521
-
544
+
522
545
chop! (LaurentPolynomial (as, m: n, p. var))
523
-
546
+
524
547
end
525
548
526
549
@@ -546,15 +569,15 @@ function integrate(p::P, k::S) where {T, P<: LaurentPolynomial{T}, S<:Number}
546
569
m = 0
547
570
end
548
571
as = zeros (R, length (m: n))
549
-
572
+
550
573
for k in eachindex (p)
551
574
as[1 + k+ 1 - m] = p[k]/ (k+ 1 )
552
575
end
553
576
554
577
as[1 - m] = k
555
578
556
579
return ⟒ (P)(as, m: n, p. var)
557
-
580
+
558
581
end
559
582
560
583
@@ -568,7 +591,7 @@ function Base.gcd(p::LaurentPolynomial{T}, q::LaurentPolynomial{T}, args...; kwa
568
591
degree (p) == 0 && return iszero (p) ? q : one (q)
569
592
degree (q) == 0 && return iszero (q) ? p : one (p)
570
593
check_same_variable (p,q) || throw (ArgumentError (" p and q have different symbols" ))
571
-
594
+
572
595
pp, qq = convert (Polynomial, p), convert (Polynomial, q)
573
596
u = gcd (pp, qq, args... , kwargs... )
574
597
return LaurentPolynomial (coeffs (u), p. var)
0 commit comments