Feature of quaternion Cos, Cot etc

I am new to SE Mathematica, and search gives no answer; so here is my problem:

During the testing of my numerical library for quaternions with Mathematica (package Quaternions) I observed the following behavior:

<<Quaternions
a = Quaternion[1, 2, 3, 4]
(* Quaternion[1, 2, 3, 4] *)

b = N[ArcCos[a]]
(* Quaternion[1.390115947, -0.8918751006, -1.337812651, -1.783750201] *)

Cos[b]
(* Quaternion[1., -2., -3., -4.] *)


i.e. the vector part is negated. I can reproduce the result for ArcCos, but my code gives Cos[b] = [1, 2, 3, 4] (also given by the quaternion postfix calculator). This is not a rounding problem, and not limited to this specific quaternion. The same happened for e.g. Cot[ArcCot[a], where as the following is as I would expect:

b = N[ArcSin[a]]
(* Quaternion[0.1806803802, 0.8918751006, 1.337812651, 1.783750201] *)

Sin[b]
(* Quaternion[1., 2., 3., 4.] *)


My first guess was that it is related to branch cuts, but the analog complex functions give the expected result Cos[ArcCos[1 + 2*I]] = 1 + 2*I.

Question: What is the explanation for the negated vector part for some trigonometric quaternion functions like $$\cos$$, $$\cot$$, etc.?

• So what does N@ArcCos@Quaternion[1,-2,-3,-4] yield? Oct 25, 2017 at 17:54
• @lllamnyp: Quaternion[1.390115947,-0.8918751006,-1.337812651,-1.783750201] i.e. the same as ArcCos[a]. Oct 25, 2017 at 18:16
• So then it's clear that arccos prefers that particular branch Oct 25, 2017 at 18:44
• I think something is wrong with AbsIJK. I believe the definition AbsIJK[a_?NumericQ] := Im[a] should be AbsIJK[a_?NumericQ] := Abs[Im[a]], given that's what the other definition of AbsIJK does. I can file an internal report for this. Oct 25, 2017 at 19:11
• @ChipHurst: Honestly I do not know, but it is valid for complex numbers and Mathematica returns FullSimplify[ArcCos[z] + ArcCos[-z]] = Pi but even with your change I get for the essentially complex quaternion a=[1,2,0,0] the value ArcCos[a] + ArcCos[-a]] = [3.141592653589793, 3.057141838961996, 0., 0.] Oct 25, 2017 at 20:02

It does seem to be a matter of branch cut choice. If I use a different definition for quaternionic ArcCos[] (e.g. the definition in Morais et al.'s book):

<<Quaternions

qq = N[Quaternion[1, 2, 3, 4]];

Sign[qq - Re[qq]] ** Log[qq + Exp[Log[qq ** qq - 1]/2]]
Quaternion[-1.39012, 0.891875, 1.33781, 1.78375]


compared with

ArcCos[qq]
Quaternion[1.39012, -0.891875, -1.33781, -1.78375]


the former yields qq when Cos[] is applied to it, while the latter has the behavior shown in the OP.

We have here the amusing conclusion that in general $$\cos q\ne\cos(-q)$$ for quaternionic $$q$$.