Basic Linear Algebra in Gaea

The Gaea package "array" is giving access to some of the most useful functions in Gaea, i.e. basic linear algebra operations. In a previous blog post we have seen the available element-wise operations. In this post we are going to have a look to the rest of package "array". More specifically this library provides the following:

  • element-wise operations of arrays,
  • elementary operations of arrays, such as [+], [-], [*], dot, cross,
  • other operations of arrays, such as diag, eye, linspace, ones, transpose, zeros,
  • a user interface for taking slices of array-like objects,
  • an extensible DSL for selecting a subset of valid subscripts,
  • a set of utility functions for traversing slices in array-like objects.

Let's take a look at some examples. First of all [+], [-], and [*] are the standard matrix addition, substraction, and multiplication, respectively. We can write 

([*] #2A((1 2) (3 4)) #2A((5 6) (7 8))) 
; returns #2A((19 22) (43 50))

dot and cross are the vector dot and cross product, respectively. For instance,

(dot #(1 2 3) #(4 5 6))
; returns 32
(cross #(1 2 3) #(4 5 6))
; returns #(-3 6 -3)

diag returns a vector which is the diagonal of a square matrix. transpose returns the transpose of a matrix.

eye returns an identity matrix. ones generates a matrix full of ones, while zeros generates a matrix full of zeros.

Useful, right? But there is more. tolist converts an array-like object to a list.

(array:tolist #2A((0 1) (2 3)))
; returns ((0 1) (2 3))

Finally, we have the function slice, which selects a slice of the array. If the index is set to t, then it selects all subscripts.

(array:slice #2A((0 1) (2 3)) t 1)
; returns #(1 3)

The chapter of linear algebra doesn't end with the package "array". Stay tuned to learn about the package "linalg" in the near future.

Tags: