# Noncommutative multiply- expand expression

I began to use Mathematica a few days ago. My problem is: how do I expand expressions like $(a+b)\ast(a+b)$, where the multiplication is noncommutative? Can Mathematica do this?

• Maybe Distribute[(a + b) ** (a + b) ] ? Apr 10, 2013 at 17:02
• Look here for some more thoughts about non commutative multiplication and more ... Apr 10, 2013 at 18:08

Distribute[] is a useful thing:

Distribute[(a + b) ** (c + d)]
a ** c + a ** d + b ** c + b ** d

• Although this works on the example used by jon, it doesn't really answer the question satisfactorily (although the question was vague). For instance, it does not work on Distribute[a.(c + d)/2]. Feb 29, 2020 at 13:55
• @Jess, yes, that case is a little problematic.OTOH, a rearrangement of that expression, along with using the second and third arguments of Distribute[] succeeds: Distribute[(a/2).(c + d), Plus, Dot] Mar 2, 2020 at 5:38
• I mean, ok, but the whole point of this is to avoid re-arranging the expressions by hand, because the cases when you really want to use this are when you have 30 terms. Mar 2, 2020 at 11:32
• It doesn't work for expression with sum. For example Distribute[(a + b) ** (c + d) + a ** (b + d)]
– dtn
May 19 at 4:18
• @dtn, indeed, so one has to use /. in such cases, e.g. (a + b) ** (c + d) + a ** (b + d) /. nc_NonCommutativeMultiply :> Distribute[nc]. May 19 at 12:04

The package NCAlgebra does exactly what you want.

NCExpand[(a + b) ** (a + b)]
(* a ** a + a ** b + b ** a + b ** b *)