Linear Algebra

Linear Algebra for Common Lisp

Overview

LLA works with matrices, that is arrays of rank 2, with all numerical values. Categorical variables could be integer coded if you need to.

Setup

lla requires a BLAS and LAPACK shared library. These may be available via your operating systems package manager, or you can download OpenBLAS, which includes precompiled binaries for MS Windows.

You can also configure the path by setting the cl-user::*lla-configuration* variable like so:

(defvar *lla-configuration*
  '(:libraries ("s:/src/lla/lib/libopenblas.dll")))

Use the location specific to your system.

To load lla:

(asdf:load-system :lla)
(use-package 'lla) ;access to the symbols

Getting Started

To make working with matrices easier, we’re going to use the matrix-shorthand library. Load it like so:

(use-package :num-utils.matrix-shorthand)

Matrix Multiplication

mm is the matrix multiplication function. It is generic and can operate on both regular arrays and ‘wrapped’ array types, e.g. hermitian or triangular. In this example we’ll multiple an array by a vector. mx is the short-hand way of defining a matrix, and vec a vector.

(let ((a (mx 'lla-double
           (1 2)
           (3 4)
           (5 6)))
      (b2 (vec 'lla-double 1 2)))
  (mm a b2))

; #(5.0d0 11.0d0 17.0d0)

Last modified 29 December 2023: Plot v2 and associated updates (7b917e1)