Safe Haskell | Safe |
---|---|
Language | Haskell2010 |
Synopsis
- type Free f = (Representable f, Eq (Rep f))
- type Basis b f = (Free f, Rep f ~ b)
- type Basis2 b c f g = (Basis b f, Basis c g)
- type Basis3 b c d f g h = (Basis b f, Basis c g, Basis d h)
- (.*) :: RightSemimodule r a => a -> r -> a
- (.#) :: Semiring a => Foldable g => Basis2 b c f g => (f ** g) a -> g a -> f a
- (*.) :: LeftSemimodule l a => l -> a -> a
- (#.) :: Semiring a => Foldable f => Basis2 b c f g => f a -> (f ** g) a -> g a
- dot :: Semiring a => Foldable f => Basis b f => f a -> f a -> a
- lerp :: LeftModule r a => r -> a -> a -> a
- quadrance :: Semiring a => Foldable f => Basis b f => f a -> a
- qd :: FreeModule a f => Foldable f => f a -> f a -> a
- cross :: Ring a => V3 a -> V3 a -> V3 a
- triple :: Ring a => V3 a -> V3 a -> V3 a -> a
- dirac :: Eq i => Semiring a => i -> i -> a
- idx :: Semiring a => Basis b f => b -> f a
- elt :: Basis b f => b -> f a -> a
- lensRep :: Basis b f => b -> forall g. Functor g => (a -> g a) -> f a -> (g ** f) a
- grateRep :: Basis b f => forall g. Functor g => (b -> g a1 -> a2) -> (g ** f) a1 -> f a2
- (.#.) :: Semiring a => Foldable g => Basis3 b c d f g h => (f ** g) a -> (g ** h) a -> (f ** h) a
- trace :: Semiring a => Foldable f => Basis b f => (f ** f) a -> a
- transpose :: Basis2 b c f g => (f ** g) a -> (g ** f) a
- inv1 :: Field a => M11 a -> M11 a
- inv2 :: Field a => M22 a -> M22 a
- bdet2 :: Semiring a => Basis2 E2 E2 f g => (f ** g) a -> (a, a)
- det2 :: Ring a => Basis2 E2 E2 f g => (f ** g) a -> a
- bdet3 :: Semiring a => Basis2 E3 E3 f g => (f ** g) a -> (a, a)
- det3 :: Ring a => Basis2 E3 E3 f g => (f ** g) a -> a
- inv3 :: Field a => M33 a -> M33 a
- bdet4 :: Semiring a => Basis2 E4 E4 f g => (f ** g) a -> (a, a)
- det4 :: Ring a => Basis2 E4 E4 f g => (f ** g) a -> a
- inv4 :: Field a => M44 a -> M44 a
- tran :: Semiring a => Basis2 b c f g => Foldable g => (f ** g) a -> Tran a b c
- elt2 :: Basis2 b c f g => b -> c -> (f ** g) a -> a
- row :: Basis b f => b -> (f ** g) a -> g a
- rows :: Basis2 b c f g => g a -> (f ** g) a
- col :: Basis2 b c f g => c -> (f ** g) a -> f a
- cols :: Basis2 b c f g => f a -> (f ** g) a
- diag :: Semiring a => Basis b f => f a -> (f ** f) a
- outer :: Semiring a => Basis2 b c f g => f a -> g a -> (f ** g) a
- identity :: Semiring a => Basis b f => (f ** f) a
- diagonal :: Representable f => (f ** f) a -> f a
- newtype V1 a = V1 a
- unV1 :: V1 a -> a
- data V2 a = V2 !a !a
- data V3 a = V3 !a !a !a
- data V4 a = V4 !a !a !a !a
- type M11 = Compose V1 V1
- type M12 = Compose V1 V2
- type M13 = Compose V1 V3
- type M14 = Compose V1 V4
- type M21 = Compose V2 V1
- type M31 = Compose V3 V1
- type M41 = Compose V4 V1
- type M22 = Compose V2 V2
- type M23 = Compose V2 V3
- type M24 = Compose V2 V4
- type M32 = Compose V3 V2
- type M33 = Compose V3 V3
- type M34 = Compose V3 V4
- type M42 = Compose V4 V2
- type M43 = Compose V4 V3
- type M44 = Compose V4 V4
- m11 :: a -> M11 a
- m12 :: a -> a -> M12 a
- m13 :: a -> a -> a -> M13 a
- m14 :: a -> a -> a -> a -> M14 a
- m21 :: a -> a -> M21 a
- m31 :: a -> a -> a -> M31 a
- m41 :: a -> a -> a -> a -> M41 a
- m22 :: a -> a -> a -> a -> M22 a
- m23 :: a -> a -> a -> a -> a -> a -> M23 a
- m24 :: a -> a -> a -> a -> a -> a -> a -> a -> M24 a
- m32 :: a -> a -> a -> a -> a -> a -> M32 a
- m33 :: a -> a -> a -> a -> a -> a -> a -> a -> a -> M33 a
- m34 :: a -> a -> a -> a -> a -> a -> a -> a -> a -> a -> a -> a -> M34 a
- m42 :: a -> a -> a -> a -> a -> a -> a -> a -> M42 a
- m43 :: a -> a -> a -> a -> a -> a -> a -> a -> a -> a -> a -> a -> M43 a
- m44 :: a -> a -> a -> a -> a -> a -> a -> a -> a -> a -> a -> a -> a -> a -> a -> a -> M44 a
Types
Vector arithmetic
(.*) :: RightSemimodule r a => a -> r -> a infixl 7 Source #
(*.) :: LeftSemimodule l a => l -> a -> a infixr 7 Source #
(#.) :: Semiring a => Foldable f => Basis2 b c f g => f a -> (f ** g) a -> g a infix 7 Source #
Multiply a matrix on the left by a row vector.
>>>
V2 1 2 #. m23 3 4 5 6 7 8
V3 15 18 21
>>>
(V2 1 2 #. m23 3 4 5 6 7 8) #. m32 1 0 0 0 0 0
V2 15 0
lerp :: LeftModule r a => r -> a -> a -> a Source #
Linearly interpolate between two vectors.
>>>
u = V3 (1 :% 1) (2 :% 1) (3 :% 1) :: V3 Rational
>>>
v = V3 (2 :% 1) (4 :% 1) (6 :% 1) :: V3 Rational
>>>
r = 1 :% 2 :: Rational
>>>
lerp r u v
V3 (6 % 4) (12 % 4) (18 % 4)
qd :: FreeModule a f => Foldable f => f a -> f a -> a Source #
Squared l2 norm of the difference between two vectors.
cross :: Ring a => V3 a -> V3 a -> V3 a Source #
Cross product
a `cross'
a =zero
a `cross'
b =negate
( b `cross'
a ) , a `cross'
( b+
c ) = ( a `cross'
b )+
( a `cross'
c ) , ( r a ) `cross'
b = a `cross'
( r b ) = r ( a `cross'
b ) . a `cross'
( b `cross'
c )+
b `cross'
( c `cross'
a )+
c `cross'
( a `cross'
b ) =zero
.
See Jacobi identity.
Vector accessors and constructors
idx :: Semiring a => Basis b f => b -> f a Source #
Create a unit vector at an index.
>>>
idx E21 :: V2 Int
V2 1 0
>>>
idx E42 :: V4 Int
V4 0 1 0 0
Matrix arithmetic
(.#.) :: Semiring a => Foldable g => Basis3 b c d f g h => (f ** g) a -> (g ** h) a -> (f ** h) a infixr 7 Source #
Multiply two matrices.
>>>
m22 1 2 3 4 .#. m22 1 2 3 4 :: M22 Int
Compose (V2 (V2 7 10) (V2 15 22))
>>>
m23 1 2 3 4 5 6 .#. m32 1 2 3 4 4 5 :: M22 Int
Compose (V2 (V2 19 25) (V2 43 58))
trace :: Semiring a => Foldable f => Basis b f => (f ** f) a -> a Source #
Compute the trace of a matrix.
>>>
trace $ m22 1.0 2.0 3.0 4.0
5.0
transpose :: Basis2 b c f g => (f ** g) a -> (g ** f) a Source #
Transpose a matrix.
>>>
transpose (V3 (V2 1 2) (V2 3 4) (V2 5 6))
V2 (V3 1 3 5) (V3 2 4 6)
>>>
transpose $ m23 1 2 3 4 5 6 :: M32 Int
V3 (V2 1 4) (V2 2 5) (V2 3 6)
inv1 :: Field a => M11 a -> M11 a Source #
1x1 matrix inverse over a field.
>>>
inv1 $ m11 4.0 :: M11 Double
Compose (V1 (V1 0.25))
inv2 :: Field a => M22 a -> M22 a Source #
2x2 matrix inverse over a field.
>>>
inv2 $ m22 1 2 3 4 :: M22 Double
Compose (V2 (V2 (-2.0) 1.0) (V2 1.5 (-0.5)))
bdet2 :: Semiring a => Basis2 E2 E2 f g => (f ** g) a -> (a, a) Source #
2x2 matrix bdeterminant over a commutative semiring.
>>>
bdet2 $ m22 1 2 3 4
(4,6)
bdet3 :: Semiring a => Basis2 E3 E3 f g => (f ** g) a -> (a, a) Source #
3x3 matrix bdeterminant over a commutative semiring.
>>>
bdet3 (V3 (V3 1 2 3) (V3 4 5 6) (V3 7 8 9))
(225, 225)
inv3 :: Field a => M33 a -> M33 a Source #
3x3 matrix inverse.
>>>
inv3 $ m33 1 2 4 4 2 2 1 1 1 :: M33 Double
Compose (V3 (V3 0.0 0.5 (-1.0)) (V3 (-0.5) (-0.75) 3.5) (V3 0.5 0.25 (-1.5)))
bdet4 :: Semiring a => Basis2 E4 E4 f g => (f ** g) a -> (a, a) Source #
4x4 matrix bdeterminant over a commutative semiring.
>>>
bdet4 $ m44 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
(27728,27728)
inv4 :: Field a => M44 a -> M44 a Source #
4x4 matrix inverse.
>>>
row E41 . inv4 $ m44 1 0 3 2 2 0 2 1 0 0 0 1 0 3 4 0 :: V4 Rational
V4 (6 % (-12)) ((-9) % (-12)) ((-3) % (-12)) (0 % (-12))
Matrix accessors and constructors
elt2 :: Basis2 b c f g => b -> c -> (f ** g) a -> a Source #
Retrieve an element of a matrix.
>>>
elt2 E21 E21 $ m22 1 2 3 4
1
row :: Basis b f => b -> (f ** g) a -> g a Source #
Retrieve a row of a matrix.
>>>
row E22 $ m23 1 2 3 4 5 6
V3 4 5 6
rows :: Basis2 b c f g => g a -> (f ** g) a Source #
Obtain a matrix by stacking rows.
>>>
rows (V2 1 2) :: M22 Int
V2 (V2 1 2) (V2 1 2)
col :: Basis2 b c f g => c -> (f ** g) a -> f a Source #
Retrieve a column of a matrix.
>>>
elt E22 . col E31 $ m23 1 2 3 4 5 6
4
cols :: Basis2 b c f g => f a -> (f ** g) a Source #
Obtain a matrix by stacking columns.
>>>
cols (V2 1 2) :: M22 Int
V2 (V2 1 1) (V2 2 2)
diag :: Semiring a => Basis b f => f a -> (f ** f) a Source #
Obtain a diagonal matrix from a vector.
>>>
diag $ V2 2 3
Compose (V2 (V2 2 0) (V2 0 3))
outer :: Semiring a => Basis2 b c f g => f a -> g a -> (f ** g) a Source #
Outer product of two vectors.
>>>
V2 1 1 `outer` V2 1 1
Compose (V2 (V2 1 1) (V2 1 1))
identity :: Semiring a => Basis b f => (f ** f) a Source #
Identity matrix.
>>>
identity :: M33 Int
Compose (V3 (V3 1 0 0) (V3 0 1 0) (V3 0 0 1))
diagonal :: Representable f => (f ** f) a -> f a Source #
Obtain the diagonal of a matrix as a vector.
>>>
diagonal $ m22 1.0 2.0 3.0 4.0
V2 1.0 4.0
Vector types
V1 a |
Instances
V2 !a !a |
Instances
V3 !a !a !a |
Instances
V4 !a !a !a !a |
Instances
Matrix types
m13 :: a -> a -> a -> M13 a Source #
Construct a 1x3 matrix.
>>>
m13 1 2 3 :: M13 Int
Compose (V1 (V3 1 2 3))
m14 :: a -> a -> a -> a -> M14 a Source #
Construct a 1x4 matrix.
>>>
m14 1 2 3 4 :: M14 Int
Compose (V1 (V4 1 2 3 4))
m21 :: a -> a -> M21 a Source #
Construct a 2x1 matrix.
>>>
m21 1 2 :: M21 Int
Compose (V2 (V1 1) (V1 2))
m31 :: a -> a -> a -> M31 a Source #
Construct a 3x1 matrix.
>>>
m31 1 2 3 :: M31 Int
Compose (V3 (V1 1) (V1 2) (V1 3))
m41 :: a -> a -> a -> a -> M41 a Source #
Construct a 4x1 matrix.
>>>
m41 1 2 3 4 :: M41 Int
Compose (V4 (V1 1) (V1 2) (V1 3) (V1 4))
m22 :: a -> a -> a -> a -> M22 a Source #
Construct a 2x2 matrix.
Arguments are in row-major order.
>>>
m22 1 2 3 4 :: M22 Int
Compose (V2 (V2 1 2) (V2 3 4))
m23 :: a -> a -> a -> a -> a -> a -> M23 a Source #
Construct a 2x3 matrix.
Arguments are in row-major order.
m24 :: a -> a -> a -> a -> a -> a -> a -> a -> M24 a Source #
Construct a 2x4 matrix.
Arguments are in row-major order.
m32 :: a -> a -> a -> a -> a -> a -> M32 a Source #
Construct a 3x2 matrix.
Arguments are in row-major order.
m33 :: a -> a -> a -> a -> a -> a -> a -> a -> a -> M33 a Source #
Construct a 3x3 matrix.
Arguments are in row-major order.
m34 :: a -> a -> a -> a -> a -> a -> a -> a -> a -> a -> a -> a -> M34 a Source #
Construct a 3x4 matrix.
Arguments are in row-major order.
m42 :: a -> a -> a -> a -> a -> a -> a -> a -> M42 a Source #
Construct a 4x2 matrix.
Arguments are in row-major order.