# Evaluating standard functions of general quaternions symbolically

Mathematica can easily compute exponentials and logarithms of concrete quaternions:

Needs["Quaternions"]

Exp[Quaternion[1.3, 3.5, -0.7, 0.9]]
Log[Quaternion[1.3, 3.5, -0.7, 0.9]]

Quaternion[-3.14824, -1.79206, 0.358412, -0.460816]

Quaternion[1.36196, 1.17075, -0.23415, 0.301051]


Even for exact numbers:

Exp[Quaternion[1, 3, 7/2, -5]]

Quaternion[E Cos[Sqrt/2], (6 E Sin[Sqrt/2])/Sqrt,
(7 E Sin[Sqrt/2])/Sqrt, -2 Sqrt[5/37] E Sin[Sqrt/2]]


But it seems to be unable to expand this for the general quaternion:

Exp[Quaternion[a, b, c, d]]

E^Quaternion[a, b, c, d]


I've tried using Simplify, FunctionExpand, ToQuaternion on this, but still it doesn't give a Quaternion object. But there exists a closed form for such functions.

I can, of course, define such functions myself, like:

exp[q_] = With[{v = q - Re[q]}, Exp[Re[q]] (Cos[Abs[v]] + v/Abs[v] Sin[Abs[v]]) ];
ln[q_] = Log[Abs[q]] + (q - Re[q])/AbsIJK[q] ArcCos[Re[q]/Abs[q]];


But is there a way to get Mathematica itself expand these functions of general quaternions, without me having to redefine them all?

The reason for the behavior you were seeing can be seen if you look through the definitions within the package. In particular, the extended elementary functions are defined with a format like func[a:Quaternion[__?ScalarQ]] := (* stuff *) where ScalarQ[] is a private package function that checks if the stuff within the Quaternion[] object are real numbers. Since the components of Quaternion[a, b, c, d] are manifestly not real (in the sense of not satisfying ScalarQ[]`), the formulae within are not applied to your symbolic quaternion.