ts-quantum
Version:
TypeScript library for quantum mechanics calculations and utilities
127 lines (126 loc) • 4.51 kB
TypeScript
/**
* Quantum operator implementations using math.js for enhanced numerical stability
*/
import { Complex, IStateVector, OperatorType, IOperator } from '../core/types';
import { StateVector } from '../states/stateVector';
type ComplexMatrix = Complex[][];
/**
* Creates a zero matrix of the specified dimension
* @param dimension The dimension of the square matrix
* @returns A dimension x dimension matrix filled with complex zeros
*/
export declare function createZeroMatrix(dimension: number): Complex[][];
/**
* Implementation of operator using matrix representation
*/
export declare class MatrixOperator implements IOperator {
readonly objectType: 'operator';
readonly dimension: number;
readonly type: OperatorType;
private matrix;
private validateTypeConstraints;
constructor(matrix: ComplexMatrix, type?: OperatorType, validateTypeConstraints?: boolean, additionalProps?: Record<string, any>);
/**
* Returns a string representation of the operator in matrix form
* @param precision Number of decimal places (default: 3)
*/
toString(precision?: number): string;
/**
* Applies operator to state vector: |ψ'⟩ = O|ψ⟩
*/
apply(state: IStateVector): StateVector;
/**
* Composes with another operator: O₁O₂
*/
compose(other: IOperator): IOperator;
/**
* Returns the adjoint (Hermitian conjugate) of the operator
*/
adjoint(): IOperator;
/**
* Returns matrix representation
*/
toMatrix(): ComplexMatrix;
/**
* Checks if matrix is Hermitian (self-adjoint)
*/
private isHermitian;
/**
* Checks if matrix is unitary
*/
private isUnitary;
/**
* Checks if matrix is a projection operator (P² = P)
*/
private isProjection;
/**
* Creates tensor product with another operator
*/
tensorProduct(other: IOperator): IOperator;
/**
* Creates the identity operator of given dimension
*/
static identity(dimension: number): IOperator;
/**
* Creates a zero operator of given dimension
*/
static zero(dimension: number): MatrixOperator;
/**
* Create optimized operator based on matrix structure
*/
static createOptimized(matrix: ComplexMatrix, type?: OperatorType): IOperator;
/**
* Scales operator by a complex number
*/
scale(scalar: Complex): MatrixOperator;
/**
* Adds this operator with another operator
*/
add(other: IOperator): MatrixOperator;
/**
* Performs partial trace operation over specified quantum subsystems
*
* In quantum mechanics, the partial trace is an operation that reduces the dimensionality of
* a quantum system by "tracing out" (removing) certain subsystems. This is a fundamental
* operation used to obtain the reduced density matrix of a composite system.
*
* @example
* // For a 4-dimensional system (2⊗2) representing two qubits:
* // Get reduced density matrix by tracing out the second qubit
* const reducedOperator = operator.partialTrace([2, 2], [1]);
*
* @example
* // For an 8-dimensional system (2⊗2⊗2) representing three qubits:
* // Trace out the first and third qubits
* const reducedOperator = operator.partialTrace([2, 2, 2], [0, 2]);
*
* @param dims - Array of dimensions for each subsystem. Product must equal this.dimension
* @param traceOutIndices - Array of indices indicating which subsystems to trace out
* @returns A new operator representing the reduced system after partial trace
* @throws Error if dimensions are invalid or indices are out of bounds
*/
partialTrace(dims: number[], traceOutIndices: number[]): IOperator;
/**
* Returns eigenvalues and eigenvectors of the operator
* Only works for Hermitian operators
*/
eigenDecompose(): {
values: Complex[];
vectors: MatrixOperator[];
};
/**
* Projects onto eigenspace with given eigenvalue
*/
projectOntoEigenspace(eigenvalue: Complex, tolerance?: number): MatrixOperator;
/**
* Calculates the operator norm (Frobenius norm)
*/
norm(): number;
/**
* Tests whether the operator is identically zero
* @param tolerance Numerical tolerance for zero comparison (default: 1e-12)
* @returns true if all matrix elements are within tolerance of zero
*/
isZero(tolerance?: number): boolean;
}
export {};