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

    Interface Q5mSystem

    Base interface for all quantum systems in q5m.js.

    This interface defines the fundamental contract that all quantum systems must implement, providing a unified interface for quantum state manipulation regardless of the underlying representation (pure states, mixed states, qudits, etc.).

    Design Principles:

    • Abstraction: Hide implementation details behind uniform interface
    • Extensibility: Enable future quantum system types without breaking changes
    • Performance: Allow specialized implementations for different system sizes
    • Type Safety: Provide compile-time guarantees for quantum operations

    Quantum System Types:

    • Pure states: |ψ⟩ represented as state vectors
    • Mixed states: ρ represented as density matrices
    • N-level systems: qudits with arbitrary dimension per particle
    • Composite systems: tensor products of subsystems
    interface Q5mSystem {
        dimension(): number;
        clone(): Q5mSystem;
        tensor(other: Q5mSystem): Q5mSystem;
        toString(precision?: number, threshold?: number): string;
        purity(): number;
        isPure(): boolean;
        entropy(): number;
        fidelity(other: Q5mSystem): number;
    }

    Implemented by

    Index

    Methods

    • Returns the dimension of the Hilbert space for this quantum system.

      For pure qubit states: dimension = 2^numQubits For qudits: dimension = levels^numQudits For mixed states: same as underlying pure state dimension

      Returns number

      The total number of basis states in the system

    • Creates a deep copy of this quantum system.

      The cloned system is completely independent and can be modified without affecting the original. All internal state representations (state vectors, density matrices, etc.) are copied.

      Returns Q5mSystem

      New quantum system with identical quantum state

    • Computes the tensor product with another quantum system.

      Creates a composite quantum system by combining this system with another. The resulting system has dimension equal to the product of individual system dimensions.

      For pure states: |ψ₁⟩ ⊗ |ψ₂⟩ For mixed states: ρ₁ ⊗ ρ₂

      Parameters

      • other: Q5mSystem

        Quantum system to tensor with this one

      Returns Q5mSystem

      New quantum system representing the composite system

    • Returns a string representation of the quantum state.

      The format depends on the specific quantum system type:

      • Pure states: amplitude-basis notation (e.g., "0.707|00⟩ + 0.707|11⟩")
      • Mixed states: density matrix or statistical mixture notation

      Parameters

      • Optionalprecision: number

        Number of decimal places for amplitude display (default: 3)

      • Optionalthreshold: number

        Minimum amplitude magnitude to display (default: 1e-10)

      Returns string

      Human-readable representation of the quantum state

    • Calculates the purity of the quantum state.

      Purity is defined as Tr(ρ²) where ρ is the density matrix.

      • Pure states: purity = 1
      • Maximally mixed states: purity = 1/dimension
      • Partially mixed states: 1/dimension < purity < 1

      Returns number

      Purity value between 1/dimension and 1

    • Checks if this quantum system represents a pure state.

      A quantum state is pure if it can be written as |ψ⟩⟨ψ| for some state vector |ψ⟩. Mathematically, this is equivalent to purity = 1.

      Returns boolean

      True if the state is pure, false if mixed

    • Computes the von Neumann entropy of the quantum state.

      Entropy is defined as S = -Tr(ρ log₂ ρ) where ρ is the density matrix.

      • Pure states: entropy = 0
      • Maximally mixed states: entropy = log₂(dimension)
      • Mixed states: 0 < entropy < log₂(dimension)

      Returns number

      Von Neumann entropy in bits

    • Computes the fidelity between this and another quantum system.

      Fidelity is a measure of similarity between two quantum states:

      • For pure states: F(|ψ₁⟩, |ψ₂⟩) = |⟨ψ₁|ψ₂⟩|²
      • For mixed states: F(ρ₁, ρ₂) = Tr(√(√ρ₁ρ₂√ρ₁))²
      • Pure-mixed: F(|ψ⟩, ρ) = ⟨ψ|ρ|ψ⟩

      Fidelity ranges from 0 (orthogonal states) to 1 (identical states).

      Parameters

      • other: Q5mSystem

        The other quantum system to compare with

      Returns number

      Fidelity value between 0 and 1