Vector Space Speed Run

Keith A. Lewis

Nov 4, 2026

https://wikihack.netlify.app/a/1451/apl-programming-language

Karpathy

Fasten your seatbelt.

If you don’t know what a vector space is, just assume it is the set of n-tuples {\boldsymbol{{R}}^n = \{\boldsymbol{{x}} = (x_1,\ldots,x_n)\mid x_j\in\boldsymbol{{R}}, 1\le j\le n\}} where \boldsymbol{{R}} is the field of real numbers. We use bold face \boldsymbol{{x}} to indicate a vector tuple. Any field will do, e.g., the complex numbers \boldsymbol{{C}} or finite fields {\boldsymbol{{Z}}_p = \boldsymbol{{Z}}/p\boldsymbol{{Z}}} of integers modulo a prime number p. We will use \boldsymbol{{F}} to denote any field.

Vector spaces have a scalar multiplication and vector addition. For a\in\boldsymbol{{F}} and \boldsymbol{{x}},\boldsymbol{{y}}\in\boldsymbol{{F}}^n the scalar multiplication is a(x_i) = (ax_i) and the vector addition is (\boldsymbol{{x}} + \boldsymbol{{y}})_i = x_i + y_i, 1\le i\le n.

A different, but equivalent, way to represent \boldsymbol{{F}}^n is the set of all functions x\colon\{1,\ldots,n\}\to\boldsymbol{{F}} where x_i corresponds to x(i). There seems to be no generally accepted mathematical notation to distinguish them.

This was figured out long ago by (Iverson 1980) when he was dissatisfied with the expressive power of Fortran two decades earlier. His brilliant APL: A Programming Language is still alive and kicking in its latest incarnation: kdb.

For any set I define the set product {\Pi_I\boldsymbol{{F}}= \Pi_{i\in I}\boldsymbol{{F}}= \{\boldsymbol{{x}} = (x_i)\mid x_i\in\boldsymbol{{F}}, i\in I\}}. The set exponential {\boldsymbol{{F}}^I = \{x\colon I\to\boldsymbol{{F}}\}} is equivalent by identifying x_i with x(i), i\in I.

Let’s give an explicit name to this implicit correspondence \Pi = \Pi_{\boldsymbol{{F}},I}\colon\boldsymbol{{F}}^I\to\Pi_I\boldsymbol{{F}} where (\Pi x)(i) = x_i.

This is our first example of a linear operator.

Exercise. Show \Pi(a x + y) = a\Pi(x) + \Pi(y).

Hint: This follows from the laws satisfied by the field.

Exercise. _Show \Pi(ax) = aPi(x) and \Pi(x + y) = \Pi(x) + \Pi(y), a\in\boldsymbol{{F}}, x,y\in \Pi_I \boldsymbol{{F}}.

Hint: Use \Pi(0) = 0 and 1x = x.

If V is a vector space then a subset U\subseteq V is a subspace if it is closed under scalar multiplication and vector addition. We can write this as \boldsymbol{{F}}U\subseteq U and U + U\subseteq U where {\boldsymbol{{F}}U = \{au\mid a\in\boldsymbol{{F}}, u\in U\}} and {U + U = \{u + v\mid u,v\in U\}}.

Exercise. Show if V and W are vector spaces show their intersection V\cap W and sum V + W are vector spaces.

Hint: Show they are closed under scalar addition and vector multiplication.

Given a subspace U\subseteq V define the quotient space {V/U = \{v + U\mid v\in V\}} with scalar multiplication {a(v + U) = av + U} and vector addition {(v + U) + (w + U) = (v + w) + U}.

Exercise. Show scalar multiplication and vector addition are well-defined.

Hint: This means if v + U = w + U then a(v + U) = a(w + U) and

Let {\operatorname{L}(V,W) = \{T\colon V\to W\mid T\text{ is linear}\}} be the set of all linear operators from the vector space V to the vector space W. It is also a vector space with scalar prodcut (aT)(v) = a(T(v)) and vector addition (T + U)(v) = T(v) + U(v), a\in\boldsymbol{{F}}, v\in V. This is also written as \operatorname{Hom}(V,W) for the set of homomorphism: functions that preserve the vector space structure.

The kernel of a linear oprator T\in\operatorname{L}(V,W) is \operatorname{ker}T = \{v\in V\mid Tv = 0\} and the range is \operatorname{ran}T\{Tv\mid v\in V\}\subseteq W.

If V = W we write \operatorname{End}(V) for \operatorname{Hom}(V,V), the set of endomorphisms for a vectorspace to itself.

Iverson, Kenneth E. 1980. “Notation as a Tool of Thought.” Communications of the ACM 23 (8): 444–65.