## `Dom::Quaternion` -- the skew field of quaternions

#### Introduction

The domain `Dom::Quaternion` represents the skew field of quaternions.

#### Creating Elements

`Dom::Quaternion(listi)`
`Dom::Quaternion(ex)`
`Dom::Quaternion(M)`

#### Parameters

`listi` | - | a list containing four elements of type `Type::Real`
`ex` | - | arithmetical expression
`M` | - | A matrix of type `Dom::Matrix(Dom::Complex)`. It has to be of a special form described in the Details section.

#### Categories

`Cat::SkewField`

#### Related Domains

`Dom::Complex`

#### Details

- Quaternions are usually defined to be complex 2 x 2-matrices of the special form

      +-             -+
      | a+b*I, -c-d*I |
      | c-d*I,  a-b*I |
      +-             -+

  where a,b,c,d are real numbers. Another usual notation is a+bi+cj+dk; the subfield of those quaternions for which c=d=0 is isomorphic to the field of complex numbers.

- The domain `Dom::Quaternion` regards these fields as being identical, and it allows both notations that have been mentioned, as well as simply `[a,b,c,d]`.
- If you enter a quaternion as an arithmetical expression `ex`, the identifiers `i`, `j`, and `k` are understood in the way mentioned above; `I`, `J`, and `K` may be used alternatively, and you may also mix small and capital letters. Every subexpression of `ex` not containing one of these must be real and constant.

  Be sure that you have not assigned a value to one of the identifiers mentioned.

- `Dom::Quaternion` has the domain `Dom::BaseDomain` as its super domain, i.e., it inherits each method which is defined by `Dom::BaseDomain` and not re-implemented by `Dom::Quaternion`. Methods described below are re-implemented by `Dom::Quaternion`.

#### Entries

characteristic

  the characteristic of this domain is 0

one

  the unit element; it equals `Dom::Quaternion``([1,0,0,0])`.

size

  the number of quaternions is `infinity`.

zero

  The zero element; it equals `Dom::Quaternion``([0,0,0,0])`.

#### Method _mult: multiplies quaternions

- `_mult(dom x , dom y...)`
- - This method overloads `_mult`.
  - Returns the product x * y * ... of quaternions.

#### Method _plus: adds quaternions

- `_plus(dom x , dom y...)`
- - This method overloads `_plus`.
  - Returns the sum x + y + ... of quaternions.

#### Method _power: the n-th power of a quaternion

- `_power(dom x, rational n)`
- - This method overloads `_power`.
  - This method computes x^n for rational numbers `n`.

#### Method Im: returns the imaginary (vectorial) part of a quaternion.

- `Im(dom x)`
- - This method overloads `Im`.
  - Returns the imaginary (vectorial) part of x:=a+bi+cj+dk, this is bi+cj+dk.
  - The result is still a quaternion.

#### Method Re: returns the real part of a quaternion.

- `Re(dom x)`
- - This method overloads `Re`.
  - Returns the real part of x:=a+bi+cj+dk, this is a.
  - The result is of type `Type::Real`.

#### Method abs: absolute value of a quaternion

- `abs(dom x)`
- - This method overloads `abs`.
  - Returns the absolute value of x:=a+bi+cj+dk, this is sqrt(a^2 + b^2 + c^2 + d^2).
  - The result is of type `Type::Real`.

#### Method conjugate: conjugate element

- `conjugate(dom x)`
- - This method overloads `conjugate`.
  - Returns the conjugate of x:=a+bI+cJ+dK, which is defined to be a-bI-cJ-dK.

#### Method intpower: multiplies quaternions

- `intpower(dom x, DOM_INT)`
- - This method computes x^n for integers `n`.
  - The implementation uses ``repeated squaring''.
  - `Dom::Quaternion` is used by `"_power"`.

#### Method nthroot: n-th root of a quaternion

- `nthroot(dom x, DOM_INT n)`
- - This method computes the `n`-th root of `x`.
  - The implementation uses ``repeated squaring''.
  - `Dom::Quaternion` is used by `"_power"`.

#### Method norm: norm of a quaternion

- `norm(dom x)`
- - This method overloads `norm`.
  - Returns the norm of x:=a+bi+cj+dk, this is a^2 + b^2 + c^2 + d^2.
  - The result is of type `Type::Real`.

#### Method random: random number generation

- `random()`
- - This methods returns a randomly generated quaternion x:=a+bi+cj+dk with `a, b, c` and `d` being nonnegative numbers with at most 12 digits generated by `random`.

#### Method scalarmult: scalar multiplication

- `scalarmult(Type::Real s, dom x)`
- - Returns the product s * y.

#### Method scalarprod: inner product

- `scalarprod(dom x, dom y)`
- - Returns the inner product of x:=a+bi+cj+dk and y:=e+fi+gj+hk, this is: a*e + b*f + c*g + d*h.

#### Method sign: sign of a quaternion

- `sign(dom x)`
- - This method overloads `sign`.
  - Returns the sign of x:=a+bi+cj+dk, this is 1/abs(x) * x.
  - The result is of type `Type::Real`.

#### Method convert: conversion of objects

