0
$\begingroup$

I have been working with non-commuting algebra, which is indicated in Mathematica by **. However, I want to suppress the ** from the output. Consider:

n = 4;    
Sum[Binomial[n, r] b^r ** a^(n - r), {r, 0, n}]

which gives

1 ** a^4 + 4 b ** a^3 + 6 b^2 ** a^2 + 4 b^3 ** a + b^4 ** 1

Note that all b's appear to the left of any a's. This is since they do not commute. Instead of the output above, I want to drop the ** to instead have:

a^4 + 4 b a^3 + 6 b^2 a^2 + 4 b^3 a + b^4

since it is better suited when n becomes large.

$\endgroup$

1 Answer 1

1
$\begingroup$

Perhaps the following code is close to what you want:

With[{n = 4}, Sum[Binomial[n, r] b^r ** a^(n - r), {r, 0, n}]]
  /. {NonCommutativeMultiply -> Dot} // InputForm

with resulting output

1 . a^4 + 4*b . a^3 + 6*b^2 . a^2 + 4*b^3 . a + b^4 . 1

You could use TradtionalForm instead which results in a more compact outuput.

$\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.