I often need to compute derivatives or integrals involving N-dimensional vectors (where the dimension could be equal to 2 or 3 but is not particularly relevant for the sake of the derivation). The only way I know to translate this into valid Mathematica input is to specialize to a particular N and define all quantities component-wise.

A simple example: computing the time derivative of a normalized quantity

V[t_] := {x[t], y[t], z[t]}
Simplify[D[V[t]/Sqrt[Dot[V[t], V[t]]], t]]

Time derivative of a normalized quantity

While correct, this can obviously get extremely messy fast. At that point, I find it easier to just do the computation by hand using generic vector calculus identities which work for vectors of any dimension.

I was wondering if there is a way of doing such computations using an abstract vector type? This post references a Vectors command that is potentially related, but it was not clear to me how to use it for calculus.

Edit: After some more experimentation with Vectors, I was able to get quite close to what I was looking for:

$Assumptions = V[t] \[Element] Vectors[3, Reals];
Simplify[D[V[t]/Sqrt[Dot[V[t], V[t]]], t]]

$$\frac{2 V(t).V(t) V'(t)-V(t) \left(V(t).V'(t)+V'(t).V(t)\right)}{2 (V(t).V(t))^{3/2}}$$

However, neither Simplify[] nor TensorReduce[] could simplify the commutative dot product in the expression above.

  • 2
    $\begingroup$ There may be different levels of “abstract” in “abstract vectors”. I'd say they are not “abstract” if kept in coordinate-based form {x@t, y@t, z@t}. Things will probably always get messy unless you use coordinate-free approach, or at least abstract indices. en.wikipedia.org/wiki/Abstract_index_notation To my knowledge, there is no Mathematica package for the latter (definitely no built-in support); as to the former, you might be interested in this: wolfram.com/products/applications/atlas2 $\endgroup$
    – akater
    Commented Jun 6, 2014 at 20:57
  • $\begingroup$ Plus, post code, not images as it is easier to experiment with it. $\endgroup$
    – Sektor
    Commented Jun 6, 2014 at 21:07
  • 1
    $\begingroup$ Take a look here How to declare a 3D vector variable? $\endgroup$
    – Artes
    Commented Jun 6, 2014 at 21:13
  • $\begingroup$ @Artes: I have updated my question. $\endgroup$ Commented Jun 6, 2014 at 22:14
  • $\begingroup$ How about D[V[t]/Sqrt[Dot[V[t], V[t]]], t] /. Dot[a_, b_] :> Dot[b, a] /; LeafCount[a] < LeafCount[b] $\endgroup$
    – chris
    Commented Oct 10, 2014 at 18:44

3 Answers 3


You need to tell Mathematica that both $V[t]$ and $V'[t]$ are vectors:

$Assumptions = (V[t]|V'[t]) ∈ Vectors[{n}];

TensorReduce @ D[V[t]/Sqrt[V[t] . V[t]], t] //TeXForm

$\frac{V'(t)}{\sqrt{V(t).V(t)}}-\frac{V(t) V(t).V'(t)}{(V(t).V(t))^{3/2}}$

SetAttributes[Dot, Orderless]

then try to evaluate this again

D[V[t]/Sqrt[Dot[V[t], V[t]]], t]

of course it would be better to define new function based on dot and set it attribute Orderless

  • $\begingroup$ that did it, thank you. I am curious about when Dot might ever be order-dependent? (it strikes me as an odd default) $\endgroup$ Commented Jan 18, 2015 at 20:51
  • $\begingroup$ the problem with dot starts if we try to fins the product of matrises. for this case we shoul define new function based on Dot but without Orderless attribute $\endgroup$
    – k_v
    Commented Jan 19, 2015 at 5:13

It seems the simplest way to simplify such expression is to impose sorting based on CountLeaf

D[V[t]/Sqrt[Dot[V[t], V[t]]], t] /.   
     Dot[a_, b_] :>  Dot[b, a] /; LeafCount[a] < LeafCount[b]

Mathematica graphics

so that for instance the longest expression is always last. This is not bulletproof but it seems to do the trick on your example(?)

In order to deal with equal length cases you could do

(Dot[x, y] - Dot[y, x]) /. 
 Dot[a_, b_] :> Dot[b, a] /; LeafCount[a] < LeafCount[b] /. 
 Dot[a_, b_] :> Dot @@ Sort[{b, a}] /; LeafCount[a] == LeafCount[b]
  • $\begingroup$ Sorry for the delay. This seems fairly specific to this particular example. I was hoping for something more general to tell Mathematica that the dot product arguments commute. $\endgroup$ Commented Nov 16, 2014 at 15:59
  • $\begingroup$ The following e.g. does not work (maybe I am missing something?): (Dot[x, y] - Dot[y, x]) /. Dot[a_, b_] :> Dot[b, a] /; LeafCount[a] < LeafCount[b] $\endgroup$ Commented Nov 17, 2014 at 2:08

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.