# Replace coefficient list with new coefficient list

I would like to replace all the coefficients with new conditions in a list that I specify.

For example, suppose I have the polynomial $a_1 x + a_2 x^2$.

p = a1 x + a2 x^2;
CoefficientList[p,x]


Returns the list {0,a1,a2}. I would like to replace this list from the greek alphabet ($\alpha, \beta, \gamma, \dots$) such that in this case it replaces the old coefficients with {0, $\alpha, \beta$}.

EDIT:

In general the polynomial occurs with differences between polynomials and so I end up with (a1 + b1 + c1)x + (a2 + b2 + c2)x^2. I would still like to be able to replace this as $\alpha x + \beta x^2$.

• what would be desired result for the input p1 = 3 + a1 x +2 x^2+ a2 x^3? – kglr Apr 5 '18 at 16:57
• I would want it to become $p1 = 3 + \alpha x + \beta x^2 + \gamma x^3$ – Gregory Apr 5 '18 at 18:14
• No matter what will be the structure of the coeffs, it they are constant ,i.e., independent of other variables, the current answers will be helpful... – José Antonio Díaz Navas Apr 5 '18 at 18:51
• @JoséAntonioDíazNavas, which one in particular. I tried working with kglr's answer and greekCoeffList[(a1 - b1) x + a2 x^2] returns {$\beta, \epsilon, \zeta$}, where it should return {0, $\alpha, \beta$} – Gregory Apr 5 '18 at 19:06
• Oh, So others except that from @kglr ;)), however, I am sure he/she correct it soon, after your comment.. – José Antonio Díaz Navas Apr 5 '18 at 19:08

ClearAll[greekCoeffList]
greekCoeffList = Module[{cl = CoefficientList[#, x]},
cl[[2 ;;]] = Symbol /@ FromCharacterCode /@ Range[945, 945 + Length[cl] - 2]; cl] &;


Examples:

cl2 = greekCoeffList[a1 x + a2 x^2]


{0, α, β}

Expand @ FromDigits[Reverse @ cl2, x]


x α + x^2 β

cl2 = greekCoeffList[(a1 + a2) x + (b1 - b2) x^2]


{0, α, β}

Expand @ FromDigits[Reverse @ cl2, x]


x α + x^2 β

cl2 = greekCoeffList[3 + a1 x + 5 x^2 + a2 x^3]


{3, α, β, γ}

Expand @ FromDigits[Reverse @ cl2, x]


3 + x α + x^2 β + x^3 γ

• This module seems to get confused if for example I have (a1 + a2) x + (b1 - b2) x^2 – Gregory Apr 5 '18 at 18:09
• I updated my question to reflect this. – Gregory Apr 5 '18 at 18:21
• @Gregory, please see the updated version. – kglr Apr 5 '18 at 19:44

Well, assuming that the number of your coefficients is less than the number of Greek alphabet letters:

p = a1 x + a2 x^2;
oldcoef = CoefficientList[p, x];
newcoef = Join[{First@oldcoef}, Take[EntityValue[Entity["Alphabet", "Greek::33sff"],
EntityProperty["Alphabet", "CommonAlphabet"]], Length[oldcoef] - 1]]


$$\{0,\alpha ,\beta \}$$

so:

FromDigits[Reverse@newcoef, x]


$$\beta x^2+\alpha x$$

If you need more letters, just add to the list more characters corresponding to other languages, or those in uppercase style of the Greek language:

EntityValue[Entity["Alphabet", "Greek::33sff"],
EntityProperty["Alphabet", "CommonAlphabetUpper"]]


$$\{A,B,\Gamma ,\Delta ,E,Z,H,\Theta ,I,K,\Lambda ,M,N,\Xi ,O,\Pi ,P,\Sigma ,T,\Upsilon ,\Phi ,X,\Psi ,\Omega \}$$

Treating the constant special makes things a bit messy..

 (MapIndexed[
Boole[# =!= 0] x^(#2[] - 1) FromCharacterCode[943 + #2[]] &,
CoefficientList[#, x]  ] /.
FromCharacterCode -> Coefficient[#, x, 0] // Total) &@
(3 + 2 x + 3 x^5) 