Copyright | (c) Matti A. Eskelinen 2016-2017 |
---|---|
License | MIT |
Maintainer | matti.a.eskelinen@gmail.com |
Stability | experimental |
Portability | POSIX |
Safe Haskell | Safe |
Language | Haskell2010 |
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.
- class (Ord b, Num a) => Basis b a where
- newtype Euclidean a = E {
- getE :: a
- data Lorentzian a
- orthoMul :: Basis b a => ([b], a) -> ([b], a) -> ([b], a)
- nonOrthoMul :: (Eq a, Basis b a) => ([b], a) -> ([b], a) -> [([b], a)]
- freeMul :: Num a => ([b], a) -> ([b], a) -> ([b], a)
- orderOrthoBasis :: Basis b a => [b] -> [b] -> a -> ([b], a)
- orderBasis :: (Eq a, Basis b a) => [([b], a)] -> [b] -> a -> [([b], a)]
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.
Basis construction
Data type for constructing Euclidean basis vectors (metric is 1 for matching vectors, 0 otherwise).
data Lorentzian a Source #
Data type for Lorentzian (mixed signature) basis vectors.
Eq a => Eq (Lorentzian a) Source # | |
Ord a => Ord (Lorentzian a) Source # | |
Show a => Show (Lorentzian a) Source # | |
Generic (Lorentzian a) Source # | |
(Ord b, Num a) => Basis (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)