# Wrong Output in self defined Quaternionic Multiplication

I tried to define quaternionic multiplication in terms of pairs of complex numbers where I identify $$\mathbb{C}^2$$ with $$\mathbb{H}$$ via $$(z,w)\mapsto z+jw$$. Consequently, I used the multiplication rule

Q /: Q[a_, b_]*Q[c_, d_] :=
Q[a*c - Conjugate[b]*d, Conjugate[a]*d + b*c]


Strangely enough, the input

Q[0, 1]*Q[0, I]


Gives the incorrect output

Q[I, 0]


However, typing

Q[0, 1]*Q[a, I]


Gives the correct output

Q[-I, a]


Does anyone have an idea why this is happening?

Multiplication with * is commutative (technically, Orderless), whereas quaternionic multiplication is not. Because * automatically puts its terms in normal order before multiplying, you sometimes end up with a commuted result. In your case this happens because I comes before 1 in the alphabet, and 0 comes before a, so the two terms are commuted (exchanged) automatically (try Sort[{Q[0, 1], Q[0, I]}] and Sort[{Q[0, 1], Q[a, I]}]).

The solution is to use NonCommutativeMultiply to prevent term reordering:

Q /: Q[a_, b_] ** Q[c_, d_] := Q[a*c - Conjugate[b]*d, Conjugate[a]*d + b*c]

Q[0, 1] ** Q[0, I]
(*    Q[-I, 0]    *)

Q[0, 1] ** Q[a, I]
(*    Q[-I, a]    *)

• Thank you so much!:) – deepfloe Jul 1 at 11:55