| Bytes | Lang | Time | Link |
|---|---|---|---|
| 012 | Husk | 250806T172543Z | LegionMa |
| 035 | Python + NumPy | 250804T175124Z | Albert.L |
| 060 | JavaScript ES7 | 250804T123534Z | Arnauld |
| 005 | Jelly | 250804T004618Z | Jonathan |
| 064 | Haskell | 250805T021430Z | xnor |
| 024 | Charcoal | 250804T104315Z | Neil |
| 021 | Wolfram Language Mathematica | 250804T022014Z | Lucenapo |
Husk, 12 bytes
mΣĊ2∂SṪ*z*İ_
Try it online! This uses the standard procedure of calculating -P(x)*P(-x) and dropping the odd-indexed terms. The output coefficients are negated due to the unusual definition of İ_, which is an infinite list of -(-1)^n instead of (-1)^n.
Python + NumPy, 35 bytes
lambda p:p*0+[*p*p(p*0-[1,0])][::2]
Takes and returns instances of numpy.poly1d.
How?
Multplies the given polynomial p(x) with its "mirror" q(x):=p(-x). For each root r of p, q has a root -r and the product has a quadratic factor (x2-r2). Dropping every other coefficient (they are all 0 anyways) in effect substitutes x2 by some new variable z, so the resulting polynomial has the correct roots.
The p*0 terms are type coercion starters.
Previous Python + NumPy, 36 bytes
lambda p:p*0+(p*p(p*0-[1,0])).c[::2]
Previous Python + NumPy, 63 bytes
lambda p:P((p*p(-P([1,0]))).c[::2])
from numpy import*
P=poly1d
(Boring) Python + NumPy, 45 bytes
lambda p:poly(roots(p)**2)
from numpy import*
JavaScript (ES7), 60 bytes
This is a port of Neil's answer.
a=>a.map((_,k)=>a.reduce((t,x,i)=>t+(-1)**i*x*~~a[k*2-i],0))
Jelly, 5 bytes
Ær²Æṛ
A monadic Link that accepts and yields coefficients in descending order.
How?
Builtins...
Ær²Æṛ - Link: list of numbers, Coefficients
Ær - roots of {Coefficients}
² - square {those}
Æṛ - polynomial with roots {that}
Haskell, 64 bytes
h?(a:b:t)=2*h*b:h?t++[0]
_?l=[0]
f(h:t)=h^2:zipWith(-)(h?t)(f t)
No built-in algebra, just list manipulation. Given \$p\$, we're looking for \$q\$ with
$$ q(x^2) = p(x)p(-x)$$
If we express \$p(x) = h + x p'(x)\$, then we can recurse as
$$p(x)p(-x) = h^2+x^2 \left( 2h \frac{p'(x)-p'(-x)}{2x} - p'(x)p'(-x)\right)$$
So, the first term of \$q(x^2)\$ is \$h^2\$, and the remaining terms are the expression after \$x^2\$. The term \$\frac{p'(x)-p'(-x)}{2x}\$ deletes every other coefficient from \$p'(x)\$. From it, we subtract \$ p'(x)p'(-x)\$, which is the recursive evaluation of our main function on \$p'(x)\$.
If we may stretch polynomial representation to an infinite list trailing with zeroes, we can just write:
Haskell, 51 bytes
h?(a:b:t)=2*h*b:h?t
f(h:t)=h^2:zipWith(-)(h?t)(f t)
Charcoal, 30 24 bytes
IEθΣEθΣEθ∧⁼⊗κ⁺μξ×X±¹ξ×λν
Try it online! Link is to verbose version of code. I/O is a list in ascending order of exponent. Explanation: Directly calculates a polynomial whose roots are the squares of the given polynomial. Works even when the original roots do not have a closed form. Edit: Saved 6 bytes by using @Albert.Lang's optimisation to calculate the sign of each term.
θ Input array
E Map over values
θ Input array
E Map over values
θ Input array
E Map over values
κ Outer index
⊗ Doubled
⁼ Equals
μ Inner index
⁺ Plus
ξ Innermost index
∧ Logical And
¹ Literal integer `1`
± Negated
X Raised to power
ξ Innermost index
× Multiplied by
λ Inner value
× Multiplied by
ν Innermost value
Σ Take the sum
Σ Take the sum
I Cast to string
Implicitly print