The Quipper System

Safe HaskellNone




Authors: Keith Kim, Peter LeFanu Lumsdaine, Alexandr Virodov

An implementation of Hallgren’s Class Number algorithm. This algorithm computes various invariants of a real quadratic number field K = ℚ(√Δ), notably the class number and the structure of the class group CL(K). The field K is specified by its discriminant Δ, the main input to the algorithm.

The algorithm may also be adapted to other problems from algebraic number theory, including Pell's equation (finding integer solutions to x 2dy 2 = 1, for non-square d) and the principal ideal problem (determining whether an ideal of a number field is principal, and finding a generator if so).

The present implementation falls into five stages, which we will refer to throughout the documentation:

  1. Approximate the regulator of K, to low precision, using a version of the the (quantum) HSP algorithm.
  2. Classically, refine the approximation from part 1 to higher precision.
  3. Classically compute a small generating set for the class group, using the value of the regulator from part 2.
  4. Compute relations for these generators, again using a version of the HSP algorithm.
  5. Classically compute from these the structure of the class group, and hence the class number.

Further details are given in the documentation of individual modules.

The algorithm and its mathematical background are described in:

  • Sean Hallgren, "Polynomial-time quantum algorithms for Pell’s equation and the principal ideal problem", in STOC ’02: Proceedings of the thirty-fourth annual ACM symposium on Theory of computing, pp. 653–658, 2002. (Also published in J. ACM, 54(1), 2007.)
  • Richard Jozsa, "Quantum computation in algebraic number theory: Hallgren’s efficient quantum algorithm for solving Pell’s equation." Annals of Physics, 306:241–279, February 2003; also available as All references in documentation refer to arXiv version.
  • Daniel Haase and Helmut Maier, "Quantum algorithms for number fields." Fortschr. Phys., 54(8):866–881, 2006.

The present implementation is based on a detailed algorithm specification that was provided to us by the IARPA QCS program and written by Brian J. Matt, Durward McDonell, and David Zaret.



Command line interface

This module provides a command line interface for Hallgren’s Class Number algorithm. This allows the user, for example, to print or simulate the circuits used in quantum portions of the algorithm, or to run small instances of the algorithm in a classical implementation.

Sample invocations:

>>> ./cl -R

Compute, classically, the regulator of ℚ[√Δ], with Δ = 28 (default value).

>>> ./cl -P -d 17

Compute, classically, the fundamental solution of Pell’s equation x2dy2 = 1 with d = Δ = 17.

>>> ./cl -S fn -d 5 -f eps > cl_fn_d5.eps

Produce an .eps file of the quantum circuit implementing the pseudo-periodic function fN used for regulator estimation, for Δ = 5

>>> ./cl -S starprod -d 60 -f gatecount

Give gate-count for the quantum circuit implementing the star-product on ideals, for Δ = 17

>>> ./cl --help

Print detailed usage information.

Option processing

data WhatToShow Source #

An enumeration type for determining what the main function should do.



Show the circuit for stage 1 of the algorithm


Show the circuit for stage 4 of the algorithm


Show the circuit for a specific quantum subroutine


Classically, find the regulator


Classically, find the fundamental unit


Classically, find the fundamental solution of Pell’s equation

subroutine_enum :: [(String, Subroutine)] Source #

An enumeration of available subroutines. (Compare format_enum, gatebase_enum.)

data Options Source #

A data type to hold values set by command line options.





default_options :: Options Source #

The default options.

show_default :: Show a => (Options -> a) -> String Source #

Show the default value of an option.

options :: [OptDescr (Options -> IO Options)] Source #

The list of command line options, in the format required by getOpt.

dopts :: [String] -> IO Options Source #

Process argv-style command line options into an Options structure.

usage :: IO () Source #

Print usage message to stdout.

The CL circuit generation main function

main :: IO () Source #

Main function: read options, then execute the appropriate task.

main_stage1 :: Options -> IO () Source #

Main function for outputting the circuit for stage 1 of Hallgren’s algorithm.

main_stage4 :: Options -> IO () Source #

Main function for outputting the circuit for stage 4 of Hallgren’s algorithm.

main_sub :: Options -> IO () Source #

Main function for outputting the circuits for specific subroutines.