So I want to do a sum of the form $p+q$ where both are vectors, however, I know the components of $p$ but not of $q$ (as I will be integrating over it eventually). I have tried setting $q=(q_1,q_2,q_3)$ however then the output is very messy and it would be much nice to be able to collect terms in powers of $q^2, q.p$ etc

Is there any way to do this?

  • $\begingroup$ Have you seen TranslationTransform[]? $\endgroup$ Feb 6, 2021 at 21:29
  • 1
    $\begingroup$ Mathematica is "an infinite evaluation system." That means it will keep trying to apply every operator and function until there is nothing left it can do. But what you want is for it to not do that to q^2 and q.p, etc. You can try to use Mathematica as a word processor, where you control exactly what it displays, but it will fight you every way it can. You can try things like Hold and HoldForm and see if you can restrict it from doing what it desperately wants to do. But either of those will likely not be what you want, which is a "Do what I mean" button. $\endgroup$
    – Bill
    Feb 6, 2021 at 21:30

1 Answer 1


You could make use of the built in operator CenterDot which has no properties assigned yet (you can either type it in as a function, or hit ESC then . then ESC to get the operator form), and provide properties such as:

SetAttributes[CenterDot, Orderless]
CenterDot[x_ + y_, z_] := CenterDot[x, z] + CenterDot[y, z]
CenterDot[z_, x_ + y_] := CenterDot[z, x] + CenterDot[z, y]
CenterDot[y___, c_ vec[x_], z___] := c CenterDot[y, vec[x], z]

Then a calculation could look something like

    CenterDot[(a vec[p] + b vec[q] + c vec[w]), (d vec[p] + e vec[q] + f vec[w])]
, CenterDot[x_, y_]]

enter image description here

Finally, if you want to evaluate the vector product numerically, you can get rid of the CenterDot construct by using the substitution rule

rule = {CenterDot[vec[x_],vec[y_]]->x.y};

Let's say your numerical vectors for p and q are actually

P = {1,2,3};
Q = {4,5,6};

Then we get by substituting the rule and vector values above

CenterDot[vec[p],vec[q]] /.rule /.p->P /.q->Q


as expected.


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.