Skip to content
Symi Docs
Python
On this page

Linear algebra

Matrix arithmetic and linear algebra operations are exact symbolic operations.

Arithmetic#

Python additionally overloads +, -, and * over these named methods. * is the matrix product when both operands are matrices and scales every entry when either operand is an expression-like scalar, on either side: A * 2, 2 * A, and x * A are all scalar_multiply. A matrix displays its entries: repr(A) in Python and toString() in JavaScript are its summary, such as Matrix([[1, x], [0, 1]]), eliding beyond eight rows or columns and stating the full shape when it does.

add#

Matrix method

add(other: Matrix) -> Matrix

Entrywise sum of two matrices of the same shape.

subtract#

Matrix method

subtract(other: Matrix) -> Matrix

Entrywise difference of two matrices of the same shape.

multiply#

Matrix product; inner dimensions must agree.

Matrix method

multiply(other: Matrix) -> Matrix

Matrix product; inner dimensions must agree.

scalar_multiply#

Matrix method

scalar_multiply(scalar: Any) -> Matrix

Scale every entry by scalar.

Matrix assumptions#

Matrix predicates are available as methods on Matrix, as constructors on an explicit Context, and as default-context module functions in Python and WASM. Native Rust uses the corresponding Session methods. Query methods return True/False/None (or the native TruthValue), preserving unknown when the exact symbolic engine cannot decide.

matrix_shape#

Default context

matrix_shape(
    subject: Matrix,
    rows: int,
    columns: int,
) -> AssumptionProposition
Calling forms

Explicit context: Context.matrix_shape

matrix_shape(
    subject: Matrix,
    rows: int,
    columns: int,
) -> AssumptionProposition

Assert or query an exact positive row and column count.

square_matrix#

Default context

square_matrix(subject: Matrix) -> AssumptionProposition
Calling forms

Explicit context: Context.square_matrix

square_matrix(subject: Matrix) -> AssumptionProposition

Assert or query that the matrix has equal row and column counts.

zero_matrix#

Assert or query that all entries are zero.

identity_matrix#

Assert or query the identity-matrix structure.

diagonal_matrix#

Assert or query diagonal structure.

upper_triangular_matrix#

Default context

upper_triangular_matrix(subject: Matrix) -> AssumptionProposition
Calling forms

Explicit context: Context.upper_triangular_matrix

upper_triangular_matrix(subject: Matrix) -> AssumptionProposition

Assert or query upper-triangular structure.

lower_triangular_matrix#

Default context

lower_triangular_matrix(subject: Matrix) -> AssumptionProposition
Calling forms

Explicit context: Context.lower_triangular_matrix

lower_triangular_matrix(subject: Matrix) -> AssumptionProposition

Assert or query lower-triangular structure.

symmetric_matrix#

Default context

symmetric_matrix(subject: Matrix) -> AssumptionProposition
Calling forms

Explicit context: Context.symmetric_matrix

symmetric_matrix(subject: Matrix) -> AssumptionProposition

Assert or query equality with the transpose.

hermitian_matrix#

Default context

hermitian_matrix(subject: Matrix) -> AssumptionProposition
Calling forms

Explicit context: Context.hermitian_matrix

hermitian_matrix(subject: Matrix) -> AssumptionProposition

Assert or query equality with the conjugate transpose.

orthogonal_matrix#

Default context

orthogonal_matrix(subject: Matrix) -> AssumptionProposition
Calling forms

Explicit context: Context.orthogonal_matrix

orthogonal_matrix(subject: Matrix) -> AssumptionProposition

Assert or query the real orthogonality condition.

unitary_matrix#

Default context

unitary_matrix(subject: Matrix) -> AssumptionProposition
Calling forms

Explicit context: Context.unitary_matrix

unitary_matrix(subject: Matrix) -> AssumptionProposition

Assert or query the unitary condition.

normal_matrix#

Default context

normal_matrix(subject: Matrix) -> AssumptionProposition
Calling forms

