Introduction were “discovered” in 1843 by Sir William Hamilton, who was looking for the extension to 3D space of the complex as rotation operators.

Figure 1: Sir William Rowland Hamilton (1805-1865) and the plaque on Broom Bridge, where the quater- nions were discovered.

Definitions The generic will be indicated as q. Quaternions are elements of a 4D linear space H(R), defined on the real numbers field F = R, with base {1ijk}. i, j and k are ipercomplex numbers that satisfy the following anticommutative multiplication rules:

i2 = j2 = k2 = ijk = −1 ij = −ji = k jk = −kj = i ki = −ik = j

Definitions A quaternion q ∈ H is defined as a expressed in the base {1ijk}:

q = q01 + q1i + q2j + q3k

3 where the coefficients {qi}i=0 are real. Another way to represent a quaternion is to define it as a quadruple of reals, (q0,q1,q2,q3)

q = (q0,q1,q2,q3) in analogy with complex numbers c = a + jb, where c is represented by a couple of reals, c = (a,b),

Definitions Quaternions are also defined as hypercomplexnumbers, i.e., those “complex numbers” having complex coefficients: q = c1 + jc2, where c1 = q0 + kq3 e c2 = q2 + kq1. Therefore, considering multiplication rules, it results:

q = c1 + jc2 = q0 + kq3 + jq2 + jkq1 = q01 + q1i + q2j + q3k

1 Definitions In analogy with complex numbers that are the sum of a real part and an imaginary part, quaternions are the sum of a real part and a vectorial part.

The real part qr is defined as qr = q0, and the vectorial part qv is defined as qv = q1i + q2j + q3k. We write q = (qr, qv) or q = qr + qv; note that the vectorial part is not “transposed” since the conven- tional definition for the vectorial part of a quaternion assumes a row representation. T Using the convention that defines vectors as “column” vectors, we can write q = (qr, qv ).

Definitions Quaternions are general mathematical objects, that include real numbers

r = (r, 0, 0, 0), r ∈ R complex numbers a + ib = (a, b, 0, 0), a,b ∈ R real vectors in R3 (with some caution, since not all vectorial parts represents vectors)

v = (0, v1, v2, v3), vi ∈ R.

In this last case, elements {i j k} are to be understood as unit vectors {i j k} forming an orthonor- mal base in a cartesian right-handed reference frame.

Definitions Multiplication rules between elements i,j,k have the same properties of the between unit vectors i,j,k:

ij = k ⇔ i × j = k ji = −k ⇔ j × i = −k etc.

In the following we will use all the possible alternative notations to indicate quaternions

q = q01 + q1i + q2j + q3k = (qr,qv)= qr + qv = (q0,q1,q2,q3) i.e., a) a hypercomplexnumber; b) the sum of a real part and a vectorial part; c) a quadruple of reals.

Definitions An alternative way to write a quaternion is the following

q = q01 + q1i + q2j + q3k where now 1 0 i 0 0 1 0 i 1 = ; i = ; j = ; k = ; 0 1 0 −i −1 0 i 0         and i2 = −1. Hence every matrix is of the form c d ; −d∗ c∗   These matrices are called Cayley matrices [see Rotations - Pauli spin matrices].

2 Quaternions algebra

Given a quaternion q = q01+q1i+q2j+q3k = qr +qv = (q0,q1,q2,q3), the following properties hold: • a null or zero 0 quaternion exists 0 = 01 + 0i+ 0j+ 0k = (0,0)= 0 + 0 = (0,0,0,0)

• a conjugate quaternion q∗ exists, having the same real part and the opposite vectorial part:

∗ q = q0 − (q1i + q2j + q3k) = (qr,−qv)= qr − qv = (q0,−q1,−q2,−q3) Conjugate quaternions satisfy (q∗)∗ = q

Quaternions algebra

• a non-negative function, called quaternion norm exists kqk, defined as

3 2 ∗ ∗ 2 2 T kqk = qq = q q = ∑ qℓ = q0 + qv qv ℓ=0 A quaternion with unit norm kqk = 1 is called unit quaternion. Quaternion q and its conjugate q∗ have the same norm kqk = kq∗k

