cayley-dickson-0.3.1.0: Complex numbers, quaternions, octonions, sedenions, etc.

Copyright (c) James M. Lawrence MIT James M. Lawrence provisional portable Safe Haskell2010

Math.CayleyDickson

Description

Cayley-Dickson constructions (complex numbers, quaternions, octonions, sedenions, etc.) over general scalars without limit to the number of dimensions.

An element of this structure is composed of an m-dimensional scalar part and an m*(2^n - 1)-dimensional pure part (unrelated to Haskell's uses of "pure"). An element whose scalar part is zero is called a pure. Construction with real scalars yields the Cayley-Dickson algebras, in which case the scalar part is also called the real part. Other structures may be obtained by considering general scalars, for instance the quaternions over complex scalars.

Synopsis

# Types

data Nion n a Source

General Cayley-Dickson construction producing "N-ions". The first parameter is a `Tag` instance that determines the dimension, which is 2 raised to `tagVal`. The second parameter is the scalar type.

Instances

 (Conjugable a, Eq a) => Eq (Nion n a) Source (Tag n, Conjugable a, RealFloat a) => Floating (Nion n a) Source The first pure basis element is arbitrarily chosen as sqrt (-1). (Conjugable a, Fractional a) => Fractional (Nion n a) Source Conjugable a => Num (Nion n a) Source (Tag n, Show a, Num a) => Show (Nion n a) Source Conjugable a => Conjugable (Nion n a) Source

type Complex a = Nion Tag1 a Source

Complex numbers, the 2^1-dimensional construction.

type Quaternion a = Nion Tag2 a Source

Quaternions, the 2^2-dimensional construction.

type Octonion a = Nion Tag3 a Source

Octonions, the 2^3-dimensional construction.

type Sedenion a = Nion Tag4 a Source

Sedenions, the 2^4-dimensional construction.

# Construction

nion :: (Tag n, Num a) => [a] -> Nion n a Source

Construct an element from a list of coordinates. If the list is too small then the remaining coordinates are padded with zeros. If the list is too large then the extra values are ignored.

fromScalar :: a -> Nion n a Source

Promote a scalar, returning an element whose scalar part is the argument and whose pure part is zero. The element behaves as if it were padded with zeros, but no actual padding is done.

complex :: a -> a -> Complex a Source

Construct a complex number.

quaternion :: a -> a -> a -> a -> Quaternion a Source

Construct a quaternion.

octonion :: a -> a -> a -> a -> a -> a -> a -> a -> Octonion a Source

Construct an octonion.

sedenion :: a -> a -> a -> a -> a -> a -> a -> a -> a -> a -> a -> a -> a -> a -> a -> a -> Sedenion a Source

Construct a sedenion.

# Operations

dot :: Conjugable a => Nion n a -> Nion n a -> a Source

Dot product. For real scalars, `(1 `dot`)` is equivalent to `scalarPart`.

cross :: Conjugable a => Nion n a -> Nion n a -> Nion n a Source

Cross product. The cross product of two pures yields a pure that is orthogonal to both operands. For real scalars, `(1 `cross`)` is equivalent to `purePart`.

sqnorm :: Conjugable a => Nion n a -> a Source

Squared norm: the dot product of an element with itself.

norm :: (Conjugable a, Floating a) => Nion n a -> a Source

Square root of `sqnorm`.

polar :: (Tag n, Conjugable a, RealFloat a) => Nion n a -> (a, a, Nion n a) Source

Return `(s, t, u)` such that (approximately)

`x == s .* `exp` (t .* u)`

where `s` and `t` are scalars, `s >= 0`, and `u` is a unit pure.

If `x` has no pure part then `u` is arbitrarily chosen to be the first pure basis element.

## Operations with scalars

The mnemonic is that the period (".") is on the side of the scalar.

(**.) :: (Tag n, Conjugable a, RealFloat a) => Nion n a -> a -> Nion n a infixr 8 Source

Raise to a scalar power.

(.+) :: Conjugable a => a -> Nion n a -> Nion n a infix 6 Source

Equivalent to `fromScalar x + y`.

(+.) :: Conjugable a => Nion n a -> a -> Nion n a infix 6 Source

Equivalent to `x + fromScalar y`.

(.-) :: Conjugable a => a -> Nion n a -> Nion n a infix 6 Source

Equivalent to `fromScalar x - y`.

(-.) :: Conjugable a => Nion n a -> a -> Nion n a infix 6 Source

Equivalent to `x - fromScalar y`.

(.*) :: Conjugable a => a -> Nion n a -> Nion n a infix 7 Source

Equivalent to `fromScalar x * y`.

(*.) :: Conjugable a => Nion n a -> a -> Nion n a infix 7 Source

Equivalent to `x * fromScalar y`.

(/.) :: (Conjugable a, Fractional a) => Nion n a -> a -> Nion n a infix 7 Source

Equivalent to `x / fromScalar y`.

# Accessors

coord :: (Tag n, Num a, Integral b, Bits b) => Nion n a -> b -> a Source

Get the nth coordinate.

coords :: (Tag n, Num a) => Nion n a -> [a] Source

List of coordinates for this element.

setCoord :: (Tag n, Conjugable a, Integral b, Bits b) => Nion n a -> b -> a -> Nion n a Source

Set the nth coordinate, returning a new element.

scalarPart :: Nion n a -> a Source

Equivalent to `coord x 0`.

purePart :: Num a => Nion n a -> Nion n a Source

Equivalent to `setCoord x 0 0`.

# Constants

basisElement :: (Tag n, Conjugable a, Bits i, Integral i) => i -> Nion n a Source

The nth basis element.

# Classes

class Num a => Conjugable a where Source

The conjugate of an element is obtained by negating the pure part and conjugating the scalar part. The conjugate of a real number is the identity (`id`), which is the default implementation.

Minimal complete definition

Nothing

Methods

conj :: a -> a Source

Conjugate.

scalarPart' :: a -> a Source

Equivalent to `(x + conj x) / 2`.

Instances

 Source Source Source Source Source Source Source Source Source Source Source Source Integral a => Conjugable (Ratio a) Source HasResolution a => Conjugable (Fixed a) Source (Conjugable a, RealFloat a) => Conjugable (Complex a) Source Conjugable a => Conjugable (Nion n a) Source

## Tags

class Tag n where Source

Tags serve to determine a type's dimension, which is 2 raised to `tagVal`. Tag instances are included for convenience only, as you may create your own tag.

Methods

tagVal :: Proxy n -> Integer Source

data Tag0 Source

Instances

 Source

data Tag1 Source

Instances

 Source

data Tag2 Source

Instances

 Source

data Tag3 Source

Instances

 Source

data Tag4 Source

Instances

 Source

data Tag5 Source

Instances

 Source

data Tag6 Source

Instances

 Source

data Tag7 Source

Instances

 Source

data Tag8 Source

Instances

 Source

data Tag9 Source

Instances

 Source

data Tag10 Source

Instances

 Source

data Tag11 Source

Instances

 Source

data Tag12 Source

Instances

 Source

data Tag13 Source

Instances

 Source

data Tag14 Source

Instances

 Source

data Tag15 Source

Instances

 Source

data Tag16 Source

Instances

 Source

data Tag17 Source

Instances

 Source

data Tag18 Source

Instances

 Source

data Tag19 Source

Instances

 Source

data Tag20 Source

Instances

 Source

data Tag21 Source

Instances

 Source

data Tag22 Source

Instances

 Source

data Tag23 Source

Instances

 Source

data Tag24 Source

Instances

 Source

data Tag25 Source

Instances

 Source

data Tag26 Source

Instances

 Source

data Tag27 Source

Instances

 Source

data Tag28 Source

Instances

 Source

data Tag29 Source

Instances

 Source

data Tag30 Source

Instances

 Source