quaternionic.algebra

Source: quaternionic/algebra.py

Essential functions for quaternion algebra. These functions form the basic algebraic behavior of quaternions — addition, multiplication, exp, log, etc. Each function takes one or two array-like inputs — depending on whether it is unary or binary — as the first parameter or two, and another array-like object for output as the final parameter. Even for functions that return a single float or bool, the output must be array-like so that it can be modified inside the function. These functions are JIT-compiled by numba's guvectorize function, meaning that they can also act on arbitrary arrays just like standard numpy arrays, as long as the final dimension of any quaternion-valued input has size 4 to represent the components of the quaternion. These functions are generic, meaning that they can be used without the quaternionic.array object. However, these functions are implemented as the "ufunc"s of those arrays, meaning that we can perform algebra directly on them in natural ways — as in q1+q2, q1*q2, etc. — and using the standard numpy functions — as in np.exp(q), np.log(q), etc. For this purpose, we implement as many of the standard ufuncs as make sense for quaternions. For the most part, this means ignoring operations related to integers, remainders, ordering, or trigonometric functions. The bit-twiddling functions are re-interpreted as they usually are in geometric algebra to denote geometric operations. All functions in this module are magically compiled to ufuncs in __init__.py and placed attached to the algebra_ufuncs object.

absolute

absolute(q, qout)

Source: quaternionic/algebra.py

Return absolute value of quaternion |q|

add

add(q1, q2, qout)

Source: quaternionic/algebra.py

Add two quaternions q1+q2

angle

angle(q, qout)

Source: quaternionic/algebra.py

Return angle (in radians) through which input quaternion rotates a vector If q = np.exp(v̂ * θ/2) for some unit vector and an angle θ ∈[-2π,2π], then this function returns abs(θ). This equals 2*abs(log(q)), but is more efficient.

bitwise_or

bitwise_or(q1, q2, qout)

Source: quaternionic/algebra.py

Return scalar product of quaternions q1|q2. If we denote by ⟨a⟩ₛ the grade-s component of the general multivector a, we can express this product as a | b = Σₛ,ᵣ ⟨⟨a⟩ₛ ⟨b⟩ᵣ⟩₀ Note that this is different from the "Hestenes dot" product where the sum runs over s≠0 and r≠0; that is the product returned by galgebra using this operator.

bitwise_xor

bitwise_xor(q1, q2, qout)

Source: quaternionic/algebra.py

Return outer product of quaternions q1^q2. This is the generalized outer product of geometric algebra. If we denote by ⟨a⟩ₛ the grade-s component of the general multivector a, we can express this product as a ^ b = Σₛ,ᵣ ⟨⟨a⟩ₛ ⟨b⟩ᵣ⟩ₛ₊ᵣ Note that the result may seem surprising because we sometimes think of quaternions as

conj

conj(q, qout)

Source: quaternionic/algebra.py

Return quaternion-conjugate of quaternion q̄

conjugate

conjugate(q, qout)

Source: quaternionic/algebra.py

Return quaternion-conjugate of quaternion q̄

divide

divide(q1, q2, qout)

Source: quaternionic/algebra.py

Divide quaternions q1/q2 = q1 * q2.inverse

divide_scalar

divide_scalar(s, q, qout)

Source: quaternionic/algebra.py

Divide scalar by quaternion s/q = s * q.inverse

equal

equal(q1, q2, bout)

Source: quaternionic/algebra.py

exp

exp(q, qout)

Source: quaternionic/algebra.py

Return exponential of input quaternion exp(q)

float_power

float_power(q, s, qout)

Source: quaternionic/algebra.py

Raise quaternion to scalar power exp(log(q)*s)

invert

invert(q, qout)

Source: quaternionic/algebra.py

Return quaternion-conjugate of quaternion q̄

isfinite

isfinite(qin, bout)

Source: quaternionic/algebra.py

isinf

isinf(qin, bout)

Source: quaternionic/algebra.py

isnan

isnan(qin, bout)

Source: quaternionic/algebra.py

left_shift

left_shift(q1, q2, qout)

Source: quaternionic/algebra.py

Return left-contraction of quaternions q1<<q2 = q1⌋q1. For all quaternions a, b, c, we have (a ^ b) * c = a * (b ⌋ c)

log

log(q, qout)

Source: quaternionic/algebra.py

Return logarithm of input quaternion log(q)

logical_and

logical_and(q1, q2, bout)

Source: quaternionic/algebra.py

logical_or

logical_or(q1, q2, bout)

Source: quaternionic/algebra.py

multiply

multiply(q1, q2, qout)

Source: quaternionic/algebra.py

Multiply quaternions q1*q2

multiply_scalar

multiply_scalar(s, q, qout)

Source: quaternionic/algebra.py

Multiply scalar by quaternion s*q

negative

negative(q, qout)

Source: quaternionic/algebra.py

Return negative quaternion -q

not_equal

not_equal(q1, q2, bout)

Source: quaternionic/algebra.py

positive

positive(q, qout)

Source: quaternionic/algebra.py

Return input quaternion q

reciprocal

reciprocal(q, qout)

Source: quaternionic/algebra.py

Return reciprocal (inverse) of quaternion q.inverse

right_shift

right_shift(q1, q2, qout)

Source: quaternionic/algebra.py

Return right-contraction of quaternions q1>>q2 = q1⌊q2. For all quaternions a, b, c, we have c * (b ^ a) = (c ⌊ b) * a

scalar_divide

scalar_divide(q, s, qout)

Source: quaternionic/algebra.py

Divide quaternion by scalar q/s

scalar_multiply

scalar_multiply(q, s, qout)

Source: quaternionic/algebra.py

Multiply quaternion by scalar q*s

scalar_true_divide

scalar_true_divide(q, s, qout)

Source: quaternionic/algebra.py

Divide quaternion by scalar q/s

sqrt

sqrt(q, qout)

Source: quaternionic/algebra.py

Return square-root of input quaternion √q. The general formula whenever the denominator is nonzero is √q = (|q| + q) / √(2|q| + 2q.w) This can be proven by expanding q as q.w + q.vec and multiplying the expression above by itself. When the denominator is zero, the quaternion is a pure-real negative number. It is not clear what the appropriate square-root is in this case (because the quaternions come with infinitely many elements that square to -1), so we arbitrarily choose the result to be proportional to the x quaternion.

square

square(q, qout)

Source: quaternionic/algebra.py

Return square of quaternion q*q

subtract

subtract(q1, q2, qout)

Source: quaternionic/algebra.py

Subtract quaternion q1-q2

true_divide

true_divide(q1, q2, qout)

Source: quaternionic/algebra.py

Divide quaternions q1/q2 = q1 * q2.inverse

true_divide_scalar

true_divide_scalar(s, q, qout)

Source: quaternionic/algebra.py

Divide scalar by quaternion s/q = s * q.inverse