Skip to content
This repository has been archived by the owner on Jan 12, 2024. It is now read-only.

Table Lookup #604

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions Standard/src/Canon/Utils/Multiplexer.qs
Original file line number Diff line number Diff line change
Expand Up @@ -482,4 +482,43 @@ namespace Microsoft.Quantum.Canon {
return (N, n);
}

/// # Summary
/// Performs a table lookup operation.
///
/// # Description
/// A table lookup uses an address to return classical data from quantum registers.
/// Computes the following map:
/// $$\sum_{j=0}^{L-1}\ket{j}\ket{0} \rightarrow \sum_{j=0}^{L-1}\ket{j}\ket{data_j}$$
/// where $L$ is the length of the table.
///
/// # Input
/// ## data
/// The classical bit data that represents the table.
/// The length of data has to be in the interval [0, 2^(number of qubits in address) - 1.
/// The length of each element of `data` has to be equal to the number of qubits in `target`.
/// ## address
/// The address used to lookup from the table.
/// ## target
/// Qubits in which the result of the lookup will be stored.
///
/// # Example
/// Below is an example that flips each bit in a two bit register
/// ```qsharp
adrianleh marked this conversation as resolved.
Show resolved Hide resolved
/// operation InvertTwoBitNumber(address : LittleEndian, target : Qubit[]) : Unit {
/// let data = [[true, true], [true, false], [false, true], [false, false]];
/// TableLookup(data, address, target);
/// }
/// ```
///
/// # References
/// - Windowed quantum arithmetic
/// Craig Gidney
/// https://arxiv.org/abs/1905.07682
operation ApplyTableLookup(data : Bool[][], address : LittleEndian, target : Qubit[]) : Unit is Adj + Ctl {
let applyXFromBitString = ApplyPauliFromBitString(PauliX, true, _, _); // Applies X conditionally based on bitstring
// Create unitaries that encode elements of data as bit flips
let unitaries = Mapped(bitstring -> applyXFromBitString(bitstring, _), data);
MultiplexOperations(unitaries, address, target); // Multiplex over address onto target
}

}