Mathematical operations and utilities for quantum algorithms.
Mathematical operations and utilities for quantum algorithms.
(continued-fraction num den)
(continued-fraction num den max-depth)
(continued-fraction num den max-depth epsilon)
Convert a fraction to continued fraction representation.
This implementation handles numerical precision issues and early termination conditions that are important for Shor's algorithm. It can detect periodic patterns in the continued fraction expansion, which is crucial for finding the correct period.
Parameters:
Returns: Vector of continued fraction terms
Convert a fraction to continued fraction representation. This implementation handles numerical precision issues and early termination conditions that are important for Shor's algorithm. It can detect periodic patterns in the continued fraction expansion, which is crucial for finding the correct period. Parameters: - num: Numerator of the fraction - den: Denominator of the fraction - max-depth: (Optional) Maximum depth of continued fraction expansion - epsilon: (Optional) Precision threshold for detecting near-zero remainders Returns: Vector of continued fraction terms
(convergents cf)
Calculate convergents from continued fraction representation.
This enhanced implementation handles edge cases better and includes additional validation to ensure proper convergence, which is important for accurately extracting periods in Shor's algorithm.
Parameters:
Returns: Vector of convergents as [numerator denominator] pairs
Calculate convergents from continued fraction representation. This enhanced implementation handles edge cases better and includes additional validation to ensure proper convergence, which is important for accurately extracting periods in Shor's algorithm. Parameters: - cf: Vector of continued fraction terms Returns: Vector of convergents as [numerator denominator] pairs
(gcd a b)
Calculate greatest common divisor using Euclidean algorithm.
Calculate greatest common divisor using Euclidean algorithm.
(mod-exp base exp m)
Calculate (base^exp) mod m efficiently using binary exponentiation.
Calculate (base^exp) mod m efficiently using binary exponentiation.
(round-precision x precision)
Round a number to specified decimal places.
Parameters:
Returns: Number rounded to specified precision
Round a number to specified decimal places. Parameters: - x: Number to round - precision: Number of decimal places Returns: Number rounded to specified precision
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close