Safe Haskell | None |
---|
Algorithms.QLS.QSignedInt
Description
A module implementing signed quantum integers. We piggy-back on
the type IntM
, considering it as a type of unsigned quantum
integers.
- data SignedInt x = SInt [x] x
- type FSignedInt = SignedInt Bool
- type QSignedInt = SignedInt Qubit
- type CSignedInt = SignedInt Bit
- fsint_of_integer :: Int -> Integer -> FSignedInt
- integer_of_fsint :: FSignedInt -> Integer
- sint_length :: SignedInt x -> Int
- left_pad_qulist :: [Qubit] -> [Qubit] -> Circ ([Qubit], [Qubit])
- fsint_shift :: Int -> FSignedInt -> FSignedInt
- s_qdint_of_qsint :: QSignedInt -> (Qubit, QDInt)
- qsint_of_s_qdint :: (Qubit, QDInt) -> QSignedInt
- qsint_shift :: Int -> QSignedInt -> Circ QSignedInt
- q_mod :: QSignedInt -> QSignedInt -> Circ QSignedInt
Signed integer type
Data type for signed integers. Note that this particular variant does not use two's complement to represent negative numbers, but an explicit sign bit. In particular, there are two different representations of 0 (however, the arithmetic operations always produce +0).
This is the generic type, where x represents a bit. An integer is
represented as Sint
digits sign, where digits is a
big-headian list of digits (i.e., the most significant bit occupies
the head of the list), and sign is the sign, with False
representing plus and True
representing minus.
When we speak of the "length" of a SignedInt
, we mean the
number of digits excluding the sign.
Constructors
SInt [x] x |
Instances
Enum FSignedInt | |
Eq QSignedInt | |
Eq FSignedInt | |
Integral FSignedInt | |
Num FSignedInt | |
Ord FSignedInt | |
Real FSignedInt | |
Typeable1 SignedInt | |
QOrd QSignedInt | |
QNum QSignedInt | |
Show x => Show (SignedInt x) | |
QCLeaf x => QCData (SignedInt x) | |
QCLeaf x => Labelable (SignedInt x) String |
type FSignedInt = SignedInt BoolSource
The parameter type of signed integers.
type QSignedInt = SignedInt QubitSource
The quantum type of signed integers.
type CSignedInt = SignedInt BitSource
The classical type of signed integers.
Conversions for FSignedInt
fsint_of_integer :: Int -> Integer -> FSignedIntSource
Take a length and an integer, and return a FSignedInt
of the
given length.
integer_of_fsint :: FSignedInt -> IntegerSource
Convert an FSignedInt
to an integer.
sint_length :: SignedInt x -> IntSource
Get the length of a SignedInt
.
Operations
left_pad_qulist :: [Qubit] -> [Qubit] -> Circ ([Qubit], [Qubit])Source
Make two qubit lists be of the same length, by prepending qubits
initialized to False
to the head of the shorter of the two lists.
fsint_shift :: Int -> FSignedInt -> FSignedIntSource
Shift an FSignedInt
by k digits to the left. In other words,
multiply it by 2k, while simultaneously increasing the
length by k.
s_qdint_of_qsint :: QSignedInt -> (Qubit, QDInt)Source
One half of an isomorphism between QSignedInt
and (Qubit
, QDInt
).
qsint_of_s_qdint :: (Qubit, QDInt) -> QSignedIntSource
The other half of an isomorphism between QSignedInt
and
(Qubit
, QDInt
).
qsint_shift :: Int -> QSignedInt -> Circ QSignedIntSource
Shift a QSignedInt
by k digits to the left. In other words,
multiply it by 2k, while simultaneously increasing the
length by k.
q_mod :: QSignedInt -> QSignedInt -> Circ QSignedIntSource
The modulo operation on QSignedInt
.