Skip to content

Section documentation for STACK-Maxima /linearalgebra/predicates

Predicates for matrix shape and algebraic properties, available in core STACK.

Use col_vecp, row_vecp and vectorp to distinguish column and row matrices; use squarep, diagp, triup and trilp to check their structure. A diagonal matrix may be rectangular, and a triangular matrix need not be invertible or in row echelon form.

Use REFp for row echelon form, symp for symmetry, invertiblep for invertibility, and diagonalizablep for diagonalizability. The orthogonality predicates test columns using the ordinary dot product or a supplied scalar product.

Most predicates require a Maxima matrix. orthogonal_columnsp and orthonormal_columnsp also accept lists of column vectors through cols_to_matrix. Consult each function for its accepted inputs and optional arguments. Simplification and Maxima's ability to recognise zero expressions can affect the result; add explicit size or entry constraints when needed.


REFp(M,[normalize_pivots])

Predicate to determine whether a matrix is in row echelon form i.e. Is every zero-row below all non-zero rows and does the pivot in each row appear to the right of the previous pivot? Optionally checks whether each pivot is equal to 1 Non-matrix input returns false. The zero matrix and matrices with no entries satisfy these conditions. Pivots are identified using is; simplify entries first if algebraically zero expressions should be recognised.

Argument name type description
M matrix An mxn matrix
normalize_pivots boolean Optional: If true is given here, then pivots are required to be equal to 1
Return type description
boolean Is this matrix in row echelon form?

col_vecp(ex)

Return true when the argument is a Maxima matrix with exactly one column. A 1-by-1 matrix satisfies both col_vecp and row_vecp.

For example, col_vecp(matrix([a],[b])) is true, but col_vecp(matrix([a,b])) and col_vecp(c(a,b)) are false. Use vec_convert first when accepting the inert c/r notation. Lists, scalars and matrix() return false.

Argument name type description
ex expression the object whose shape is checked.
Return type description
boolean whether the object is a matrix with exactly one column.

diagonalizablep(M)

Is a given object a diagonalizable matrix? i.e. Is there an invertible matrix P and diagonal matrix D such that P^^-1 . M . P = D?

This uses Maxima's jordan and dispJordan functions and inherits their computational limits. Non-square and non-matrix inputs return false.

Argument name type description
M matrix a matrix
Return type description
boolean Is M a diagonalizable matrix?

diagp(M)

Return true when the argument is a matrix whose off-diagonal entries are recognised as zero by is. The matrix need not be square; use squarep as well if the task requires a square diagonal matrix. Diagonal entries may be zero or symbolic. Rectangular diagonal matrices occur as the Sigma factor in a singular value decomposition (SVD).

For example, diagp(matrix([a,0,0],[0,b,0])) is true, but diagp(matrix([1,x],[0,1])) is false for an unconstrained symbol x. Non-matrix arguments return false. Empty matrices have no off-diagonal entries to reject, so matrix(), matrix([]) and matrix([],[]) return true.

The simplification mode matters. With simp:false, the off-diagonal entry 1-1 in matrix([1,0],[1-1,1]) is not simplified and this predicate returns false; with simp:true it returns true. Simplify the matrix explicitly first if algebraically zero expressions should be accepted.

Argument name type description
M expression the object whose off-diagonal entries are checked.
Return type description
boolean whether every off-diagonal entry is recognised as zero.

invertiblep(M)

Is a given object an invertible matrix? i.e. Is there a matrix M^^-1 such that M^^-1 . M = M . M^^-1 = I? A square matrix is accepted when Maxima recognises its simplified determinant as nonzero. Non-square and non-matrix inputs return false.

Argument name type description
M matrix a matrix
Return type description
boolean Is M an invertible matrix?

orth_matrixp(M)

Is a given object an orthogonal matrix? i.e. Is M^T . M = M . M^T = I? Requires a square Maxima matrix and uses the ordinary dot product. Unlike orthonormal_columnsp, this function has no scalar-product argument.

Argument name type description
M matrix a matrix
Return type description
boolean Is M an orthogonal matrix?

orthogonal_columnsp(L,[sp])

Does the given matrix/list have orthogonal columns with respect to scalar product sp? i.e. for any two distinct columns v1 and v2, is sp(v1, v2) = 0? Returns false in case of malformed input. In case no scalar product is provided, the standard dot product is used. These are bilinear products, without complex conjugation.

