algebrite logo

algebrite

Computer Algebra System in Javascript.
View on GitHub.
latest-stable: v1.4.0


back to main page

Why the tensor notation changes in v1.0.0?

v1.0.0 changed the notation of tensors: instead of using parentheses Algebrite now uses square brackets. E.g. instead of:
(0,1,2)
Algebrite now uses:
[0,1,2]

This is because parentheses are also used for precedence, and for basic algebra rules we have to allow things like (x) to be evaluated to x. So, while (2) was previously a valid vector representation (a one-dimensional vector of length 1), it would effectively be evaluated to 2, which is a scalar.
As another example, the columnar vector ((1),(2),(3)), which has rank 2 and is a 3x1 matrix, would be evaluated to the row vector (1,2,3) of rank 1.

Some examples of the new notation:
[1,2,3]: a 1-dimensional vector of length 3
[[1,2,3]]: a row vector: a 2-dimensional vector of length 3, also a 1x3 matrix
[[1],[2],[3]]: a column vector: a 2-dimensional vector of length 3, also a 3x1 matrix
[[[a,b,c]]]: a three-dimensional tensor of size [1,1,3]
[[[a],[b],[c]]]: a three-dimensional tensor of size [1,3,1]
[[[a]],[[b]],[[c]]]: a three-dimensional tensor of size [3,1,1]

In general, the trick to count the rank (i.e. dimensions) is to count the number of nested brackets, and the trick to determine the shape is to count the commas proceeding from the outermost to the inner-most brackets.