Message Boards Message Boards

0
|
7963 Views
|
6 Replies
|
2 Total Likes
View groups...
Share
Share this post:

Bug in the Quaternions package?

Posted 8 years ago

Using the Quaternions package, one would expect Exp[Quaternion[1, 0, 0, 0]] to be $e$.

But Mathematica gives

 In[3]:= Exp[Quaternion[1, 0, 0, 0]]

During evaluation of In[3]:= Power::infy: Infinite expression 1/0 encountered. >>

During evaluation of In[3]:= Power::infy: Infinite expression 1/0 encountered. >>

During evaluation of In[3]:= Power::infy: Infinite expression 1/0 encountered. >>

During evaluation of In[3]:= General::stop: Further output of Power::infy will be suppressed during this calculation. >>

During evaluation of In[3]:= $RecursionLimit::reclim: Recursion depth of 1024 exceeded. >>

During evaluation of In[3]:= $RecursionLimit::reclim: Recursion depth of 1024 exceeded. >>

During evaluation of In[3]:= $RecursionLimit::reclim: Recursion depth of 1024 exceeded. >>

During evaluation of In[3]:= General::stop: Further output of $RecursionLimit::reclim will be suppressed during this calculation. >>

During evaluation of In[3]:= $IterationLimit::itlim: Iteration limit of 4096 exceeded. >>

During evaluation of In[3]:= Infinity::indet: Indeterminate expression 0 ComplexInfinity encountered. >>

Out[3]= Indeterminate

Does anyone have a solution?

POSTED BY: Josef Dvo?ák
6 Replies

The package quaternion Norm[] isn't right either.

I'm using a mobile browser, so I don't dare try to format an example, but it's easily checked.

Sorry.

Fred

POSTED BY: Fred Klingener
Posted 8 years ago

Adding a quaternion Log function that works also when first nonzero element of vector part is negative.

Input and output quaternions are represented as lists.

quatLog[q : {q0_, q1_, q2_, q3_}] := With[
  {qV = {q1, q2, q3}},
  If[And[VectorQ[q, NumericQ], N@Norm[q] == 1],
    Flatten@{0, Normalize[qV] ArcCos[q0]},
    Simplify@Flatten@{Log@Norm[q], Normalize[qV] ArcCos[q0/Norm[q]]}
  ]
]
POSTED BY: Hans Milton
Posted 8 years ago

Another odd thing. Raising e to an unnormalized quaternion, and then taking the logarithm does not return the original.

Normalized, OK:

Log@Exp@Quaternion[0.5, 0.5, 0.5, 0.5]

Quaternion[0.5, 0.5, 0.5, 0.5]

Unnormalized:

Log@Exp@Quaternion[1., 2., 3., 4.]

Quaternion[1., 0.333516, 0.500275, 0.667033]

EDIT: This does not happen with all unnormalized quaternions. Only with those that has the norm of vector part > $\pi$. Same behavior as for complex numbers, when absolute value of the imaginary part is > $\pi$:

Log@Exp[1. + 3. I]
1. + 3. I

Log@Exp[1. + 3.5 I]
1. - 2.78319 I

So this is not so odd after all. The reason is that the logarithm of quaternions is multivalued. As it is for complex numbers.

POSTED BY: Hans Milton
Posted 8 years ago

Came across another issue with the Quaternions package. Taking the logarithm of a quaternion and then raising e to the log should return the original quaternion. But that is not always the case.

These works as expected:

Needs@"Quaternions`"

Exp@Log@Quaternion[1., 2., 3., 4.]
Exp@Log@Quaternion[1., 2., -3., 4.]

Quaternion[1., 2., 3., 4.]
Quaternion[1., 2., -3., 4.]

But not these:

Exp@Log@Quaternion[1., -2., 3., 4.]
Exp@Log@Quaternion[1., 0., -3., 4.]

Quaternion[1., 2., -3., -4.]
Quaternion[1., 0., 3., -4.]

The problem occurs when the first nonzero element of the vector part (= last 3 elements) is negative.

POSTED BY: Hans Milton
Posted 8 years ago

An alternative quaternion Exp function. Where the input quaternion is given as a list. The output is also a quaternion list.

quatExp[{q0_, q1_, q2_, q3_}] := With[
  {qV = {q1, q2, q3}},
  Flatten[E^q0 {Cos[Norm@qV], Normalize[qV] Sin[Norm@qV]}]
]

enter image description here

POSTED BY: Hans Milton
Posted 8 years ago

The failure is due to a faulty definition of Sign[] for Quaternion[] objects. To fix this, you'll need to edit the package yourself. Find the line

Quaternion /:
    Sign[a:Quaternion[__?ScalarQ]]:= a / Abs[a]

in the package, and replace it with

Quaternion /:
    Sign[a:Quaternion[__?ScalarQ]]:= With[{d = Abs[a]}, If[d != 0, a / d, 0]]
POSTED BY: J. M.
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract