Skip to content

Vector space functions for STACK

STACK has a contributed library for vector space functions. To use this library you must load it into the question variables.

  • To use the latest code from GitHub: stack_include_contrib("vectorspaces.mac");

This page contains reference documentation on functions in this library.

Student vector input

Students can enter column or row vectors using vector notation.

Unit vectors and scalar products

vectorspaces.mac provides a few functions to manipulate vectors.

  • unit_vecp(ex) is a predicate function that tests whether a given input is a unit vector. ex must be a matrix (use vec_convert for vector notation) with exactly one row or one column.

The following functions have the optional argument sp. If this argument is omitted then the standard inner product is used: the dot product for real vectors, and x . conjugate(y) for complex vectors, linear in the first slot (entries are conjugated only when a vector contains %i, so symbolic entries are treated as real). Otherwise, sp must be the name of a function that performs a scalar product of two vectors; i.e. it takes two vector inputs and outputs a scalar. If given, this scalar product function will be used in place of the standard inner product.

  • proj(u, v, [sp]) will compute the projection of v onto u using scalar product sp (the standard inner product if omitted).
  • orthogonalize(L, [sp]) will orthogonalise a list of vectors L with respect to scalar product sp (the standard inner product if omitted)
  • normalize(L, [sp]) will normalise a list of vectors L with respect to scalar product sp (the standard inner product if omitted)

For complex vectors, a supplied sp should be linear in its first argument and conjugate-linear in its second, as in most linear algebra texts.

Equivalence functions

  • lin_indp(ex) is a predicate function that tests whether a set of vectors is linearly independent. It can take many forms of input (see cols_to_matrix in the core linear algebra documentation). If given a matrix, it tests whether it has full column rank. The empty set ([], {}, ntuple() or span()) is linearly independent, since it is a basis of .
  • row_equivp(ex,ta) checks whether matrix ex is row equivalent to matrix ta. Literally, this checks whether the row-reduced echelon forms of the matrices are exactly equal.
  • col_equivp(ex,ta) does the same for column equivalence.
  • subspace_equivp(ex,ta) checks whether two collections of column vectors span the same subspace. i.e. Is each element of ex linearly dependent on ta and vice versa? Like lin_indp(ex), this function accepts many forms of input. It does not check whether each set of vectors is linearly independent. To check whether two bases are equivalent, use this function in conjunction with lin_indp. The empty set spans , so it is equivalent to another empty set or to any collection of zero vectors.

Manipulating subspaces

Maxima provides columnspace and nullspace functions natively. This will return a span object, where span is an inert function. vectorspaces.mac also provides rowspace and nullTspace functions to extract the row space and cokernel (left null space or null space of the transpose). Literally, these functions just call columnspace and nullspace on the transpose matrix.

  • columnspace(matrix([1,2,3],[4,5,6],[7,8,9])) gives span(matrix([1],[4],[7]),matrix([2],[5],[8]))
  • rowspace(matrix([1,2,3],[4,5,6],[7,8,9])) gives span(matrix([1],[2],[3]),matrix([4],[5],[6]))
  • nullspace(matrix([1,2,3],[4,5,6],[7,8,9])) gives span(matrix([-3],[6],[-3]))
  • nullTspace(matrix([1,2,3],[4,5,6],[7,8,9])) gives span(matrix([-3],[6],[-3]))

vectorspaces.mac also provides functions to "trim out" linearly dependent vectors from a set and to extend a basis to .

  • remove_dep(ex) takes exactly a list of lists or a matrix (it is not flexible like lin_indp) and removes any linearly dependent vectors (or columns if given a matrix). It works from left to right but keeps the left-most vector when comparing vectors.
  • For example, remove_dep(matrix([1,2,3],[1,2,4],[1,2,5])) gives matrix([1,3],[1,4],[1,5])
  • basisify(ex) will generate a basis for where each vector in ex has elements. This will first remove any dependent vectors using remove_dep and then attempt to extend the basis by adding for from to one at a time.
  • It will take an optional argument that, when true, orthonormalises the basis, i.e. basisify(ex, true). This is only really useful when ex is already orthonormal (or at least orthogonal), because if not Gram-Schmidt orthogonalisation will remove most of the original vectors anyway.
  • For example, basisify(matrix([1,1],[1,-1],[0,1])) will give

    but basisify(matrix([1,1],[1,-1],[0,1]),true) will give

  • The intended use of this function is for making the in factorisations orthogonal or for computing a full SVD

Projection matrices

  • projection_matrix(A) will produce the symmetric, idempotent matrix that orthogonally projects vectors in onto the column space of matrix A. For a complex matrix A it produces the Hermitian, idempotent matrix that projects vectors in , using the conjugate transpose.