Skip to content
Symi Docs
Swift
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#

UniffiMatrix method

func add(other: UniffiMatrix) -> UniffiMatrix

Entrywise sum of two matrices of the same shape.

subtract#

UniffiMatrix method

func subtract(other: UniffiMatrix) -> UniffiMatrix

Entrywise difference of two matrices of the same shape.

multiply#

Matrix product; inner dimensions must agree.

UniffiMatrix method

func multiply(other: UniffiMatrix) -> UniffiMatrix

Matrix product; inner dimensions must agree.

scalar_multiply#

UniffiMatrix method

func 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

func matrixShape(
    subject: UniffiMatrix,
    rows: UInt64,
    columns: UInt64,
) -> UniffiAssumptionProposition

Assert or query an exact positive row and column count.

square_matrix#

Explicit context

func 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

func upperTriangularMatrix(subject: UniffiMatrix) -> UniffiAssumptionProposition

Assert or query upper-triangular structure.

lower_triangular_matrix#

Explicit context

func lowerTriangularMatrix(subject: UniffiMatrix) -> UniffiAssumptionProposition

Assert or query lower-triangular structure.

symmetric_matrix#

Explicit context

func symmetricMatrix(subject: UniffiMatrix) -> UniffiAssumptionProposition

Assert or query equality with the transpose.

hermitian_matrix#

Explicit context

func hermitianMatrix(subject: UniffiMatrix) -> UniffiAssumptionProposition

Assert or query equality with the conjugate transpose.

orthogonal_matrix#

Explicit context

func orthogonalMatrix(subject: UniffiMatrix) -> UniffiAssumptionProposition

Assert or query the real orthogonality condition.

unitary_matrix#

Explicit context

func unitaryMatrix(subject: UniffiMatrix) -> UniffiAssumptionProposition

Assert or query the unitary condition.

normal_matrix#

Explicit context

func normalMatrix(subject: UniffiMatrix) -> UniffiAssumptionProposition

Assert or query commutation with the conjugate transpose.

full_rank_matrix#

Explicit context

func fullRankMatrix(subject: UniffiMatrix) -> UniffiAssumptionProposition

Assert or query full rank.

invertible_matrix#

Explicit context

func invertibleMatrix(subject: UniffiMatrix) -> UniffiAssumptionProposition

Assert or query square invertibility.

singular_matrix#

Explicit context

func singularMatrix(subject: UniffiMatrix) -> UniffiAssumptionProposition

Assert or query square singularity.

integer_entries#

Explicit context

func integerEntries(subject: UniffiMatrix) -> UniffiAssumptionProposition

Assert or query integer entries.

real_entries#

Explicit context

func realEntries(subject: UniffiMatrix) -> UniffiAssumptionProposition

Assert or query real entries.

complex_entries#

Explicit context

func complexEntries(subject: UniffiMatrix) -> UniffiAssumptionProposition

Assert or query finite complex entries.

positive_definite_matrix#

Explicit context

func positiveDefiniteMatrix(subject: UniffiMatrix) -> UniffiAssumptionProposition

Assert or query exact positive definiteness.

positive_semidefinite_matrix#

Explicit context

func positiveSemidefiniteMatrix(subject: UniffiMatrix) -> UniffiAssumptionProposition

Assert or query exact positive semidefiniteness.

transpose#

UniffiMatrix method

func transpose() -> UniffiMatrix

The transpose, with rows and columns exchanged.

determinant#

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

UniffiMatrix method

func determinant() -> UniffiExpression

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

trace#

UniffiMatrix method

func trace() -> UniffiExpression

Sum of the diagonal entries of a square matrix.

characteristic_polynomial#

UniffiMatrix method

func characteristicPolynomial(variable: String) -> UniffiExpression

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

minimal_polynomial#

UniffiMatrix method