The quaternion

qv = 01+ q1i + q2j + q3k = (0,qv)= 0 + qv = (0,q1,q2,q3), that has a zero real part is called pure quaternion or vector. The conjugate of a pure quaternion qv is the opposite of the original pure quaternion ∗ qv = −qv

Quaternions algebra Given two quaternions

h = h01 + h1i + h2j + h3k = (hr,hv)= hr + hv = (h0,h1,h2,h3) and g = g01 + g1i + g2j + g3k = (gr,gv)= gr + gv = (g0,g1,g2,g3) the following operations are defined

Sum Sum or addition h + g

h + g = (h0 + g0)1 + (h1 + g1)i + (h2 + g2)j + (h3 + g3)k = ((hr + gr), (hv + gv)) = (hr + gr) + (hv + gv) = (h0 + g0,h1 + g1,h2 + g2,h3 + g3)

Difference Difference or subtraction

h − g = (h0 − g0)1 + (h1 − g1)i + (h2 − g2)j + (h3 − g3)k = ((hr − gr), (hv − gv)) = (hr − gr) + (hv − gv) = (h0 − g0,h1 − g1,h2 − g2,h3 − g3)

3 Product Product

hg = (h0g0 − h1g1 − h2g2 − h3g3)1 + (h1g0 + h0g1 − h3g2 + h2g3)i + (h2g0 + h3g1 + h0g2 − h1g3)j + (h3g0 − h2g1 + h1g2 + h0g3)k

= (hrgr − hv · gv, hrgv + grhv + hv × gv) where hv · gv is the scalar product

T T hv · gv = ∑hvigvi = hv gv = gv hv i Rn R3 defined in , and hv × gv is the cross product (defined only in )

h2g3 − h3g2 hv × gv = h3g1 − h1g3 = S(hv)gv "h1g2 − h2g1#

Product The quaternion product is anti-commutative, since, being

gv × hv = −hv × gv it follows gh = (hrgr − hv · gv, hrgv + grhv − hv × gv) 6= hg; Notice that the real part remains the same, while the vectorial part changes. Product commutes only if hv × gv = 0, i.e., when the vectorial parts are parallel. The conjugate of a quaternion product satisfies

(gh)∗ = h∗g∗.

The product norm satisfies khgk = khkkgk.

Product properties

• associative (gh)p = g(hp)

• multiplication by the unit scalar

1q = q1 = (1,0)(qr,qv) = (1qr,1qv) = (qr,qv)

• multiplication by the real λ λ λ λ λ q = ( ,0)(qr,qv) = ( qr, qv)

• bilinearity, with real λ1,λ2

g(λ1h1 + λ2h2) = λ1gh1 + λ2gh2 λ λ λ λ ( 1g1 + 2g2)h = 1g1h + 2g2h

4 Product Alternative forms Quaternion product may be written as matrix product forms:

h0 −h1 −h2 −h3 g0 g0 T h1 h0 −h3 h2 g1 h −h g1 hg = = 0 v h2 h3 h0 −h1g2 hv h0I + S(hv) g2 h −h h h g   g  3 2 1 0  3  3      = FL(h)g or

g0 −g1 −g2 −g3 h0 h0 g g g −g h g −gT h hg = 1 0 3 2 1 = 0 v 1 g2 −g3 g0 g1 h2 gv g0I − S(gv) h2 g g −g g h   h  3 2 1 0  3  3      = FR(g)h

Quotient Since the quaternion product is anti-commutative we must distinguish between the left and the right quotient or division.

Given two quaternions h e p, we define the left quotient of p by h the quaternion qℓ that satisfies

hqℓ = p while we define the right quotient of p by h the quaternion qr that satisfies

qrh = p Hence h∗ h∗ qℓ = p; qr = p khk2 khk2

Inverse −1 −1 Given a quaternion q, in principle one must define the right qr and the left inverse qℓ as −1 −1 qqℓ = 1 = (1,0,0,0); qr q = 1 = (1,0,0,0)

