ts-quantum
Version:
TypeScript library for quantum mechanics calculations and utilities
173 lines (172 loc) • 6.41 kB
TypeScript
/**
* Operator algebra extensions for quantum mechanics
*
* Provides fundamental operator algebra operations including commutators,
* anti-commutators, Lie algebraic structures, and more.
*/
import { Complex, IOperator, IStateVector } from '../core/types';
/**
* Adds two operators
*
* @param a First operator
* @param b Second operator
* @returns The sum operator
*/
export declare function addOperators(a: IOperator, b: IOperator): IOperator;
/**
* Subtracts one operator from another
*
* @param a First operator
* @param b Second operator to subtract
* @returns The difference operator
*/
export declare function subtractOperators(a: IOperator, b: IOperator): IOperator;
/**
* Calculates the commutator [A,B] = AB - BA between two operators
*
* Used for determining whether operators commute, which is essential
* for determining if observables can be measured simultaneously.
*
* @param A First operator
* @param B Second operator
* @returns The commutator operator [A,B]
*/
export declare function commutator(A: IOperator, B: IOperator): IOperator;
/**
* Calculates the anti-commutator {A,B} = AB + BA between two operators
*
* Important for fermion systems and in supersymmetry.
*
* @param A First operator
* @param B Second operator
* @returns The anti-commutator operator {A,B}
*/
export declare function antiCommutator(A: IOperator, B: IOperator): IOperator;
/**
* Calculates a nested commutator [A, [B, C]] and more complex structures
*
* Useful for higher-order perturbation theory and quantum field calculations.
*
* @param ops Array of operators to use in nested commutator
* @param indices Array of pairs of indices specifying the commutator structure.
* Each pair [a, b] creates a commutator between operators.
* Pairs are processed from last to first (innermost to outermost).
* IMPORTANT: This function only supports strictly nested commutators of the form [A,[B,[C,D]]], not branched structures like [[A,B],[C,D]].
*
* @example
* // For a structure [A,[B,C]] with ops = [A, B, C]
* // indices = [[0, 1], [1, 2]]
* // 1. First computes [B,C] using indices [1,2] (last pair)
* // 2. Then computes [A,[B,C]] using [0,1] (first pair)
*
* @example
* // For the Jacobi identity [X,[Y,Z]] + [Y,[Z,X]] + [Z,[X,Y]]
* // term1 = nestedCommutator([X, Y, Z], [[0, 1], [1, 2]])
* // term2 = nestedCommutator([Y, Z, X], [[0, 1], [1, 2]])
* // term3 = nestedCommutator([Z, X, Y], [[0, 1], [1, 2]])
*
* @note For the LAST (innermost) pair: both indices refer to operators in the ops array
* @note For ALL OTHER pairs: the first index refers to an operator in the ops array,
* while the second operand is always the result of the previous calculation
*
* @returns The resulting operator from the nested commutator structure
*
* @see createNestedCommutator - For a more intuitive way to create nested commutators
*/
export declare function nestedCommutator(ops: IOperator[], indices: number[][]): IOperator;
/**
* Calculates the Lie derivative L_A(B) = [A, B]
*
* Important in the theory of Lie algebras and quantum mechanics.
*
* @param A First operator (generator)
* @param B Second operator
* @returns The Lie derivative operator
*/
export declare function lieDerivative(A: IOperator, B: IOperator): IOperator;
/**
* Implements the Baker-Campbell-Hausdorff formula to calculate exp(A)exp(B)
*
* Formula: exp(A)exp(B) = exp(A + B + 1/2[A,B] + 1/12[A,[A,B]] - 1/12[B,[A,B]] + ...)
* Essential for quantum mechanics when dealing with non-commuting operators.
*
* @param A First operator in exponential
* @param B Second operator in exponential
* @param order Maximum order of nested commutators to include
* @returns Approximation of exp(A+B) based on BCH formula
*/
export declare function BCHFormula(A: IOperator, B: IOperator, order?: number): IOperator;
/**
* Checks if two operators commute (within numerical tolerance)
*
* @param A First operator
* @param B Second operator
* @param tolerance Numerical tolerance for zero check
* @returns True if operators commute
*/
export declare function operatorsCommute(A: IOperator, B: IOperator, tolerance?: number): boolean;
/**
* Calculates the expectation value of a commutator [A,B] for a state
*
* Important for uncertainty relations in quantum mechanics.
*
* @param state Quantum state
* @param A First operator
* @param B Second operator
* @returns Complex expectation value
*/
export declare function commutatorExpectation(state: IStateVector, A: IOperator, B: IOperator): Complex;
/**
* Calculates the uncertainty product ΔA·ΔB for a state
*
* For the uncertainty principle: ΔA·ΔB ≥ |⟨[A,B]⟩|/2
*
* @param state Quantum state
* @param A First operator
* @param B Second operator
* @returns Real number representing uncertainty product
*/
export declare function uncertaintyProduct(state: IStateVector, A: IOperator, B: IOperator): number;
/**
* Checks if an operator is normal (AA† = A†A)
*
* Normal operators have special spectral properties.
*
* @param A Operator to check
* @param tolerance Numerical tolerance
* @returns True if operator is normal
*/
export declare function isNormalOperator(A: IOperator, tolerance?: number): boolean;
/**
* Creates an operator from its generating function: exp(iG)
*
* Common in quantum mechanics where G is the generator (often Hermitian)
*
* @param generator Generator operator G
* @returns Resulting operator exp(iG)
*/
export declare function operatorFromGenerator(generator: IOperator): IOperator;
/**
* Creates a nested commutator in a more intuitive way
*
* This function provides a simpler interface for creating nested commutators
* compared to the more complex indexing scheme used by nestedCommutator.
*
* @param ops Array of operators in the exact order they should appear in the commutator
* @returns The resulting operator from the nested commutator structure
*
* @example
* // To compute [X, [Y, Z]]:
* createNestedCommutator([X, Y, Z]);
*
* // To compute [A, [B, [C, D]]]:
* createNestedCommutator([A, B, C, D]);
*/
export declare function createNestedCommutator(ops: IOperator[]): IOperator;
/**
* Creates projection operator |ψ⟩⟨ψ| from a state
*
* @param state Quantum state to project onto
* @returns Projection operator
*/
export declare function projectionOperator(state: IStateVector): IOperator;