Copyright | (c) Eric Crockett 2011-2017 Chris Peikert 2011-2017 |
---|---|
License | GPL-2 |
Maintainer | ecrockett0@email.com |
Stability | experimental |
Portability | POSIX \( \def\Z{\mathbb{Z}} \) \( \def\C{\mathbb{C}} \) |
Safe Haskell | None |
Language | Haskell2010 |
Crypto.Lol.Prelude
Description
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 :: *
- module Crypto.Lol.Types.Unsafe.Complex
- 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 (ToInteger (ModRep a), Additive a) => Mod a where Source #
Represents a quotient group modulo some integer.
Minimal complete definition
class (Additive a, Additive b) => Subgroup a b where Source #
Represents that a
is a subgroup of b
.
Minimal complete definition
Methods
fromSubgroup :: a -> b Source #
class (Additive a, Additive b) => Reduce a b where Source #
Represents that b
is a quotient group of a
.
Minimal complete definition
Instances
(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.
Minimal complete definition
Instances
(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.
Minimal complete definition
Instances
(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.
Minimal complete definition
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.
Arguments
:: 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
Instances
Complex
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 # | |