Hi Marc,
this is a bug
In[1]:= Needs["Quaternions`"]
In[2]:= Quaternion[1, 2, 0, 1]^2.5
Out[2]= Quaternion[-9.0604, 2.20741, 0., 1.1037]
In[3]:= QuaternionQ[(Quaternion[1, 2, 0, 1]^(2.5))^(2.5)]
Out[3]= False
but, normally, if one speaks about
the root of a number, one
has to mean the principal root (cmp. http://mathworld.wolfram.com/PrincipalSquareRoot.html).
This seems to be implemented in the Quaternions package
In[4]:= (Quaternion[1, 2, 0, 1]^(1/2))^(5) // N
Out[4]= Quaternion[-9.0604, 2.20741, 0., 1.1037]
In[5]:= (Quaternion[1, 2, 0, 1]^5)^(1/2) // N
Out[5]= Quaternion[9.0604, -2.20741, 0., -1.1037]
try
Quaternion[1,2,0,1]^(1/n) // N
for integers n. Therefore one has simply to modify the rules for Power in the package
Quaternion[a,b,c,d]^(p/q) => (Quaternion[a,b,c,d]^p)^(1/q)
adding to the original ones
(* *************** Rules for Power *************** *)
(* Power is essentially de Moivre's theorem for quaternions. *)
Quaternion /:
Power[a:Quaternion[__?ScalarQ],0]:= 1
Quaternion /:
Power[a:Quaternion[__?ScalarQ],n_]:= Power[1/a, -n] /; n < 0 && n != -1
Quaternion /:
Power[a:Quaternion[__?ScalarQ],-1]:= Conjugate[a] ** 1/Norm[a]
Quaternion /:
Power[a:Quaternion[__?ScalarQ], n_]:=
Module[{angle, pqradius},
angle = toAngle[a];
pqradius = angle[[2]]^n Sin[n angle[[3]]];
Quaternion[
angle[[2]]^n Cos[n angle[[3]]],
Cos[angle[[4]]] pqradius,
Sin[angle[[4]]] Cos[angle[[5]]] pqradius,
Sin[angle[[4]]] Sin[angle[[5]]] pqradius
] // QSimplify
] /; ScalarQ[n] && n > 0
one more rule and modifying another one
(* *************** Rules for Power *************** *)
(* Power is essentially de Moivre's theorem for quaternions. *)
Quaternion /:
Power[a:Quaternion[__?ScalarQ],0]:= 1
Quaternion /:
Power[a:Quaternion[__?ScalarQ],n_]:= Power[1/a, -n] /; n < 0 && n != -1
Quaternion /:
Power[a:Quaternion[__?ScalarQ],-1]:= Conjugate[a] ** 1/Norm[a]
Quaternion /:
Power[a:Quaternion[__?ScalarQ], n_]:=
Module[{angle, pqradius, r},
angle = toAngle[a];
pqradius = angle[[2]]^n Sin[n angle[[3]]];
Quaternion[
angle[[2]]^n Cos[n angle[[3]]],
Cos[angle[[4]]] pqradius,
Sin[angle[[4]]] Cos[angle[[5]]] pqradius,
Sin[angle[[4]]] Sin[angle[[5]]] pqradius
] // QSimplify
] /; ScalarQ[n] && (Numerator[Rationalize[n]]==1 || Denominator[Rationalize[n]]==1)
Quaternion /:
Power[a:Quaternion[__?ScalarQ], n_]:=Block[{r=Rationalize[n], y},
y=If[Element[n,Rationals],1,1.,1.];
Power[Power[a,Numerator[r]],y/Denominator[r]]
] /; ScalarQ[n] && n > 0
finally (after restarting Mma and reloading the package) arriving at
In[1]:= Needs["Quaternions`"]
In[2]:= Quaternion[1, 2, 0, 1]^2.5
Out[2]= Quaternion[9.0604, -2.20741, 0., -1.1037]
In[3]:= (Quaternion[1, 2, 0, 1]^2.5)^(2.5)
Out[3]= Quaternion[212.669, -149.11, 4.56519*10^-15, -74.5552]
In[6]:= QuaternionQ[(Quaternion[1, 2, 0, 1]^2.5)^(2.5)]
Out[6]= True
be aware that the arithmetics of quaternions is not too similar to the arithmetics of complex numbers. For example there is a continuum of square roots
of -1 in the skew field of quaternions showing another weakness of the Quaternions package
In[4]:= Sqrt[Quaternion[-1, 0, 0, 0]]
During evaluation of In[4]:= Power::infy: Infinite expression 1/0 encountered. >>
During evaluation of In[4]:= Infinity::indet: Indeterminate expression 0 ComplexInfinity encountered. >>
Out[4]= Quaternion[Sqrt[\[Pi]/2], 0, Indeterminate, Indeterminate]
Compare this to the well-known
In[5]:= Sqrt[-1]
Out[5]= I
again, note that it says I, not -I ...
Regards
Udo.