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#
UniffiMatrix method
fun add(other: UniffiMatrix): UniffiMatrix
Entrywise sum of two matrices of the same shape.
subtract#
UniffiMatrix method
fun subtract(other: UniffiMatrix): UniffiMatrix
Entrywise difference of two matrices of the same shape.
multiply#
Matrix product; inner dimensions must agree.
UniffiMatrix method
fun multiply(other: UniffiMatrix): UniffiMatrix
Matrix product; inner dimensions must agree.
scalar_multiply#
UniffiMatrix method
fun scalarMultiply(scalar: UniffiExpression): UniffiMatrix
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#
Explicit context
fun matrixShape(
subject: UniffiMatrix,
rows: kotlin.ULong,
columns: kotlin.ULong,
): UniffiAssumptionProposition
Assert or query an exact positive row and column count.
square_matrix#
Explicit context
fun squareMatrix(subject: UniffiMatrix): UniffiAssumptionProposition
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#
Explicit context
fun upperTriangularMatrix(subject: UniffiMatrix): UniffiAssumptionProposition
Assert or query upper-triangular structure.
lower_triangular_matrix#
Explicit context
fun lowerTriangularMatrix(subject: UniffiMatrix): UniffiAssumptionProposition
Assert or query lower-triangular structure.
symmetric_matrix#
Explicit context
fun symmetricMatrix(subject: UniffiMatrix): UniffiAssumptionProposition
Assert or query equality with the transpose.
hermitian_matrix#
Explicit context
fun hermitianMatrix(subject: UniffiMatrix): UniffiAssumptionProposition
Assert or query equality with the conjugate transpose.
orthogonal_matrix#
Explicit context
fun orthogonalMatrix(subject: UniffiMatrix): UniffiAssumptionProposition
Assert or query the real orthogonality condition.
unitary_matrix#
Explicit context
fun unitaryMatrix(subject: UniffiMatrix): UniffiAssumptionProposition
Assert or query the unitary condition.
normal_matrix#
Explicit context
fun normalMatrix(subject: UniffiMatrix): UniffiAssumptionProposition
Assert or query commutation with the conjugate transpose.
full_rank_matrix#
Explicit context
fun fullRankMatrix(subject: UniffiMatrix): UniffiAssumptionProposition
Assert or query full rank.
invertible_matrix#
Explicit context
fun invertibleMatrix(subject: UniffiMatrix): UniffiAssumptionProposition
Assert or query square invertibility.
singular_matrix#
Explicit context
fun singularMatrix(subject: UniffiMatrix): UniffiAssumptionProposition
Assert or query square singularity.
integer_entries#
Explicit context
fun integerEntries(subject: UniffiMatrix): UniffiAssumptionProposition
Assert or query integer entries.
real_entries#
Explicit context
fun realEntries(subject: UniffiMatrix): UniffiAssumptionProposition
Assert or query real entries.
complex_entries#
Explicit context
fun complexEntries(subject: UniffiMatrix): UniffiAssumptionProposition
Assert or query finite complex entries.
positive_definite_matrix#
Explicit context
fun positiveDefiniteMatrix(subject: UniffiMatrix): UniffiAssumptionProposition
Assert or query exact positive definiteness.
positive_semidefinite_matrix#
Explicit context
fun positiveSemidefiniteMatrix(subject: UniffiMatrix): UniffiAssumptionProposition
Assert or query exact positive semidefiniteness.
transpose#
UniffiMatrix method
fun transpose(): UniffiMatrix
The transpose, with rows and columns exchanged.
determinant#
Fraction-free (Berkowitz/Bareiss) determinant of a square matrix.
UniffiMatrix method
fun determinant(): UniffiExpression
Fraction-free (Berkowitz/Bareiss) determinant of a square matrix.
trace#
UniffiMatrix method
fun trace(): UniffiExpression
Sum of the diagonal entries of a square matrix.
characteristic_polynomial#
UniffiMatrix method
fun characteristicPolynomial(variable: kotlin.String): UniffiExpression
det(λI−M) as a polynomial in the named variable.
minimal_polynomial#
UniffiMatrix method
fun minimalPolynomial(variable: kotlin.String): UniffiExpression
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.
UniffiMatrix method
fun eigenvalues(): List<UniffiExpression>
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.
UniffiMatrix method
fun eigenvectors(): List<UniffiEigenpair>
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#
UniffiEigenpair method
fun eigenvalue(): UniffiExpression
vectors#
UniffiEigenpair method
fun vectors(): List<UniffiMatrix>
A basis of the eigenspace, as column matrices.
inverse#
Inverse via the adjugate; raises on singular input.
UniffiMatrix method
fun inverse(): UniffiMatrix
Inverse via the adjugate; raises on singular input.
rank#
UniffiMatrix method
Rank via Bareiss fraction-free elimination.
row_reduce#
Bareiss row-reduced form (fraction-free; pivots remain on the diagonal).
UniffiMatrix method
fun rowReduce(): UniffiMatrix
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.
UniffiMatrix method
fun nullspaceBasis(): List<UniffiMatrix>
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)I.
UniffiMatrix method
fun adjugate(): UniffiMatrix
The classical adjoint (transpose of the cofactor matrix); satisfies Madj(M)=det(M)I.
cofactor_matrix#
UniffiMatrix method
fun cofactorMatrix(): UniffiMatrix
The matrix of cofactors, whose transpose is the adjugate.
lower_upper_decomposition#
Partial-pivoting LU decomposition returned as
(permutation, lower, upper) with permutationM=lowerupper. The
permutation matrix is reconstructed from the pivoting row-swap record.
Notes: WASM returns a 3-element array [permutation, lower, upper].
UniffiMatrix method
fun lowerUpperDecomposition(): UniffiMatrixMatrixMatrixTuple
Partial-pivoting LU decomposition returned as (permutation, lower, upper) with permutationM=lowerupper.
Example#
Additional API#
IntegerCokernelData#
IntegerCokernelData.free_rank#
UniffiIntegerCokernelData method
fun freeRank(): kotlin.ULong
Rank of the free part of the cokernel.
IntegerCokernelData.torsion_invariant_factors#
UniffiIntegerCokernelData method
fun torsionInvariantFactors(): List<UniffiExpression>
The invariant factors of the torsion part of the cokernel.
Matrix#
Matrix.execute#
UniffiMatrix method
fun execute(): UniffiMatrix
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#
UniffiMatrix method
fun hasComplexEntries(): UniffiTruthValue
Query whether every entry is finite complex.
Matrix.has_integer_entries#
UniffiMatrix method
fun hasIntegerEntries(): UniffiTruthValue
Query whether every entry is an integer.
Matrix.has_real_entries#
UniffiMatrix method
fun hasRealEntries(): UniffiTruthValue
Query whether every entry is real.
Matrix.is_diagonal_matrix#
UniffiMatrix method
fun isDiagonalMatrix(): UniffiTruthValue
Query whether this matrix is diagonal.
Matrix.is_equality#
UniffiMatrix method
fun isEquality(): kotlin.Boolean
Always false: a matrix is never an equal relation node.
Matrix.is_finite_set#
UniffiMatrix method
fun isFiniteSet(): kotlin.Boolean
Always false: a matrix is never a finite set.
Matrix.is_full_rank_matrix#
UniffiMatrix method
fun isFullRankMatrix(): UniffiTruthValue
Query whether this matrix has full rank.
Matrix.is_hermitian_matrix#
UniffiMatrix method
fun isHermitianMatrix(): UniffiTruthValue
Query whether this matrix is Hermitian.
Matrix.is_identity_matrix#
UniffiMatrix method
fun isIdentityMatrix(): UniffiTruthValue
Query whether this matrix is the identity matrix.
Matrix.is_image_set#
UniffiMatrix method
fun isImageSet(): kotlin.Boolean
Always false: a matrix is never an image set.
Matrix.is_integral#
UniffiMatrix method
fun isIntegral(): kotlin.Boolean
Always false: a matrix is never an unevaluated integral node.
Matrix.is_invertible_matrix#
UniffiMatrix method
fun isInvertibleMatrix(): UniffiTruthValue
Query whether this matrix is invertible.
Matrix.is_matrix#
UniffiMatrix method
fun isMatrix(): kotlin.Boolean
Always False on expressions and True on matrix objects, so mixed result streams can be discriminated.
Matrix.is_normal_matrix#
UniffiMatrix method
fun isNormalMatrix(): UniffiTruthValue
Query whether this matrix is normal.
Matrix.is_orthogonal_matrix#
UniffiMatrix method
fun isOrthogonalMatrix(): UniffiTruthValue
Query whether this matrix is orthogonal.
Matrix.is_positive#
UniffiMatrix method
fun isPositive(): kotlin.Boolean?
Always None: positivity is a property of the entries, not of the matrix.
Matrix.is_positive_definite_matrix#
UniffiMatrix method
fun isPositiveDefiniteMatrix(): UniffiTruthValue
Query whether this matrix is positive definite.
Matrix.is_positive_semidefinite_matrix#
UniffiMatrix method
fun isPositiveSemidefiniteMatrix(): UniffiTruthValue
Query whether this matrix is positive semidefinite.
Matrix.is_real#
UniffiMatrix method
fun isReal(): kotlin.Boolean?
Always None: realness is a property of the entries, not of the matrix.
Matrix.is_singular_matrix#
UniffiMatrix method
fun isSingularMatrix(): UniffiTruthValue
Query whether this matrix is singular.
Matrix.is_square#
UniffiMatrix method
fun isSquare(): UniffiTruthValue
Query whether this matrix is square.
Matrix.is_stale#
UniffiMatrix method
fun isStale(): kotlin.Boolean
Reports whether resetting the owning context invalidated the expression. All other operations reject a stale receiver with an actionable error.
Matrix.is_symmetric_matrix#
UniffiMatrix method
fun isSymmetricMatrix(): UniffiTruthValue
Query whether this matrix is symmetric.
Matrix.is_union#
UniffiMatrix method
fun isUnion(): kotlin.Boolean
Always false: a matrix is never a union of sets.
Matrix.is_unitary_matrix#
UniffiMatrix method
fun isUnitaryMatrix(): UniffiTruthValue
Query whether this matrix is unitary.
Matrix.is_zero_matrix#
UniffiMatrix method
fun isZeroMatrix(): UniffiTruthValue
Query whether this matrix is the zero matrix.
Matrix.summary#
UniffiMatrix method
fun summary(): kotlin.String
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.