ts-quantum
Version:
TypeScript library for quantum mechanics calculations and utilities
127 lines (126 loc) • 3.8 kB
TypeScript
/**
* Quantum state vector implementation
*/
import { Complex, IStateVector } from '../core/types';
export interface AngularMomentumMetadata {
type: 'angular_momentum';
j: number;
mRange: [number, number];
couplingHistory: CouplingRecord[];
jComponents: Map<number, JComponentMetadata>;
isComposite: boolean;
}
export interface CouplingRecord {
operation: 'single' | 'coupling';
j1?: number;
j2?: number;
resultJ: number[];
timestamp: number;
}
export interface JComponentMetadata {
j: number;
startIndex: number;
dimension: number;
normalizationFactor: number;
}
export declare class StateVector implements IStateVector {
readonly objectType: 'state';
readonly dimension: number;
readonly amplitudes: Complex[];
readonly basis?: string;
readonly properties?: Record<string, any>;
constructor(dimension: number, amplitudes?: Complex[], basis?: string, properties?: Record<string, any>);
/**
* Sets amplitude at specified index
*/
setState(index: number, value: Complex): void;
/**
* Gets amplitude at specified index
*/
getState(index: number): Complex;
/**
* Calculates inner product ⟨ψ|φ⟩ with another state
*/
innerProduct(other: StateVector): Complex;
/**
* Calculates norm of state vector
*/
norm(): number;
/**
* Returns normalized version of state vector
*/
normalize(): StateVector;
/**
* Computes tensor product with another state vector
*/
tensorProduct(other: StateVector): StateVector;
/**
* Returns true if state is zero vector
*/
isZero(tolerance?: number): boolean;
/**
* Get a copy of the amplitudes array
*/
getAmplitudes(): Complex[];
/**
* Check if this state vector equals another within tolerance
*/
equals(other: IStateVector, tolerance?: number): boolean;
/**
* Scale the state vector by a complex number
* @param factor Complex scaling factor
* @returns New scaled state vector
*/
scale(factor: Complex): IStateVector;
/**
* Add another state vector to this one
* @param other The state vector to add
* @returns New state vector representing the sum
*/
add(other: IStateVector): IStateVector;
/**
* Returns array representation of state vector
*/
toArray(): Complex[];
/**
* Returns string representation of state vector
*/
toString(): string;
/**
* Returns string representation in computational basis |n⟩
*/
toComputationalString(): string;
/**
* Returns string representation in angular momentum basis |j,m⟩
* @param j Total angular momentum quantum number
*/
toAngularString(j: number): string;
/**
* Creates a computational basis state |i⟩
*/
static computationalBasis(dimension: number, index: number): StateVector;
/**
* Returns array of all computational basis states
*/
static computationalBasisStates(dimension: number): StateVector[];
/**
* Creates normalized superposition of basis states with given coefficients
*/
static superposition(coefficients: Complex[]): StateVector;
/**
* Creates an equally weighted superposition of all basis states
*/
static equalSuperposition(dimension: number): StateVector;
/**
* Sets angular momentum metadata for this state
*/
setAngularMomentumMetadata(metadata: AngularMomentumMetadata): void;
/**
* Gets angular momentum metadata if present
*/
getAngularMomentumMetadata(): AngularMomentumMetadata | null;
/**
* Checks if this state has angular momentum structure
*/
hasAngularMomentumStructure(): boolean;
}