Since qq∗ = q∗q = kqk2 = kqkkq∗k, one can write q q∗ q∗ q = = 1 = (1,0,0,0) kqk kq∗k kq∗k kqk It follows that right inverse and left inverse are equal ∗ ∗ −1 −1 −1 q −1 c q = qr = q = similar to c = ℓ kqk2 kck2

Inverse For a unit quaternion u, kuk = 1, inverse and conjugate coincide u−1 = u∗, kuk = 1 and for a pure unit quaternion q = (0,qv), kqk = 1, i.e., a unit vector −1 ∗ qv = qv = −qv. Inverse satisfies (q−1)−1 = q; (pq)−1 = q−1p−1

5 Selection function We define the selection function ρ(q)= q0 = qr as the function that “extracts” the real part of a quaternion This function satisfies q + q∗ ρ(q)= . 2

Hamilton product If we multiply two pure quaternions , i.e., two vectors

uv = (0,uv)= u1i + u2j + u3k and vv = (0,vv)= v1i + v2j + v3k we obtain uvvv = (−uv · vv, u × v). Hence, with a slight notation abuse, we can define a new vector product, called Hamilton product

uv = −u· v + u× v.

This product implies uu = −u · u, and for this reason, among others the quaternions were abandoned in favor of vectors. Nonetheless the quaternion product has an important role in representing rotations.

Unit quaternions Before starting to illustrate the relations between quaternions and rotation, we look closer to the prop- erties of the unit quaternions, that we indicate with the symbol u. A unit quaternion (kuk = 1) has an unit inverse and the product of two unit quaternions is still a unit quaternion. We assume that a unit quaternion is represented by a sum of two trigonometric functions

u = cosθ + usinθ = (cosθ,usinθ) where u is a unit norm vector and θ a generic angle.

Unit quaternions Notice the analogy with the unit complex expression

c = cosθ + jsinθ

The analogy applies also to the exponential expression c = ejθ; substituting x with uθ in the series expansion of ex and recalling that uu = −1, we have

θ eu = cosθ + usinθ = u

The relation above shows a formal identity between a unit quaternion and the exponential of a unit vector multiplied by a scalar θ Notice the similarity between u = euθ and R(u,θ)= eS(u)θ

6 Unit quaternions From the previous relation one obtains the power p of a unit quaternion as

θ up = (cosθ + usinθ)p = eu p = cos(θp)+ usin(θp) and the logarithm of a unit quaternion

θ logu = log(cosθ + usinθ)= log(eu )= uθ

Notice that the anti-commutativity of the quaternion product inhibits to use the standard identities u u u +u between exponential and logarithms. For instance, e 1 e 2 it is not necessarily equal to e 1 2 , andlog(u1u2) is not necessarily equal to log(u1)+ log(u2).

Quaternions and Rotations Now we relate rotations and unit quaternions Given the unit quaternion

u = (u0,u1,u2,u3) = (u0,u)= cosθ + usinθ

T this represents the rotation Rot(u,2θ) around u = [u1 u2 u3] The converse is also true, i.e., given a rotation Rot(u,θ) of an angle θ around the axis specified by the T unit vector u = [u1 u2 u3] , the unit quaternion

θ θ θ θ θ θ u = cos ,u sin ,u sin ,u sin = cos , usin = 2 1 2 2 2 3 2 2 2     θ θ cos + usin 2 2 represents the same rotations.

Quaternions and Rotations We know that a rigid rotation in R3 is represented by a rotation (orthonormal)matrix R ∈ SO(3) ⊂ R3×3. We can associate to every rotation matrix R a unit quaternion u and viceversa, indicating this relation as R(u) ⇔ u.

Quaternions and Rotations

To compute the rotation matrix R(u) given a unit quaternion u = (u0,u), we use the following relation

2 T T R(u) = (u0 − u u)I + 2uu − 2u0S(u)= 2 2 2 2 u0 + u1 − u2 − u3 2(u1u2 − u3u0) 2(u1u3 + u2u0) 2 2 2 2  2(u1u2 + u3u0) u0 − u1 + u2 − u3 2(u2u3 − u1u0)  2(u u − u u ) 2(u u + u u ) u2 − u2 − u2 + u2  1 3 2 0 2 3 1 0 0 1 2 3   where S(u) is an antisymmetric matrix.

