TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/Nonanti/mathcore/llms.txt
Use this file to discover all available pages before exploring further.
mathcore::matrix module exposes two primary types: SymbolicMatrix, a row-major matrix whose cells hold Expr nodes and thus support fully symbolic arithmetic, and LinearAlgebra, a namespace of numerical linear-algebra routines backed by the nalgebra crate. Together they cover construction, element access, addition, multiplication, transposition, determinant computation, eigenvalue analysis, LU/QR/SVD decompositions, and linear system solving.
pub struct SymbolicMatrix
A two-dimensional matrix storing Expr values. Dimensions are fixed at construction time; operations that require matching or compatible dimensions return Err(MathError::InvalidOperation) on mismatch.
new
Creates a zero-initialised matrix of the given dimensions. Every cell is set to Expr::zero().
Number of rows.
Number of columns.
from_vec
Constructs a SymbolicMatrix from a nested Vec<Vec<f64>>. Each inner f64 value is wrapped in Expr::Number. Returns an error if the outer vector is empty or any row has an inconsistent length.
Outer vector represents rows; each inner vector represents columns. All inner vectors must have the same length.
Ok(SymbolicMatrix) or Err(MathError::InvalidOperation) for an empty or jagged input.
identity
Creates the size × size identity matrix with Expr::one() on the diagonal and Expr::zero() elsewhere.
The dimension of the square identity matrix.
get
Returns an immutable reference to the Expr stored at (row, col), or None when the indices are out of bounds.
Zero-based row index.
Zero-based column index.
set
Writes value into cell (row, col). Returns Err(MathError::InvalidOperation) when either index is out of bounds.
Zero-based row index.
Zero-based column index.
The symbolic expression to store in the cell.
add
Element-wise symbolic addition of two matrices. Both matrices must have the same dimensions.
The matrix to add. Must have the same number of rows and columns as
self.Ok(SymbolicMatrix) with each cell holding an Expr::Binary { op: Add, .. } node, or Err(MathError::InvalidOperation) on dimension mismatch.
multiply
Symbolic matrix multiplication. Requires self.cols == other.rows.
The right-hand matrix. Its row count must equal the column count of
self.Ok(SymbolicMatrix) of dimension self.rows × other.cols, or Err(MathError::InvalidOperation) on incompatible dimensions.
transpose
Returns a new matrix that is the transpose of self. For an m × n matrix the result is n × m.
determinant
Computes the symbolic determinant via cofactor expansion along the first row. Requires a square matrix. For a 1×1 matrix the single element is returned; for 2×2 the standard ad - bc formula is used; larger matrices recurse using the minor sub-matrix.
Ok(Expr) containing the symbolic determinant expression, or Err(MathError::InvalidOperation) for non-square or empty matrices.
trace
Returns the symbolic sum of the main diagonal entries. Requires a square matrix.
Ok(Expr) with the sum data[0][0] + data[1][1] + ..., or Err(MathError::InvalidOperation) for non-square matrices.
Eigenvalues, Characteristic Polynomial, and Decompositions
These operations are provided byLinearAlgebra and operate on numerical nalgebra matrices (DMatrix<f64>) rather than the symbolic SymbolicMatrix type.
pub struct LinearAlgebra
A zero-sized unit struct providing numerical linear algebra routines backed by nalgebra.
solve_system
Solves the linear system Ax = b using LU decomposition with partial pivoting (via nalgebra’s lu().solve()).
The coefficient matrix. Must be square and non-singular.
The right-hand side vector. Its length must equal the number of rows in
a.Ok(DVector<f64>) containing the solution vector x, or Err(MathError::InvalidOperation("System has no unique solution")) when the matrix is singular.
eigenvalues
Computes all eigenvalues of a square matrix using Schur decomposition. Returns complex eigenvalues in a Vec<Complex64>.
A square numeric matrix.
Ok(Vec<Complex64>) with one entry per eigenvalue, or Err(MathError::InvalidOperation) for non-square input.
qr_decomposition
Decomposes a matrix into an orthogonal matrix Q and an upper-triangular matrix R such that A = QR.
(Q, R).
svd
Computes the full Singular Value Decomposition A = U Σ Vᵀ.
Ok((U, singular_values, Vᵀ)) on success, or Err(MathError::InvalidOperation("SVD computation failed")) on failure.
rank
Estimates the numerical rank of a matrix by counting the number of singular values that exceed tolerance. Uses SVD internally.
The matrix whose rank is to be estimated.
Singular values strictly greater than this threshold are counted as non-zero. A typical value is
1e-10.usize.
norm
Computes a matrix norm of the requested type. Four norm types are supported; see NormType below.
The matrix to compute the norm of.
The norm variant to compute. See
NormType for available options.f64.
condition_number
Computes the condition number of a square matrix as the ratio of its largest to smallest singular value. A large condition number indicates a nearly-singular matrix that is sensitive to perturbations.
A square matrix. Non-square input returns an error.
Ok(f64) with the condition number (σ_max / σ_min). Returns Ok(f64::INFINITY) when the smallest singular value is effectively zero (below 1e-15). Returns Err(MathError::InvalidOperation) for non-square input.
pub enum NormType
Selects the matrix norm variant used by LinearAlgebra::norm.
| Variant | Definition | ||
|---|---|---|---|
Frobenius | Square root of the sum of squared entries: √(Σ aᵢⱼ²) | ||
L1 | Maximum absolute column sum: `max_j Σᵢ | aᵢⱼ | ` |
L2 | Largest singular value (spectral norm): σ_max | ||
LInf | Maximum absolute row sum: `max_i Σⱼ | aᵢⱼ | ` |
