# FsAlg: Generic Linear Algebra Library

FsAlg is a linear algebra library that supports generic types. It is implemented in the F# language.

The library provides generic Vector and Matrix types that support most of the commonly used linear algebra operations, including matrix–vector operations, matrix inverse, determinants, eigenvalues, LU and QR decompositions. Its intended use is to enable writing generic linear algebra code with custom numeric types. It can also be used as a lightweight library for prototyping and scripting with primitive floating point types.

FsAlg is developed by Atılım Güneş Baydin and Barak A. Pearlmutter as part of their work at the Brain and Computation Lab, Hamilton Institute, National University of Ireland Maynooth.

## How to Get

You can install the library via NuGet. You can also download the source code or the binaries of the latest release on GitHub.

PM> Install-Package FsAlg

## Quick Usage Example

1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: |
open FsAlg.Generic let A = matrix [[3.; 1.]; [2.; -1.]] let b = vector [5.; 0.] // Solve a matrix equation let x = Matrix.solve A b // Find inverse of A let Ainv = Matrix.inverse A // Initialize a vector let w = Vector.init 2 (fun i -> float (i * i)) // Map a function to a vector let y = Vector.map (fun x -> sin (exp x)) w // Matrix-vector operations let z = A * (x - y) |

Full name: Index.A

Full name: FsAlg.Generic.Ops.matrix

Full name: Index.b

Full name: FsAlg.Generic.Ops.vector

Full name: Index.x

union case Matrix.Matrix: 'T [,] -> Matrix<'T>

--------------------

module Matrix

from FsAlg.Generic

--------------------

type Matrix<'T (requires member get_Zero and member get_One and member ( + ) and member ( - ) and member ( * ) and member ( / ) and member ( ~- ) and member Abs and member Pow and member Sqrt and member op_Explicit and comparison)> =

| ZeroMatrix of 'T

| Matrix of 'T [,]

member Copy : unit -> Matrix<'T>

member GetDeterminant : unit -> 'T

member GetDiagonal : unit -> 'T []

member GetEigenvalues : unit -> 'T []

member GetEnumerator : unit -> IEnumerator<'T>

member GetInverse : unit -> Matrix<'T>

member GetLUDecomposition : unit -> Matrix<'T> * int [] * 'T

member GetQRDecomposition : unit -> Matrix<'T> * Matrix<'T>

member GetSlice : rowStart:int option * rowFinish:int option * col:int -> Matrix<'T>

member GetSlice : row:int * colStart:int option * colFinish:int option -> Matrix<'T>

member GetSlice : rowStart:int option * rowFinish:int option * colStart:int option * colFinish:int option -> Matrix<'T>

member GetTrace : unit -> 'T

member GetTranspose : unit -> Matrix<'T>

member ToArray : unit -> 'T [] []

member ToArray2D : unit -> 'T [,]

member ToMathematicaString : unit -> string

member ToMatlabString : unit -> string

member ToSeq : unit -> seq<'T>

member Cols : int

member Item : i:int * j:int -> 'T with get

member Rows : int

member Item : i:int * j:int -> 'T with set

static member Zero : Matrix<'T>

static member ( + ) : a:'T * b:Matrix<'T> -> Matrix<'T>

static member ( + ) : a:Matrix<'T> * b:'T -> Matrix<'T>

static member ( + ) : a:Matrix<'T> * b:Matrix<'T> -> Matrix<'T>

static member ( / ) : a:'T * b:Matrix<'T> -> Matrix<'T>

static member ( / ) : a:Matrix<'T> * b:'T -> Matrix<'T>

static member ( ./ ) : a:Matrix<'T> * b:Matrix<'T> -> Matrix<'T>

static member ( .* ) : a:Matrix<'T> * b:Matrix<'T> -> Matrix<'T>

static member op_Explicit : m:Matrix<'T> -> float [,]

static member ( * ) : a:'T * b:Matrix<'T> -> Matrix<'T>

static member ( * ) : a:Matrix<'T> * b:'T -> Matrix<'T>

static member ( * ) : a:Vector<'T> * b:Matrix<'T> -> Vector<'T>

static member ( * ) : a:Matrix<'T> * b:Vector<'T> -> Vector<'T>

static member ( * ) : a:Matrix<'T> * b:Matrix<'T> -> Matrix<'T>

