24
2
Given a polynomial p(x)
with integral coefficients and a constant term of p(0) = 1 or -1
, and a nonnegative integer N
, return the N
-th coefficient of the power seris (sometimes called "Taylor series") of f(x) = 1/p(x)
developed at x0 = 0
, i.e., the coefficient of the monomial of degree N
.
The given conditions ensure that the power series exist and that the its coefficients are integers.
Details
As always the polynomial can be accepted in any convenient format, e.g. a list of coefficients, for instance p(x) = x^3-2x+5
could be represented as [1,0,-2,5]
.
The powerseries of a function f
developed at 0
is given by
and the N
-th coefficient (the coefficient of x^N
) is given by
where denotes the
n
-th derivative of f
Examples
The polynomial
p(x) = 1-x
results in the geometric seriesf(x) = 1 + x + x^2 + ...
so the output should be1
for allN
.p(x) = (1-x)^2 = x^2 - 2x + 1
results in the derivative of the geometric seriesf(x) = 1 + 2x + 3x^2 + 4x^3 + ...
, so the output forN
isN+1
.p(x) = 1 - x - x^2
results in the generating function of the Fibonacci sequencef(x) = 1 + x + 2x^2 + 3x^3 + 5x^4 + 8x^5 + 13x^6 + ...
p(x) = 1 - x^2
results in the generating function of1,0,1,0,...
i.e.f(x) = 1 + x^2 + x^4 + x^6 + ...
p(x) = (1 - x)^3 = 1 -3x + 3x^2 - x^3
results in the generating function of the triangular numbersf(x) = 1 + 3x + 6x^6 + 10x^3 + 15x^4 + 21x^5 + ...
that means theN
-th coefficient is the binomial coefficient(N+2, N)
p(x) = (x - 3)^2 + (x - 2)^3 = 1 + 6x - 5x^2 + x^3
results inf(x) = 1 - 6x + 41x^2 - 277x^3 + 1873x4 - 12664x^5 + 85626x^6 - 57849x^7 + ...
Would it be acceptable to take a polynomial as an infinite list of power-series coefficients like
[1,-1,0,0,0,0,...]
? – xnor – 2017-01-01T21:48:33.380Yes, I think that this is an acceptable format. – flawr – 2017-01-01T21:54:19.650
Nice examples chosen! – Greg Martin – 2017-01-01T22:02:37.703
I'm glad you appreciate it, thank you=) – flawr – 2017-01-02T12:38:08.283