Package

org.taffy.core.maths

Object Hierarchy
What is it?

A Matrix is a representation of a mathematical matrix. It supports all Taffy mathematical operators.

Quick Example
matrix = ||1, 2
           3, 4||

Table of Contents:

Constructing a Matrix

A Matrix that is n rows by m columns is constructed like so:

matrix1 = ||1, 2 ; 3, 4||

we can separate rows with an end-line instead of a semicolon:

matrix2 = ||1, 2
            3, 4||

matrix1 == matrix2
==> true

Arithmetic

The Matrix class supports many Taffy mathematical operators. Some operators support both Matrix and non-Matrix right-sides, while some operators, such as divide (/) support only non-Matrix right-sides.

// we can add numbers, or matrices of the same size
matrix1 = ||1, 2, 3 ; 4, 5, 6||
matrix1 + 1

==> ||2, 3, 4 ; 5, 6, 7||

matrix2 = ||-1, -2, -3 ; -4, -5, -6||
matrix1 + matrix2
==> ||0, 0, 0 ; 0, 0, 0||

Setting and Getting

We use the [] operator to get values from a Matrix, and the []= operator to set values. The [] operator takes two arguments: {row, column}:

matrix = ||1, 2, 3 ; 4, 5, 6||

matrix[0, 0]
==> 1

matrix[0, 1]
==> 2

matrix[1, 2]
==> 6
For matrixes with one row, the [] and []= operators take a single value: {column},
but they also accept the standard two-argument syntax:
matrix = ||"one", "two", "three"||

matrix[0]
==> "one"

matrix[1] = "four"
==> ||"one", "four", "three"||

Vectorization

The vectorize: method takes one argument, a Function to apply to each element in the Matrix:

f(x) = x^3
a = ||1, 2, 3||

a vectorize: f
==> ||1, 8, 27||

Supported Arithmetic

Matrix-on-Matrix Operators
+ (add)
- (subtract)
* (multiply)
~= (delta-equal)
Matrix-on-non-Matrix Operators
+ (add)
* (multiply)
+= (add-equals)
- (subtract)
-= (subtract-equals)
/ (divide)
/= (divide-equals)
* (multiply)
*= (multiply-equals)
^ (raise)
^= (raise-equals)
% (modulus)
Operators Requiring Whole Left and Right Values (Matrix-on-non-Matrix)
// operators requiring whole left and right values
<< (left-shift)
<<= (left-shift-self)
>> (right-shift)
>>= (right-shift-self)
| (bit-or)
|= (bit-or-self)
& (bit-and)
&= (bit-and-self)
^^ (bit-xor)
^^= (bit-xor-self)
Standalone Operators
++ (add-one-to-self)
-- (subtract-self-by-one)
! (factorial)