Explicit context: Context.normal_matrix

normal_matrix(subject: Matrix) -> AssumptionProposition

Assert or query commutation with the conjugate transpose.

full_rank_matrix#

Default context

full_rank_matrix(subject: Matrix) -> AssumptionProposition
Calling forms

Explicit context: Context.full_rank_matrix

full_rank_matrix(subject: Matrix) -> AssumptionProposition

Assert or query full rank.

invertible_matrix#

Default context

invertible_matrix(subject: Matrix) -> AssumptionProposition
Calling forms

Explicit context: Context.invertible_matrix

invertible_matrix(subject: Matrix) -> AssumptionProposition

Assert or query square invertibility.

singular_matrix#

Default context

singular_matrix(subject: Matrix) -> AssumptionProposition
Calling forms

Explicit context: Context.singular_matrix

singular_matrix(subject: Matrix) -> AssumptionProposition

Assert or query square singularity.

integer_entries#

Default context

integer_entries(subject: Matrix) -> AssumptionProposition
Calling forms

Explicit context: Context.integer_entries

integer_entries(subject: Matrix) -> AssumptionProposition

Assert or query integer entries.

real_entries#

Default context

real_entries(subject: Matrix) -> AssumptionProposition
Calling forms

Explicit context: Context.real_entries

real_entries(subject: Matrix) -> AssumptionProposition

Assert or query real entries.

complex_entries#

Default context

complex_entries(subject: Matrix) -> AssumptionProposition
Calling forms

Explicit context: Context.complex_entries

complex_entries(subject: Matrix) -> AssumptionProposition

Assert or query finite complex entries.

positive_definite_matrix#

Default context

positive_definite_matrix(subject: Matrix) -> AssumptionProposition
Calling forms

Explicit context: Context.positive_definite_matrix

positive_definite_matrix(subject: Matrix) -> AssumptionProposition

Assert or query exact positive definiteness.

positive_semidefinite_matrix#

Default context

positive_semidefinite_matrix(subject: Matrix) -> AssumptionProposition
Calling forms

Explicit context: Context.positive_semidefinite_matrix

positive_semidefinite_matrix(subject: Matrix) -> AssumptionProposition

Assert or query exact positive semidefiniteness.

transpose#

Matrix method

transpose() -> Matrix

The transpose, with rows and columns exchanged.

determinant#

Fraction-free (Berkowitz/Bareiss) determinant of a square matrix.

Matrix method

determinant() -> Expression

Fraction-free (Berkowitz/Bareiss) determinant of a square matrix.

trace#

Matrix method

trace() -> Expression

Sum of the diagonal entries of a square matrix.

characteristic_polynomial#

Matrix method

characteristic_polynomial(variable: Any) -> Expression

det⁡(λI−M)\det(\lambda I - M) as a polynomial in the named variable.

minimal_polynomial#

Matrix method

minimal_polynomial(variable: Any) -> Expression

The monic minimal polynomial over the rationals. The matrix must have rational entries.

eigenvalues#

Eigenvalues with multiplicity, via the characteristic polynomial and the root finder; eigenvalues the root finder cannot close remain as exact first-class polynomial_root values.

Matrix method

eigenvalues() -> list[Expression]

Eigenvalues with multiplicity, via the characteristic polynomial and the root finder; eigenvalues the root finder cannot close remain as exact first-class polynomial_root values.

eigenvectors#

For each eigenvalue, a basis of its eigenspace as column matrices. Notes: WASM returns Eigenpair objects with eigenvalue/vectors getters.

Matrix method

eigenvectors() -> list[tuple[Expression, list[Matrix]]]

For each eigenvalue, a basis of its eigenspace as column matrices. Notes: WASM returns eigenpair objects with eigenvalue/vectors getters.

eigenpair (WASM result class)#

eigenvalue#

Not exposed by the Python bindings. Available as UniffiEigenpair.eigenvalue in Kotlin, UniffiEigenpair.eigenvalue in Swift, api::results::Eigenpair::eigenvalue in Rust.

