When you make a Dot[a,(a+b+c)] the output will be:

a.(a + b + c)

I want to make a function that expands the dot product, for the previous example would be:

a^2 + a.b + a.c

I don't have much knowledge about pure function. I start to create the function as following:

DotExpand[Dot[l_, r_]] := Map[Times[#, #] &, {l, r}]

In[36]:= DotExpand[(a + b + c).a]

Out[36]= {(a + b + c)^2, a^2}

As you see, is not working. What I have do modify to works?

  • $\begingroup$ seeTensorExpand? $\endgroup$ – kglr Jan 31 '19 at 15:02
  • $\begingroup$ Ok, but if I want to create my own TensorExpand, some like a DotExpand? $\endgroup$ – Mateus Jan 31 '19 at 15:59
  • $\begingroup$ Replace the first line by Apply[Times[#1, #2] &, {l, r}]; $\endgroup$ – Wen Chern Jan 31 '19 at 16:08
  • $\begingroup$ The output still the same @WenChern if I use Dot: a (a + b + c) $\endgroup$ – Mateus Jan 31 '19 at 16:52

Not sure, are you looking for something using Distribute?


For example,


a.a + a.b + a.c


a.b + a.c + b.b + b.c


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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