# Defining Quaternions

According to the documentation online, we can use the following command to load the Quaternion package.

<< Quaternions 

It is clear that the pakage uses left handed quaternions for all its quaternion algebra. Is it possible to define the explicitly right handed quaternions in mathematica and thereby use algebra like multiplication, conjugates etc. ?

For eg.  Quaternion[2, 0, -6, 3] ** Quaternion[1, 3, -2, 2] results in a different value depending on whether the defined quaternions are left or right handed.

P.S: I know that I can manually shuffle the last element to convert a right quaternion to a left quaternion. I was just wondering whether it is possible with the help of definion in mathematica itself.

• Just curious, as just yesterday I became aware of the work mathematican, Chole Furey, has undertaken in relating quaternions and octonions to the Standard Model of particle physics (see: furey.space). I'd love to know what has brought you to quaternions and what you want to do with them. Also raises the question about how this stuff might relate to the Wolfram Physics Project. I know I've gone a bit off-topic but this seems like very interesting stuff. Jul 21, 2022 at 22:24
• I am trying to understand flexible mechanisms in outer space. They often encounter large displacements/strains which may be prone to gimbal lock in case of the very friendly SO(3) group of matrices. Jul 21, 2022 at 23:02
• Interesting. Thanks. Jul 21, 2022 at 23:58

OP wants another version of the quaternions that I denote myQuaternion that are related to the usual Quaternion by a change of basis given by some invertible real $$4 \times 4$$ matrix M. In the code below, one can adjust M.

Definition.

<<Quaternions

(* fix the invertible real 4 x 4 matrix you want
the one I use here is just an example *)
M=DiagonalMatrix[{1,1,1,-1}];
invM=Inverse[M];

(* change of basis from and to usual Quaternion *)
iso[myQuaternion[a__]]:=Quaternion@@(M.{a});
invIso[Quaternion[a__]]:=myQuaternion@@(invM.{a});

(* define multiplication and conjugation *)
myQuaternion/:(a_myQuaternion)**(b_myQuaternion):=invIso[iso[a]**iso[b]];
myQuaternion/:Conjugate[a_myQuaternion]:=invIso[Conjugate[iso[a]]];


One can add more operations if required. If one uses something like this more regularly, one should put it into a dedicated package, see also here, with only myQuaternion public.

Usage.

myQuaternion[2,0,-6,3]**myQuaternion[1,3,-2,2]
(* myQuaternion[-16,12,-19,-11] *)

Conjugate[myQuaternion[12,3,-1,3]]
(* myQuaternion[12,-3,1,-3] *)


Comment. The myQuaternion/: is used above to define an upvalue, which allows us to get the desired behavior without modifying the built-in functions ** and Conjugate.

• That's exactly what I wanted to know! Thank you @user293787 ! Jul 22, 2022 at 18:25