Vector Spaces#

Basic Introduction to Vector Spaces#

Definition

In mathematics, a vector space is a structure made up of a set of vectors, that can be added together and scaled by numbers called scalars. These vectors and scalars must satisfy certain properties, including associativity, commutativity, and the existence of an additive identity and additive inverses.

In simpler terms, a vector space provides a framework for manipulating and studying collections of objects that can be combined and stretched without losing their essential properties.

For those interested, the basic mathematical properties can be found on Wikipedia

In SageMath, we can work with vector spaces to perform operations on vectors in a structured and consistent manner.

# Define a vector space over the rational numbers of dimension 3
V = VectorSpace(QQ, 3)

# Define two vectors in the vector space
v = V([1, 2, 3])  # Define a vector [1, 2, 3]
w = V([4, 5, 6])  # Define another vector [4, 5, 6]

# Vector addition
u = v + w

Try changing the VectorSpace dimension to 2 and see what happens.

Here’s how the vector space concept helps us in this example:

  1. Rigorous Definition: By defining V as a vector space over the rational numbers (QQ) of dimension 3, we establish a clear mathematical structure for our vectors. This ensures that operations like addition and scalar multiplication adhere to the properties of vector spaces.

  2. Consistent Operations: When we perform vector addition u = v + w, SageMath ensures that the addition is carried out element-wise, respecting the rules of vector addition defined in the vector space. This guarantees consistency and correctness in our computations.

  3. Type Safety: By encapsulating vectors within the vector space V, we ensure type safety. That is, v and w are recognized as elements of the vector space V, preventing unintended operations or errors that may arise from mixing vectors from different spaces.

  4. Abstraction: We can perform vector operations without needing to worry about the specific underlying representation of vectors. This abstraction allows us to work with vectors in a general and flexible manner, facilitating code reuse and scalability.

  5. Scalability: Vector spaces in SageMath can handle vectors of arbitrary dimension and over various fields (e.g., real numbers, rational numbers). This scalability enables us to work with vectors in high-dimensional spaces and in different mathematical contexts with ease.

In summary, leveraging the vector space concept in SageMath provides a solid foundation for performing vector operations, ensuring correctness, consistency, and abstraction in our computations.

Testing if a Vector is in a VectorSpace#

Think of a vector space as a place with specific rules for how its elements interact. Testing if a vector belongs in that space is like checking if it follows those rules. This is important because it ensures the vector can seamlessly interact with the others in the space, without disrupting the underlying structure. If it doesn’t follow the rules, it’s like trying to force a square peg into a round hole – it won’t fit, and it could cause problems.

V = VectorSpace(QQ, 3)
v = vector(RR, [1,2,3])
v in V
True

In the above example, v in V evaluates to True because although v is defined over the real numbers (RR), it is considered a valid member of the vector space V, which is defined over the rational numbers (QQ). SageMath handles this type conversion implicitly when checking for membership.

V = VectorSpace(QQ, 3)
v = vector(CC, [1,2,3])
v in V
False

In the above example, v in V evaluates to False because v is defined over a different field (complex numbers) than the one specified for the vector space V (rational numbers).

V = VectorSpace(QQ, 3)
v = vector(QQ, [1,2,3,4])
v in V
False

In the above example, v in V evaluates to False because the dimension of v is different from the dimension specified for the vector space V.

V = VectorSpace(QQ, 3)

v = V([1, 2, 3]) 
w = V([4, 5, 6])

# Check if linear combination is in V
2*v - 3*w in V
True

Basis#

V = VectorSpace(QQ, 3)
V.basis()
[(1, 0, 0), (0, 1, 0), (0, 0, 1)]

Note: The concept of basis is foundational in linear algebra. If you’re not familiar with it, don’t worry! We’ll delve into it in depth in a later lesson: 07 Basis. For now, just know that a basis is like a set of building blocks for a vector space.

Dimension#

V = VectorSpace(QQ, 3)
V.dimension()
3

The dimension of a vector space is a fundamental measure of its “size” or “complexity.” It tells us how many independent directions we need to fully describe any vector within that space. Think of it as the minimum number of “building blocks” required to construct any element within the space through linear combinations.

Linear independence#

V = VectorSpace(QQ, 3)
v1 = V([1, 0, 0])
v2 = V([0, 1, 0])
v3 = V([0, 0, 1])
is_linearly_independent = V.subspace([v1, v2, v3]).dimension() == len([v1, v2, v3])
is_linearly_independent
True

Checking for linear dependence or independence of vectors is a fundamental concept in linear algebra with several practical implications which we will cover in the next lesson: 06 Linear Dependence.

Spanning Set#

V = VectorSpace(QQ, 3)
span_set = V.span([V([1, 0, 0]), V([0, 1, 0])])
span_set
Vector space of degree 3 and dimension 2 over Rational Field
Basis matrix:
[1 0 0]
[0 1 0]

Spanning sets are essential because they provide a minimal set of vectors that collectively describe the entire vector space, enabling the representation of any vector within that space through linear combinations of the spanning set’s vectors.

We will cover span and spanning sets in the lesson 07 Span.

Orthogonality#

V = VectorSpace(QQ, 3)
v1 = V([1, 0, 0])
v2 = V([0, 1, 0])
is_orthogonal = v1.dot_product(v2) == 0
is_orthogonal
True

Orthogonality between vectors signifies that they are perpendicular to each other in a vector space, implying a zero dot product between them, and often indicates independence or a decomposition into orthogonal components.

We will cover this in a later lesson.

Projection#

V = VectorSpace(QQ, 3)
v = V([1, 2, 3])
w = V([4, 5, 6])
proj_v_on_w = (v.dot_product(w) / w.dot_product(w)) * w
proj_v_on_w
(128/77, 160/77, 192/77)

The results (128/77, 160/77, 192/77) represent the components of the vector \(\text{proj}_w(v)\), showing how much of vector \(v\) lies in the direction of \(w\). Understanding projections is vital as they allow for the decomposition of vectors into components along specific directions, aiding in analysis, optimization, and simplification of vector quantities in various mathematical and computational contexts.

This will also be covered in a later lesson.