static member ( - ) : a:'T * b:Matrix<'T> -> Matrix<'T>

static member ( - ) : a:Matrix<'T> * b:'T -> Matrix<'T>

static member ( - ) : a:Matrix<'T> * b:Matrix<'T> -> Matrix<'T>

static member ( ~- ) : a:Matrix<'T> -> Matrix<'T>

Full name: FsAlg.Generic.Matrix<_>

Full name: FsAlg.Generic.Matrix.solve

Full name: Index.Ainv

Full name: FsAlg.Generic.Matrix.inverse

Full name: Index.w

union case Vector.Vector: 'T [] -> Vector<'T>

--------------------

module Vector

from FsAlg.Generic

--------------------

type Vector<'T (requires member get_Zero and member get_One and member ( + ) and member ( - ) and member ( * ) and member ( / ) and member ( ~- ) and member Abs and member Pow and member Sqrt and member op_Explicit and comparison)> =

| ZeroVector of 'T

| Vector of 'T []

member Convert : f:('T -> 'a) -> Vector<'a> (requires member get_Zero and member get_One and member ( + ) and member ( - ) and member ( * ) and member ( / ) and member ( ~- ) and member Abs and member Pow and member Sqrt and member op_Explicit and comparison)

member Copy : unit -> Vector<'T>

member GetEnumerator : unit -> IEnumerator<'T>

member GetL1Norm : unit -> 'T

member GetL2Norm : unit -> 'T

member GetL2NormSq : unit -> 'T

member GetLPNorm : p:'T -> 'T

member GetMax : unit -> 'T

member GetMaxBy : f:('T -> 'a1) -> 'T (requires comparison)

member GetMin : unit -> 'T

member GetMinBy : f:('T -> 'a1) -> 'T (requires comparison)

member GetSlice : lower:int option * upper:int option -> Vector<'T>

member GetSubVector : s:int * c:int -> Vector<'T>

member GetUnitVector : unit -> Vector<'T>

member Split : n:seq<int> -> seq<Vector<'T>>

member SplitEqual : n:int -> seq<Vector<'T>>

member ToArray : unit -> 'T []

member ToMathematicaString : unit -> string

member ToMatlabString : unit -> string

member ToSeq : unit -> seq<'T>

member FirstItem : 'T

member Item : i:int -> 'T with get

member Length : int

member Item : i:int -> 'T with set

static member Zero : Vector<'T>

static member ( + ) : a:'T * b:Vector<'T> -> Vector<'T>

static member ( + ) : a:Vector<'T> * b:'T -> Vector<'T>

static member ( + ) : a:Vector<'T> * b:Vector<'T> -> Vector<'T>

static member ( / ) : a:'T * b:Vector<'T> -> Vector<'T>

static member ( / ) : a:Vector<'T> * b:'T -> Vector<'T>

static member ( ./ ) : a:Vector<'T> * b:Vector<'T> -> Vector<'T>

static member ( .* ) : a:Vector<'T> * b:Vector<'T> -> Vector<'T>

static member op_Explicit : v:Vector<'T> -> float []

static member ( * ) : a:'T * b:Vector<'T> -> Vector<'T>

static member ( * ) : a:Vector<'T> * b:'T -> Vector<'T>

static member ( * ) : a:Vector<'T> * b:Vector<'T> -> 'T

static member ( %* ) : a:Vector<'T> * b:Vector<'T> -> Vector<'T>

static member ( - ) : a:'T * b:Vector<'T> -> Vector<'T>

static member ( - ) : a:Vector<'T> * b:'T -> Vector<'T>

static member ( - ) : a:Vector<'T> * b:Vector<'T> -> Vector<'T>

static member ( ~- ) : a:Vector<'T> -> Vector<'T>

Full name: FsAlg.Generic.Vector<_>

Full name: FsAlg.Generic.Vector.init

val float : value:'T -> float (requires member op_Explicit)

Full name: Microsoft.FSharp.Core.Operators.float

--------------------

type float = System.Double

Full name: Microsoft.FSharp.Core.float

--------------------

type float<'Measure> = float

Full name: Microsoft.FSharp.Core.float<_>

Full name: Index.y

Full name: FsAlg.Generic.Vector.map

Full name: Microsoft.FSharp.Core.Operators.sin

Full name: Microsoft.FSharp.Core.Operators.exp

Full name: Index.z