vectors#

Not exposed by the Python bindings. Available as UniffiEigenpair.vectors in Kotlin, UniffiEigenpair.vectors in Swift, api::results::Eigenpair::vectors in Rust.

inverse#

Inverse via the adjugate; raises on singular input.

Matrix method

inverse() -> Matrix

Inverse via the adjugate; raises on singular input.

rank#

Matrix method

rank() -> int

Rank via Bareiss fraction-free elimination.

row_reduce#

Bareiss row-reduced form (fraction-free; pivots remain on the diagonal).

Matrix method

row_reduce() -> Matrix

Bareiss row-reduced form (fraction-free; pivots remain on the diagonal).

nullspace_basis#

A basis of the kernel, as column matrices; empty list for full column rank.

Matrix method

nullspace_basis() -> list[Matrix]

A basis of the kernel, as column matrices; empty list for full column rank.

adjugate#

The classical adjoint (transpose of the cofactor matrix); satisfies Madj⁡(M)=det⁡(M)IM\operatorname{adj}(M) = \det(M) I.

Matrix method

adjugate() -> Matrix

The classical adjoint (transpose of the cofactor matrix); satisfies Madj⁡(M)=det⁡(M)IM\operatorname{adj}(M) = \det(M) I.

cofactor_matrix#

Matrix method

cofactor_matrix() -> Matrix

The matrix of cofactors, whose transpose is the adjugate.

lower_upper_decomposition#

Partial-pivoting LU decomposition returned as (permutation, lower, upper) with permutation⁡M=lower⁡ upper⁡\operatorname{permutation} M = \operatorname{lower}\,\operatorname{upper}. The permutation matrix is reconstructed from the pivoting row-swap record. Notes: WASM returns a 3-element array [permutation, lower, upper].

Matrix method

lower_upper_decomposition() -> tuple[Matrix, Matrix, Matrix]

Partial-pivoting LU decomposition returned as (permutation, lower, upper) with permutation⁡M=lower⁡ upper⁡\operatorname{permutation} M = \operatorname{lower}\,\operatorname{upper}.

Example#

Exact matrix arithmetic and spectral data.

Python
import symi

matrix = symi.Matrix([[1, 2], [3, 4]])

print(matrix.determinant())
print(matrix.trace())
print(matrix.transpose())
print(matrix.inverse())
print(matrix.eigenvalues())

Additional API#

Matrix#

Matrix constructor

Matrix(rows: Any)

Build a matrix from ordered rows. Direct Python construction and the facade module function use the shared default context. The raw wasm-bindgen compatibility layer retains (rows, columns, flat_entries); new JavaScript code should use the nested facade form.

Matrix.add#

Matrix method

__add__(other: Matrix) -> Matrix

Entrywise sum self + other of two matrices of the same shape.

Matrix.getattribute#

Matrix method

__getattribute__(name: str) -> Any

Reject attribute access on a stale object before delegating to the default lookup.

Matrix.getitem#

Matrix method

__getitem__(index: tuple[int, int]) -> Expression

The entry at the (row, column) index pair.

Matrix.mul#

Matrix method

__mul__(other: Any) -> Matrix

Matrix product self * other when other is a matrix, and scaling of every entry when other is an expression-like scalar.

Matrix.repr#

Matrix method

__repr__() -> str

The repr() text: the entries row by row, as Matrix([[a, b], [c, d]]), eliding beyond eight rows or columns. It reports staleness instead of failing.

Matrix.rmul#

Matrix method

__rmul__(scalar: Any) -> Matrix

Scaling scalar * self of every entry by an expression-like scalar, the same product as self * scalar.

Matrix.sub#

Matrix method

__sub__(other: Matrix) -> Matrix

Entrywise difference self - other of two matrices of the same shape.

Matrix.execute#

Matrix method

execute() -> Matrix

