Safe Haskell | None |
---|
This module defines the specialized datatypes of the Class Number algorithm, and basic utility functions on these types.
Synopsis
- type CLInt = IntM
- type CLIntP = Integer
- type CLRational = Rational
- type CLReal = FPReal
- bigD_of_d :: Integral a => a -> a
- d_of_bigD :: Integral a => a -> a
- is_valid_d :: Integral a => a -> Bool
- is_valid_bigD :: Integral a => a -> Bool
- all_small_ds :: Integral int => [int]
- all_bigDs :: Integral int => [int]
- data AlgNumGen a
- = AlgNum a a CLIntP
- | AlgNum_indet a
- type AlgNum = AlgNumGen CLRational
- fst_AlgNum :: AlgNumGen a -> a
- snd_AlgNum :: Num a => AlgNumGen a -> a
- pretty_show_AlgNum :: Show a => AlgNumGen a -> String
- floating_of_AlgNum :: (Real a, Floating b) => AlgNumGen a -> b
- number_promote :: Num a => AlgNumGen a -> AlgNumGen b -> ErrMsg -> AlgNumGen a
- conjugate :: Num a => AlgNumGen a -> AlgNumGen a
- is_alg_int :: (Ord a, RealFrac a) => AlgNumGen a -> Bool
- is_unit :: (Ord a, RealFrac a) => AlgNumGen a -> Bool
- omega_of_bigD :: CLIntP -> AlgNum
- data IdealX x = Ideal CLIntP (XInt x) (XInt x) (XInt x) (XInt x)
- type Ideal = IdealX Bool
- type IdealQ = IdealX Qubit
- type IdealC = IdealX Bit
- data IdealRedX x = IdealRed CLIntP (XInt x) (XInt x)
- type IdealRed = IdealRedX Bool
- type IdealRedQ = IdealRedX Qubit
- type IdealRedC = IdealRedX Bit
- type IdDist = (Ideal, FPReal)
- type IdDistQ = (IdealQ, FPRealQ)
- type IdRedDist = (IdealRed, FPReal)
- type IdRedDistQ = (IdealRedQ, FPRealQ)
- d_of_Ideal :: IdealX a -> CLIntP
- d_of_IdealRed :: IdealRedX a -> CLIntP
- bigD_of_Ideal :: IdealX a -> CLIntP
- bigD_of_IdealRed :: IdealRedX a -> CLIntP
- delta :: IdDist -> CLReal
- tau :: (Integral int, Integral int') => int' -> int -> int -> int
- is_standard :: Ideal -> Bool
- is_reduced :: Ideal -> Bool
- is_really_reduced :: IdealRed -> Bool
- forget_reduced :: IdealRed -> Ideal
- to_reduced :: Ideal -> IdealRed
- assert_reduced :: Ideal -> a -> a
- assert_really_reduced :: IdealRed -> a -> a
- q_tau :: CLIntP -> QDInt -> QDInt -> Circ (QDInt, QDInt, QDInt)
- q_is_reduced :: IdealQ -> Circ (IdealQ, Qubit)
- q_is_really_reduced :: IdealRedQ -> Circ (IdealRedQ, Qubit)
- q_forget_reduced :: IdealRedQ -> Circ IdealQ
- q_assert_reduced :: IdealQ -> Circ IdealRedQ
- q_assert_really_reduced :: IdealRedQ -> Circ IdealRedQ
- length_for_ab :: CLIntP -> Int
- length_for_ml :: CLIntP -> Int
- n_of_bigD :: Integral int => CLIntP -> int
- precision_for_fN :: CLIntP -> Int -> Int -> Int
- fix_sizes_Ideal :: Ideal -> Ideal
- fix_sizes_IdealRed :: IdealRed -> IdealRed
Type synonyms
First, we define some type synonyms for arithmetic types, selecting which will be used in the functions for the Class Number algorithm.
We use three different integer types. For interfacing with quantum computation, we use CLInt
:= IntM
. For efficient classical (i.e. circuit-generation time) computation on potentially large integers, we use CLIntP
:= Integer
, Haskell’s arbitrary-precision integers. (Δ, for instance, is taken to be a CLIntP
). For small classical integers (typically for register sizes), we use Int
, Haskell’s bounded-precision integers.
For the first two of these, we define type synonyms, so that they can be swapped out to other types if desired (they are to a large extent modular). For Int
we do not, since we make un-coerced use of built-in Haskell functions like length
which give it specifically.
Where not dictated by these conventions, integer types are generalized, i.e., (Integral a) =>
…
Rational and real numbers have not yet been similarly stratified.
type CLIntP = Integer Source #
Integers that will be used for parameter computation only, potentially large.
type CLRational = Rational Source #
Rational numbers for the Class Number code.
Algebraic number fields
Discriminants
The functions of this subsection are needed only for circuit-generation-time classical computation, not for quantum circuit computation.
bigD_of_d :: Integral a => a -> a Source #
Compute Δ, given d. (See [Jozsa 2003], Prop. 6 et seq. We use Δ, or in code bigD, where Jozsa uses D.)
d_of_bigD :: Integral a => a -> a Source #
Compute d, given Δ. (Again, see [Jozsa 2003], Prop. 6 et seq.)
is_valid_d :: Integral a => a -> Bool Source #
Check if d is a valid input to Hallgren’s algorithm, i.e. correctly defines a real quadratic number field.
is_valid_bigD :: Integral a => a -> Bool Source #
Check if Δ is a valid input to Hallgren’s algorithm, i.e. is the discriminant of a real quadratic number field. (Cf. http://en.wikipedia.org/wiki/Fundamental_discriminant)
all_small_ds :: Integral int => [int] Source #
The (infinite, lazy) list of all valid inputs d, i.e. of all square-free integers above 2.
all_bigDs :: Integral int => [int] Source #
The (infinite, lazy) list of all valid inputs Δ, i.e. of all discriminants of real quadratic number fields.
Field elements
A data type describing a number in the algebraic number field K =
ℚ[√Δ]:
represents a + b√Δ.AlgNumGen
a b Δ
In general, the type of coefficients may be any type of (classical
or quantum) numbers, i.e. an instance of the Num
or QNum
class.
Given this, the algebraic numbers with a fixed Δ will in turn be an
instance of Num
or QNum
.
A value a :: x
may also be used as an
, with
no Δ specified, to represent simply a + 0√Δ; this can be
considered polymorphic over all possible values of Δ.AlgNumGen
x
This is similar to the use of IntM
s or FPReal
s of indeterminate
size, although unlike for them, we do not restrict this to the
classical case. However, the question of whether an AlgNumGen
has
specified √Δ is (like e.g. the length of a list) is a parameter
property, known at circuit generation time, not a purely quantum
property.
AlgNum a a CLIntP | |
AlgNum_indet a |
Instances
(Eq a, Num a) => Eq (AlgNumGen a) # | |
(Ord a, Fractional a) => Fractional (AlgNumGen a) # | |
(Ord a, Num a) => Num (AlgNumGen a) # | |
Defined in Quipper.Algorithms.CL.Types (+) :: AlgNumGen a -> AlgNumGen a -> AlgNumGen a # (-) :: AlgNumGen a -> AlgNumGen a -> AlgNumGen a # (*) :: AlgNumGen a -> AlgNumGen a -> AlgNumGen a # negate :: AlgNumGen a -> AlgNumGen a # abs :: AlgNumGen a -> AlgNumGen a # signum :: AlgNumGen a -> AlgNumGen a # fromInteger :: Integer -> AlgNumGen a # | |
(Ord a, Num a) => Ord (AlgNumGen a) # | |
Defined in Quipper.Algorithms.CL.Types | |
Real a => Real (AlgNumGen a) # | |
Defined in Quipper.Algorithms.CL.Types toRational :: AlgNumGen a -> Rational # | |
RealFrac a => RealFrac (AlgNumGen a) # | |
Show a => Show (AlgNumGen a) # | |
type AlgNum = AlgNumGen CLRational Source #
The specific instance of AlgNumGen
used for classical
(parameter) computation.
fst_AlgNum :: AlgNumGen a -> a Source #
Extract the first co-ordinate of an AlgNumGen
pretty_show_AlgNum :: Show a => AlgNumGen a -> String Source #
Print an algebraic number in human-readable (though not Haskell-readable) format, as e.g. a + b√Δ.
floating_of_AlgNum :: (Real a, Floating b) => AlgNumGen a -> b Source #
Realize an algebraic number as a real number (of any Floating
type).
number_promote :: Num a => AlgNumGen a -> AlgNumGen b -> ErrMsg -> AlgNumGen a Source #
Coerce one algebraic number into the field of a second, if possible. If not possible (i.e. if their Δ’s mismatch), throw an error.
conjugate :: Num a => AlgNumGen a -> AlgNumGen a Source #
The algebraic conjugate: sends a + b √Δ to a - b √Δ.
is_alg_int :: (Ord a, RealFrac a) => AlgNumGen a -> Bool Source #
Test whether an algebraic number is an algebraic integer.
(A number is an algebraic integer iff it can be written in the form m + n(Δ + √Δ)/2, where m, n are integers. See [Jozsa 2003], proof of Prop. 14.)
is_unit :: (Ord a, RealFrac a) => AlgNumGen a -> Bool Source #
Test whether an algebraic number is a unit of the ring of algebraic integers.
omega_of_bigD :: CLIntP -> AlgNum Source #
The number ω associated to the field K.
Ideals
Data specifying an ideal in an algebraic number field. An ideal is described by a tuple (Δ,m,l,a,b), representing the ideal
m/l (aZ + (b+√Δ)/2 Z),
where moreover we assume and ensure always that the ideal is in standard form ([Jozsa 2003], p.11, Prop. 16). Specifically,
- a,k,l > 0;
- 4a | b2 – Δ;
- b = τ(a,b);
- gcd(k,l) = 1
In particular, this gives us bounds on the size of a and b,
and hence tells us the sizes needed for these registers (see length_for_ab
below).
Instances
Eq Ideal # | |
Show Ideal # | |
Labelable IdealQ (String, String, String, String) # | |
Defined in Quipper.Algorithms.CL.Types | |
Eq x => Eq (IdealX x) # | |
Show x => Show (IdealX x) # | |
QCLeaf x => QCData (IdealX x) # | |
Defined in Quipper.Algorithms.CL.Types qcdata_mapM :: Monad m => IdealX x -> (q -> m q') -> (c -> m c') -> QCType q c (IdealX x) -> m (QCType q' c' (IdealX x)) Source # qcdata_zip :: IdealX x -> q -> c -> q' -> c' -> QCType q c (IdealX x) -> QCType q' c' (IdealX x) -> ErrMsg -> QCType (q, q') (c, c') (IdealX x) Source # qcdata_promote :: BType (IdealX x) -> IdealX x -> ErrMsg -> BType (IdealX x) Source # | |
QCLeaf x => Labelable (IdealX x) String # | |
Defined in Quipper.Algorithms.CL.Types | |
type QTypeB Ideal # | |
Defined in Quipper.Algorithms.CL.Types | |
type QCType x y (IdealX z) # | |
Defined in Quipper.Algorithms.CL.Types |
Data specifying a reduced ideal, by a tuple (Δ,a,b); this corresponds to the ideal specified by (Δ,1,a,a,b), i.e., Z + (b+√Δ)/2a Z.
Instances
Eq IdealRed # | |
Show IdealRed # | |
Show x => Show (IdealRedX x) # | |
QCLeaf x => QCData (IdealRedX x) # | |
Defined in Quipper.Algorithms.CL.Types qcdata_mapM :: Monad m => IdealRedX x -> (q -> m q') -> (c -> m c') -> QCType q c (IdealRedX x) -> m (QCType q' c' (IdealRedX x)) Source # qcdata_zip :: IdealRedX x -> q -> c -> q' -> c' -> QCType q c (IdealRedX x) -> QCType q' c' (IdealRedX x) -> ErrMsg -> QCType (q, q') (c, c') (IdealRedX x) Source # qcdata_promote :: BType (IdealRedX x) -> IdealRedX x -> ErrMsg -> BType (IdealRedX x) Source # | |
QCLeaf x => Labelable (IdealRedX x) String # | |
Defined in Quipper.Algorithms.CL.Types | |
QCLeaf x => Labelable (IdealRedX x) (String, String) # | |
Defined in Quipper.Algorithms.CL.Types | |
type QTypeB IdealRed # | |
Defined in Quipper.Algorithms.CL.Types | |
type QCType x y (IdealRedX z) # | |
Defined in Quipper.Algorithms.CL.Types |
type IdDist = (Ideal, FPReal) Source #
An ideal I, together with a distance δ for it — that is, some representative, mod R, for δ(I) as defined on G p.4. Most functions described as acting on ideals need in fact to be seen as a pair of an ideal and a distance for it.
Trivial access functions
Assertions, coercions
Elements of the types IdealX
, IdealRedX
, etc are assumed to
satisfy certain extra conditions. This section includes functions
for checking that these conditions are satisfied, and for safely
coercing between these types.
tau :: (Integral int, Integral int') => int' -> int -> int -> int Source #
: the function τ(b,a). Gives the representative for b mod 2a, in a range dependent on a and √Δ. tau
Δ b a
(This doesn't quite belong here, but is included as a prerequisite of the assertions).
is_standard :: Ideal -> Bool Source #
Return True
if the given ideal is in standard form. (Functions should always keep ideals in standard form).
is_reduced :: Ideal -> Bool Source #
Test whether an IdealX
is reduced. (An ideal <m,l,a,b> is reduced iff m = 1, l = a, b ≥ 0 and b + √Δ > 2a ([Jozsa 2003], Prop. 20)).
is_really_reduced :: IdealRed -> Bool Source #
Test whether an IdealRedX
is really reduced. (An ideal <1,a,a,b> is reduced iff b ≥ 0 and b + √Δ > 2a ([Jozsa 2003], Prop. 20)).
to_reduced :: Ideal -> IdealRed Source #
assert_reduced :: Ideal -> a -> a Source #
Throw an error if an IdealX
is not reduced; otherwise, the identity function.
assert_really_reduced :: IdealRed -> a -> a Source #
Throw an error if an IdealRedX
is not really reduced; otherwise, the identity function.
q_is_reduced :: IdealQ -> Circ (IdealQ, Qubit) Source #
Test whether a given IdealQ
is reduced. <m,l,a,b> is reduced iff m = 1, l = a, b ≥ 0 and b + √Δ > 2a ([Jozsa 2003], Prop. 20).
q_is_really_reduced :: IdealRedQ -> Circ (IdealRedQ, Qubit) Source #
Test whether a given IdealQ
is really reduced (as it should always be, if code is written correctly). An ideal <1,a,a,b> is reduced iff b ≥ 0 and b + √Δ > 2a ([Jozsa 2003], Prop. 20).
q_assert_really_reduced :: IdealRedQ -> Circ IdealRedQ Source #
Throw a (quantum-runtime) error if an IdealRedQ
is not really reduced; otherwise, do nothing.
Compare assert_reduced
, q_is_really_reduced
in Quipper.Algorithms.CL.RegulatorQuantum, and [Jozsa 2003] Prop. 20.
Bounds on coefficient sizes
Given Δ, how much space should be allocated for the coefficients of ideals? Most of these bounds are currently missing or uncertain, as documented below. Note these bounds are intended to be sufficient for the calculations occurring in this algorithm, not for representing arbitrary ideals.
length_for_ab :: CLIntP -> Int Source #
Given Δ, return the size of integers to be used for the coefficients a, b of reduced ideals.
Note: can we bound this more carefully? In reduced ideals, we always have 0 ≤ a,b ≤ √Δ (see notes on is_standard
, is_reduced
), and the outputs of ρ, ρ–1 and dot-products of reduced ideals always keep |a| ≤ Δ. However, intermediate calculations may involve larger values, so we allocate a little more space. For now, this padding is a seat-of-the-pants estimate.
length_for_ml :: CLIntP -> Int Source #
Given Δ, return the size of integers to be used for the coefficients m, l of general ideals.
TODO: bound this! Neither Hallgren nor [Jozsa 2003] discusses bounds on the values of m and l that will appear, and we do not yet have a bound. For now we use the same length as for a and b, for convenience; this should be considered a dummy bound, quite possibly not sufficient in general.
n_of_bigD :: Integral int => CLIntP -> int Source #
Given Δ, return the precision n = log2N to be used for discretizing the quasi-periodic function f to fN.
(“Precision” here means the number of binary digits after the point).
Taken to ensure 1/N < 3/(32 Δ log Δ). (Cf. [Jozsa 2003], Prop. 36 (iii).)
precision_for_fN :: CLIntP -> Int -> Int -> Int Source #
Given Δ, n, l (as for
fN
,
q_fN
), return the
precision required for intermediate distance calculations during
the computation of fN.
TODO: bound this more carefully. [Jozsa 2003] asks for the final output to be precision n, but does not discuss intermediate precision, and we have not yet got a confident answer. For now, just a back-of-the-envelope estimate, which should be sufficient and O(correct), but is almost certainly rather larger than necessary.
fix_sizes_Ideal :: Ideal -> Ideal Source #
Set the IntM
coefficients of an IdealX
to the standard lengths, if they are not already fixed incompatibly. The standard lengths are determined by length_for_ml
, length_for_ab
. (Compare intm_promote
, etc.)
fix_sizes_IdealRed :: IdealRed -> IdealRed Source #
Set the IntM
coefficients of an IdealRedX
to the standard lengths, if they are not already fixed incompatibly. The standard lengths are determined by length_for_ml
, length_for_ab
. (Compare intm_promote
, etc.)