2026-02-26
matrix world
(w.i.p.) Purposeful re-learnings in linear algebra.
I watched a math video series.
Proving grounds for math typesetting and core competencies in AI.
Matrix world
i love matrices, they're facing me
song: LEARNING TIME - slowerpace 音楽
[experience the full animation on desktop]
Introduction: Why re-learn linear algebra for ai safety
I took linear algebra in university. The professor was writing the book at the time of the course. I was allowed to fail one class, so it worked out in the end.
My preference is to know ahead of time what I will be learning, and why I am learning it. How does this thing pertain to the ends that I am pursuing, and how do all the items of the syllabus pertain to this thing.
If someone had told me that linear algebra is the key to making AI work, I would have paid more attention. Nah, who am I kidding, I probably would have missed that detail.
It's also the key to having more spatial awareness, as well as making cool art, with the help of open source libraries and AI for the tedious work.
I am (re-)learning linear algebra in order to have a deeper understanding of artificial intelligence; that is, specifically Large Language Models (LLMs).
This knowledge yields a deeper understanding, because the Tensor object in PyTorch generalizes vectors and matrices, enabling researchers to perform large-scale matrix operations efficiently on GPUs. Under the hood, computations like gradient descent, backpropagation, and optimization are all orchestrated via linear transformations and their derived functions.
PyTorch is widely used in the space of "research", which includes AI safety research; thus, it is important to learn PyTorch; thus, it is important to (re-)learn linear algebra.
The "Essence of linear algebra" video series by 3Blue1Brown is highly recommended for the intuitive and visual approach to learning that it provides.
If you want to learn properly, go to my sources. These are simply my notes from the video series.
Hence, the very loose language and informal style.
0. Study tips
Pomodoro technique. 3Blue1Brown's videos are roughly 10 minutes each.
That is half a pomodoro. The other half can be spent writing notes and solidifying personal interpretation.
Then niksen. Then repeat.
Vamos a empezar.
1. Vectors
Vectors — to me — are ordered lists of numbers, because I align with the computer science perspective, a concrete perspective for our purposes.
Vectors represent, from the origin of the axis, a direction and magnitude. You'll often hear the terms vectors and matrices intermixed, at least from me, and when people are talking like human beings. Vectors typically imply motion, and the Matrix typically implies Keeanu Reeves.
Since we are only working up to the third dimension, it is easy to represent this using the Cartesian coordinate system.
The origin has zero coordinates:
Vectors in two-dimensional space are represented with a pair of numbers where each number represents the displacement along the respective axes from the origin. The positive direction for is right. The positive direction for is up.
Here is a 2-D vector:
Vectors in three-dimensional space are represented with a triplet written where is orthogonal (perpendicular) to the other two axes.
Here is a 3-D vector:
Note: points are written in order to differentiate from vectors.
See my point?
Where and can be any real number. too, so we may say that .
(Note: means "in" as in... these variables can be ANY real number — so, anything EXCEPT FOR a complex number)
If we square , which represents one-dimensional space, we arrive in two-dimensional space, represented by .
If we cube , we arrive in three-dimensional space, represented by .
Thus, the shape of is an infinite cube in all directions from the origin.
We won't get into higher dimensions than this, but mathematically, it may be said that, a vector in is an ordered list of real numbers.
We use the term "ordered list" of numbers because "set" of numbers implies uniqueness. A vector is a list of components (numbers), where order matters.
Vector Addition
Adding two vectors combines them component-wise:
For example, and :
Vector addition is commutative and associative .
Scalar Multiplication
Vector (scalar) multiplication magnifies a vector by a constant. These constants are called scalars because they scale vectors. Scalars are the only numbers in linear algebra — these terms are use interchangeably.
Multiplying a vector by a scalar scales each component:
Scaling by when :
Negative scalars reverse direction:
Finally, collapses the vector to the zero vector:
Thus, there are only three outcomes from scalar multiplication:
- Magnification of the vector
- Inversion of the vector
2. Linear combinations, span, and basis (unit) vectors
Vectors are stretched or squished by scalars.
A unit is a very basic thing. A unit vector is a very special thing. It is like the number one, but for vectors.
The unit vector and the unit vector .
The unit vector is the unit vector in three-dimensional space; that is, it is the unit vector that represents .
Here is what they look like:
The unit vectors and thus represent one positive step in each dimension available in two-dimensional space.
Taking this a step further, we see an un-interesting pattern emerge:
No further steps than that. This is enough to see that the unit vector of any given dimension should — in best practice and textbooks — represent a single step into that dimension.
We may scale that single step; that is to say, we may scale unit vectors, in order to arrive at any point in for however many dimensions are available.
The unit vectors are special because they allow us to represent vectors in either of these ways:
Together, and are called the basis, because everything else is based on these two vectors, in two-dimensional space.
Every vector may be formed through scaling and .
The span is formed through all possible linear combinations of the two vectors:
A span in may be thought of as area.
A span in may be thought of as volume.
Tune the span — tune the space.
I should also note that the unit vectors are unit vectors because they have magnitude one (). They are also linearly independent; that is to say, you cannot find a scalar to magnify one vector unto the other:
Which is why they form the basis of separate dimensions.
3. Linear transformations and matrices
Transformations are movement. Movement from one space to another space.
That other space is stretchy by comparison, because in actuality, we are transforming the grid-space.
Or at least, that is just one perspective, that the grid itself is moving — the points are simply along for the ride.
Linear transformations must let lines be lines, and must not move the origin.
Grid lines remain parallel and evenly spaced as an effect; that is to say, the grid lines are not unevenly stretched, sheared, etc. The grid lines are transformed uniformly.
Here is an example of a linear transformation applied against , when and :
So given a and , we are able to construct the formula:
This means that, given some and in one space, we have a formula to find to where and have been moved. A succinct method of encoding these two vectors involves a 2x2 ("two-by-two") matrix:
Allowing us to rewrite the previous formula:
Yielding the same effect. Thus, a linear transformation in two-dimensional space may be mathematically described as:
If these vectors are linearly dependent; that is to say:
In other words, if can be magnified onto , or, if can be magnified onto ; then there exists a one-dimensional span, whereby all of planar space is collapsed (onto a line).
4. Matrix multiplication as composition
Continuing the idea of a linear transformations; we may chain together linear transformations via composition matrices, which compose two or more separate linear transformations in the form of a matrix, as the name implies.
Thankfully I am also studying Semitic languages at this moment; it helps with reading, because linear transformations in linear compositions are applied right-to-left.
This website is very useful for visualizing matrix multiplication.
For my own reference, here are some examples of rotations and shears (two common linear transformations).
Scaling
Preserve direction, changes scale.
Rotations
Preserves scale, changes direction.
90° Clockwise Rotation:
180° Clockwise Rotation:
270° Clockwise Rotation:
Shears
Slides one of the unit vectors, shearing the area.
Horizontal shear:
Vertical shear:
Reflections
Useful for flipping the area, and self-improvement.
Reflection across the x-axis:
Reflection across the y-axis:
Therefore, the above linear composition applies a 270° clockwise rotation, then a horizontal shear.
These are composition matrix; that is, a chain of linear transformations applied to a vector? Applied to a grid-space?
You decide.
When applying these linear transformations, we simply apply matrix multiplication:
Simply is an understatement. A pneumonic that I have devised to remember the row/column business (apart from row/column itself tells the row of the first matrix, multiplied by column the second matrix):
- First marches forward
- Second slides downward
The row of the first matrix is multiplied by the column of the second matrix, and if there are variables, the calculation results in a number at the intersection of that row and column in a square, matrix.
The inner dimensions between two matrices must match in order to apply linear transformations, perform matrix multiplication; that is to say, matrix multiplication can only take place between an matrix and an matrix, because the inner dimensions match on .
Matrix multiplication is always applied this way — this is imperative to understand, because:
Changing the order of the matrices in matrix multiplication, changes the overall composition of the transformations.
5. Three-dimensional linear transformations
Now for extending the composition of linear transformations into three-dimensional space.
Let's not take longer than we have to — this place hurts my head.
Simply adding one extra direction introduces much complexity, but introduces no more complication than before, when we were working in two-dimensional space.
Behold, a linear transformation in three-dimensional space:
6. The determinant
All this talk of scaling an area, all this talk of scaling a space — but by what factor?
And what if we're interested in the factor after applying a linear transformation which does more than just scale? (e.g. shearing)
The determinant of a transformation tells us by what factor an area is scaled as result of said transformation.
The determinant of a matrix:
The determinant of a matrix:
These determinant formulas are themselves determined from the Leibniz formula for determinants.
When the output of the determinant function is zero, then the given linear transformation will collapse a space below the present dimension.
When the output of the determinant function is negative, then the given linear transformation will invert a space — a space, defined by a given, input matrix.
The determinant of a transformation in three-dimensional space tells us by what factor a volume is scaled as a result of said transformation.
Multiplying the amount that one matrix scales (the determinant) by the amount that another matrix scales is mathematically the same as calculating the amount scaled as a result of sequentially applying the two linear transformations (matrices):
The glob, the shape of a matrix in my mind — is transformation, space, movement.
7. Inverse matrices, column space and null space
Systems of equations can be represented as a combination of linear transformations.
This system of equations:
Can also be written this way:
Can be expressed as a series of matrices:
I should add that this is intended for systems of linear equations.
You won't see anything like , , or in linear equations.
No functions like either.
Linear equations are useful in the form of
If we could play this computation in reverse, we could retrieve , , and — and we can.
Such that — by morphing space, and remembering that linear transformations in linear compositions are applied right-to-left, we may deduce from the knowns.
Morphing backwards in space, otherwise known as applying the inverse transformation, looks something like this:
For a more concrete example, let's reference the 90° Clockwise Rotation example from before, and the application of the inverse transformation:
But how do we know the inverse for any given linear transformation? By doing nothing. I'm serious.
The matrix that does nothing is the identity matrix, much like the number in multiplication. When the identity matrix:
— is used, it leaves and where they are.
Once you find the inverse of , it may be used to find :
This is because anything multiplied by , is itself. So at any point, we are allowed to multiply any coefficient by the identity, . The inverse transformation works like the inverse exponent in regular maths; that is to say, if we have the number, say , and multiply by , or , then we end up with one.
I'm quite bad at this. Behold, a very loose analogy:
To recap, we take known variables in the matrix , utilize a computer/keen intuition to find , which is then utilized to find .
People don't understand — there's a lot that goes into doing nothing.
A loss of information occurs when . Once a matrix has been squished into a lower dimension, there exists no inverse.
In the case of three-dimensional space, we have the luxury of losing information twice without knowing, when . This is because the determinant alone does not signify the number of dimensions, or rank, of the transformation.
Predictably, is a point, and represents nothingness, total collapse; is a line, and represents one-dimensional space; is a plane, and represents two-dimensional space; is a volume-spanning subspace, or simply, space, and represents three-dimensional space.
Rank is the number of dimensions in the column space, or the span of the columns of the matrix .
The zero vector, , is always in the column space.
Full rank means that the output space still has all the dimensions it started with.
The null space, also called kernel, is the space of all vectors that become null, or zero, through the applied linear transformation.
Concretely, this means that like setting in , such that gives a point at the solution, the null space in the following, familiar equation:
— forms a span at the solution(s).
Column space helps us know when a solution exists.
Kernel helps us know the set of all possible solutions.
8. Non-square matrices as transformations between dimensions
Non-square matrices are portals between real-space, speaking loosely.
For our purposes, a non-square matrix is any matrix where , which is only two matrices: and .
Because we work primarily in square matrices, a non-square matrix represents transformation from three-dimensional space to two-dimensional space, and a non-square matrix represents transformation from two-dimensional space to three-dimensional space.
9. Dot products and duality
The dot product produces a scalar from two vectors:
Geometrically it encodes the angle between the vectors:
When the vectors are orthogonal (perpendicular), because the dot product measures how much the two vectors point in the same direction. No overlap yields a zero value.
Duality in mathematics describes the phenomenon that one concept often has dual, or multiple, different applications. Like taijitu, mathematical duality reveals how opposing concepts reflect and sustain one another, exposing an underlying symmetry that unites what first appears divided.
10. Cross products
11. Cross products in the light of linear transformations
12. Cramer's rule, explained geometrically
13. Change of basis
Given bases and and target vector , translation between coordinate systems is possible:
14. Eigenvector and eigenvalues
15. A quick trick for computing eigenvalues
16. Abstract vector spaces
Trivia
The title of this article refers to the Wikipedia article entitled "Matrix decomposition", which references an image entitled "Matrix World", which was useful to me — a visual thinker. The canvas artwork is also entitled "Matrix world", but with sentence casing to comply with corporate style guidelines.
I thought the grids in the video "Inverse matrices, column space and null space | Chapter 7, Essence of linear algebra" looked pretty cool, so I decided to create my own rendition of it here using Three.js drawn on an html canvas.
The color scheme was inspired, roughly, by the logo for the musical, Joseph and the Amazing Technicolor Dreamcoat, for which I played "left-hand piano" (the bass part (which inspired me to learn the ACTUAL upright bass + bass guitar [Thanks, Pat])) during freshman year in public high school. I don't know how that happened outside a private school. Anyways, I hope you've enjoyed.