Efficient Evaluation of Quaternion Functions

Brian Martin

The Algorithm

This section explains the steps necessary to create simplified functions for each quaternion element of a quaternion function. Operators are assumed to be elements of the set \( \left\{ +,-,*,x^{y}\right\} \), with increasing precedence. Operands are assumed to be operators, literal or variable quaternions, or literal scalars.

Generating formulas for the individual quaternion components

For each scalar quaternion element \( q_{e}\in \left\{ q_{s},q_{a},q_{b},q_{c}\right\} \)we will generate a scalar function \( f_{e}\left( q\right) \) from \( f\left( q\right) \).

To do this we need to process \( f\left( q\right) \) under context \( c\in \left\{ s,a,b,c\right\} \). Let \( C_{e}\left( x\right) \) denote processing expression x under context e. Then \( f_{e}\left( q\right) =C_{e}\left( f\left( q\right) \right) \). Using the following formulations derived from quaternion algebra, we can express \( C_{e}\left( x\right) \) as a function of smaller subproblems for any expression x and context c.

1.
\( C_{e}\left( q\right) =q_{e} \), where q is a quaternion
2.
\( C_{e}\left( s\right) =s \), where s is a scalar
3.
\( C_{e}\left( x+y\right) =C_{e}\left( x\right) +C_{e}\left( y\right) \)
4.
\( C_{e}\left( x-y\right) =C_{e}\left( x\right) -C_{e}\left( y\right) \)
5.
\( C_{s}\left( x*y\right) =C_{s}\left( x\right) *C_{s}\left( y\right) -C_{a}\lef...
...t( x\right) *C_{b}\left( y\right) -C_{c}\left( x\right) *C_{c}\left( y\right) \)
6.
\( C_{a}\left( x*y\right) =C_{a}\left( x\right) *C_{s}\left( y\right) +C_{s}\lef...
...t( x\right) *C_{c}\left( y\right) -C_{c}\left( x\right) *C_{b}\left( y\right) \)
7.
\( C_{b}\left( x*y\right) =C_{b}\left( x\right) *C_{s}\left( y\right) +C_{s}\lef...
...t( x\right) *C_{a}\left( y\right) -C_{a}\left( x\right) *C_{c}\left( y\right) \)
8.
\( C_{c}\left( x*y\right) =C_{c}\left( x\right) *C_{s}\left( y\right) +C_{s}\lef...
...t( x\right) *C_{b}\left( y\right) -C_{b}\left( x\right) *C_{a}\left( y\right) \)
9.
\( C_{e}\left( q^{s}\right) =C_{e}\left( q^{s-1}*q\right) \), \( s\, mod\, 2\equiv 1 \)
10.
\( C_{s}\left( q^{s}\right) =C_{s}\left( q^{\frac{s}{2}}\right) ^{2}-C_{a}\left(...
...{b}\left( q^{\frac{s}{2}}\right) ^{2}-C_{c}\left( q^{\frac{s}{2}}\right) ^{2} \), \( s\, mod\, 2\equiv 0 \)
11.
\( C_{e}\left( q^{s}\right) =2*C_{e}\left( q^{\frac{s}{2}}\right) *C_{s}\left( q^{\frac{s}{2}}\right) \), \( e\in \left\{ a,b,c\right\} \), \( s\, mod\, 2\equiv 0 \)
12.
\( C_{s}\left( s^{q}\right) =s^{C_{a}\left( q\right) }*\left( \begin{array}{c}
\...
...) \right) *\sin \left( \ln s*C_{d}\left( q\right) \right)
\end{array}\right) \)
13.
\( C_{a}\left( s^{q}\right) =s^{C_{a}\left( q\right) }*\left( \begin{array}{c}
\...
...) \right) *\cos \left( \ln s*C_{d}\left( q\right) \right)
\end{array}\right) \)
14.
\( C_{b}\left( s^{q}\right) =s^{C_{a}\left( q\right) }*\left( \begin{array}{c}
\...
...) \right) *\sin \left( \ln s*C_{d}\left( q\right) \right)
\end{array}\right) \)
15.
\( C_{c}\left( s^{q}\right) =s^{C_{a}\left( q\right) }*\left( \begin{array}{c}
\...
...) \right) *\cos \left( \ln s*C_{d}\left( q\right) \right)
\end{array}\right) \)

Tabluating results

