View on GitHub
Open this notebook in GitHub to run it yourself
Given a scalar function of dimensions, , computing its gradient at a specific point is often essential. On a classical computer, this requires at least queries to . This notebook presents a quantum algorithm that computes the gradient with a single query, based on the paper by S. P. Jordan [1]. This represents a dramatic speedup for high-dimensional functions, where function evaluation is typically the dominant computational cost.The core idea is an in-place computation: first, the function is encoded directly into the phases of the coordinate superposition state. Then, an inverse QFT is applied to overwrite that exact same coordinate register with the gradient, extracting it as a measurable outcome without needing a separate output register. We demonstrate this step by step - first with a simplified version to build intuition, then with refinements for the complete algorithm.Complexity: In black-box query complexity, the classical algorithm requires at least queries to , while the quantum algorithm requires only one.
- Input: A black-box function of dimensions.
- Promise: The function is smooth and has bounded gradient: .
- Output: The gradient at the origin with bits of precision, encoded on a quantum register.
Keywords: Foundational quantum algorithms, Gradient, Function evaluation, Oracle problem, Quantum Fourier Transform (QFT)

Introduction
Initialization
Simplified Explanation of the Algorithm
The algorithm has two main steps:- Encode the function into the phases of the coordinate register’s superposition
- Apply an inverse QFT to transform the coordinate register directly into the measurable gradient state
- We define an interval with points around the origin where we estimate the gradient, establishing a resolution .
- Using a phase oracle or the phase kickback technique, we encode the function as phases:

- For a sufficiently small interval, we approximate , allowing us to factor the state:

- This state is exactly the QFT of the computational basis state .
- Measure the register to obtain (or for multi-dimensional functions).
Full Explanation of the Algorithm
The simplified explanation captures the key idea but omits two important details: handling negative values and fractional representation. When estimating the gradient, we analyze an interval around the origin. The state represents equally spaced points in this interval, normalized as: With signed ranging from to : is the leftmost point (), is the origin, and is the rightmost point ()*. We also normalize the output. Assuming the gradient is bounded between and , we represent those values using the states: When applying the algorithm, we choose and based on prior knowledge of . The value determines the final resolution. must be small enough to keep the function approximately linear, and must exceed the maximum expected gradient magnitude while maintaining sufficient resolution. Using these two normalizations, we modify the algorithm:- In step 2, instead of applying , we apply .
- In step 5, the signed measurement directly gives , so .
Parameter Selection
We need to select appropriate values for , , and . We use the following notation:- - bound on the gradient magnitude:
- - desired accuracy:
- - dimensionality of
- - bound on the second derivative of near the origin
Selecting
Choose to ensure the function remains approximately linear. Similar to classical numerical differentiation, this interval must be sufficiently small. To keep gradient variation within accuracy , we require . For a single dimension, the second derivative is approximately . This gives . Using as the second derivative bound, we get . In multiple dimensions, we sum deviations as root-mean-square across all dimensions, introducing a factor of . To improve this bound, we scale by the uniform distribution variance, . The final bound for is: For a one-dimensional quadratic function , we need smaller than . Furthermore, in order to minimize the number of bits of precision to which must be evaluated, should be chosen as large as possible, subject to the constraint above. So should be chosen tightly. See Jordan’s paper [1] for a full derivation.Selecting
The parameter bounds the gradient magnitude. Since the gradient is signed, we need . The resolution of the result is . For a given register size and accuracy , the upper bound is .Selecting
defines the result resolution. The step size between possible outcomes is . To achieve accuracy , we need . Assuming tight selection, this gives a lower bound for the number of qubits:Summary
Given and desired accuracy , select parameters as:Outline
This notebook covers:- Theoretical foundation and parameter selection
- Implementation
- Phase state preparation (phase kickback and direct methods)
- Inverse QFT for gradient extraction
- Examples with linear and non-linear functions
- Performance analysis
- Multi-dimensional examples ()
Implementation
State Preparation
Phase Kickback
The first step is to prepare the state: The paper assumes an oracle , which we use with the phase kickback technique to create this state. The next example demonstrates how this works. The phase kickback has three main steps:- Apply Hadamard gates on to create a superposition of all sample points
- Initialize the ancilla to (in binary) and apply QFT
- Add to the ancilla; the function value is “kicked back” as a phase
Output:
Output:
Output:
Let’s examine the phase compared to the classical function value:

