liveBook · Manning

Function encoding

As explained in Building Quantum Software with Python

A function-encoding circuit is a quantum circuit that maps encoded function inputs to corresponding encoded function outputs in quantum registers.

A function-encoding circuit prepares two quantum registers so each encoded input k is paired with its corresponding encoded output f(k). The key register represents candidate inputs; the value register stores signed outputs, enabling Grover search to evaluate and optimize the function. section 11.2

A practical construction uses:

  • Three key qubits to represent integers 0 through 7 and six value qubits to encode outputs in two’s complement. section 11.2
  • A polynomial over binary variables, converted into circuit terms and passed to build_polynomial_circuit. section 11.2
  • Measurement and outcome processing that decodes k and f(k), checks progress, and updates the circuit’s free term. section 11.2

Encoding a parabola

For f(k) = -(k - 3)^2 + 3, the circuit encodes values from -13 through 3. Integrated with Grover iterations, repeated measurements and parameter updates eventually return (3, 3), the maximum found by the optimizer. section 11.2

Figure 11.6 A flow chart of the Grover optimizer
figure

Trace the preparation, Grover-search, evaluation, and circuit-update loop visually. section 11.2

How Building Quantum Software with Python covers it

How deep it goes
Explains register sizing, binary-polynomial construction, decoding, and iterative updates, but defers gate-level derivations.
Examples
Uses f(k) = -(k - 3)^2 + 3, two’s-complement outputs, measurement counts, and a final result of (3, 3).
What it assumes
Assumes quantum registers and Grover search while teaching binary-variable expansion and signed output encoding through the example.
What you can do after
Build it from scratch using polynomial terms, register widths, outcome decoding, and an iterative Grover-optimizer workflow.
How it connects
Connects quantum registers, polynomial representations, Grover's algorithm, oracles, measurement, and iterative optimization.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Building Quantum Software with Python. The section links point to the parts of the book it draws on.