{-# LINE 1 "src/Data/Number/Flint/Fq/Poly/Factor/FFI.hsc" #-}
module Data.Number.Flint.Fq.Poly.Factor.FFI (
FqPolyFactor (..)
, CFqPolyFactor (..)
, newFqPolyFactor
, withFqPolyFactor
, withNewFqPolyFactor
, fq_poly_factor_init
, fq_poly_factor_clear
, fq_poly_factor_realloc
, fq_poly_factor_fit_length
, fq_poly_factor_set
, fq_poly_factor_print_pretty
, fq_poly_factor_print
, fq_poly_factor_insert
, fq_poly_factor_concat
, fq_poly_factor_pow
, fq_poly_remove
, fq_poly_is_irreducible
, fq_poly_is_irreducible_ddf
, fq_poly_is_irreducible_ben_or
, _fq_poly_is_squarefree
, fq_poly_is_squarefree
, fq_poly_factor_equal_deg_prob
, fq_poly_factor_equal_deg
, fq_poly_factor_split_single
, fq_poly_factor_distinct_deg
, fq_poly_factor_squarefree
, fq_poly_factor
, fq_poly_factor_cantor_zassenhaus
, fq_poly_factor_kaltofen_shoup
, fq_poly_factor_berlekamp
, fq_poly_factor_with_berlekamp
, fq_poly_factor_with_cantor_zassenhaus
, fq_poly_factor_with_kaltofen_shoup
, fq_poly_iterated_frobenius_preinv
, fq_poly_roots
) where
import Control.Monad
import Foreign.C.String
import Foreign.C.Types
import qualified Foreign.Concurrent
import Foreign.ForeignPtr
import Foreign.Ptr ( Ptr, FunPtr, plusPtr )
import Foreign.Storable
import Foreign.Marshal ( free )
import Foreign.Marshal.Array ( advancePtr )
import Data.Number.Flint.Flint
import Data.Number.Flint.Fmpz
import Data.Number.Flint.Fmpz.Mod.Poly
import Data.Number.Flint.Fmpz.Mod.Mat
import Data.Number.Flint.Fmpq
import Data.Number.Flint.Fq
import Data.Number.Flint.Fq.Poly
data FqPolyFactor = FqPolyFactor {-# UNPACK #-} !(ForeignPtr CFqPolyFactor)
data CFqPolyFactor = CFqPolyFactor (Ptr CFqPoly) (Ptr CLong) CLong CLong
instance Storable CFqPolyFactor where
{-# INLINE sizeOf #-}
sizeOf :: CFqPolyFactor -> Int
sizeOf CFqPolyFactor
_ = (Int
32)
{-# LINE 88 "src/Data/Number/Flint/Fq/Poly/Factor/FFI.hsc" #-}
{-# INLINE alignment #-}
alignment :: CFqPolyFactor -> Int
alignment CFqPolyFactor
_ = Int
8
{-# LINE 90 "src/Data/Number/Flint/Fq/Poly/Factor/FFI.hsc" #-}
peek ptr = do
poly <- (\hsc_ptr -> peekByteOff hsc_ptr 0) ptr
{-# LINE 92 "src/Data/Number/Flint/Fq/Poly/Factor/FFI.hsc" #-}
exp <- (\hsc_ptr -> peekByteOff hsc_ptr 8) ptr
{-# LINE 93 "src/Data/Number/Flint/Fq/Poly/Factor/FFI.hsc" #-}
num <- (\hsc_ptr -> peekByteOff hsc_ptr 16) ptr
{-# LINE 94 "src/Data/Number/Flint/Fq/Poly/Factor/FFI.hsc" #-}
alloc <- (\hsc_ptr -> peekByteOff hsc_ptr 24) ptr
{-# LINE 95 "src/Data/Number/Flint/Fq/Poly/Factor/FFI.hsc" #-}
return $ CFqPolyFactor poly exp num alloc
poke :: Ptr CFqPolyFactor -> CFqPolyFactor -> IO ()
poke = forall a. HasCallStack => a
undefined
newFqPolyFactor :: FqCtx -> IO FqPolyFactor
newFqPolyFactor ctx :: FqCtx
ctx@(FqCtx ForeignPtr CFqCtx
fctx) = do
ForeignPtr CFqPolyFactor
x <- forall a. Storable a => IO (ForeignPtr a)
mallocForeignPtr
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr CFqPolyFactor
x forall a b. (a -> b) -> a -> b
$ \Ptr CFqPolyFactor
x -> do
forall {a}. FqCtx -> (Ptr CFqCtx -> IO a) -> IO (FqCtx, a)
withFqCtx FqCtx
ctx forall a b. (a -> b) -> a -> b
$ \Ptr CFqCtx
ctx -> do
Ptr CFqPolyFactor -> Ptr CFqCtx -> IO ()
fq_poly_factor_init Ptr CFqPolyFactor
x Ptr CFqCtx
ctx
forall env a.
FinalizerEnvPtr env a -> Ptr env -> ForeignPtr a -> IO ()
addForeignPtrFinalizerEnv FunPtr (Ptr CFqPolyFactor -> Ptr CFqCtx -> IO ())
p_fq_poly_factor_clear Ptr CFqPolyFactor
x ForeignPtr CFqCtx
fctx
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ ForeignPtr CFqPolyFactor -> FqPolyFactor
FqPolyFactor ForeignPtr CFqPolyFactor
x
{-# INLINE withFqPolyFactor #-}
withFqPolyFactor :: FqPolyFactor -> (Ptr CFqPolyFactor -> IO a) -> IO (FqPolyFactor, a)
withFqPolyFactor (FqPolyFactor ForeignPtr CFqPolyFactor
x) Ptr CFqPolyFactor -> IO a
f = do
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr CFqPolyFactor
x forall a b. (a -> b) -> a -> b
$ \Ptr CFqPolyFactor
px -> Ptr CFqPolyFactor -> IO a
f Ptr CFqPolyFactor
px forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall (m :: * -> *) a. Monad m => a -> m a
return forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ForeignPtr CFqPolyFactor -> FqPolyFactor
FqPolyFactor ForeignPtr CFqPolyFactor
x,)
{-# INLINE withNewFqPolyFactor #-}
withNewFqPolyFactor :: FqCtx -> (Ptr CFqPolyFactor -> IO a) -> IO (FqPolyFactor, a)
withNewFqPolyFactor FqCtx
ctx Ptr CFqPolyFactor -> IO a
f = do
FqPolyFactor
x <- FqCtx -> IO FqPolyFactor
newFqPolyFactor FqCtx
ctx
forall {a}.
FqPolyFactor -> (Ptr CFqPolyFactor -> IO a) -> IO (FqPolyFactor, a)
withFqPolyFactor FqPolyFactor
x Ptr CFqPolyFactor -> IO a
f
foreign import ccall "fq_poly_factor.h fq_poly_factor_init"
fq_poly_factor_init :: Ptr CFqPolyFactor -> Ptr CFqCtx -> IO ()
foreign import ccall "fq_poly_factor.h fq_poly_factor_clear"
fq_poly_factor_clear :: Ptr CFqPolyFactor -> Ptr CFqCtx -> IO ()
foreign import ccall "fq_poly_factor.h &fq_poly_factor_clear"
p_fq_poly_factor_clear :: FunPtr (Ptr CFqPolyFactor -> Ptr CFqCtx -> IO ())
foreign import ccall "fq_poly_factor.h fq_poly_factor_realloc"
fq_poly_factor_realloc :: Ptr CFqPolyFactor -> CLong -> Ptr CFqCtx -> IO ()
foreign import ccall "fq_poly_factor.h fq_poly_factor_fit_length"
fq_poly_factor_fit_length :: Ptr CFqPolyFactor -> CLong -> Ptr CFqCtx -> IO ()
foreign import ccall "fq_poly_factor.h fq_poly_factor_set"
fq_poly_factor_set :: Ptr CFqPolyFactor -> Ptr CFqPolyFactor -> Ptr CFqCtx -> IO ()
fq_poly_factor_print_pretty :: Ptr CFqPolyFactor -> CString -> Ptr CFqCtx -> IO ()
fq_poly_factor_print_pretty Ptr CFqPolyFactor
fac CString
var Ptr CFqCtx
ctx = do
CFqPolyFactor Ptr CFqPoly
poly Ptr CLong
exp CLong
num CLong
alloc <- forall a. Storable a => Ptr a -> IO a
peek Ptr CFqPolyFactor
fac
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ [Int
0..forall a b. (Integral a, Num b) => a -> b
fromIntegral CLong
numforall a. Num a => a -> a -> a
-Int
1] forall a b. (a -> b) -> a -> b
$ \Int
j -> do
Ptr CFqPoly -> CString -> Ptr CFqCtx -> IO CInt
fq_poly_print_pretty (Ptr CFqPoly
poly forall a. Storable a => Ptr a -> Int -> Ptr a
`advancePtr` Int
j) CString
var Ptr CFqCtx
ctx
CLong
m <- forall a. Storable a => Ptr a -> IO a
peek (Ptr CLong
exp forall a. Storable a => Ptr a -> Int -> Ptr a
`advancePtr` Int
j)
String -> IO ()
putStrLn forall a b. (a -> b) -> a -> b
$ String
" ^ " forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> String
show CLong
m
fq_poly_factor_print :: Ptr CFqPolyFactor -> Ptr CFqCtx -> IO ()
fq_poly_factor_print Ptr CFqPolyFactor
fac Ptr CFqCtx
ctx = do
CFqPolyFactor Ptr CFqPoly
poly Ptr CLong
exp CLong
num CLong
alloc <- forall a. Storable a => Ptr a -> IO a
peek Ptr CFqPolyFactor
fac
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ [Int
0..forall a b. (Integral a, Num b) => a -> b
fromIntegral CLong
numforall a. Num a => a -> a -> a
-Int
1] forall a b. (a -> b) -> a -> b
$ \Int
j -> do
Ptr CFqPoly -> Ptr CFqCtx -> IO CInt
fq_poly_print (Ptr CFqPoly
poly forall a. Storable a => Ptr a -> Int -> Ptr a
`advancePtr` Int
j) Ptr CFqCtx
ctx
CLong
m <- forall a. Storable a => Ptr a -> IO a
peek (Ptr CLong
exp forall a. Storable a => Ptr a -> Int -> Ptr a
`advancePtr` Int
j)
String -> IO ()
putStrLn forall a b. (a -> b) -> a -> b
$ String
" ^ " forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> String
show CLong
m
foreign import ccall "fq_poly_factor.h fq_poly_factor_insert"
fq_poly_factor_insert :: Ptr CFqPolyFactor -> Ptr CFqPoly -> CLong -> Ptr CFqCtx -> IO ()
foreign import ccall "fq_poly_factor.h fq_poly_factor_concat"
fq_poly_factor_concat :: Ptr CFqPolyFactor -> Ptr CFqPolyFactor -> Ptr CFqCtx -> IO ()
foreign import ccall "fq_poly_factor.h fq_poly_factor_pow"
fq_poly_factor_pow :: Ptr CFqPolyFactor -> CLong -> Ptr CFqCtx -> IO ()
foreign import ccall "fq_poly_factor.h fq_poly_remove"
fq_poly_remove :: Ptr CFqPoly -> Ptr CFqPoly -> Ptr CFqCtx -> IO CULong
foreign import ccall "fq_poly_factor.h fq_poly_is_irreducible"
fq_poly_is_irreducible :: Ptr CFqPoly -> Ptr CFqCtx -> IO CInt
foreign import ccall "fq_poly_factor.h fq_poly_is_irreducible_ddf"
fq_poly_is_irreducible_ddf :: Ptr CFqPoly -> Ptr CFqCtx -> IO CInt
foreign import ccall "fq_poly_factor.h fq_poly_is_irreducible_ben_or"
fq_poly_is_irreducible_ben_or :: Ptr CFqPoly -> Ptr CFqCtx -> IO CInt
foreign import ccall "fq_poly_factor.h _fq_poly_is_squarefree"
_fq_poly_is_squarefree :: Ptr (Ptr CFq) -> CLong -> Ptr CFqCtx -> IO CInt
foreign import ccall "fq_poly_factor.h fq_poly_is_squarefree"
fq_poly_is_squarefree :: Ptr CFqPoly -> Ptr CFqCtx -> IO CInt
foreign import ccall "fq_poly_factor.h fq_poly_factor_equal_deg_prob"
fq_poly_factor_equal_deg_prob :: Ptr CFqPoly -> Ptr CFRandState -> Ptr CFqPoly -> CLong -> Ptr CFqCtx -> IO CInt
foreign import ccall "fq_poly_factor.h fq_poly_factor_equal_deg"
fq_poly_factor_equal_deg :: Ptr CFqPolyFactor -> Ptr CFqPoly -> CLong -> Ptr CFqCtx -> IO ()
foreign import ccall "fq_poly_factor.h fq_poly_factor_split_single"
fq_poly_factor_split_single :: Ptr CFqPoly -> Ptr CFqPoly -> Ptr CFqCtx -> IO ()
foreign import ccall "fq_poly_factor.h fq_poly_factor_distinct_deg"
fq_poly_factor_distinct_deg :: Ptr CFqPolyFactor -> Ptr CFqPoly -> Ptr (Ptr CLong) -> Ptr CFqCtx -> IO ()
foreign import ccall "fq_poly_factor.h fq_poly_factor_squarefree"
fq_poly_factor_squarefree :: Ptr CFqPolyFactor -> Ptr CFqPoly -> Ptr CFqCtx -> IO ()
foreign import ccall "fq_poly_factor.h fq_poly_factor"
fq_poly_factor :: Ptr CFqPolyFactor -> Ptr CFq -> Ptr CFqPoly -> Ptr CFqCtx -> IO ()
foreign import ccall "fq_poly_factor.h fq_poly_factor_cantor_zassenhaus"
fq_poly_factor_cantor_zassenhaus :: Ptr CFqPolyFactor -> Ptr CFqPoly -> Ptr CFqCtx -> IO ()
foreign import ccall "fq_poly_factor.h fq_poly_factor_kaltofen_shoup"
fq_poly_factor_kaltofen_shoup :: Ptr CFqPolyFactor -> Ptr CFqPoly -> Ptr CFqCtx -> IO ()
foreign import ccall "fq_poly_factor.h fq_poly_factor_berlekamp"
fq_poly_factor_berlekamp :: Ptr CFqPolyFactor -> Ptr CFqPoly -> Ptr CFqCtx -> IO ()
foreign import ccall "fq_poly_factor.h fq_poly_factor_with_berlekamp"
fq_poly_factor_with_berlekamp :: Ptr CFqPolyFactor -> Ptr CFq -> Ptr CFqPoly -> Ptr CFqCtx -> IO ()
foreign import ccall "fq_poly_factor.h fq_poly_factor_with_cantor_zassenhaus"
fq_poly_factor_with_cantor_zassenhaus :: Ptr CFqPolyFactor -> Ptr CFq -> Ptr CFqPoly -> Ptr CFqCtx -> IO ()
foreign import ccall "fq_poly_factor.h fq_poly_factor_with_kaltofen_shoup"
fq_poly_factor_with_kaltofen_shoup :: Ptr CFqPolyFactor -> Ptr CFq -> Ptr CFqPoly -> Ptr CFqCtx -> IO ()
foreign import ccall "fq_poly_factor.h fq_poly_iterated_frobenius_preinv"
fq_poly_iterated_frobenius_preinv :: Ptr (Ptr CFqPoly) -> CLong -> Ptr CFqPoly -> Ptr CFqPoly -> Ptr CFqCtx -> IO ()
foreign import ccall "fq_poly_factor.h fq_poly_roots"
fq_poly_roots :: Ptr CFqPolyFactor -> Ptr CFqPoly -> CInt -> Ptr CFqCtx -> IO ()