Deutsch Algorithm
The Deutsch algorithm is a quantum algorithm that determines whether a given function f: {0,1} → {0,1} is constant (f(0) = f(1)) or balanced (f(0) ≠ f(1)) using only one quantum query, compared to 2 classical queries needed.
This implementation builds the quantum circuit for the Deutsch algorithm and executes it on a specified quantum backend.
Deutsch Algorithm
The Deutsch algorithm is a quantum algorithm that determines whether a given
function f: {0,1} → {0,1} is constant (f(0) = f(1)) or balanced (f(0) ≠ f(1))
using only one quantum query, compared to 2 classical queries needed.
This implementation builds the quantum circuit for the Deutsch algorithm
and executes it on a specified quantum backend.(add-oracle-fn oracle-fn & _)Build the quantum circuit for the Deutsch oracle Uf.
Parameters:
The oracle function should behave as follows:
Build the quantum circuit for the Deutsch oracle Uf.
Parameters:
- oracle-fn: Function that takes a boolean input and returns boolean output
             Represents the quantum oracle Uf
Returns:
A function that takes a quantum circuit and applies the Deutsch oracle Uf
 to it based on the behavior of the oracle function.
 The oracle function should behave as follows:
 - If oracle-fn false, returns false for both inputs (constant function f(x) = 0)
 - If oracle-fn true, returns true for both inputs (constant function f(x) = 1)
 - If oracle-fn false for input 0 and true for input 1 (balanced function f(x) = x)
 - If oracle-fn true for input 0 and false for input 1 (balanced function f(x) = NOT x)(deutsch-algorithm backend oracle-fn)(deutsch-algorithm backend oracle-fn options)Implement the Deutsch algorithm to determine if a function is constant or balanced.
The Deutsch algorithm solves the problem: Given a function f: {0,1} → {0,1}, determine whether f is constant (f(0) = f(1)) or balanced (f(0) ≠ f(1)) using only one quantum query, compared to 2 classical queries needed.
Algorithm steps:
Parameters:
Returns: Map containing:
Example: (deutsch-algorithm (fn [x] true) simulator) ;=> {:result :constant} (deutsch-algorithm (fn [x] x) simulator) ;=> {:result :balanced}
Implement the Deutsch algorithm to determine if a function is constant or balanced.
The Deutsch algorithm solves the problem: Given a function f: {0,1} → {0,1},
determine whether f is constant (f(0) = f(1)) or balanced (f(0) ≠ f(1))
using only one quantum query, compared to 2 classical queries needed.
Algorithm steps:
1. Initialize |0⟩|1⟩ state (input qubit |0⟩, ancilla qubit |1⟩)
2. Apply Hadamard to both qubits: |+⟩|-⟩
3. Apply oracle function Uf
4. Apply Hadamard to input qubit
5. Measure input qubit: 0 = constant, 1 = balanced
Parameters:
- backend: Quantum backend implementing the QuantumBackend protocol to execute the circuit
- oracle-fn: Function that takes a boolean input and returns boolean output
             Represents the quantum oracle Uf
- options: Optional map with execution options (default: {:shots 1024})
Returns:
Map containing:
- :algorithm 
- :result - :constant or :balanced  
- :probability-zero - the probability of the first qubit being |0⟩
- :circuit - The quantum circuit used
- :execution-result - Full backend execution result
Example:
(deutsch-algorithm (fn [x] true) simulator)     ;=> {:result :constant}
(deutsch-algorithm (fn [x] x) simulator)        ;=> {:result :balanced}(deutsch-circuit oracle-fn)Build the quantum circuit for the Deutsch algorithm.
Parameters:
Build the quantum circuit for the Deutsch algorithm.
Parameters:
- oracle-fn: Function that takes a boolean input and returns boolean output
             Represents the quantum oracle Uf
Returns:
A quantum circuit implementing the Deutsch algorithm using the provided oracle function.cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs | 
| ← | Move to previous article | 
| → | Move to next article | 
| Ctrl+/ | Jump to the search field |