clif-0.1.0.0: A Clifford algebra number type for Haskell

Copyright(c) Matti A. Eskelinen 2016-2017
LicenseMIT
Maintainermatti.a.eskelinen@gmail.com
Stabilityexperimental
PortabilityPOSIX
Safe HaskellSafe
LanguageHaskell2010

Clif.Basis

Contents

Description

Motivation

A Clifford algebra is generated by a set of linearly independent (but not necessarily orthogonal) basis vectors and a metric (bilinear form) from the vectors to a field (or unital ring). After the basis and bilinear form are fixed, the Clifford algebra is exactly the quotient of the free algebra of the basis vectors by the equality relation generated by the form (see https://en.wikipedia.org/wiki/Clifford_algebra).

Implementation

Defining a basis is abstracted using the two-parameter typeclass Basis. A Basis b a for a Clifford algebra is defined by implementing a metric that takes two vectors of type b (for basis) and returns a number of type a, which is then used by basisMul to implement multiplication of vectors. For computational reasons, any vector type must have some canonical ordering (i.e. be an instance of Ord). The constructors for Euclidean and Lorentzian types can be used to map any such type with a corresponding metric.

While not strictly necessary for the abstraction, functions canonical and basisMul are included in the class with respective default implementations (orderOrthoBasis and orthoMul) in order to provide an easy way to override them using a more efficient implementation for a user-supplied basis. Note that the default implementations are only valid for a diagonal metric; Use orderBasis and nonOrthoMul if you define a non-diagonal metric.

Synopsis

Classes

class (Ord b, Num a) => Basis b a where Source #

A typeclass for specifying a metric space The default implementation uses orthoMul; Replace it if you require a non-diagonal metric.

Minimal complete definition

metric

Methods

metric :: b -> b -> a Source #

canonical :: ([b], a) -> [([b], a)] Source #

basisMul :: ([b], a) -> ([b], a) -> [([b], a)] Source #

Instances

(Ord b, Num a) => Basis (Lorentzian b) a Source # 

Methods

metric :: Lorentzian b -> Lorentzian b -> a Source #

canonical :: ([Lorentzian b], a) -> [([Lorentzian b], a)] Source #

basisMul :: ([Lorentzian b], a) -> ([Lorentzian b], a) -> [([Lorentzian b], a)] Source #

(Ord b, Num a) => Basis (Euclidean b) a Source # 

Methods

metric :: Euclidean b -> Euclidean b -> a Source #

canonical :: ([Euclidean b], a) -> [([Euclidean b], a)] Source #

basisMul :: ([Euclidean b], a) -> ([Euclidean b], a) -> [([Euclidean b], a)] Source #

Basis construction

newtype Euclidean a Source #

Data type for constructing Euclidean basis vectors (metric is 1 for matching vectors, 0 otherwise).

Constructors

E 

Fields

Instances

Eq a => Eq (Euclidean a) Source # 

Methods

(==) :: Euclidean a -> Euclidean a -> Bool #

(/=) :: Euclidean a -> Euclidean a -> Bool #

Ord a => Ord (Euclidean a) Source # 
Show a => Show (Euclidean a) Source # 
Generic (Euclidean a) Source # 

Associated Types

type Rep (Euclidean a) :: * -> * #

Methods

from :: Euclidean a -> Rep (Euclidean a) x #

to :: Rep (Euclidean a) x -> Euclidean a #

(Ord b, Num a) => Basis (Euclidean b) a Source # 

Methods

metric :: Euclidean b -> Euclidean b -> a Source #

canonical :: ([Euclidean b], a) -> [([Euclidean b], a)] Source #

basisMul :: ([Euclidean b], a) -> ([Euclidean b], a) -> [([Euclidean b], a)] Source #

type Rep (Euclidean a) Source # 
type Rep (Euclidean a) = D1 (MetaData "Euclidean" "Clif.Basis" "clif-0.1.0.0-H0KqGNtDxY8DPUhAB26yxH" True) (C1 (MetaCons "E" PrefixI True) (S1 (MetaSel (Just Symbol "getE") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 a)))

data Lorentzian a Source #

Data type for Lorentzian (mixed signature) basis vectors.

Constructors

T a

Timelike basis vector (-1)

S a

Spacelike basis vector (+1)

Instances

Eq a => Eq (Lorentzian a) Source # 

Methods

(==) :: Lorentzian a -> Lorentzian a -> Bool #

(/=) :: Lorentzian a -> Lorentzian a -> Bool #

Ord a => Ord (Lorentzian a) Source # 
Show a => Show (Lorentzian a) Source # 
Generic (Lorentzian a) Source # 

Associated Types

type Rep (Lorentzian a) :: * -> * #

Methods

from :: Lorentzian a -> Rep (Lorentzian a) x #

to :: Rep (Lorentzian a) x -> Lorentzian a #

(Ord b, Num a) => Basis (Lorentzian b) a Source # 

Methods

metric :: Lorentzian b -> Lorentzian b -> a Source #

canonical :: ([Lorentzian b], a) -> [([Lorentzian b], a)] Source #

basisMul :: ([Lorentzian b], a) -> ([Lorentzian b], a) -> [([Lorentzian b], a)] Source #

type Rep (Lorentzian a) Source # 

Multiplication of blades

orthoMul :: Basis b a => ([b], a) -> ([b], a) -> ([b], a) Source #

Multiplies together two blades of orthogonal vectors and simplifies the results to canonical order using orderOrthoBasis.

nonOrthoMul :: (Eq a, Basis b a) => ([b], a) -> ([b], a) -> [([b], a)] Source #

Multiplies two blades of (possibly non-orthogonal) basis vectors and simplifies the result to canonical order using orderBasis. Note that this generally results in a direct sum of blades, i.e. a list.

freeMul :: Num a => ([b], a) -> ([b], a) -> ([b], a) Source #

Free multiplication of scaled blades (concatenation of vectors and multiplication of scalars).

Computation of canonical order

orderOrthoBasis :: Basis b a => [b] -> [b] -> a -> ([b], a) Source #

Canonical (ordered) form of a scaled basis blade of orthogonal vectors Uses a gnome sort to commute the basis vectors to order and keeps track of the commutations w.r.t. the blade multiplier, applying the equation

ba = -ab

for each consecutive pair ba in wrong order. Note that this relation holds only for a basis with a diagonal bilinear form, for others use the more general (albeit slower) orderBasis.

orderBasis :: (Eq a, Basis b a) => [([b], a)] -> [b] -> a -> [([b], a)] Source #

Canonical (ordered) form of a scaled basis blade of vectors Uses a gnome sort to commute the basis vectors to order and keeps track of the commutations applying the equation

ab = 2 B(a,b) - ba

for any given bilinear form B between the basis vectors and the number ring. Note that this is slower than using orderOrthoBasis if your bilinear form is diagonal (B(a,b) = 0 for a != b)