func minimalPolynomial(variable: 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

func eigenvalues() -> [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

func eigenvectors() -> [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

func eigenvalue() -> UniffiExpression

vectors#

UniffiEigenpair method

func vectors() -> [UniffiMatrix]

A basis of the eigenspace, as column matrices.

inverse#

Inverse via the adjugate; raises on singular input.

UniffiMatrix method

func inverse() -> UniffiMatrix

Inverse via the adjugate; raises on singular input.

rank#

UniffiMatrix method

func rank() -> UInt64

Rank via Bareiss fraction-free elimination.

row_reduce#

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

UniffiMatrix method

func 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

func nullspaceBasis() -> [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)IM\operatorname{adj}(M) = \det(M) I.

UniffiMatrix method

func adjugate() -> UniffiMatrix

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

cofactor_matrix#

UniffiMatrix method

func cofactorMatrix() -> UniffiMatrix

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].

UniffiMatrix method

func lowerUpperDecomposition() -> UniffiMatrixMatrixMatrixTuple

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

Example#

Additional API#

IntegerCokernelData#

IntegerCokernelData.free_rank#

UniffiIntegerCokernelData method

func freeRank() -> UInt64

Rank of the free part of the cokernel.

IntegerCokernelData.torsion_invariant_factors#

UniffiIntegerCokernelData method

func torsionInvariantFactors() -> [UniffiExpression]

The invariant factors of the torsion part of the cokernel.

Matrix#

Matrix.execute#

UniffiMatrix method

func 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

func hasComplexEntries() -> UniffiTruthValue

Query whether every entry is finite complex.

Matrix.has_integer_entries#

UniffiMatrix method

func hasIntegerEntries() -> UniffiTruthValue

Query whether every entry is an integer.

Matrix.has_real_entries#

UniffiMatrix method

func hasRealEntries() -> UniffiTruthValue

Query whether every entry is real.

Matrix.is_diagonal_matrix#

UniffiMatrix method

func isDiagonalMatrix() -> UniffiTruthValue

Query whether this matrix is diagonal.

Matrix.is_equality#

UniffiMatrix method

func isEquality() -> Bool

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

Matrix.is_finite_set#

UniffiMatrix method

func isFiniteSet() -> Bool

Always false: a matrix is never a finite set.

Matrix.is_full_rank_matrix#

UniffiMatrix method

func isFullRankMatrix() -> UniffiTruthValue

Query whether this matrix has full rank.

Matrix.is_hermitian_matrix#

UniffiMatrix method

func isHermitianMatrix() -> UniffiTruthValue

Query whether this matrix is Hermitian.

Matrix.is_identity_matrix#

UniffiMatrix method

func isIdentityMatrix() -> UniffiTruthValue

Query whether this matrix is the identity matrix.

Matrix.is_image_set#

UniffiMatrix method

func isImageSet() -> Bool

Always false: a matrix is never an image set.

Matrix.is_integral#

UniffiMatrix method

func isIntegral() -> Bool

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

Matrix.is_invertible_matrix#

UniffiMatrix method

func isInvertibleMatrix() -> UniffiTruthValue

Query whether this matrix is invertible.

Matrix.is_matrix#

UniffiMatrix method

func isMatrix() -> Bool

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

Matrix.is_normal_matrix#

UniffiMatrix method

func isNormalMatrix() -> UniffiTruthValue

Query whether this matrix is normal.

Matrix.is_orthogonal_matrix#

UniffiMatrix method

func isOrthogonalMatrix() -> UniffiTruthValue

Query whether this matrix is orthogonal.

Matrix.is_positive#

UniffiMatrix method

func isPositive() -> Bool?

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

Matrix.is_positive_definite_matrix#

UniffiMatrix method

func isPositiveDefiniteMatrix() -> UniffiTruthValue

Query whether this matrix is positive definite.

Matrix.is_positive_semidefinite_matrix#

UniffiMatrix method

func isPositiveSemidefiniteMatrix() -> UniffiTruthValue

Query whether this matrix is positive semidefinite.

Matrix.is_real#

UniffiMatrix method

func isReal() -> Bool?

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

Matrix.is_singular_matrix#

UniffiMatrix method

func isSingularMatrix() -> UniffiTruthValue

Query whether this matrix is singular.

Matrix.is_square#

UniffiMatrix method

func isSquare() -> UniffiTruthValue

Query whether this matrix is square.

Matrix.is_stale#

UniffiMatrix method

func isStale() -> 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#

UniffiMatrix method

func isSymmetricMatrix() -> UniffiTruthValue

Query whether this matrix is symmetric.

Matrix.is_union#

UniffiMatrix method

func isUnion() -> Bool

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

Matrix.is_unitary_matrix#

UniffiMatrix method

func isUnitaryMatrix() -> UniffiTruthValue

Query whether this matrix is unitary.

Matrix.is_zero_matrix#

UniffiMatrix method

func isZeroMatrix() -> UniffiTruthValue

Query whether this matrix is the zero matrix.

Matrix.summary#

UniffiMatrix method

func summary() -> 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.

Symi documentation · Swift