The type parameter T in Quaternion{T}

The type parameter T <: Real in Quaternion{T} represents the type of real and imaginary parts of a quaternion.

Lipschitz quaternions

By using this type parameter, some special quaternions such as Lipschitz quaternions $L$ can be represented.

\[L = \left\{a+bi+cj+dk \in \mathbb{H} \mid a,b,c,d \in \mathbb{Z}\right\}\]

julia> q1 = Quaternion{Int}(1,2,3,4)Quaternion{Int64}(1, 2, 3, 4)
julia> q2 = Quaternion{Int}(5,6,7,8)Quaternion{Int64}(5, 6, 7, 8)
julia> islipschitz(q::Quaternion) = isinteger(q.s) & isinteger(q.v1) & isinteger(q.v2) & isinteger(q.v3)islipschitz (generic function with 1 method)
julia> islipschitz(q1)true
julia> islipschitz(q2)true
julia> islipschitz(q1 + q2)true
julia> islipschitz(q1 * q2)true
julia> islipschitz(q1 / q2) # Division is not defined on L.false
julia> q1 * q2 == q2 * q1 # non-commutativefalse

Hurwitz quaternions

If all coefficients of a quaternion are integers or half-integers, the quaternion is called a Hurwitz quaternion. The set of Hurwitz quaternions is defined by

\[H = \left\{a+bi+cj+dk \in \mathbb{H} \mid a,b,c,d \in \mathbb{Z} \ \text{or} \ a,b,c,d \in \mathbb{Z} + \tfrac{1}{2}\right\}.\]

Hurwitz quaternions can be implemented with HalfIntegers.jl package.

julia> using HalfIntegers
julia> q1 = Quaternion{HalfInt}(1, 2, 3, 4)Quaternion{Half{Int64}}(1, 2, 3, 4)
julia> q2 = Quaternion{HalfInt}(5.5, 6.5, 7.5, 8.5)Quaternion{Half{Int64}}(11/2, 13/2, 15/2, 17/2)
julia> q3 = Quaternion{HalfInt}(1, 2, 3, 4.5) # not Hurwitz quaternionQuaternion{Half{Int64}}(1, 2, 3, 9/2)
julia> ishalfodd(x::Number) = isodd(twice(x)) # Should be defined in HalfIntegers.jl (HalfIntegers.jl#59)ishalfodd (generic function with 1 method)
julia> ishurwitz(q::Quaternion) = (isinteger(q.s) & isinteger(q.v1) & isinteger(q.v2) & isinteger(q.v3)) | (ishalfodd(q.s) & ishalfodd(q.v1) & ishalfodd(q.v2) & ishalfodd(q.v3))ishurwitz (generic function with 1 method)
julia> ishurwitz(q1)true
julia> ishurwitz(q2)true
julia> ishurwitz(q3)false
julia> ishurwitz(q1 + q2)true
julia> ishurwitz(q1 * q2)true
julia> ishurwitz(q1 / q2) # Division is not defined on H.false
julia> q1 * q2 == q2 * q1 # non-commucativefalse
julia> abs2(q1) # Squared norm is always an integer.30.0
julia> abs2(q2) # Squared norm is always an integer.201.0
julia> abs2(q3) # Squared norm is not an integer because `q3` is not Hurwitz quaternion.34.25

Biquaternions

If all coefficients of a quaternion are complex numbers, the quaternion is called a Biquaternion. However, the type parameter T is restricted to <:Real, so biquaternions are not supported in this package. Note that Base.Complex has the same type parameter restriction, and bicomplex numbers are not supported in Base. See issue#79 for more discussion.