To avoid recalculating any of the results it's best to store the intermediate values in a table. The rows of this table will be indexed by a context \( c\in \left\{ s,a,b,c\right\} \). The columns will be indexed by expressions. Each entry in the table will hold the result of evaulationg the given expression under the given context. The first column index will be the function \( f\left( q\right) \) that we are using for evaluation. The entires in this column will be computed based upon values from successive columns, given the rules listed above. We can recursively generate these indicies. If for each entry in the table we store the indicies of the columns that it depends on, and also the rule by which the problem was decomposed at that point, then we can then fill out every entry in the table given some quaternion point q.

Generating the table

We can factor the table generation out of the divergence testing loop if we generate it at the time the divergence function is processed. Table generation will consist of determining the proper column indicies and saving the required state to process points. The first column in the table will be the divergence function f. This column will eventually contain the quaternion that results from evaluating the function at some given point. The other column indicies can be deduced recursively by applying the rules for \( C_{e}\left( x\right) \)above. Then for each table entry:

1.
Determine what sub expressions, if any, this entry depends upon. Look for said expressions along top of table. If found, record index of each expression as well as rule by which the current expression was decomposed. If the required subexpression is not found, add a new column to the table indexed by the subexpression
2.
Repeat process for each new generated column.

Evaluating points with the table

Evaluating points with the table is easy. If the column index of the dependent variable (q here) is stored when the table is generated, then the function can be applied by writing the desired value of q into the table at that spot, and then filling in all unused entries in the table. Since each entry will only depend upon values to the right of it in the table, filling out columns from the left will work. The result of the function will then be in the first column of the table.

Example

In this section I will attempt to show how DP can be used in conjunction with the ^ operator to make things a lot faster.

I will attempt to derive \( C_{e}\left( f\left( q\right) \right) \) for \( c\in \left\{ a,b,c\right\} \), where \( f\left( q\right) =q^{2}*\left( q-1\right) \).

1.
\( C_{s}\left( f\left( q\right) \right) =C_{s}\left( q^{2}\right) *C_{s}\left( q...
...ht) *C_{b}\left( q-1\right) -C_{c}\left( q^{2}\right) *C_{c}\left( q-1\right) \)

(a)
\( C_{s}\left( q^{2}\right) =C_{s}\left( q\right) ^{2}-C_{a}\left( q\right) ^{2}...
...right) ^{2}-C_{c}\left( q\right) ^{2}=q_{s}^{2}-q_{a}^{2}-q_{b}^{2}-q_{c}^{2} \)
(b)
\( C_{s}\left( q-1\right) =q_{s}-1 \)
(c)
\( C_{a}\left( q^{2}\right) =2*C_{a}\left( q\right) *C_{s}\left( q\right) =2q_{a}q_{s} \)
(d)
\( C_{a}\left( q-1\right) =q_{a}-1 \)
(e)
\( C_{b}\left( q^{2}\right) =2*C_{b}\left( q\right) *C_{s}\left( q\right) =2q_{b}q_{s} \)
(f)
\( C_{b}\left( q-1\right) =q_{b}-1 \)
(g)
\( C_{c}\left( q^{2}\right) =2*C_{c}\left( q\right) *C_{s}\left( q\right) =2q_{c}q_{s} \)
(h)
\( C_{c}\left( q-1\right) =q_{c}-1 \)
2.
\( C_{a}\left( f\left( q\right) \right) =C_{a}\left( q^{2}\right) *C_{s}\left( q...
...ht) *C_{c}\left( q-1\right) -C_{c}\left( q^{2}\right) *C_{b}\left( q-1\right) \)
3.
\( C_{b}\left( f\left( q\right) \right) =C_{b}\left( q^{2}\right) *C_{s}\left( q...
...ht) *C_{a}\left( q-1\right) -C_{a}\left( q^{2}\right) *C_{c}\left( q-1\right) \)
4.
\( C_{c}\left( f\left( q\right) \right) =C_{c}\left( q^{2}\right) *C_{s}\left( q...
...ht) *C_{b}\left( q-1\right) -C_{b}\left( q^{2}\right) *C_{a}\left( q-1\right) \)
This example uses 26 multiplications and 14 additions.

About this document ...

Efficient Evaluation of Quaternion Functions

This document was generated using the LaTeX2HTML translator Version 98.1p1 release (March 2nd, 1998)

Copyright © 1993, 1994, 1995, 1996, 1997, Nikos Drakos, Computer Based Learning Unit, University of Leeds.

The command line arguments were:
latex2html -antialias_text -antialias -split 0 -no_navigation diverg.tex.

The translation was initiated by brian martin on 1998-07-22


brian martin
1998-07-22