Argument name type description
L matrix A mxn matrix or list of column vectors, see cols_to_matrix
sp function or matrix (Optional) A scalar product or a symmetric positive definite matrix S representing a scalar product sp(u, v) := u^T.S.v
Return type description
boolean Does L have orthogonal columns with respect to sp?

orthonormal_columnsp(L,[sp])

Does the given matrix/list have orthonormal columns with respect to scalar product sp? i.e. for columns v_i and v_j, is sp(v_i, v_i) = 1 and sp(v_i, v_j) = 0 for i # j? Returns false in case of malformed input. In case no scalar product is provided, the standard dot product is used. These are bilinear products, without complex conjugation.

Argument name type description
L matrix A mxn matrix or list of column vectors, see cols_to_matrix
sp function or matrix (Optional) A scalar product or a symmetric positive definite matrix S representing a scalar product sp(u, v) := u^T.S.v
Return type description
boolean Does L have orthonormal columns with respect to sp?

row_vecp(ex)

Return true when the argument is a Maxima matrix with exactly one row. A 1-by-1 matrix satisfies both row_vecp and col_vecp.

For example, row_vecp(matrix([a,b])) is true, but row_vecp(matrix([a],[b])) and row_vecp(r(a,b)) are false. Use vec_convert first when accepting the inert c/r notation. Lists, scalars and matrix() return false.

This is a shape check: matrix([]) has one row and no columns, so it returns true. Check the number of columns separately if entries are required.

Argument name type description
ex expression the object whose shape is checked.
Return type description
boolean whether the object is a matrix with exactly one row.

squarep(M)

Return true when the argument is a matrix with equal row and column counts. The entries need not be numeric, and a square matrix need not be invertible.

For example, squarep(matrix([a,b],[c,d])) is true, while squarep(matrix([a],[b])) and squarep([a,b]) are false. The empty 0-by-0 matrix matrix() returns true; matrix([]) returns false. Check the size separately if a nonempty square matrix is required.

Argument name type description
M expression the object whose shape is checked.
Return type description
boolean whether the object is a square matrix.

symp(M)

Is a given object a symmetric matrix? i.e. Is M = M^T? This uses transpose without complex conjugation, so it tests symmetry, not the Hermitian property. Non-square and non-matrix inputs return false.

Argument name type description
M matrix a matrix
Return type description
boolean Is M a symmetric matrix?

trilp(M)

Return true when every entry above the main diagonal of a Maxima matrix is recognised as zero by is. The matrix may be rectangular; use squarep as well if a square lower triangular matrix is required.

For example, trilp(matrix([a,0],[b,c],[d,e])) is true. Diagonal entries may be zero or symbolic, so this does not test invertibility or row echelon form. Use triup to check the other triangular part.

Non-matrix arguments, including lists and inert c/r expressions, return false. With no entries to reject, matrix(), matrix([]) and matrix([],[]) return true.

The simplification mode matters: trilp(matrix([1,1-1],[0,1])) returns false with simp:false and true with simp:true. Simplify the matrix first if algebraically zero expressions should be accepted.

Argument name type description
M expression the object whose triangular structure is checked.
Return type description
boolean whether every entry above the diagonal is recognised as zero.

triup(M)

Return true when every entry below the main diagonal of a Maxima matrix is recognised as zero by is. The matrix may be rectangular; use squarep as well if a square upper triangular matrix is required.

For example, triup(matrix([a,b,c],[0,d,e])) is true. Diagonal entries may be zero or symbolic, so this does not test invertibility or row echelon form. Use trilp to check the other triangular part.

Non-matrix arguments, including lists and inert c/r expressions, return false. With no entries to reject, matrix(), matrix([]) and matrix([],[]) return true.

The simplification mode matters: triup(matrix([1,0],[1-1,1])) returns false with simp:false and true with simp:true. Simplify the matrix first if algebraically zero expressions should be accepted.

Argument name type description
M expression the object whose triangular structure is checked.
Return type description
boolean whether every entry below the diagonal is recognised as zero.

vectorp(ex)

Return true for a matrix accepted by either col_vecp or row_vecp. This includes 1-by-1 matrices. It does not accept lists or inert c/r expressions; apply vec_convert first if the c/r forms are permitted.

For example, vectorp(matrix([a],[b])) and vectorp(matrix([a,b])) are true, while vectorp(matrix([a,b],[c,d])) is false. As with row_vecp, the one-row empty matrix matrix([]) is accepted; matrix() is not. This predicate does not check entries or non-emptiness.

Argument name type description
ex expression the object whose shape is checked.
Return type description
boolean whether the object is a row or column matrix.