3
$\begingroup$

I'd like to give my students a little visualization of the fact: $$x^n-a^n=(x-a)(x^{n-1}+x^{n-2}a+\cdots+x a^{n-2}+a^{n-1})$$

So, I've tried:

list = Table[PolynomialQuotient[x^n - a^n, x - a, x], {n, 2, 12}];
Column[list] // TraditionalForm

Which gave me the following output.

a+x
a^2+a x+x^2
a^3+a^2 x+a x^2+x^3
a^4+a^3 x+a^2 x^2+a x^3+x^4
a^5+a^4 x+a^3 x^2+a^2 x^3+a x^4+x^5
a^6+a^5 x+a^4 x^2+a^3 x^3+a^2 x^4+a x^5+x^6
a^7+a^6 x+a^5 x^2+a^4 x^3+a^3 x^4+a^2 x^5+a x^6+x^7
a^8+a^7 x+a^6 x^2+a^5 x^3+a^4 x^4+a^3 x^5+a^2 x^6+a x^7+x^8
a^9+a^8 x+a^7 x^2+a^6 x^3+a^5 x^4+a^4 x^5+a^3 x^6+a^2 x^7+a x^8+x^9
a^10+a^9 x+a^8 x^2+a^7 x^3+a^6 x^4+a^5 x^5+a^4 x^6+a^3 x^7+a^2 x^8+a x^9+x^10
a^11+a^10 x+a^9 x^2+a^8 x^3+a^7 x^4+a^6 x^5+a^5 x^6+a^4 x^7+a^3 x^8+a^2 x^9+a x^10+x^11

Is there a way I can put the x's before the a's, for example, arranging $$a+x\qquad\text{as}\qquad x+a,$$ and $$a^2+ax+x^2\qquad\text{as}\qquad x^2+xa+a^2,$$ etc.?

$\endgroup$
1
  • 1
    $\begingroup$ Some related Q&A: (33130), (37339) -- The solution to the second might work here. $\endgroup$
    – Michael E2
    Jan 8, 2016 at 19:14

1 Answer 1

2
$\begingroup$

Disclaimer: Doesn't work with TraditionalForm

list = Table[PolynomialQuotient[x^n - a^n, x - a, x], {n, 2, 12}];

ClearAttributes[{Plus, Times}, Orderless]

list /.
   {h_[a, x] :> h[x, a],
    t : Times[Power[a, i_], Power[x, j_]] :> Reverse@t,
    t : Times[a, Power[x, j_]] :> Reverse@t,
    t : Times[Power[a, i_], x] :> Reverse@t} /.
    Plus[a : Power[a, i_], b__, c : Power[x, j_]] :> Plus[c, b, a] // Column  

enter image description here

Don't forget

SetAttributes[{Plus, Times}, Orderless]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.