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

    Function normalizeAmplitudes

    • Normalizes an array of complex numbers to ensure they form valid quantum amplitudes. The normalized amplitudes will satisfy Σ|αᵢ|² = 1. Optionally skips normalization if the norm is below a threshold.

      Parameters

      • values: Complex[]

        Array of complex numbers to normalize

      • tolerance: number = 1e-12

        Minimum norm threshold below which the vector is considered zero (default: 1e-12)

      • Optionaltolerant: number

        Optional minimum norm threshold. If provided, normalization is skipped if norm <= threshold.

      Returns Complex[]

      Normalized amplitude array, or unchanged if below tolerant threshold

      Error if input is zero vector (norm below tolerance and tolerant not provided)