# How to find the basis functions of a polynomial?

For example, if I have,

e = a0 + a1 x + a2 (-x + x^2) + a3(-x + x^3) + .... + an (-x + x^n)


how do I find and list

{x, (-x + x^2), ..., (-x + x^n)}?

I tried

Coefficient[e, a[i], {i, 0, 10}]


where, n = 10. It shows some error. Please help.

• Basis with respect to what notion of independence? Commented Jul 5, 2017 at 18:01

e = a0 + a1 x + a2 (-x + x^2) + a3 (-x + x^3) + an (-x + x^n);

Cases[List @@ e, a_ b_ /; (FreeQ[a, x] && Not[FreeQ[b, x]]) :> b]


{x, -x + x^2, -x + x^3, -x + x^n}

Or

rule = Alternatives @@ Select[Variables[e], FreeQ[#, x] &] -> 1;
Rest[List @@ e /. rule]


{x, -x + x^2, -x + x^3, -x + x^n}

• Since "The first argument to Cases need not have head List", you can use Cases[e, a_ b_ /; (FreeQ[a, x] && Not[FreeQ[b, x]]) :> b] Commented Nov 2, 2017 at 12:06
coef = Table[a[i], {i, 0, 10}];
e = coef.Table[If[i >= 2, x^i - x, x^i], {i, 0, 10}];

Reap[Collect[e, coef, Sow]][[2, 1]]
(* or *)
Reap[Collect[e, Complement[Variables[e], {x}], Sow]][[2, 1]]

{1, x, -x + x^2, -x + x^3, -x + x^4, -x + x^5, -x + x^6, -x + x^7, -x + x^8, -x + x^9, -x + x^10}


Did you forget 1` when writing the desired output or shouldn't it be there?