Skip to main content
1 of 2
Somos
  • 5.1k
  • 1
  • 10
  • 16

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
Somos
  • 5.1k
  • 1
  • 10
  • 16