- `convert(any x)`
- - This method tries to convert `x` into an element of `Dom::Quaternion`. If `x` is a list, it must consist of four real numbers (type `Type::Real`). Constant real expressions and the identifiers`i`, `J`, `j`, `K`, and `k` can also be converted to domain elements, as well as sums and products of them. A matrix of the type `Dom::Matrix(Dom::Complex)` can be converted if and only if it is of the special form:

        +-             -+
        | a+b*I, -c-d*I |
        | c-d*I,  a-b*I |
        +-             -+

    If the conversion fails, `FAIL` is returned.

#### Method convert_to: conversion to other domains

- `convert_to(dom x, any T)`
- - This method tries to convert the number `x` to an element of type `T`, or, if `T` is not a domain, to the domain type of `T`. If the conversion fails, `FAIL` is returned.
  - It currently handles the following domains for `T`: `DOM_EXPR`, `DOM_LIST`, `Dom::Matrix``(Dom::Complex)`.

#### Method expr: converts a quaternion to an object of a kernel domain

- `expr(dom x)`
- - This method overloads `expr`.
  - This method converts `x` into an expression of the form `a+bI+cJ+dK`.
  - The result is an object of the kernel domain `DOM_EXPR`.
  - This method overloads the function `expr` for quaternions, i.e., you may use it in the form `expr(x)`.

#### Method matrixform: converts a quaternion to a 2 x 2 matrix with complex entries.

- `matrixform(dom x)`
- - This method converts x:=a+bI+cJ+dK to the 2 x 2-matrix:

        +-             -+
        | a+b*I, -c-d*I |
        | c-d*I,  a-b*I |
        +-             -+

  - The result is an object of the domain `Dom::Matrix(Dom::Complex)`.

#### Method TeX: generate TeX-formatted string

- `TeX(dom x)`
- - This method overloads `generate::TeX`.
  - `Dom::Quaternion(`x`)` returns a TeX-formatted string representing `x`.

#### Method map: apply a function to all components of a quaternion

- `map(dom x, function f, any arg...)`
- - This method overloads `map`.
  - `Dom::Quaternion(`x, f`)` returns a copy of `x` where each component `co` of `x` has been replaced by `f(co)`. So for the quaternion x:=a+bi+cj+dk, `Dom::Quaternion(`x, f`)` returns the quaternion f(a)+f(b)i+f(c)j+f(d)k.
  - If optional arguments are present, then each component `co` of `x` is replaced by f(co, arg...). So for the quaternion x:=a+bi+cj+dk, `Dom::Quaternion(`x, f, arg, ...`)` returns the quaternion f(a, arg,...)+f(b, arg,...)i+f(c, arg,...)j+f(d, arg,...)k.

#### Method simplify: simplification of a quaternion

- `simplify(dom x)`
- - This method overloads `simplify`.
  - Tries to simplify the quaternion x:=a+bi+cj+dk by trying to simplify every component `a, b, c, d` of `x`.

#### Example 1

Creating some quaternions.

    >> Dom::Quaternion([1,2,3,4]),
       Dom::Quaternion(11+12*i+13*j+14*k);
       M := Dom::Matrix(Dom::Complex)([[3+4*I,-6-2*I],[6-2*I,3-4*I]]):
       M, Dom::Quaternion(M)

                 3 J + 4 K + (1 + 2 I), 13 J + 14 K + (11 + 12 I)

                  +-                    -+
                  |  3 + 4 I, - 6 - 2 I  |
                  |                      |, 6 J + 2 K + (3 + 4 I)
                  |  6 - 2 I,  3 - 4 I   |
                  +-                    -+

#### Example 2

Doing some standard arithmetic.

    >> a:=Dom::Quaternion([1,2,3,4]):
       b:=Dom::Quaternion([11,2,33.3,2/3]):
       a*b, a+b, a^2/3, b^3;

          72.96666667 J + 105.2666667 K - (95.56666667 + 107.2 I),

                      14 K                     8 K
             36.3 J + ---- + (12 + 4 I), 2 J + --- - (28/3 - 4/3 I),
                       3                        3

             - 24986.137 J - 500.222963 K - (35409.03666 + 1500.668889 I)

#### Example 3

More mathematical operations:

    >> a:=Dom::Quaternion([1,2,3,4]):
       b:=Dom::Quaternion([11,2,33.3,2/3]):
       Dom::Quaternion::nthroot(b,3);
       abs(a), sign(b)

          1.325212827 J + 0.02653078732 K +

             (2.993953193 + 0.07959236197 I)

            1/2
          30   , 0.9478242358 J + 0.01897546018 K +

             (0.3130950929 + 0.05692638053 I)

#### Example 4

Some miscellaneous operations.

    >> a:=Dom::Quaternion([1,2,3,4]):
       Dom::Quaternion::matrixform(a);
       map(a, sqrt), map(a, _plus, 1);

                             +-                    -+
                             |  1 + 2 I, - 3 - 4 I  |
                             |                      |
                             |  3 - 4 I,  1 - 2 I   |
                             +-                    -+

                          1/2      1/2
                 2 K + I 2    + J 3    + 1, 4 J + 5 K + (2 + 3 I)

#### Super-Domain

`Dom::BaseDomain`

#### Axioms

`Ax::canonicalRep`

#### Changes

- no changes

Do you have questions or comments?
Copyright © SciFace Software GmbH & Co. KG 2000