5
f1 = a x^2 + b x + c + x^3

(* a x^2+b x+c+x^3 *)

f1 /. x -> (x - a/3) // Expand

(* (2 a^3)/27-(a^2 x)/3-(a b)/3+b x+c+x^3 *)

I've tried this:

f1 /. x -> (x - a/3) // Expand // Collect[#, x] &

(* (2 a^3)/27+x (b-a^2/3)-(a b)/3+c+x^3 *)

f1 /. x -> (x - a/3) // Expand // Collect[#, x] & // PolynomialForm

(* (2 a^3)/27-(b a)/3+x^3+c+(b-a^2/3) x *)

integer
  • 93
  • 5

2 Answers2

8

Try this formatting

OrderedForm[x_] := HoldForm[+##] & @@ (x^#1[[1]] #2 & @@@ CoefficientRules[#, x]) &;

f1 /. x -> (x - a/3) // OrderedForm[x]
x^3+(-(a^2/3)+b) x+((2 a^3)/27-(a b)/3+c)

See also my answer here.

ybeltukov
  • 43,673
  • 5
  • 108
  • 212
3

The OP almost had it with attempting to use PolynomialForm[]. All that was missing is the use of an appropriate setting:

PolynomialForm[a x^2 + b x + c + x^3 /. x -> (x - a/3), 
               TraditionalOrder -> True]
   (x - a/3)^3 + a (x - a/3)^2 + b (x - a/3) + c

As is usual with *Form[] functions, this is only suitable for display/pretty printing.

J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574