Safe Haskell | None |
---|---|
Language | Haskell2010 |
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
- values :: [a]
- class (ToInteger (ModRep a), Additive a) => Mod a where
- class (Additive a, Additive b) => Reduce a b where
- reduce :: a -> b
- 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
- rescale :: a -> b
- class (Field src, Field tgt) => Encode src tgt where
- lsdToMSD :: (src, tgt)
- 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
- (^) :: 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, Ord 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 => TaggedT t Identity 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
.
GFCtx k fp d => Enumerable (GF k fp d) Source | |
(ReflectsTI k q z, Enum z) => Enumerable (ZqBasic k q z) Source |
class (ToInteger (ModRep a), Additive a) => Mod a where Source
Represents a quotient group modulo some integer.
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 | |
(Reflects k q z, Ring (ZqBasic k q z)) => Reduce Integer (ZqBasic k q z) Source | |
ReflectsTI k q z => Reduce z (ZqBasic k q z) 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 Factored t m D a) (UCyc Factored t m D b) Source | |
(Reduce a b, Tensor t, Fact m, TElt t a, TElt t b) => Reduce (UCyc Factored t m P a) (UCyc Factored 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 LiftOf (a, b) = Integer Source | |
type LiftOf (ZqBasic k q z) = z Source | |
type LiftOf (Cyc t m r) = Cyc t m (LiftOf r) Source | |
type LiftOf (UCyc k t m D r) = UCyc k t m D (LiftOf r) Source | |
type LiftOf (UCyc k t m P r) = UCyc k t m P (LiftOf r) Source | |
type LiftOf (Linear t zp e r s) = Linear t (LiftOf zp) e r s Source |
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 | |
ReflectsTI k q z => Lift' (ZqBasic k q z) Source | |
(Lift' r, Tensor t, Fact m, TElt t r, TElt t (LiftOf r)) => Lift' (UCyc Factored t m D r) Source | |
(Lift' r, Tensor t, Fact m, TElt t r, TElt t (LiftOf r)) => Lift' (UCyc Factored 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 |
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 | |
(Ring a, Mod b, Reduce (ModRep b) a) => Rescale a (a, b) Source | |
(Rescale ((a, b), c) (a, b), Rescale (a, b) a) => Rescale ((a, b), c) a Source | |
(Rescale (a, (b, c)) (b, c), Rescale (b, c) c) => Rescale (a, (b, c)) c Source | |
(Mod b, Field a, Lift b (ModRep b), Reduce (LiftOf b) a) => Rescale (a, b) a Source | |
(Mod a, Field b, Lift a (ModRep a), Reduce (LiftOf a) b) => Rescale (a, b) b Source | |
(ReflectsTI k q z, ReflectsTI k1 q' z, Ring z) => Rescale (ZqBasic k q z) (ZqBasic k q' z) Source | |
(Rescale a b, Tensor t, Fact m, TElt t a, TElt t b) => Rescale (UCyc Factored t m D a) (UCyc Factored t m D b) Source | |
(Rescale a b, Tensor t, Fact m, TElt t a, TElt t b) => Rescale (UCyc Factored t m P a) (UCyc Factored 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.
The factor that converts an element from LSD to MSD encoding in the target field, with associated scale factor to apply to correct the resulting encoded value.
Numeric
realToField :: (Field b, ToRational a) => a -> b Source
The hidden NP function from 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, Ord i) | |
=> i | dividend |
-> i | divisor |
-> (i, i) | (quotient, remainder) |
Variant of divMod
in which the remainder
is in the range [-b/2,b/2)
.
module NumericPrelude
data Int64 :: *
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 | |
Random Int64 | |
Arbitrary Int64 | |
CoArbitrary Int64 | |
Storable Int64 | |
Bits Int64 | |
FiniteBits Int64 | |
NFData Int64 | |
Hashable Int64 | |
C Int64 | |
C Int64 | |
C Int64 | |
C Int64 | |
C Int64 | |
C Int64 | |
C Int64 | |
C Int64 | |
C Int64 | |
C Int64 | |
Prim Int64 | |
Elt Int64 | |
Unbox Int64 | |
Lift Int64 | |
CRTEmbed Int64 Source | |
CRTrans Int64 Source | |
Vector Vector Int64 | |
MVector MVector Int64 | |
data Vector Int64 = V_Int64 (Vector Int64) | |
type CRTExt Int64 = Complex Double Source | |
data MVector s Int64 = MV_Int64 (MVector s Int64) |
Complex
Newtype wrapper (with slightly different instances) for numeric-prelude Complex.
Unbox a0 => Vector Vector (Complex a) Source | |
Unbox a0 => MVector MVector (Complex a) Source | |
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 | |
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 a) Source | |
Transcendental a => CRTEmbed (Complex a) Source | |
Transcendental a => CRTrans (Complex a) Source | |
data MVector s0 (Complex a0) = MV_Complex (MVector s (a, a)) Source | |
data Vector (Complex a0) = V_Complex (Vector (a, a)) Source | |
type CRTExt (Complex a) = 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 (modulo 2*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 => TaggedT t Identity 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