UNPKG

ts-quantum

Version:

TypeScript library for quantum mechanics calculations and utilities

70 lines (69 loc) 2.21 kB
/** * Sparse matrix utilities for quantum operators */ import { Complex } from 'mathjs'; import { ISparseMatrix } from '../core/types'; /** * Create an empty sparse matrix */ export declare function createSparseMatrix(rows: number, cols: number): ISparseMatrix; /** * Add entry to sparse matrix */ export declare function setSparseEntry(matrix: ISparseMatrix, row: number, col: number, value: Complex): void; /** * Get entry from sparse matrix */ export declare function getSparseEntry(matrix: ISparseMatrix, row: number, col: number): Complex; /** * Multiply sparse matrix by dense vector */ export declare function sparseVectorMultiply(matrix: ISparseMatrix, vector: Complex[]): Complex[]; /** * Multiply two sparse matrices */ export declare function sparseMatrixMultiply(a: ISparseMatrix, b: ISparseMatrix): ISparseMatrix; /** * Convert sparse matrix to dense */ export declare function sparseToDense(matrix: ISparseMatrix): Complex[][]; /** * Convert dense matrix to sparse */ export declare function denseToSparse(dense: Complex[][]): ISparseMatrix; /** * Transpose sparse matrix */ export declare function sparseTranspose(matrix: ISparseMatrix): ISparseMatrix; /** * Conjugate transpose sparse matrix */ export declare function sparseConjugateTranspose(matrix: ISparseMatrix): ISparseMatrix; /** * Calculate trace of sparse matrix */ export declare function sparseTrace(matrix: ISparseMatrix): Complex; /** * Calculate Frobenius norm of sparse matrix */ export declare function sparseNorm(matrix: ISparseMatrix): number; /** * Check if matrix is identity */ export declare function isIdentityMatrix(matrix: ISparseMatrix, tolerance?: number): boolean; /** * Check if matrix is diagonal */ export declare function isSparseDiagonalMatrix(matrix: ISparseMatrix): boolean; /** * Extract diagonal entries from sparse matrix */ export declare function extractDiagonalEntries(matrix: ISparseMatrix): Complex[]; /** * Validate sparse matrix structure */ export declare function validateSparseMatrix(matrix: ISparseMatrix): boolean; /** * Remove entries that are effectively zero */ export declare function removeSparseZeros(matrix: ISparseMatrix, tolerance?: number): void;