maths.freeAbstract Algebra › 20. Vector Spaces › Sage

Sage

Many computations, in seemingly very different areas of mathematics, can be translated into questions about linear combinations, or other areas of linear algebra.

Sage

Many computations, in seemingly very different areas of mathematics, can be translated into questions about linear combinations, or other areas of linear algebra. So Sage has extensive and thorough support for topics such as vector spaces.

Vector Spaces

The simplest way to create a vector space is to begin with a field and use an exponent to indicate the number of entries in the vectors of the space.

Elements can be built with the vector constructor.

Notice that vectors are printed with parentheses, which helps distinguish them from lists (though they alos look like tuples). Vectors print horizontally, but in Sage there is no such thing as a row vector or a column vector, though once matrices get involved we need to address this distinction. Finally, notice how the elements of the finite field have been converted to an alternate representation.

Once we have vector spaces full of vectors, we can perform computations with them. Ultimately, all the action in a vector space comes back to vector addition and scalar multiplication, which together create linear combinations.

Subspaces

Sage can create subspaces in a variety of ways, such as in the creation of row or column spaces of matrices. However, the most direct way is to begin with a set of vectors to use as a spanning set.

Notice that the information printed about S includes a basis matrix. The rows of this matrix are a basis for the vector space. We can get the basis, as a list of vectors (not rows of a matrix), with the .basis() method.

Notice that Sage has converted the spanning set of three vectors into a basis with two vectors. This is partially due to the fact that the original set of three vectors is linearly dependent, but a more substantial change has occurred.

This is a good place to discuss some of the mathematics behind what makes Sage work. A vector space over an infinite field, like the rationals or the reals, is an infinite set. No matter how expansive computer memory may seem, it is still finite. How does Sage fit an infinite set into our finite machines? The main idea is that a finite-dimensional vector space has a finite set of generators, which we know as a basis. So Sage really only needs the elements of a basis (two vectors in the previous example) to be able to work with the infinitely many possibilities for elements of the subspace.

Furthermore, for every basis associated with a vector space, Sage performs linear combinations to convert the given basis into another standard basis. This new basis has the property that as the rows of a matrix, the matrix is in reduced row-echelon form. You can see this in the basis matrix above. The reduced row-echelon form of a matrix is unique, so this standard basis allows Sage to recognize when two vector spaces are equal. Here is an example.

As you might expect, it is easy to determine the dimension of a vector space.

Linear Independence

There are a variety of ways in Sage to determine if a set of vectors is linearly independent or not, and to find relations of linear dependence if they exist. The technique we will show here is a simple test to see if a set of vectors is linearly independent or not. Simply use the vectors as a spanning set for a subspace, and check the dimension of the subspace. The dimension equals the number of vectors in the spanning set if and only if the spanning set is linearly independent.

So the first set of vectors, [u, v, w], is linearly independent, while the second set, [u, v, a^3*u + a^11*v], is not.

Abstract Vector Spaces

Sage does not implement many abstract vector spaces directly, such as \(P_n\), the vector space of polynomials of degree \(n\) or less. This is due in part to the fact that a finite-dimensional vector space over a field \(F\) is isomorphic to the vector space \(F^n\). So Sage captures all the functionality of finite-dimensional vector spaces, and it is left to the user to perform the conversions according to the isomorphism (which is often trivial with the choice of an obvious basis).

However, there are instances where rings behave naturally as vector spaces and we can exploit this extra structure. We will see much more of this in the chapters on fields and Galois theory. As an example, finite fields have a single generator, and the first few powers of the generator form a basis. Consider creating a vector space from the elements of a finite field of order \(7^6=117\,649\). As elements of a field we know they can be added, so we will define this to be the addition in our vector space. For any element of the integers mod 7, we can multiply an element of the field by the integer, so we define this to be our scalar multiplication. Later, we will be certain that these two definitions lead to a vector space, but take that for granted now. So here are some operations in our new vector space.

You might recognize that this looks very familiar to how we add polynomials, and multiply polynomials by scalars. You would be correct. However, notice that in this vector space construction, we are totally ignoring the possibility of multiplying two field elements together. As a vector space with scalars from \({\mathbb Z}_7\), a basis is the first six powers of the generator, \(\{1,\,a,\,a^2,\,a^3,\,a^4,\,a^5\}\). (Notice how counting from zero is natural here.) You may have noticed how Sage consistently rewrites elements of fields as linear combinations now you have a good explanation.

Here is what Sage knows about a finite field as a vector space. First, it knows that the finite field is a vector space, and what the field of scalars is. We suppress additional output with isomorphisms between the finite field structure and the vector space structure.

So the finite field (as a vector space) is isomorphic to the vector space \(({\mathbb Z}_7)^6\). Notice this is not a ring or field isomorphism, as it does not fully address multiplication of elements, even though that is possible in the field.

Condensed — the full section is in Judson, Abstract Algebra: Theory and Applications.

Linear Algebra

Sage has extensive support for linear algebra, well beyond what we have described here, or what we will need for the remaining chapters. Create vector spaces and vectors (with different fields of scalars), and then use tab-completion on these objects to explore the large sets of available commands.

Symbols used here

\mathbb{N},\ \mathbb{Z},\ \mathbb{Q},\ \mathbb{R},\ \mathbb{C}
number sets
Naturals, integers, rationals, reals, complex numbers.
x \in A,\ A \subseteq B
element of, subset
x belongs to A; every element of A is in B.
\blacksquare\ \text{or}\ \square
end of proof (halmos)
Marks the point where the statement has been established.
a \equiv b \pmod n
congruent modulo n
n divides a − b; a and b have the same remainder.
a \mid b,\ \gcd(a,b)
divides, greatest common divisor
b is a multiple of a; the largest number dividing both.
(G, \cdot),\ e,\ g^{-1}
group, identity, inverse
A set with an operation; the do-nothing element; the element that undoes g.
G \cong H,\ G / N
isomorphic, quotient group
Same structure; the group of cosets of a normal subgroup N.
\mathbb{Z}/n\mathbb{Z},\ \mathbb{Z}_n
integers modulo n
The remainders 0…n−1 with clock arithmetic.
\operatorname{Hom}(A, B),\ f \circ g
arrows from A to B, composition
The set of morphisms; do g then f.

Questions people ask

What is a group, in plain words?

A set with one operation that is associative, has an identity, and lets every element be undone. Symmetries of any object form a group — that is where the idea came from.

What is the difference between a ring and a field?

A ring has addition and multiplication that behave like the integers (you cannot always divide); a field is a ring where every non-zero element has a reciprocal, like the rationals or the reals.

તમારા પોતાના પ્રયત્ન કરો

Parts of this page are adapted from Judson, Abstract Algebra: Theory and Applications (GFDL 1.3). Condensed and re-explained here; errors are ours.

આમાં વધુ Abstract Algebra