Safe Haskell | None |
---|---|
Language | Haskell2010 |
\( \def\Z{\mathbb{Z}} \) \( \def\C{\mathbb{C}} \)
A substitute for the Prelude that is more suitable for Lol. This module exports most of the Numeric Prelude and other frequently used modules, plus some low-level classes, missing instances, and assorted utility functions.
- class Enumerable a where
- class (ToInteger (ModRep a), Additive a) => Mod a where
- type ModRep a
- class (Additive a, Additive b) => Subgroup a b where
- class (Additive a, Additive b) => Reduce a b where
- type family LiftOf b
- type Lift b a = (Lift' b, LiftOf b ~ a)
- class Reduce (LiftOf b) b => Lift' b where
- class (Additive a, Additive b) => Rescale a b where
- class (Field src, Field tgt) => Encode src tgt where
- msdToLSD :: Encode src tgt => (src, tgt)
- type family CharOf fp :: k
- max :: Ord a => a -> a -> a
- min :: Ord a => a -> a -> a
- abs :: Absolute a => a -> a
- realToField :: (Field b, ToRational a) => a -> b
- type ZeroTestable a = C a
- type Additive a = C a
- type Ring a = C a
- type Module a v = C a v
- type IntegralDomain a = C a
- type ToRational a = C a
- type Field a = C a
- type RealRing a = C a
- type RealField a = C a
- type Algebraic a = C a
- type Transcendental a = C a
- type RealTranscendental a = C a
- type OrdFloat a = (Ord a, Transcendental a)
- type ToInteger a = C a
- type Absolute a = C a
- type RealIntegral a = C a
- type PID a = C a
- type Polynomial a = T a
- type Matrix a = T a
- (^) :: forall a i. (Ring a, ToInteger i) => a -> i -> a
- modinv :: (PID i, Eq i) => i -> i -> Maybe i
- decomp :: (IntegralDomain z, Ord z) => [z] -> z -> [z]
- roundMult :: (RealField r, ToInteger i) => i -> r -> i
- roundScalarCentered :: (RealField r, Random r, ToInteger i, MonadRandom mon) => i -> r -> mon i
- divModCent :: IntegralDomain i => i -> i -> (i, i)
- module NumericPrelude
- data Int64 :: *
- data Complex a
- roundComplex :: (RealRing a, ToInteger b) => Complex a -> (b, b)
- cis :: Transcendental a => a -> Complex a
- real :: Complex a -> a
- imag :: Complex a -> a
- fromReal :: Additive a => a -> Complex a
- module Crypto.Lol.Factored
- rescaleMod :: forall a b. (Mod a, Mod b, ModRep a ~ ModRep b, Lift a (ModRep b), Ring b) => a -> b
- roundCoset :: forall zp z r. (Mod zp, z ~ ModRep zp, Lift zp z, RealField r) => zp -> r -> z
- fromJust' :: String -> Maybe a -> a
- pureT :: Applicative f => Tagged t a -> TaggedT t f a
- peelT :: Tagged t (f a) -> TaggedT t f a
- pasteT :: TaggedT t f a -> Tagged t (f a)
- withWitness :: forall n r. (SingI n => Tagged n r) -> Sing n -> r
- withWitnessT :: forall n mon r. (SingI n => TaggedT n mon r) -> Sing n -> mon r
- module Data.Functor.Trans.Tagged
- module Data.Proxy
Classes and families
class Enumerable a where Source #
Poor man's Enum
.
class (ToInteger (ModRep a), Additive a) => Mod a where Source #
Represents a quotient group modulo some integer.
class (Additive a, Additive b) => Subgroup a b where Source #
Represents that a
is a subgroup of b
.
fromSubgroup :: a -> b Source #
class (Additive a, Additive b) => Reduce a b where Source #
Represents that b
is a quotient group of a
.
(Reduce a b1, Reduce a b2) => Reduce a (b1, b2) Source # | Reduce into product ring. |
(Reflects k q z, ToInteger z, Additive (ZqBasic k q z)) => Reduce Integer (ZqBasic k q z) Source # | |
(Reflects k q z, ToInteger z) => Reduce z (ZqBasic k q z) Source # | |
(Reflects k q r, RealField r, Additive (RRq k q r)) => Reduce r (RRq k q r) Source # | |
(Reduce a b, Fact m, CElt t a, CElt t b) => Reduce (Cyc t m a) (Cyc t m b) Source # | |
(Reduce a b, Tensor t, Fact m, TElt t a, TElt t b) => Reduce (UCyc t m D a) (UCyc t m D b) Source # | |
(Reduce a b, Tensor t, Fact m, TElt t a, TElt t b) => Reduce (UCyc t m P a) (UCyc t m P b) Source # | |
(Reduce z zq, Fact s, CElt t z, CElt t zq) => Reduce (Linear t z e r s) (Linear t zq e r s) Source # | |
The type of representatives of b
.
type Lift b a = (Lift' b, LiftOf b ~ a) Source #
Represents that b
can be lifted to a "short" a
congruent to b
.
class Reduce (LiftOf b) b => Lift' b where Source #
Fun-dep version of Lift.
(Mod a, Mod b, Lift' a, Lift' b, Reduce Integer (a, b), ToInteger (LiftOf a), ToInteger (LiftOf b)) => Lift' (a, b) Source # | Lift product ring of \(\Z_q\)s to |
(Reflects k q z, ToInteger z) => Lift' (ZqBasic k q z) Source # | |
(Reflects k q r, Reduce r (RRq k q r), Ord r, Ring r) => Lift' (RRq k q r) Source # | |
(Lift' r, Tensor t, Fact m, TElt t r, TElt t (LiftOf r)) => Lift' (UCyc t m D r) Source # | |
(Lift' r, Tensor t, Fact m, TElt t r, TElt t (LiftOf r)) => Lift' (UCyc t m P r) Source # | |
(CElt t zp, CElt t z, (~) * z (LiftOf zp), Lift zp z, Fact s) => Lift' (Linear t zp e r s) Source # | lifts with respect to powerful basis, for best geometry |
class (Additive a, Additive b) => Rescale a b where Source #
Represents that a
can be rescaled to b
, as an "approximate"
additive homomorphism.
(Ring b, Mod a, Reduce (ModRep a) b) => Rescale b (a, b) Source # | Rescale up to a product ring of \(\Z_q\)s |
(Ring a, Mod b, Reduce (ModRep b) a) => Rescale a (a, b) Source # | Rescale up to a product ring of \(\Z_q\)s |
(Rescale ((a, b), c) (a, b), Rescale (a, b) a, Additive a, Additive c) => Rescale ((a, b), c) a Source # | Rescale a (multi-)product ring of \(\Z_q\)s |
(Rescale (a, (b, c)) (b, c), Rescale (b, c) c, Additive a, Additive c) => Rescale (a, (b, c)) c Source # | Rescale a (multi-)product ring of \(\Z_q\)s |
(Mod b, Field a, Lift b (ModRep b), Reduce (LiftOf b) a) => Rescale (a, b) a Source # | Rescale a product ring of \(\Z_q\)s |
(Mod a, Field b, Lift a (ModRep a), Reduce (LiftOf a) b) => Rescale (a, b) b Source # | Rescale a product ring of \(\Z_q\)s |
(Reflects k1 q z, ToInteger z, Reflects k q' z, Ring z) => Rescale (ZqBasic k1 q z) (ZqBasic k q' z) Source # | |
(Rescale a b, Tensor t, Fact m, TElt t a, TElt t b) => Rescale (UCyc t m D a) (UCyc t m D b) Source # | |
(Rescale a b, Tensor t, Fact m, TElt t a, TElt t b) => Rescale (UCyc t m P a) (UCyc t m P b) Source # | |
class (Field src, Field tgt) => Encode src tgt where Source #
Represents that the target ring can "noisily encode" values from the source ring, in either "most significant digit" (MSD) or "least significant digit" (LSD) encodings, and provides conversion factors between the two types of encodings.
Numeric
realToField :: (Field b, ToRational a) => a -> b Source #
The hidden NP function from Algebra.ToRational.
type ZeroTestable a = C a Source #
Sane synonym for C
.
type IntegralDomain a = C a Source #
Sane synonym for C
.
type ToRational a = C a Source #
Sane synonym for C
.
type Transcendental a = C a Source #
Sane synonym for C
.
type RealTranscendental a = C a Source #
Sane synonym for C
.
type OrdFloat a = (Ord a, Transcendental a) Source #
Convenient synonym for (
Ord
a, Transcendental
a)
type RealIntegral a = C a Source #
Sane synonym for C
.
type Polynomial a = T a Source #
Sane synonym for T
.
(^) :: forall a i. (Ring a, ToInteger i) => a -> i -> a Source #
Our custom exponentiation, overriding NP's version that
requires Integer
exponent.
Copied from http://hackage.haskell.org/package/base-4.7.0.0/docs/src/GHC-Real.html#%5E
modinv :: (PID i, Eq i) => i -> i -> Maybe i Source #
Inverse of \(a\) modulo \(q\), in range \([0,q-1]\). (Argument order is infix-friendly.)
decomp :: (IntegralDomain z, Ord z) => [z] -> z -> [z] Source #
Decompose an element into a list of "centered" digits with respect to relative radices.
roundMult :: (RealField r, ToInteger i) => i -> r -> i Source #
Deterministically round to the nearest multiple of \( i \).
roundScalarCentered :: (RealField r, Random r, ToInteger i, MonadRandom mon) => i -> r -> mon i Source #
Randomly round to the nearest larger or smaller multiple of \( i \), where the round-off term has expectation zero.
:: IntegralDomain i | |
=> i | dividend \(a\) |
-> i | divisor \(b\) |
-> (i, i) | (quotient, remainder) |
Variant of divMod
in which the remainder
is in the range \([-b/2,b/2)\).
module NumericPrelude
64-bit signed integer type
Bounded Int64 | |
Enum Int64 | |
Eq Int64 | |
Integral Int64 | |
Data Int64 | |
Num Int64 | |
Ord Int64 | |
Read Int64 | |
Real Int64 | |
Show Int64 | |
Ix Int64 | |
Lift Int64 | |
Random Int64 | |
Arbitrary Int64 | |
CoArbitrary Int64 | |
Storable Int64 | |
Bits Int64 | |
FiniteBits Int64 | |
Default Int64 | |
NFData Int64 | |
CRandom Int64 | |
CRandomR Int64 | |
C Int64 | |
C Int64 | |
C Int64 | |
C Int64 | |
C Int64 | |
C Int64 | |
C Int64 | |
C Int64 | |
C Int64 | |
C Int64 | |
Prim Int64 | |
GPB Int64 | |
Wire Int64 | |
TextType Int64 | |
Mergeable Int64 | |
Default Int64 | |
Elt Int64 | |
Unbox Int64 | |
CRTEmbed Int64 Source # | Embeds into the complex numbers \(\C\). |
Vector Vector Int64 | |
MVector MVector Int64 | |
CRTrans Maybe Int64 Source # | Returns |
MessageAPI msg (msg -> Int64) Int64 | |
(Fact m, Reflects k q Int64) => Protoable (CT m (ZqBasic k q Int64)) Source # | |
(Fact m, Reflects k q Int64) => Protoable (RT m (ZqBasic k q Int64)) Source # | |
data Vector Int64 | |
type CRTExt Int64 Source # | |
data MVector s Int64 | |
type ProtoType (CT m (ZqBasic k q Int64)) Source # | |
type ProtoType (RT m (ZqBasic k q Int64)) Source # | |
Complex
Newtype wrapper (with slightly different instances) for
Number.Complex
.
Unbox a0 => Vector Vector (Complex a0) Source # | |
Unbox a0 => MVector MVector (Complex a0) Source # | |
(Monad mon, Transcendental a) => CRTrans mon (Complex a) Source # | Complex numbers have |
Eq a => Eq (Complex a) Source # | |
Show a => Show (Complex a) Source # | |
Random a => Random (Complex a) Source # | |
Arbitrary a => Arbitrary (Complex a) Source # | |
Storable a => Storable (Complex a) Source # | |
NFData a => NFData (Complex a) Source # | |
C a => C (Complex a) Source # | |
Field a => C (Complex a) Source # | Custom instance replacing the one provided by numeric prelude: it
always returns 0 as the remainder of a division. (The NP instance
sometimes has precision issues, because it yields nonzero
remainders, which is a problem for |
C a => C (Complex a) Source # | |
C a => C (Complex a) Source # | |
C a => C (Complex a) Source # | |
Elt a => Elt (Complex a) Source # | |
Unbox a0 => Unbox (Complex a0) Source # | |
Transcendental a => CRTEmbed (Complex a) Source # | Self-embed |
data MVector s (Complex a0) Source # | |
data Vector (Complex a0) Source # | |
type CRTExt (Complex a) Source # | |
roundComplex :: (RealRing a, ToInteger b) => Complex a -> (b, b) Source #
Rounds the real and imaginary components to the nearest integer.
cis :: Transcendental a => a -> Complex a Source #
cis
\(t\) is a complex value with magnitude 1 and phase \(t \bmod 2\cdot\pi\)).
fromReal :: Additive a => a -> Complex a Source #
Embeds a scalar as the real component of a complex number.
Factored
module Crypto.Lol.Factored
Miscellaneous
rescaleMod :: forall a b. (Mod a, Mod b, ModRep a ~ ModRep b, Lift a (ModRep b), Ring b) => a -> b Source #
A default implementation of rescaling for Mod
types.
roundCoset :: forall zp z r. (Mod zp, z ~ ModRep zp, Lift zp z, RealField r) => zp -> r -> z Source #
Deterministically round to a nearby value in the desired coset.
pureT :: Applicative f => Tagged t a -> TaggedT t f a Source #
Apply any applicative to a Tagged
value.
withWitness :: forall n r. (SingI n => Tagged n r) -> Sing n -> r Source #
Use a singleton as a witness to extract a value from a Tagged
value.
withWitnessT :: forall n mon r. (SingI n => TaggedT n mon r) -> Sing n -> mon r Source #
Transformer version of withWitness
.
module Data.Functor.Trans.Tagged
module Data.Proxy
Orphan instances
Default Bool Source # | |
(Default a0, Unbox a0) => Vector Vector (Maybe a0) Source # | |
(Default a0, Unbox a0) => MVector MVector (Maybe a0) Source # | |
(Default a0, Unbox a0) => Unbox (Maybe a0) Source # | |
(Random a, Random b) => Random (a, b) Source # | |
(Field f1, Field f2) => C (f1, f2) Source # | Product ring as an (almost) field |
(IntegralDomain a, IntegralDomain b) => C (a, b) Source # | Product ring as an (almost) integral domain |
(Ring r1, Ring r2) => C (r1, r2) Source # | Pair as product ring |
MonadRandom m => MonadRandom (TaggedT * k tag m) Source # | |
NFData (m a) => NFData (TaggedT k k1 s m a) Source # | |