Liking cljdoc? Tell your friends :D
Clojure only.

org.soulspace.qclojure.application.algorithm.shor


shor-algorithmclj

(shor-algorithm N)
(shor-algorithm N options)

Shor's algorithm for integer factorization.

Shor's algorithm is a quantum algorithm that can factor large integers exponentially faster than the best known classical algorithms. It combines classical preprocessing, quantum period finding, and classical post-processing.

This improved implementation supports:

  1. Hardware-compatible mode for real quantum hardware execution
  2. Multiple measurements for statistical robustness
  3. Enhanced period extraction for better success rate

Algorithm steps:

  1. Classical preprocessing: Check for trivial cases
  2. Choose random a < N, check gcd(a,N)
  3. Quantum period finding: Find period r of f(x) = a^x mod N
  4. Classical post-processing: Extract factors from the period

Parameters:

  • N: Integer to factor (should be composite)
  • options: (Optional) Map containing:
    • :n-qubits - Number of qubits for quantum period finding (default: 2*⌈log₂(N)⌉)
    • :hardware-compatible - Boolean indicating if hardware-optimized circuit should be used
    • :n-measurements - Number of measurements for statistical analysis (default: 10)
    • :max-attempts - Maximum number of random 'a' values to try (default: 10)

Returns: Map containing:

  • :factors - Vector of non-trivial factors found (empty if factorization failed)
  • :success - Boolean indicating if factorization succeeded
  • :N - The input number
  • :attempts - Vector of maps describing each attempt with different 'a' values
  • :quantum-circuit - The quantum circuit from the successful attempt (if any)
  • :statistics - Performance statistics and confidence metrics

Example: (shor-algorithm 15) ;=> {:factors [3 5], :success true, :N 15, ...} (shor-algorithm 21 {:hardware-compatible true}) ;=> {:factors [3 7], :success true, ...}

Shor's algorithm for integer factorization.

Shor's algorithm is a quantum algorithm that can factor large integers
exponentially faster than the best known classical algorithms. It combines
classical preprocessing, quantum period finding, and classical post-processing.

This improved implementation supports:
1. Hardware-compatible mode for real quantum hardware execution
2. Multiple measurements for statistical robustness
3. Enhanced period extraction for better success rate

Algorithm steps:
1. Classical preprocessing: Check for trivial cases
2. Choose random a < N, check gcd(a,N)  
3. Quantum period finding: Find period r of f(x) = a^x mod N
4. Classical post-processing: Extract factors from the period

Parameters:
- N: Integer to factor (should be composite)
- options: (Optional) Map containing:
  - :n-qubits - Number of qubits for quantum period finding (default: 2*⌈log₂(N)⌉)
  - :hardware-compatible - Boolean indicating if hardware-optimized circuit should be used
  - :n-measurements - Number of measurements for statistical analysis (default: 10)
  - :max-attempts - Maximum number of random 'a' values to try (default: 10)

Returns:
Map containing:
- :factors - Vector of non-trivial factors found (empty if factorization failed)
- :success - Boolean indicating if factorization succeeded
- :N - The input number
- :attempts - Vector of maps describing each attempt with different 'a' values
- :quantum-circuit - The quantum circuit from the successful attempt (if any)
- :statistics - Performance statistics and confidence metrics

Example:
(shor-algorithm 15)    ;=> {:factors [3 5], :success true, :N 15, ...}
(shor-algorithm 21 {:hardware-compatible true})   ;=> {:factors [3 7], :success true, ...}
sourceraw docstring

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

× close