Safe Haskell | None |
---|
Algorithms.CL.Types
Contents
Description
This module defines the specialized datatypes of the Class Number algorithm, and basic utility functions on these types.
- 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.
Integers that will be used for parameter computation only, potentially large.
type CLRational = RationalSource
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 -> aSource
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 -> aSource
Compute d, given Δ. (Again, see [Jozsa 2003], Prop. 6 et seq.)
is_valid_d :: Integral a => a -> BoolSource
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 -> BoolSource
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√Δ.
AlgNum
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 AlgNumQ
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.
Constructors
AlgNum a a CLIntP | |
AlgNum_indet a |
type AlgNum = AlgNumGen CLRationalSource
The specific instance of AlgNumGen
used for classical (parameter) computation.
fst_AlgNum :: AlgNumGen a -> aSource
Extract the first co-ordinate of an AlgNumGen
snd_AlgNum :: Num a => AlgNumGen a -> aSource
Extract the second co-ordinate of an AlgNumGen
pretty_show_AlgNum :: Show a => AlgNumGen a -> StringSource
Print a Number
in human-readable (though not Haskell-readable) format, as e.g.
floating_of_AlgNum :: (Real a, Floating b) => AlgNumGen a -> bSource
Realize an algebraic number as a real number (of any Floating
type).
number_promote :: Num a => AlgNumGen a -> AlgNumGen b -> ErrMsg -> AlgNumGen aSource
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 aSource
The algebraic conjugate: sends a + b √Δ to a - b √Δ.
is_alg_int :: (Ord a, RealFrac a) => AlgNumGen a -> BoolSource
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 -> BoolSource
Test whether an algebraic number is a unit of the ring of algebraic integers.
omega_of_bigD :: CLIntP -> AlgNumSource
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).
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.
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.
type IdRedDistQ = (IdealRedQ, FPRealQ)Source
Quantum analogue of IdRedDist
.
Trivial access functions
d_of_Ideal :: IdealX a -> CLIntPSource
Extract the d component from an IdealQ
.
d_of_IdealRed :: IdealRedX a -> CLIntPSource
Extract the d component from an IdealRedQ
.
bigD_of_Ideal :: IdealX a -> CLIntPSource
Extract Δ from an IdealQ
.
bigD_of_IdealRed :: IdealRedX a -> CLIntPSource
Extract Δ from an IdealRedQ
.
Assertions, coercions
Elements of the types Ideal
, IdealRed
, 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 -> intSource
: 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 -> BoolSource
Return True
if the given ideal is in standard form. (Functions should always keep ideals in standard form).
is_reduced :: Ideal -> BoolSource
Test whether an Ideal
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 -> BoolSource
Test whether an IdealRed
is really reduced. (An ideal <1,a,a,b> is reduced iff b ≥ 0 and b + √Δ > 2a ([Jozsa 2003], Prop. 20)).
to_reduced :: Ideal -> IdealRedSource
assert_reduced :: Ideal -> a -> aSource
Throw an error if an Ideal
is not reduced; otherwise, the identity function.
assert_really_reduced :: IdealRed -> a -> aSource
Throw an error if an IdealRed
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 IdealRedQSource
Throw a (quantum-runtime) error if an IdealRedQ
is not really reduced; otherwise, do nothing.
Compare assert_reduced
, q_is_really_reduced
in 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 -> IntSource
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 -> IntSource
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 -> intSource
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 -> IntSource
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 -> IdealSource
Set the IntM
coefficients of an Ideal
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 -> IdealRedSource
Set the IntM
coefficients of an IdealRed
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.)