The graph shows the original function (gray), classical values (blue), and quantum phase at sample points (orange).
Results are displayed in both normalized coordinates (black axes) and original values (blue axes).
Direct Phase
While the phase kickback approach is sometimes well-suited for hardware implementations with a state oracle, it requires significant circuit overhead in simulation. A direct approach provides more efficient state preparation for our purposes. A simpler approach is to directly prepare the desired state: The example below demonstrates this method. Compare the circuit width, depth, and gate counts to see the efficiency gain. In practice, the choice between methods depends on whether you have access to an efficient oracle for the function.Output:
Output:
Output:

Quadratic Function
Non-linear functions are more interesting. In the next example, we explore a quadratic function. Note that the critical step occurs in the next phase when we apply the QFT. Here, the phases follow the function exactly without linearization. The QFT will extract the linear (gradient) component from these phase values.Output:
Output:
Output:

Output:
Output:
Output:

Full Algorithm
Implementation
The final step is to apply the inverse QFT to the coordinates. This extracts the gradient from the phases and produces a measurable state containing the normalized gradient value. We will first define a QFunc that preforms the algorithm and calculates the gradient of a given function , for single and multiple dimensions, and another function that transforms a given function (either Callable or QCallable) into a normalized phase oracle.Linear Functions
We will see the first example on a linear function.We switch from statevector simulation to standard simulation, which measures the final result rather than examining phase values directly.
Output:
Output:

Output:
Output:

Output:
Quadratic Function
For non-linear functions, the interval must be chosen carefully. The algorithm requires the function to be approximately linear over the interval, which means must be sufficiently small. The next example demonstrates this dependency. With appropriate selection of , the function remains nearly linear over the sampling interval, yielding high success rates.Output:
Output:

Output:
Output:

Performance Analysis
We can plot the success rate as a function of parameter choices. Consider a quadratic function with , and target accuracy . To determine valid parameter ranges, we need to use:- (dimensionality)
- (second derivative bound)
- : With , we have , so
Output:
Multi-Dimensional Examples
The algorithm extends to multiple dimensions. In this example we will demonstrate a general quadratic coupled function:Summary and Discussion
This notebook demonstrated Jordan’s quantum gradient estimation algorithm, which estimates at the origin using a single query to , compared to the classical lower bound of queries.Algorithm
- Prepare a uniform superposition over sample points using Hadamard gates.
- Encode as phases, either via phase kickback from a state oracle or directly using a phase oracle.
- Apply the inverse QFT to map the phase encoding onto a measurable computational basis state containing .
Parameter Selection
Potential Use Cases
The query reduction is most valuable when is large and each function evaluation is expensive. Potential applications include: Optimization, Root-finding, Functional minimization and PDEs and more.Limitation: Higher-Order Derivatives
The algorithm cannot be applied recursively to compute second or higher-order derivatives of . The method requires a quantum oracle that evaluates coherently as a phase across all simultaneously. After running the circuit and measuring, the output is a single classical value - not a new quantum oracle for at arbitrary points . Estimating by this approach would require such an oracle for , which the algorithm does not construct. In classical finite differences, second derivatives are obtained by calling at multiple points and differencing the first-derivative estimates. Replicating this quantumly would require separate oracle queries for each evaluation point, reducing the query complexity back to the classical regime and eliminating the quantum advantage entirely.Appendices
Appendix 1
- Phase Kickback