# Working with abstract vectors

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]]


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. • 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 Jun 6 '14 at 20:57 • Plus, post code, not images as it is easier to experiment with it. Jun 6 '14 at 21:07 • Take a look here How to declare a 3D vector variable? Jun 6 '14 at 21:13 • @Artes: I have updated my question. Jun 6 '14 at 22:14 • How about D[V[t]/Sqrt[Dot[V[t], V[t]]], t] /. Dot[a_, b_] :> Dot[b, a] /; LeafCount[a] < LeafCount[b] Oct 10 '14 at 18:44 ## 3 Answers 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}}$

Unprotect[Dot];
SetAttributes[Dot, Orderless]
Protect[Dot]


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

• that did it, thank you. I am curious about when Dot might ever be order-dependent? (it strikes me as an odd default) Jan 18 '15 at 20:51
• 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
– k_v
Jan 19 '15 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]


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]

• 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. Nov 16 '14 at 15:59
• 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] Nov 17 '14 at 2:08