Quaternions and Rotations

7 To compute the unit quaternion u = (u0,u) given a rotation matrix R we use the following relation 1 u = ± (1 + r + r + r ) 0 2 11 22 33 1 p u1 = (r32 − r23) 4u0 1 u2 = (r13 − r31) 4u0 1 u3 = (r21 − r12) 4u0

Quaternions and Rotations Another alternative relation is 1 u = (1 + r + r + r ) 0 2 11 22 33 1p u = sign(r − r ) (1 + r − r − r ) 1 2 32 23 11 22 33 1 p u = sign(r − r ) (1 − r + r − r ) 2 2 13 31 11 22 33 1 p u = sign(r − r ) (1 − r − r + r ) 3 2 21 12 11 22 33 where sign(x) is the sign function, with sign(0)= 0. p

This relation is never singular compared with the previous one that is singular for u0 = 0

Quaternions and Rotations Elementary rotations around the three principal axes R(i,α), R(j,β) and R(k,γ), correspond to the following elementary quaternions α α R(i,α) → u = cos , sin , 0, 0 x 2 2  β β  R(j,β) → u = cos , 0, sin , 0 y 2 2  γ γ  R(k,γ) → u = cos , 0, 0, sin z 2 2   It is easy to see hat the “vectorial base” of quaternions correspond to elementary rotations of π around the principal axes i = (0,1,0,0) → R(i,π) j = (0,0,1,0) → R(j,π) k = (0,0,0,1) → R(k,π)

Quaternions and Rotations Notice an important fact: while the product among the unit base quaternions gives ii = jj = kk = ijk = (−1, 0, 0, 0), the product among the associated rotation matrices gives:

R(i,π)R(i,π)= R(j,π)R(j,π)= R(k,π)R(k,π)= R(i,π)R(j,π)R(k,π)= I

8 Since I represents a rotation that leaves the vectors unchanged, it seems natural to associate it to positive unit scalar, i.e., the quaternion (1,0,0,0). The apparent discrepancy between the two results can be explained only introducing a most basic mathematical quantity, called spinor, not discussed in the present context

Quaternions and Rotations We shall see now some correspondence between quaternion operations and matrix operations Rotation product

Given n rotations R1, R2, ···, Rn and the corresponding unit quaternions u1, u2, ···, un, the product

R(u)= R(u1)R(u2)···R(un) corresponds to the product u = u1u2 ···un in the shown order.

Quaternions and Rotations Transpose matrix Given the rotation R(u) and its corresponding unit quaternion u, the transpose matrix (i.e., the inverse rotation) RT corresponds to the conjugate unit quaternion u∗ (i.e., the inverse quaternion) R ⇔ u RT ⇔ u∗

Quaternions and Rotations Vector rotation Given a generic vector x, and the corresponding pure quaternion

qx = (0,x) = (0,x1,x2,x3) and given a rotation matrix R(u) with its corresponding unit quaternion u, the rotated vector y = R(u)x is given by the vectorial part of the quaternion obtained as

∗ qy = (0,y)= uqxu where qy = kqxk The map ∗ qx 7→ qy = uqxu ⇔ y = R(u)x that transforms a pure vector into its rotated counterpart, in quaternion form, is called conjugation by u. Notice that the transpose map is equivalent to exchange the order of the conjugation

∗ T qx 7→ qy = u qxu ⇔ y = R (u)x

Quaternions u and u∗ = u−1 are called antipodal, because they represent opposite points on the 3-sphere of unit quaternions.

Quaternions and Rotations If we use the homogeneous coordinates to express the vector x

T x˜ = [wx1 wx2 wx3 w] and the quaternion x is defined as x = (w,wx)

9 the product uxu∗ provides the quaternion y, defined as y = (w,wR(u)x) The resulting vector y, in homogeneous coordinates is therefore

T y˜ = [wy1 wy2 wy3 w] ⇔ y = R(u)x

Quaternions and Rotations Product matrices Since the bi-linearity property holds for the product between two quaternions, this can be represented by linear operators (i.e., matrices). We recall that the product qp can be expressed in matrix form as

