harpie-numhask-0.1.0.0: numhask shim for harpie.
Safe HaskellSafe-Inferred
LanguageGHC2021

Harpie.NumHask

Description

numhask orphan instances and shim for harpie.

Synopsis

Usage

ident :: (KnownNats s, Additive a, Multiplicative a) => Array s a Source #

The identity array.

>>> pretty $ ident @[3,3]
[[1,0,0],
 [0,1,0],
 [0,0,1]]

undiag :: forall s' a s. (KnownNats s, KnownNats s', s' ~ Eval ((++) s s), Additive a) => Array s a -> Array s' a Source #

Expand the array to form a diagonal array

>>> pretty $ undiag (range @'[3])
[[0,0,0],
 [0,1,0],
 [0,0,2]]

mult :: forall a ds0 ds1 s0 s1 so0 so1 st si. (Ring a, KnownNats s0, KnownNats s1, KnownNats ds0, KnownNats ds1, KnownNats so0, KnownNats so1, KnownNats st, KnownNats si, so0 ~ Eval (DeleteDims ds0 s0), so1 ~ Eval (DeleteDims ds1 s1), si ~ Eval (GetDims ds0 s0), si ~ Eval (GetDims ds1 s1), st ~ Eval ((++) so0 so1), ds0 ~ '[Eval ((-) (Eval (Rank s0)) 1)], ds1 ~ '[0]) => Array s0 a -> Array s1 a -> Array st a Source #

Array multiplication.

matrix multiplication

>>> pretty $ mult m (F.transpose m)
[[5,14],
 [14,50]]

inner product

>>> pretty $ mult v v
5

matrix-vector multiplication

>>> pretty $ mult v (F.transpose m)
[5,14]
>>> pretty $ mult m v
[5,14]

invtri :: forall a n. (KnownNat n, ExpField a, Eq a) => Matrix n n a -> Matrix n n a Source #

Inversion of a Triangular Matrix

>>> t = array @[3,3] @Double [1,0,1,0,1,2,0,0,1]
>>> pretty (invtri t)
[[1.0,0.0,-1.0],
 [0.0,1.0,-2.0],
 [0.0,0.0,1.0]]
ident == mult t (invtri t)

True

inverse :: (Eq a, ExpField a, KnownNat m) => Matrix m m a -> Matrix m m a Source #

Inverse of a square matrix.

mult (inverse a) a == a
>>> e = array @[3,3] @Double [4,12,-16,12,37,-43,-16,-43,98]
>>> pretty (inverse e)
[[49.36111111111111,-13.555555555555554,2.1111111111111107],
 [-13.555555555555554,3.7777777777777772,-0.5555555555555555],
 [2.1111111111111107,-0.5555555555555555,0.1111111111111111]]

chol :: (KnownNat m, ExpField a) => Matrix m m a -> Matrix m m a Source #

cholesky decomposition

Uses the Cholesky-Crout algorithm.

>>> e = array @[3,3] @Double [4,12,-16,12,37,-43,-16,-43,98]
>>> pretty (chol e)
[[2.0,0.0,0.0],
 [6.0,1.0,0.0],
 [-8.0,5.0,3.0]]
>>> mult (chol e) (F.transpose (chol e)) == e
True

Orphan instances

Additive a => AdditiveAction (Array s a) Source # 
Instance details

Associated Types

type AdditiveScalar (Array s a) #

Methods

(|+) :: Array s a -> AdditiveScalar (Array s a) -> Array s a #

Divisive a => DivisiveAction (Array s a) Source # 
Instance details

Methods

(|/) :: Array s a -> Scalar (Array s a) -> Array s a #

Multiplicative a => MultiplicativeAction (Array s a) Source # 
Instance details

Associated Types

type Scalar (Array s a) #

Methods

(|*) :: Array s a -> Scalar (Array s a) -> Array s a #

Subtractive a => SubtractiveAction (Array s a) Source # 
Instance details

Methods

(|-) :: Array s a -> AdditiveScalar (Array s a) -> Array s a #

(Additive a, KnownNats s) => Additive (Array s a) Source # 
Instance details

Methods

(+) :: Array s a -> Array s a -> Array s a #

zero :: Array s a #

(Subtractive a, KnownNats s) => Subtractive (Array s a) Source # 
Instance details

Methods

negate :: Array s a -> Array s a #

(-) :: Array s a -> Array s a -> Array s a #

(KnownNats s, JoinSemiLattice a) => JoinSemiLattice (Array s a) Source # 
Instance details

Methods

(\/) :: Array s a -> Array s a -> Array s a #

(KnownNats s, MeetSemiLattice a) => MeetSemiLattice (Array s a) Source # 
Instance details

Methods

(/\) :: Array s a -> Array s a -> Array s a #

(KnownNats s, Subtractive a, Epsilon a) => Epsilon (Array s a) Source # 
Instance details

Methods

epsilon :: Array s a #

FromInteger a => FromInteger (Array ('[] :: [Nat]) a) Source # 
Instance details

Methods

fromInteger :: Integer -> Array '[] a #

FromRational a => FromRational (Array ('[] :: [Nat]) a) Source # 
Instance details

Methods

fromRational :: Rational -> Array '[] a #

(Multiplicative a, Distributive a, Subtractive a, Eq a, ExpField a, KnownNat m) => Divisive (Matrix m m a) Source # 
Instance details

Methods

recip :: Matrix m m a -> Matrix m m a #

(/) :: Matrix m m a -> Matrix m m a -> Matrix m m a #

(Multiplicative a, Distributive a, Subtractive a, KnownNat m) => Multiplicative (Matrix m m a) Source # 
Instance details

Methods

(*) :: Matrix m m a -> Matrix m m a -> Matrix m m a #

one :: Matrix m m a #