Liking cljdoc? Tell your friends :D

org.soulspace.qclojure.application.algorithm.deutsch


deutsch-algorithmclj

(deutsch-algorithm oracle-fn backend)
(deutsch-algorithm oracle-fn backend 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:

  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:

  • oracle-fn: Function that takes a boolean input and returns boolean output Represents the quantum oracle Uf
  • backend: Quantum backend implementing the QuantumBackend protocol
  • options: Optional map with execution options (default: {:shots 1024})

Returns: Map containing:

  • :result - :constant or :balanced
  • :measurement-outcome - measurement outcome from backend
  • :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}

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:
- oracle-fn: Function that takes a boolean input and returns boolean output
             Represents the quantum oracle Uf
- backend: Quantum backend implementing the QuantumBackend protocol
- options: Optional map with execution options (default: {:shots 1024})

Returns:
Map containing:
- :result - :constant or :balanced  
- :measurement-outcome - measurement outcome from backend
- :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}
sourceraw docstring

deutsch-circuitclj

(deutsch-circuit oracle-fn)

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.
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.
sourceraw docstring

deutsch-oracle-circuitclj

(deutsch-oracle-circuit oracle-fn & _)

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)
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)
sourceraw docstring

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close