# What is the inverse of CoefficientList?

I have numbers in vector notation. I need to get polynomial notation from them.

My numbers are {0, 1, 23, 5, 15, 0, 0, 0}. I want to get x + 23x^2 + 5x^3 + 15x^4 from this list.

How can I get that polynomial?

-
Thanks for your help. –  Serkan Mar 31 '13 at 4:00
Related question: mathematica.stackexchange.com/questions/21340/… –  Michael E2 Mar 31 '13 at 18:37

One straightforward approach is to calculate the answer directly:

Total[{0, 1, 23, 5, 15, 0, 0, 0} x^(Range[8] - 1)]

-

The following (taken from the Mathematica documentation) will do what you ask.

Expand[FromDigits[Reverse[{0, 1, 23, 5, 15, 0, 0, 0}], x]]


x + 23 x^2 + 5 x^3 + 15 x^4

I found the needed code in Properties & Relations section of the documentation page on CoefficientList. In general, it is a good idea to look for information on inverses in the Properties & Relations section of any function of interest.

-
m_goldberg, would you join me in Chat? –  Mr.Wizard Apr 1 '13 at 4:04

Dot can be very efficient here:

c.(x^Range[0, Length@c - 1])

x + 23 x^2 + 5 x^3 + 15 x^4


Comparative timings:

n = 5000;
c = RandomInteger[30, n];

SetAttributes[timeAvg, HoldFirst]
timeAvg[func_] := Do[If[# > 0.3, Return[#/5^i]] & @@ Timing@Do[func, {5^i}], {i, 0, 15}]

Expand @ FromDigits[Reverse@c, x] // timeAvg
Total[c * x^(Range@n - 1)] // timeAvg
MapIndexed[#1*x^(#2 - 1) &, c] // Total // timeAvg
c.(x^Range[0, n - 1]) // timeAvg


0.03616

0.004992

0.01744

0.003616

I also like this formulation though it is not quite as fast:

c.Array[x^# &, n, 0]

-
MapIndexed[#1*x^(#2 - 1) &, {0, 1, 23, 5, 15, 0, 0, 0}] // Total