qp = FL(q)p This can be interpreted as the left product of q by p.

Similarly for the right product pq, expressed as pq = FR(q)p.

Quaternions and Rotations ∗ ∗ We can obtain pq as FR(q )p and ∗ ∗ qpq = FL(q)FR(q )p = Qp where the matrix Q ∈ R4×4 is

∗ Q = FL(q)FR(q )= 2 2 2 2 q0 + q1 − q2 − q3 2(q1q2 − q3q0) 2(q1q3 + q2q0) 0 2 2 2 2  2(q1q2 + q3q0) q0 − q1 + q2 − q3 2(q2q3 − q1q0) 0  2 q q q q 2 q q q q q2 q2 q2 q2 0  ( 1 3 − 2 0) ( 2 3 + 1 0) 0 − 1 − 2 + 3     0 0 0 kqk2     We observe that the upper left 3 × 3 matrix of Q equals the matrix R(q) previously defined

Quaternions in Aerospace literature In space applications quaternions are used when dealing with satellite orientation control; unfortunately they may be “organized” in a different way wrt to our conventions: often the real part is the last element of quaternions q = (q1,q2,q3,q0)

Historical notes Hamilton tried to use the quaternions for a unified description of space-time physics (before Einstein), considering the real part of the quaternion as the representation of time, and the vectorial part as the representation of space q = (t,x,y,z). Unfortunately the

q∗q = qq∗ = t2 + x2 + y2 + z2 has the wrong signature (+,+,+,+). We know that, in , the Minkowski standard basis has a set of four mutually orthogonal vectors (e0,e1,e2,e3) such that

2 2 2 2 −(e0) = (e1) = (e2) = (e3) = 1

10 with signature (+,−,−,−) or (−,+,+,+). The development of hyperbolic quaternions in the 1890s prepared the way for . Indeed, as a mathematical structure, Minkowski space can be taken as hyperbolic quaternions minus the multiplicative product, retaining only the pq∗ + (pq∗)∗ η(p,q)= − 2 which is generated (evidently) by the hyperbolic quaternion product pq∗. [from Wikipedia: Minkowski space] Hamilton tried for many years to extend the complex numbers rotation operator from plane to space trying with triads of (a,b,c), with base (1,i,j), but he did not succeed. A story goes that every morning his sons would inquire “Well, Papa can you multiply triplets?” Theproblemis thatthe generalresulton which he based his reasoning, i.e., the extension of the result 2 2 2 2 2 2 (a1 + a2)(b1 + b2) = (c1 + c2) to the R3 space, cannot be solved with triads of numbers, i.e., 2 2 2 2 2 2 2 2 2 (a1 + a2 + a3)(b1 + b2 + b3) 6= (c1 + c2 + c3) that is the same to ask for the existence kakkbk = kabk in general cases (three components vectors in particular). [from J. Stillwell, Mathematics and Its History, Springer] The problem is that, while for complex numbers the product result is well known

(a1 + ja2)(b1 + jb2)= a1b1 − a2b2 + j(a2b1 + a1b2) or (a1,a2)(b1,b2) = (a1b1 − a2b2,a2b1 + a1b2) for triad of numbers it is impossible. Hamilton failed to acknowledge this and did not notice a result already given by Diophantus, that for example, 3 = 11 + 12 + 12 and 5 = 02 + 12 + 22 are both sums of three squares, but their product 15 is not. So he persisted for 13 years before discovering that he needed four numbers, i.e., the quaternions. By the way the only number systems with a product satisfying kakkbk = kabk are

• the real numbers R = R1. • the complex numbers C = R2; they are couples or real numbers. • the quaternions H = R4; they are couples or complex numbers. • the O = R8; they are couples or quaternions.

• Commutative multiplication is possible only on R1 and R2 and it yields the number systems R and C. • Associative, but noncommutative, multiplication is possible only on R4, and it yields the quaternions H. • Alternative, but nonassociative, multiplication is possible only on R8, and it yields a system called the octonions O.

Partial associativity law called cancellation or alternativity a−1(ab)= b = (ba)a−1

11