7
$\begingroup$

Not related to question

I assume this question (as it is of very general structure) might have been asked before, unfortunately I did not find an answer to it - despite what I used as search queries. If it already has been answered a reference is greatly appreciated.


Question

Assume a cross product is calculated as in

Cross[{d, e, f}, {a, b, c}]
(* Out: {c e - b f, -c d + a f, b d - a e} *).

Then MMA uses the commutative properties, i.e. $ec = c e$, to simplify the result. Though, my variables are not commutative implying that $ec \neq ce$ holds. I already know about NonCommutativeMultiply but do not see a possibility to include it here. How is it possible to ensure that the exact order is preserved for (repeated) applications of Cross to vectors/List objects?


Sense of this question

For all of you who are astonished why the heck anybody wants to preserve the order in cross multiplication: The variables are physical operators in reality such that $AB = BA + [A,B]$ where $[.,.]$ means the commutator. Thus, not changing the multiplication order ensures my results are also valid for noncommuting operators $A,B$.

$\endgroup$

1 Answer 1

7
$\begingroup$

It's handy to use a wrapper for things like vectors with nonstandard properties. So, choose a name like ncVec for your non-commutative vectors. Define its behavior in an upvalue:

Cross[ncVec[x_, y_, z_], ncVec[u_, v_, w_]] ^:= 
 ncVec[y ** w - z ** v, -x ** w + z ** u, x ** v - y ** u]

Cross[ncVec[d, e, f], ncVec[a, b, c]]
(* ncVec[e ** c - f ** b, -d ** c + f ** a, d ** b - e ** a] *)

And, of course, you may then define more special behaviors with additional upvalues.

$\endgroup$
1
  • 1
    $\begingroup$ Elegant and simple. Exactly what I was looking for. $\endgroup$
    – pbx
    Jun 20, 2017 at 12:39

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.