q5m.js - Quantum Computing Library - v0.1.1
    Preparing search index...

    Class Q5mOperator<TMatrix>

    Type Parameters

    Hierarchy (View Summary)

    Index

    Constructors

    • Creates a new quantum operator.

      Type Parameters

      • TMatrix extends Matrix = Matrix

      Parameters

      • matrix: TMatrix

        The matrix representation of the operator

      • Optionalname: string

        Optional name for the operator

      • skipValidation: boolean = false

        Skip validation for performance (use with caution)

      Returns Q5mOperator<TMatrix>

      If the matrix is not square

    Methods

    • Creates a unitary Q5mOperator with validation.

      Parameters

      • matrix: Matrix

        The unitary matrix

      • Optionalname: string

        Optional name for the operator

      Returns Q5mOperator<Matrix>

      A new Q5mOperator

      If the matrix is not unitary

    • Creates a Hermitian Q5mOperator with validation.

      Parameters

      • matrix: Matrix

        The Hermitian matrix

      • Optionalname: string

        Optional name for the operator

      Returns Q5mOperator<Matrix>

      A new Q5mOperator

      If the matrix is not Hermitian

    • Computes the time evolution operator U(t) = exp(-iHt/ℏ).

      For simplicity, we set ℏ = 1 in our units. The time evolution operator is unitary and generates the time evolution of quantum states according to the Schrödinger equation.

      Parameters

      • time: number

        The evolution time

      • hbar: number = 1

        Reduced Planck constant (default: 1 in natural units)

      Returns Matrix

      The unitary time evolution operator as a matrix

    • Creates a Q5mOperator from a matrix, with optional validation.

      Type Parameters

      • T extends Matrix

      Parameters

      • matrix: T

        The matrix to convert to an operator

      • Optionalname: string

        Optional name for the operator

      • skipValidation: boolean = false

        Whether to skip validation (default: false)

      Returns Q5mOperator<T>

      A new Q5mOperator

      If validation fails

    • Creates a Hadamard operator of the specified dimension.

      The Hadamard operator is a fundamental quantum gate that creates superposition by transforming computational basis states. For a single qubit (dimension 2), it maps |0⟩ → (|0⟩ + |1⟩)/√2 and |1⟩ → (|0⟩ - |1⟩)/√2.

      For higher dimensions, this creates a generalized Walsh-Hadamard transform. The matrix elements are H[i,j] = (1/√n) * (-1)^(i·j) where n is the dimension and i·j is the dot product of the binary representations of i and j.

      Type Parameters

      • T extends Matrix = Matrix

      Parameters

      • dimension: number

        The dimension of the Hadamard operator (must be a power of 2)

      Returns Q5mOperator<T>

      A new Q5mOperator representing the Hadamard transformation

      If dimension is not a positive power of 2

    • Creates a phase gate operator (Unitary).

      Type Parameters

      • T extends Matrix = Matrix

      Parameters

      • phase: number

        The phase angle in radians

      Returns Q5mOperator<T>

      A new Q5mOperator representing the phase gate

    • Creates a rotation gate around the X axis (Unitary).

      Type Parameters

      • T extends Matrix = Matrix

      Parameters

      • angle: number

        The rotation angle in radians

      Returns Q5mOperator<T>

      A new Q5mOperator representing Rx(angle)

    • Creates a rotation gate around the Y axis (Unitary).

      Type Parameters

      • T extends Matrix = Matrix

      Parameters

      • angle: number

        The rotation angle in radians

      Returns Q5mOperator<T>

      A new Q5mOperator representing Ry(angle)

    • Creates a rotation gate around the Z axis (Unitary).

      Type Parameters

      • T extends Matrix = Matrix

      Parameters

      • theta: number

        The rotation angle in radians

      Returns Q5mOperator<T>

      A new Q5mOperator representing Rz(theta)

    • Creates a SWAP gate that exchanges quantum states between two qubits (Unitary).

      The SWAP gate is a fundamental two-qubit gate that exchanges the quantum states of two qubits. It permutes the computational basis states as follows:

      • |00⟩ → |00⟩ (no change)
      • |01⟩ → |10⟩ (swap qubits)
      • |10⟩ → |01⟩ (swap qubits)
      • |11⟩ → |11⟩ (no change)

      Matrix representation in computational basis |00⟩, |01⟩, |10⟩, |11⟩:

      SWAP = [1 0 0 0]
      [0 0 1 0]
      [0 1 0 0]
      [0 0 0 1]

      Properties:

      • Self-inverse: SWAP² = I
      • Symmetric: SWAP₀₁ = SWAP₁₀
      • Can be decomposed into 3 CNOT gates
      • Preserves entanglement structure

      Type Parameters

      • T extends Matrix = Matrix

      Returns Q5mOperator<T>

      A new Q5mOperator representing the SWAP gate

    • Calculates the sparsity ratio of the operator matrix.

      This method counts non-zero elements to determine how sparse the matrix is, which is crucial for selecting optimal computation algorithms. A sparsity ratio close to 0 indicates a very sparse matrix (few non-zeros), while a ratio close to 1 indicates a dense matrix.

      Parameters

      • tolerance: number = 1e-15

        Threshold for considering elements as zero (default: 1e-15)

      Returns number

      Sparsity ratio between 0 and 1 (non-zero elements / total elements)

    • Determines if this operator is sparse enough to benefit from sparse algorithms.

      This method uses a configurable threshold to classify matrices as sparse or dense. Sparse matrices can use specialized algorithms that skip zero elements.

      Parameters

      • sparsityThreshold: number = 0.3

        Maximum sparsity ratio to consider sparse (default: 0.3 = 30% non-zero)

      Returns boolean

      True if the matrix is below the sparsity threshold

    • Analyzes the structure of the operator matrix to identify common patterns.

      This analysis detects quantum gate patterns that can benefit from specialized algorithms:

      • Controlled gates: Identity in top-left, unitary in bottom-right
      • Single-qubit gates: 2×2 matrices
      • Block diagonal: Independent blocks that can be processed separately

      The analysis results can guide algorithm selection for specific gate structures.

      Returns {
          sparsity: number;
          isSparse: boolean;
          isControlled: boolean;
          isSingleQubit: boolean;
          hasBlockStructure: boolean;
      }

      Analysis object with structure information

    Properties

    matrix: TMatrix

    The matrix representation of the operator

    dimension: number

    The dimension of the operator (size of the Hilbert space)

    name?: string

    Optional name for the operator