Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/itsubaki/qasm-playground/llms.txt

Use this file to discover all available pages before exploring further.

Quantum Signal Processing (QSP) is a framework for applying polynomial transformations to quantum states. By alternating a signal operator W(theta) with phase operators S(phi), you can realize any bounded real polynomial of cos(theta) on the amplitude of a single qubit. This example implements the polynomial P(x) = 2x³ − x using a 5-gate sequence.

Circuit

The phase sequence is W(theta) → S(π/4) → W(theta) → S(−π/4) → W(theta), where:
  • W(theta) is the signal operator: Rx(−2·theta), a rotation about the X axis
  • S(phi) is the phase operator: U(0, 0, −2·phi), a Z-axis phase rotation
Quantum Signal Processing
// Quantum Signal Processing
//
// This example uses standard QSP building blocks:
//   W(theta): signal operator
//   S(phi):   phase operator
//
// The phase sequence is:
//   W(theta) -> S(pi/4) -> W(theta) -> S(-pi/4) -> W(theta)
//
// For this sequence, the amplitude of |0> becomes:
//   P(x) = 2x^3 - x
// where x = cos(theta).
//
// Example:
//   theta = pi/6 -> x = cos(pi/6) = sqrt(3)/2
//   P(x) = 2x^3 - x = sqrt(3)/4 ≈ 0.433013
//
// The final state has the form:
//   P(x)|0> + Q(x)|1>
//
// Verified for theta = pi/6:
//   final state = 0.433013|0> + (-0.5 + 0.75i)|1>

OPENQASM 3.0;

gate Rx(theta) q { U(theta, -pi/2, pi/2) q; }
gate W(theta) q { Rx(-2*theta) q; }
gate S(phi) q { U(0, 0, -2*phi) q; }

qubit q;
reset q;

const float theta = pi/6;

W(theta) q;
S(pi/4) q;
W(theta) q;
S(-pi/4) q;
W(theta) q;

Expected results

With theta = pi/6, the signal value is x = cos(π/6) = √3/2. The polynomial evaluates to: P(x) = 2·(√3/2)³ − √3/2 = √3/4 ≈ 0.433013 After running, you should see two quantum states:
BasisProbabilityAmplitude
|0⟩≈ 0.1875≈ 0.433013 + 0i
|1⟩≈ 0.8125≈ −0.5 + 0.75i
The probability of |0⟩ is P(x)² = (√3/4)² = 3/16 ≈ 0.1875. The amplitude itself is P(x) ≈ 0.433013, which is what QSP encodes — the polynomial value appears as the real amplitude of the |0⟩ component.

How the circuit works

1

Define signal and phase operators

W(theta) applies Rx(−2·theta), a rotation by −2·theta around the X axis. S(phi) applies U(0, 0, −2·phi), a phase rotation around the Z axis. These are the two primitive QSP building blocks.
2

Build the alternating sequence

The 5-gate sequence W → S(π/4) → W → S(−π/4) → W alternates signal and phase operators. The specific phase angles (π/4, −π/4) determine the polynomial being implemented — different phase sequences yield different polynomials.
3

Run and read the |0⟩ amplitude

The real part of the |0⟩ amplitude encodes P(x) = 2x³ − x evaluated at x = cos(theta). Change theta to evaluate the polynomial at a different point.

Changing the input

To evaluate the polynomial at a different point, change the theta constant:
Modified theta
const float theta = pi/4;  // x = cos(pi/4) = sqrt(2)/2 ≈ 0.7071
                            // P(x) = 2*(0.7071)^3 - 0.7071 ≈ 0
QSP is the foundation of many advanced quantum algorithms including quantum linear systems solvers and quantum singular value transformation. The single-qubit structure here scales to multi-qubit block encodings in more general settings.

Build docs developers (and LLMs) love