Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Small prime fields, up to p < 2^31
(using Word64
under the hood).
This should be faster than the generic implementation which
uses Integer
under the hood.
NB: Because the multiplication of two 32 bit integers needs 64 bits,
the limit is 2^32
and not 2^64
. And because I'm lazy right now
to check if everything works properly unsigned, the actual limit
is 2^31
instead :)
Synopsis
- newtype WitnessFp (p :: Nat) = WitnessFp {}
- data SomeWitnessFp = forall p. SomeWitnessFp (WitnessFp p)
- mkSmallPrimeField :: Int -> Maybe SomeWitnessFp
- unsafeSmallPrimeField :: Int -> SomeWitnessFp
- data Fp (p :: Nat)
- primRoot :: IsSmallPrime p -> Fp p
Witness for the existence of the field
data SomeWitnessFp Source #
forall p. SomeWitnessFp (WitnessFp p) |
Instances
Show SomeWitnessFp Source # | |
Defined in Math.FiniteField.PrimeField.Small showsPrec :: Int -> SomeWitnessFp -> ShowS # show :: SomeWitnessFp -> String # showList :: [SomeWitnessFp] -> ShowS # |
mkSmallPrimeField :: Int -> Maybe SomeWitnessFp Source #
Note: currently this checks the primality of the input using trial division, so it's only practical for (very) small primes...
But you can use unsafeSmallPrimeField
to cheat.
unsafeSmallPrimeField :: Int -> SomeWitnessFp Source #
You are responsible for guaranteeing that the input is a prime.
Field elements
An element of the prime field F_p
Instances
primRoot :: IsSmallPrime p -> Fp p Source #