The Rust manual covers the recommended facade. The complete native crate is documented in the native Rust API reference .
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#
api::Matrix method
pub fn add ( & self , other: & Matrix ) -> Result < Matrix , ApiError >
Provides the add operation on this native type.
subtract#
api::Matrix method
pub fn subtract ( & self , other: & Matrix ) -> Result < Matrix , ApiError >
Subtracts another same-session matrix from this matrix.
multiply#
Matrix product; inner dimensions must agree.
api::Matrix method
pub fn multiply ( & self , other: & Matrix ) -> Result < Matrix , ApiError >
Provides the multiply operation on this native type.
scalar_multiply#
api::Matrix method
pub fn scalar_multiply (
& self ,
scalar: & Expression ,
) -> Result < Matrix , ApiError >
Multiplies this matrix by a same-session scalar expression.
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#
api::Session method
pub fn matrix_shape (
& self ,
subject: & Matrix ,
rows: usize ,
columns: usize ,
) -> Result < AssumptionProposition , ApiError >
Assert or query an exact positive row and column count.
square_matrix#
api::Session method
pub fn square_matrix (
& self ,
subject: & Matrix ,
) -> Result < AssumptionProposition , ApiError >
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#
api::Session method
pub fn upper_triangular_matrix (
& self ,
subject: & Matrix ,
) -> Result < AssumptionProposition , ApiError >
Assert or query upper-triangular structure.
lower_triangular_matrix#
api::Session method
pub fn lower_triangular_matrix (
& self ,
subject: & Matrix ,
) -> Result < AssumptionProposition , ApiError >
Assert or query lower-triangular structure.
symmetric_matrix#
api::Session method
pub fn symmetric_matrix (
& self ,
subject: & Matrix ,
) -> Result < AssumptionProposition , ApiError >
Assert or query equality with the transpose.
hermitian_matrix#
api::Session method
pub fn hermitian_matrix (
& self ,
subject: & Matrix ,
) -> Result < AssumptionProposition , ApiError >
Assert or query equality with the conjugate transpose.
orthogonal_matrix#
api::Session method
pub fn orthogonal_matrix (
& self ,
subject: & Matrix ,
) -> Result < AssumptionProposition , ApiError >
Assert or query the real orthogonality condition.
unitary_matrix#
api::Session method
pub fn unitary_matrix (
& self ,
subject: & Matrix ,
) -> Result < AssumptionProposition , ApiError >
Assert or query the unitary condition.
normal_matrix#
api::Session method
pub fn normal_matrix (
& self ,
subject: & Matrix ,
) -> Result < AssumptionProposition , ApiError >
Assert or query commutation with the conjugate transpose.
full_rank_matrix#
api::Session method
pub fn full_rank_matrix (
& self ,
subject: & Matrix ,
) -> Result < AssumptionProposition , ApiError >
Assert or query full rank.
invertible_matrix#
api::Session method
pub fn invertible_matrix (
& self ,
subject: & Matrix ,
) -> Result < AssumptionProposition , ApiError >
Assert or query square invertibility.
singular_matrix#
api::Session method
pub fn singular_matrix (
& self ,
subject: & Matrix ,
) -> Result < AssumptionProposition , ApiError >
Assert or query square singularity.
integer_entries#
api::Session method
pub fn integer_entries (
& self ,
subject: & Matrix ,
) -> Result < AssumptionProposition , ApiError >
Assert or query integer entries.
real_entries#
api::Session method
pub fn real_entries (
& self ,
subject: & Matrix ,
) -> Result < AssumptionProposition , ApiError >
Assert or query real entries.
complex_entries#
api::Session method
pub fn complex_entries (
& self ,
subject: & Matrix ,
) -> Result < AssumptionProposition , ApiError >
Assert or query finite complex entries.
positive_definite_matrix#
api::Session method
pub fn positive_definite_matrix (
& self ,
subject: & Matrix ,
) -> Result < AssumptionProposition , ApiError >
Assert or query exact positive definiteness.
positive_semidefinite_matrix#
api::Session method
pub fn positive_semidefinite_matrix (
& self ,
subject: & Matrix ,
) -> Result < AssumptionProposition , ApiError >
Assert or query exact positive semidefiniteness.
transpose#
api::Matrix method
pub fn transpose ( & self ) -> Result < Matrix , ApiError >
Provides the transpose operation on this native type.
determinant#
Fraction-free (Berkowitz/Bareiss) determinant of a square matrix.
api::Matrix method
pub fn determinant ( & self ) -> Result < Expression , ApiError >
Provides the determinant operation on this native type.
trace#
api::Matrix method
pub fn trace ( & self ) -> Result < Expression , ApiError >
Provides the trace operation on this native type.
characteristic_polynomial#
api::matrix_operations::Matrix method
pub fn characteristic_polynomial < 'a , VariableType > (
& self ,
variable: VariableType ,
) -> Result < Expression , ApiError >
where
VariableType : Into < VariableLike < 'a >> ,
det ( λ I − M ) \det(\lambda I - M) det ( λ I − M ) as a polynomial in the named variable.
minimal_polynomial#
api::matrix_operations::Matrix method
pub fn minimal_polynomial < 'a , VariableType > (
& self ,
variable: VariableType ,
) -> Result < Expression , ApiError >
where
VariableType : Into < VariableLike < 'a >> ,
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.
api::Matrix method
pub fn eigenvalues ( & self ) -> Result < Vec < Expression > , ApiError >
Returns the eigenvalues established by the exact characteristic-polynomial path.
eigenvectors#
For each eigenvalue, a basis of its eigenspace as column matrices.
Notes: WASM returns Eigenpair objects with eigenvalue/vectors
getters.
api::matrix_operations::Matrix method
pub fn eigenvectors ( & self ) -> Result < Vec < Eigenpair > , ApiError >
The eigenvalues of this matrix paired with a basis of each eigenspace.
eigenpair (WASM result class)#
eigenvalue#
api::results::Eigenpair method
pub fn eigenvalue ( & self ) -> Expression
vectors#
api::results::Eigenpair method
pub fn vectors ( & self ) -> Vec < Matrix >
A basis of the eigenspace, each vector a single-column matrix.
inverse#
Inverse via the adjugate; raises on singular input.
api::Matrix method
pub fn inverse ( & self ) -> Result < Matrix , ApiError >
Returns this matrix's exact inverse when the engine can construct one.
rank#
api::Matrix method
pub fn rank ( & self ) -> Result < usize , ApiError >
Rank via Bareiss fraction-free elimination.
row_reduce#
Bareiss row-reduced form (fraction-free; pivots remain on the diagonal).
api::Matrix method
pub fn row_reduce ( & self ) -> Result < Matrix , ApiError >
Returns the fraction-free row-reduced form of this matrix.
nullspace_basis#
A basis of the kernel, as column matrices; empty list for full column rank.
api::matrix_operations::Matrix method
pub fn nullspace_basis ( & self ) -> Result < Vec < Matrix > , ApiError >
A basis of the nullspace, each vector a single-column matrix.
adjugate#
The classical adjoint (transpose of the cofactor matrix); satisfies
M adj ( M ) = det ( M ) I M\operatorname{adj}(M) = \det(M) I M adj ( M ) = det ( M ) I .
api::Matrix method
pub fn adjugate ( & self ) -> Result < Matrix , ApiError >
Returns this matrix's classical adjugate.
cofactor_matrix#
api::Matrix method
pub fn cofactor_matrix ( & self ) -> Result < Matrix , ApiError >
Returns this matrix's cofactor matrix.
lower_upper_decomposition#
Partial-pivoting LU decomposition returned as
(permutation, lower, upper) with permutation M = lower upper \operatorname{permutation} M = \operatorname{lower}\,\operatorname{upper} permutation M = lower upper . The
permutation matrix is reconstructed from the pivoting row-swap record.
Notes: WASM returns a 3-element array [permutation, lower, upper].
api::matrix_operations::Matrix method
pub fn lower_upper_decomposition (
& self ,
) -> Result < ( Matrix , Matrix , Matrix ) , ApiError >
The LU decomposition as (permutation, lower, upper) with permutation * self = lower * upper.
Example#
Exact matrix arithmetic and spectral data.
use symi:: api:: prelude:: * ;
fn main ( ) -> Result < ( ) , Box < dyn std:: error:: Error >> {
let session = Session :: new ( ) ;
let matrix = session. matrix ( [
[ session. integer ( 1 ) , session. integer ( 2 ) ] ,
[ session. integer ( 3 ) , session. integer ( 4 ) ] ,
] ) ? ;
println! ( "{}" , matrix. determinant ( ) ? ) ;
println! ( "{}" , matrix. trace ( ) ? ) ;
println! ( "{}" , matrix. transpose ( ) ? ) ;
Ok ( ( ) )
}
Additional API#
Eigenpair#
api re_export
pub use results:: Eigenpair ;
One eigenvalue together with a basis of its eigenspace.
Calling forms
Type: api::results::Eigenpair
IntegerCokernelData#
api re_export
pub use results:: IntegerCokernelData ;
The structure of the integer cokernel of a matrix.
Calling forms
Type: api::results::IntegerCokernelData
pub struct IntegerCokernelData
IntegerCokernelData.free_rank#
api::results::IntegerCokernelData method
pub fn free_rank ( & self ) -> usize
The rank of the free part.
IntegerCokernelData.torsion_invariant_factors#
api::results::IntegerCokernelData method
pub fn torsion_invariant_factors ( & self ) -> Vec < Expression >
The invariant factors of the torsion part.
Matrix#
Type
Public native data structure named matrix.
Matrix.execute#
api::Matrix method
pub fn execute ( & self ) -> Result < Matrix , ApiError >
Provides the execute operation on this native type.
Matrix.generation#
api::Matrix method
pub fn generation ( & self ) -> u64
The session generation this object was created in.
Matrix.has_complex_entries#
api::Matrix method
pub fn has_complex_entries ( & self ) -> Result < TruthValue , ApiError >
Query whether every entry is finite complex.
Matrix.has_integer_entries#
api::Matrix method
pub fn has_integer_entries ( & self ) -> Result < TruthValue , ApiError >
Query whether every entry is an integer.
Matrix.has_real_entries#
api::Matrix method
pub fn has_real_entries ( & self ) -> Result < TruthValue , ApiError >
Query whether every entry is real.
Matrix.is_diagonal_matrix#
api::Matrix method
pub fn is_diagonal_matrix ( & self ) -> Result < TruthValue , ApiError >
Query whether this matrix is diagonal.
Matrix.is_equality#
api::matrix_operations::Matrix method
pub fn is_equality ( & self ) -> bool
Always false on a matrix: a matrix is never an equality relation node.
Matrix.is_finite_set#
api::matrix_operations::Matrix method
pub fn is_finite_set ( & self ) -> bool
Always false on a matrix: a matrix is never a finite set.
Matrix.is_full_rank_matrix#
api::Matrix method
pub fn is_full_rank_matrix ( & self ) -> Result < TruthValue , ApiError >
Query whether this matrix has full rank.
Matrix.is_hermitian_matrix#
api::Matrix method
pub fn is_hermitian_matrix ( & self ) -> Result < TruthValue , ApiError >
Query whether this matrix is Hermitian.
Matrix.is_identity_matrix#
api::Matrix method
pub fn is_identity_matrix ( & self ) -> Result < TruthValue , ApiError >
Query whether this matrix is the identity matrix.
Matrix.is_image_set#
api::matrix_operations::Matrix method
pub fn is_image_set ( & self ) -> bool
Always false on a matrix: a matrix is never an image set.
Matrix.is_integral#
api::matrix_operations::Matrix method
pub fn is_integral ( & self ) -> bool
Always false on a matrix: integrality is a property of scalar expressions.
Matrix.is_invertible_matrix#
api::Matrix method
pub fn is_invertible_matrix ( & self ) -> Result < TruthValue , ApiError >
Query whether this matrix is invertible.
Matrix.is_matrix#
api::matrix_operations::Matrix method
pub fn is_matrix ( & self ) -> bool
Always true on a matrix, so a mixed result stream can be discriminated.
Matrix.is_normal_matrix#
api::Matrix method
pub fn is_normal_matrix ( & self ) -> Result < TruthValue , ApiError >
Query whether this matrix is normal.
Matrix.is_orthogonal_matrix#
api::Matrix method
pub fn is_orthogonal_matrix ( & self ) -> Result < TruthValue , ApiError >
Query whether this matrix is orthogonal.
Matrix.is_positive#
api::matrix_operations::Matrix method
pub fn is_positive ( & self ) -> Option < bool >
Never settled on a matrix: positivity is a property of scalar expressions.
Matrix.is_positive_definite_matrix#
api::Matrix method
pub fn is_positive_definite_matrix (
& self ,
) -> Result < TruthValue , ApiError >
Query whether this matrix is positive definite.
Matrix.is_positive_semidefinite_matrix#
api::Matrix method
pub fn is_positive_semidefinite_matrix (
& self ,
) -> Result < TruthValue , ApiError >
Query whether this matrix is positive semidefinite.
Matrix.is_real#
api::matrix_operations::Matrix method
pub fn is_real ( & self ) -> Option < bool >
Never settled on a matrix: realness is a property of scalar expressions.
Matrix.is_singular_matrix#
api::Matrix method
pub fn is_singular_matrix ( & self ) -> Result < TruthValue , ApiError >
Query whether this matrix is singular.
Matrix.is_square#
api::Matrix method
pub fn is_square ( & self ) -> Result < TruthValue , ApiError >
Query whether this matrix is square.
Matrix.is_stale#
api::Matrix method
pub fn is_stale ( & self ) -> bool
Provides the is_stale operation on this native type.
Matrix.is_symmetric_matrix#
api::Matrix method
pub fn is_symmetric_matrix ( & self ) -> Result < TruthValue , ApiError >
Query whether this matrix is symmetric.
Matrix.is_union#
api::matrix_operations::Matrix method
pub fn is_union ( & self ) -> bool
Always false on a matrix: a matrix is never a set union.
Matrix.is_unitary_matrix#
api::Matrix method
pub fn is_unitary_matrix ( & self ) -> Result < TruthValue , ApiError >
Query whether this matrix is unitary.
Matrix.is_zero_matrix#
api::Matrix method
pub fn is_zero_matrix ( & self ) -> Result < TruthValue , ApiError >
Query whether this matrix is the zero matrix.
Matrix.session#
api::Matrix method
pub fn session ( & self ) -> Session
The session that owns this object, for host adapters that carry the owner alongside it.
Matrix.summary#
api::matrix_operations::Matrix method
pub fn summary ( & self ) -> Result < String , ApiError >
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, rows by columns, before the entries, so the text stays bounded and never silently drops an entry.
MatrixPredicate#
api re_export
pub use crate :: assumptions:: MatrixPredicate ;
Re-exports the matrix predicate vocabulary shared by every binding.
MatrixPredicateApplication#
api re_export
pub use crate :: assumptions:: MatrixPredicateApplication ;
Re-exports the matrix predicate vocabulary shared by every binding.