Skip to content

Commit 646e569

Browse files
committed
conj, paraconj, ccong for LaurentPolynomials
1 parent 3f09f39 commit 646e569

File tree

3 files changed

+132
-2
lines changed

3 files changed

+132
-2
lines changed

Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ RecipesBase = "3cdcf5f2-1ef4-517c-9805-6587b60abb01"
1313
[compat]
1414
Intervals = "0.5, 1.0, 1.3"
1515
RecipesBase = "0.7, 0.8, 1"
16+
OffsetArrays = "1"
1617
julia = "1"
1718

1819
[extras]

src/polynomials/LaurentPolynomial.jl

Lines changed: 121 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,122 @@ function showterm(io::IO, ::Type{<:LaurentPolynomial}, pj::T, var, j, first::Boo
278278
end
279279

280280

281+
##
282+
## ---- Conjugation has different defintions
283+
##
284+
285+
"""
286+
conj(p)
287+
288+
This satisfies `conj(p(x)) = conj(p)(conj(x)) = p̄(conj(x))` or `p̄(x) = (conj ∘ p ∘ conj)(x)`
289+
290+
Examples
291+
```jldoctest
292+
julia> z = variable(LaurentPolynomial, :z)
293+
LaurentPolynomial(z)
294+
295+
julia> p = LaurentPolynomial([im, 1+im, 2 + im], -1:1, :z)
296+
LaurentPolynomial(im*z⁻¹ + (1 + 1im) + (2 + 1im)*z)
297+
298+
julia> conj(p)(conj(z)) ≈ conj(p(z))
299+
true
300+
301+
julia> conj(p)(z) ≈ (conj ∘ p ∘ conj)(z)
302+
true
303+
```
304+
"""
305+
function LinearAlgebra.conj(p::P) where {P <: LaurentPolynomial}
306+
ps = coeffs(p)
307+
m,n = extrema(p)
308+
(P)(conj(ps),m:n, p.var)
309+
end
310+
311+
312+
"""
313+
paraconj(p)
314+
315+
[cf.](https://ccrma.stanford.edu/~jos/filters/Paraunitary_FiltersC_3.html)
316+
317+
Call `p̂ = paraconj(p)` and `p̄` = conj(p)`, then this satisfies
318+
`conj(p(z)) = p̂(1/conj(z))` or `p̂(z) = p̄(1/z) = (conj ∘ p ∘ conj ∘ inf)(z)`.
319+
320+
Examples:
321+
322+
```jldoctest
323+
julia> z = variable(LaurentPolynomial, :z)
324+
LaurentPolynomial(z)
325+
326+
julia> h = LaurentPolynomial([1,1], -1:0, :z)
327+
LaurentPolynomial(z⁻¹ + 1)
328+
329+
julia> Polynomials.paraconj(h)(z) ≈ 1 + z ≈ LaurentPolynomial([1,1], 0:1, :z)
330+
true
331+
332+
julia> h = LaurentPolynomial([3,2im,1], -2:0, :z)
333+
LaurentPolynomial(3*z⁻² + 2im*z⁻¹ + 1)
334+
335+
julia> Polynomials.paraconj(h)(z) ≈ 1 - 2im*z + 3z^2 ≈ LaurentPolynomial([1, -2im, 3], 0:2, :z)
336+
true
337+
338+
julia> Polynomials.paraconj(h)(z) ≈ (conj ∘ h ∘ conj ∘ inv)(z)
339+
true
340+
"""
341+
function paraconj(p::LaurentPolynomial)
342+
cs = p.coeffs
343+
ds = adjoint.(cs)
344+
m,n = extrema(p)
345+
LaurentPolynomial(reverse(ds), -n:-m, p.var)
346+
end
347+
348+
"""
349+
cconj(p)
350+
351+
Conjugation of a polynomial with respect to the imaginary axis.
352+
353+
The `cconj` of a polynomial, `p̃`, conjugates the coefficients and applies `s -> -s`. That is `cconj(p)(s) = conj(p)(-s)`.
354+
355+
This satisfies for *imaginary* `s`: `conj(p(s)) = p̃(s) = (conj ∘ p)(s) = cconj(p)(s) `
356+
357+
[ref](https://github.com/hurak/PolynomialEquations.jl#symmetrix-conjugate-equation-continuous-time-case)
358+
359+
Examples:
360+
```jldoctest
361+
julia> s = 2im
362+
0 + 2im
363+
364+
julia> p = LaurentPolynomial([im,-1, -im, 1], 1:2, :s)
365+
LaurentPolynomial(im*s - s² - im*s³ + s⁴)
366+
367+
julia> Polynomials.cconj(p)(s) ≈ conj(p(s))
368+
true
369+
370+
julia> a = LaurentPolynomial([-0.12, -0.29, 1],:s)
371+
LaurentPolynomial(-0.12 - 0.29*s + 1.0*s²)
372+
373+
julia> b = LaurentPolynomial([1.86, -0.34, -1.14, -0.21, 1.19, -1.12],:s)
374+
LaurentPolynomial(1.86 - 0.34*s - 1.14*s² - 0.21*s³ + 1.19*s⁴ - 1.12*s⁵)
375+
376+
julia> x = LaurentPolynomial([-15.5, 50.0096551724139, 1.19], :s)
377+
LaurentPolynomial(-15.5 + 50.0096551724139*s + 1.19*s²)
378+
379+
julia> Polynomials.cconj(a) * x + a * Polynomials.cconj(x) ≈ b + Polynomials.cconj(b)
380+
true
381+
```
382+
383+
"""
384+
function cconj(p::LaurentPolynomial)
385+
ps = conj.(coeffs(p))
386+
m,n = extrema(p)
387+
for i in m:n
388+
if isodd(i)
389+
ps[i+1-m] *= -1
390+
end
391+
end
392+
LaurentPolynomial(ps, m:n, p.var)
393+
end
394+
395+
396+
281397
##
282398
## ----
283399
##
@@ -290,10 +406,13 @@ function (p::LaurentPolynomial{T})(x::S) where {T,S}
290406
if m >= 0
291407
evalpoly(x, NTuple{n+1,T}(p[i] for i in 0:n))
292408
elseif n <= 0
293-
evalpoly(inv(x), NTuple{m+1,T}(p[i] for i in 0:-1:m))
409+
evalpoly(inv(x), NTuple{-m+1,T}(p[i] for i in 0:-1:m))
294410
else
295411
# eval pl(x) = a_mx^m + ...+ a_0 at 1/x; pr(x) = a_0 + a_1x + ... + a_nx^n at x; subtract a_0
296-
evalpoly(inv(x), NTuple{-m+1,T}(p[i] for i in 0:-1:m)) + evalpoly(x, NTuple{n+1,T}(p[i] for i in 0:n)) - p[0]
412+
l = evalpoly(inv(x), NTuple{-m+1,T}(p[i] for i in 0:-1:m))
413+
r = evalpoly(x, NTuple{n+1,T}(p[i] for i in 0:n))
414+
mid = p[0]
415+
l + r - mid
297416
end
298417
end
299418

test/StandardBasis.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,16 @@ end
598598
@test norm(P([1., 2.])) == norm([1., 2.])
599599
@test norm(P([1., 2.]), 1) == norm([1., 2.], 1)
600600
end
601+
602+
## Issue #225 and different meanings for "conjugate"
603+
P = LaurentPolynomial
604+
p = P(rand(Complex{Float64}, 4), -1:2)
605+
z = rand(Complex{Float64})
606+
s = imag(z)*im
607+
@test conj(p)(z) (conj p conj)(z)
608+
@test Polynomials.paraconj(p)(z) (conj p conj inv)(z)
609+
@test Polynomials.cconj(p)(s) (conj p)(s)
610+
601611
end
602612

603613
@testset "Indexing" begin

0 commit comments

Comments
 (0)