Re-dispatch every unevaluated node (integral, derivative, summation, transform, ODE/recurrence placeholder) in the expression; useful after substitution has changed the inputs.

Matrix.has_complex_entries#

Matrix method

has_complex_entries() -> Optional[bool]

Query whether every entry is finite complex.

Matrix.has_integer_entries#

Matrix method

has_integer_entries() -> Optional[bool]

Query whether every entry is an integer.

Matrix.has_real_entries#

Matrix method

has_real_entries() -> Optional[bool]

Query whether every entry is real.

Matrix.is_diagonal_matrix#

Matrix method

is_diagonal_matrix() -> Optional[bool]

Query whether this matrix is diagonal.

Matrix.is_equality#

Matrix method

is_equality() -> bool

Always false: a matrix is never an equal relation node.

Matrix.is_finite_set#

Matrix method

is_finite_set() -> bool

Always false: a matrix is never a finite set.

Matrix.is_full_rank_matrix#

Matrix method

is_full_rank_matrix() -> Optional[bool]

Query whether this matrix has full rank.

Matrix.is_hermitian_matrix#

Matrix method

is_hermitian_matrix() -> Optional[bool]

Query whether this matrix is Hermitian.

Matrix.is_identity_matrix#

Matrix method

is_identity_matrix() -> Optional[bool]

Query whether this matrix is the identity matrix.

Matrix.is_image_set#

Matrix method

is_image_set() -> bool

Always false: a matrix is never an image set.

Matrix.is_integral#

Matrix method

is_integral() -> bool

Always false: a matrix is never an unevaluated integral node.

Matrix.is_invertible_matrix#

Matrix method

is_invertible_matrix() -> Optional[bool]

Query whether this matrix is invertible.

Matrix.is_matrix#

Matrix property

is_matrix: bool

Always False on expressions and True on matrix objects, so mixed result streams can be discriminated.

Matrix.is_normal_matrix#

Matrix method

is_normal_matrix() -> Optional[bool]

Query whether this matrix is normal.

Matrix.is_orthogonal_matrix#

Matrix method

is_orthogonal_matrix() -> Optional[bool]

Query whether this matrix is orthogonal.

Matrix.is_positive#

Matrix method

is_positive() -> Optional[bool]

Always None: positivity is a property of the entries, not of the matrix.

Matrix.is_positive_definite_matrix#

Matrix method

is_positive_definite_matrix() -> Optional[bool]

Query whether this matrix is positive definite.

Matrix.is_positive_semidefinite_matrix#

Matrix method

is_positive_semidefinite_matrix() -> Optional[bool]

Query whether this matrix is positive semidefinite.

Matrix.is_real#

Matrix method

is_real() -> Optional[bool]

Always None: realness is a property of the entries, not of the matrix.

Matrix.is_singular_matrix#

Matrix method

is_singular_matrix() -> Optional[bool]

Query whether this matrix is singular.

Matrix.is_square#

Matrix method

is_square() -> Optional[bool]

Query whether this matrix is square.

Matrix.is_stale#

Matrix property

is_stale: bool

Reports whether resetting the owning context invalidated the expression. All other operations reject a stale receiver with an actionable error.

Matrix.is_symmetric_matrix#

Matrix method

is_symmetric_matrix() -> Optional[bool]

Query whether this matrix is symmetric.

Matrix.is_union#

Matrix method

is_union() -> bool

Always false: a matrix is never a union of sets.

Matrix.is_unitary_matrix#

Matrix method

is_unitary_matrix() -> Optional[bool]

Query whether this matrix is unitary.

Matrix.is_zero_matrix#

Matrix method

is_zero_matrix() -> Optional[bool]

Query whether this matrix is the zero matrix.

Matrix.summary#

Matrix method

summary() -> str

A one-line summary listing the entries row by row, Matrix([[a, b], [c, d]]). A matrix with more than eight rows or columns lists its leading eight of each, marks every elided run with ..., and states its full shape first.

Symi documentation · Python