{-# LINE 1 "src/Data/Number/Flint/Fq/Zech/Poly/Factor/FFI.hsc" #-}
module Data.Number.Flint.Fq.Zech.Poly.Factor.FFI (
FqZechPolyFactor (..)
, CFqZechPolyFactor (..)
, newFqZechPolyFactor
, withFqZechPolyFactor
, fq_zech_poly_factor_init
, fq_zech_poly_factor_clear
, fq_zech_poly_factor_realloc
, fq_zech_poly_factor_fit_length
, fq_zech_poly_factor_set
, fq_zech_poly_factor_print_pretty
, fq_zech_poly_factor_print
, fq_zech_poly_factor_insert
, fq_zech_poly_factor_concat
, fq_zech_poly_factor_pow
, fq_zech_poly_remove
, fq_zech_poly_is_irreducible
, fq_zech_poly_is_irreducible_ddf
, fq_zech_poly_is_irreducible_ben_or
, _fq_zech_poly_is_squarefree
, fq_zech_poly_is_squarefree
, fq_zech_poly_factor_equal_deg_prob
, fq_zech_poly_factor_equal_deg
, fq_zech_poly_factor_split_single
, fq_zech_poly_factor_distinct_deg
, fq_zech_poly_factor_squarefree
, fq_zech_poly_factor
, fq_zech_poly_factor_cantor_zassenhaus
, fq_zech_poly_factor_kaltofen_shoup
, fq_zech_poly_factor_berlekamp
, fq_zech_poly_factor_with_berlekamp
, fq_zech_poly_factor_with_cantor_zassenhaus
, fq_zech_poly_factor_with_kaltofen_shoup
, fq_zech_poly_iterated_frobenius_preinv
, fq_zech_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.Marshal.Array ( advancePtr )
import Foreign.Storable
import Foreign.Marshal ( free )
import Data.Number.Flint.Flint
import Data.Number.Flint.Fmpz
import Data.Number.Flint.Fmpz.Mod.Poly
import Data.Number.Flint.NMod.Poly
import Data.Number.Flint.NMod.Mat
import Data.Number.Flint.Fq
import Data.Number.Flint.Fq.Types
import Data.Number.Flint.Fq.NMod
import Data.Number.Flint.Fq.NMod.Mat
import Data.Number.Flint.Fq.Zech
import Data.Number.Flint.Fq.Zech.Poly
import Data.Number.Flint.Fq.Zech.Types
instance Storable CFqZechPolyFactor where
{-# INLINE sizeOf #-}
sizeOf :: CFqZechPolyFactor -> Int
sizeOf CFqZechPolyFactor
_ = (Int
32)
{-# LINE 91 "src/Data/Number/Flint/Fq/Zech/Poly/Factor/FFI.hsc" #-}
{-# INLINE alignment #-}
alignment :: CFqZechPolyFactor -> Int
alignment CFqZechPolyFactor
_ = Int
8
{-# LINE 93 "src/Data/Number/Flint/Fq/Zech/Poly/Factor/FFI.hsc" #-}
peek ptr = CFqZechPolyFactor
<$> (\hsc_ptr -> peekByteOff hsc_ptr 0) ptr
{-# LINE 95 "src/Data/Number/Flint/Fq/Zech/Poly/Factor/FFI.hsc" #-}
<*> (\hsc_ptr -> peekByteOff hsc_ptr 8) ptr
{-# LINE 96 "src/Data/Number/Flint/Fq/Zech/Poly/Factor/FFI.hsc" #-}
<*> (\hsc_ptr -> peekByteOff hsc_ptr 16) ptr
{-# LINE 97 "src/Data/Number/Flint/Fq/Zech/Poly/Factor/FFI.hsc" #-}
<*> (\hsc_ptr -> peekByteOff hsc_ptr 24) ptr
{-# LINE 98 "src/Data/Number/Flint/Fq/Zech/Poly/Factor/FFI.hsc" #-}
poke = undefined
newFqZechPolyFactor :: FqZechCtx -> IO FqZechPolyFactor
newFqZechPolyFactor ctx :: FqZechCtx
ctx@(FqZechCtx ForeignPtr CFqZechCtx
ftx) = do
ForeignPtr CFqZechPolyFactor
x <- IO (ForeignPtr CFqZechPolyFactor)
forall a. Storable a => IO (ForeignPtr a)
mallocForeignPtr
ForeignPtr CFqZechPolyFactor
-> (Ptr CFqZechPolyFactor -> IO ()) -> IO ()
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr CFqZechPolyFactor
x ((Ptr CFqZechPolyFactor -> IO ()) -> IO ())
-> (Ptr CFqZechPolyFactor -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Ptr CFqZechPolyFactor
x -> do
FqZechCtx -> (Ptr CFqZechCtx -> IO ()) -> IO (FqZechCtx, ())
forall {a}.
FqZechCtx -> (Ptr CFqZechCtx -> IO a) -> IO (FqZechCtx, a)
withFqZechCtx FqZechCtx
ctx ((Ptr CFqZechCtx -> IO ()) -> IO (FqZechCtx, ()))
-> (Ptr CFqZechCtx -> IO ()) -> IO (FqZechCtx, ())
forall a b. (a -> b) -> a -> b
$ \Ptr CFqZechCtx
ctx -> do
Ptr CFqZechPolyFactor -> Ptr CFqZechCtx -> IO ()
fq_zech_poly_factor_init Ptr CFqZechPolyFactor
x Ptr CFqZechCtx
ctx
FinalizerEnvPtr CFqZechPolyFactor CFqZechCtx
-> Ptr CFqZechPolyFactor -> ForeignPtr CFqZechCtx -> IO ()
forall env a.
FinalizerEnvPtr env a -> Ptr env -> ForeignPtr a -> IO ()
addForeignPtrFinalizerEnv FinalizerEnvPtr CFqZechPolyFactor CFqZechCtx
p_fq_zech_poly_factor_clear Ptr CFqZechPolyFactor
x ForeignPtr CFqZechCtx
ftx
FqZechPolyFactor -> IO FqZechPolyFactor
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (FqZechPolyFactor -> IO FqZechPolyFactor)
-> FqZechPolyFactor -> IO FqZechPolyFactor
forall a b. (a -> b) -> a -> b
$ ForeignPtr CFqZechPolyFactor -> FqZechPolyFactor
FqZechPolyFactor ForeignPtr CFqZechPolyFactor
x
{-# INLINE withFqZechPolyFactor #-}
withFqZechPolyFactor :: FqZechPolyFactor
-> (Ptr CFqZechPolyFactor -> IO a) -> IO (FqZechPolyFactor, a)
withFqZechPolyFactor (FqZechPolyFactor ForeignPtr CFqZechPolyFactor
x) Ptr CFqZechPolyFactor -> IO a
f = do
ForeignPtr CFqZechPolyFactor
-> (Ptr CFqZechPolyFactor -> IO (FqZechPolyFactor, a))
-> IO (FqZechPolyFactor, a)
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr CFqZechPolyFactor
x ((Ptr CFqZechPolyFactor -> IO (FqZechPolyFactor, a))
-> IO (FqZechPolyFactor, a))
-> (Ptr CFqZechPolyFactor -> IO (FqZechPolyFactor, a))
-> IO (FqZechPolyFactor, a)
forall a b. (a -> b) -> a -> b
$ \Ptr CFqZechPolyFactor
px -> Ptr CFqZechPolyFactor -> IO a
f Ptr CFqZechPolyFactor
px IO a -> (a -> IO (FqZechPolyFactor, a)) -> IO (FqZechPolyFactor, a)
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (FqZechPolyFactor, a) -> IO (FqZechPolyFactor, a)
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return ((FqZechPolyFactor, a) -> IO (FqZechPolyFactor, a))
-> (a -> (FqZechPolyFactor, a)) -> a -> IO (FqZechPolyFactor, a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ForeignPtr CFqZechPolyFactor -> FqZechPolyFactor
FqZechPolyFactor ForeignPtr CFqZechPolyFactor
x,)
foreign import ccall "fq_zech_poly_factor.h fq_zech_poly_factor_init"
fq_zech_poly_factor_init :: Ptr CFqZechPolyFactor -> Ptr CFqZechCtx -> IO ()
foreign import ccall "fq_zech_poly_factor.h fq_zech_poly_factor_clear"
fq_zech_poly_factor_clear :: Ptr CFqZechPolyFactor -> Ptr CFqZechCtx -> IO ()
foreign import ccall "fq_zech_poly_factor.h &fq_zech_poly_factor_clear"
p_fq_zech_poly_factor_clear :: FunPtr (Ptr CFqZechPolyFactor -> Ptr CFqZechCtx -> IO ())
foreign import ccall "fq_zech_poly_factor.h fq_zech_poly_factor_realloc"
fq_zech_poly_factor_realloc :: Ptr CFqZechPolyFactor -> CLong -> Ptr CFqZechCtx -> IO ()
foreign import ccall "fq_zech_poly_factor.h fq_zech_poly_factor_fit_length"
fq_zech_poly_factor_fit_length :: Ptr CFqZechPolyFactor -> CLong -> Ptr CFqZechCtx -> IO ()
foreign import ccall "fq_zech_poly_factor.h fq_zech_poly_factor_set"
fq_zech_poly_factor_set :: Ptr CFqZechPolyFactor -> Ptr CFqZechPolyFactor -> Ptr CFqZechCtx -> IO ()
fq_zech_poly_factor_print_pretty :: Ptr CFqZechPolyFactor -> CString -> Ptr CFqZechCtx -> IO ()
fq_zech_poly_factor_print_pretty :: Ptr CFqZechPolyFactor -> CString -> Ptr CFqZechCtx -> IO ()
fq_zech_poly_factor_print_pretty Ptr CFqZechPolyFactor
fac CString
var Ptr CFqZechCtx
ctx = do
CFqZechPolyFactor Ptr CFqZechPoly
poly Ptr CLong
exp CLong
num CLong
alloc <- Ptr CFqZechPolyFactor -> IO CFqZechPolyFactor
forall a. Storable a => Ptr a -> IO a
peek Ptr CFqZechPolyFactor
fac
[Int] -> (Int -> IO ()) -> IO ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ [Int
0 .. CLong -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral CLong
num Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1] ((Int -> IO ()) -> IO ()) -> (Int -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Int
j -> do
Ptr CFqZechPoly -> CString -> Ptr CFqZechCtx -> IO CInt
fq_zech_poly_print_pretty (Ptr CFqZechPoly
poly Ptr CFqZechPoly -> Int -> Ptr CFqZechPoly
forall a. Storable a => Ptr a -> Int -> Ptr a
`advancePtr` Int
j) CString
var Ptr CFqZechCtx
ctx
String -> IO ()
putStr String
" ^ "
CLong
e <- Ptr CLong -> IO CLong
forall a. Storable a => Ptr a -> IO a
peek (Ptr CLong
exp Ptr CLong -> Int -> Ptr CLong
forall a. Storable a => Ptr a -> Int -> Ptr a
`advancePtr` Int
j)
String -> IO ()
putStrLn (String -> IO ()) -> String -> IO ()
forall a b. (a -> b) -> a -> b
$ CLong -> String
forall a. Show a => a -> String
show CLong
e
fq_zech_poly_factor_print :: Ptr CFqZechPolyFactor -> Ptr CFqZechCtx -> IO ()
fq_zech_poly_factor_print :: Ptr CFqZechPolyFactor -> Ptr CFqZechCtx -> IO ()
fq_zech_poly_factor_print Ptr CFqZechPolyFactor
fac Ptr CFqZechCtx
ctx = do
CFqZechPolyFactor Ptr CFqZechPoly
poly Ptr CLong
exp CLong
num CLong
alloc <- Ptr CFqZechPolyFactor -> IO CFqZechPolyFactor
forall a. Storable a => Ptr a -> IO a
peek Ptr CFqZechPolyFactor
fac
[Int] -> (Int -> IO ()) -> IO ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ [Int
0 .. CLong -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral CLong
num Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1] ((Int -> IO ()) -> IO ()) -> (Int -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Int
j -> do
Ptr CFqZechPoly -> Ptr CFqZechCtx -> IO CInt
fq_zech_poly_print (Ptr CFqZechPoly
poly Ptr CFqZechPoly -> Int -> Ptr CFqZechPoly
forall a. Storable a => Ptr a -> Int -> Ptr a
`advancePtr` Int
j) Ptr CFqZechCtx
ctx
String -> IO ()
putStr String
" ^ "
CLong
e <- Ptr CLong -> IO CLong
forall a. Storable a => Ptr a -> IO a
peek (Ptr CLong
exp Ptr CLong -> Int -> Ptr CLong
forall a. Storable a => Ptr a -> Int -> Ptr a
`advancePtr` Int
j)
String -> IO ()
putStrLn (String -> IO ()) -> String -> IO ()
forall a b. (a -> b) -> a -> b
$ CLong -> String
forall a. Show a => a -> String
show CLong
e
foreign import ccall "fq_zech_poly_factor.h fq_zech_poly_factor_insert"
fq_zech_poly_factor_insert :: Ptr CFqZechPolyFactor -> Ptr CFqZechPoly -> CLong -> Ptr CFqZechCtx -> IO ()
foreign import ccall "fq_zech_poly_factor.h fq_zech_poly_factor_concat"
fq_zech_poly_factor_concat :: Ptr CFqZechPolyFactor -> Ptr CFqZechPolyFactor -> Ptr CFqZechCtx -> IO ()
foreign import ccall "fq_zech_poly_factor.h fq_zech_poly_factor_pow"
fq_zech_poly_factor_pow :: Ptr CFqZechPolyFactor -> CLong -> Ptr CFqZechCtx -> IO ()
foreign import ccall "fq_zech_poly_factor.h fq_zech_poly_remove"
fq_zech_poly_remove :: Ptr CFqZechPoly -> Ptr CFqZechPoly -> Ptr CFqZechCtx -> IO CULong
foreign import ccall "fq_zech_poly_factor.h fq_zech_poly_is_irreducible"
fq_zech_poly_is_irreducible :: Ptr CFqZechPoly -> Ptr CFqZechCtx -> IO CInt
foreign import ccall "fq_zech_poly_factor.h fq_zech_poly_is_irreducible_ddf"
fq_zech_poly_is_irreducible_ddf :: Ptr CFqZechPoly -> Ptr CFqZechCtx -> IO CInt
foreign import ccall "fq_zech_poly_factor.h fq_zech_poly_is_irreducible_ben_or"
fq_zech_poly_is_irreducible_ben_or :: Ptr CFqZechPoly -> Ptr CFqZechCtx -> IO CInt
foreign import ccall "fq_zech_poly_factor.h _fq_zech_poly_is_squarefree"
_fq_zech_poly_is_squarefree :: Ptr (Ptr CFqZech) -> CLong -> Ptr CFqZechCtx -> IO CInt
foreign import ccall "fq_zech_poly_factor.h fq_zech_poly_is_squarefree"
fq_zech_poly_is_squarefree :: Ptr CFqZechPoly -> Ptr CFqZechCtx -> IO CInt
foreign import ccall "fq_zech_poly_factor.h fq_zech_poly_factor_equal_deg_prob"
fq_zech_poly_factor_equal_deg_prob :: Ptr CFqZechPoly -> Ptr CFRandState -> Ptr CFqZechPoly -> CLong -> Ptr CFqZechCtx -> IO CInt
foreign import ccall "fq_zech_poly_factor.h fq_zech_poly_factor_equal_deg"
fq_zech_poly_factor_equal_deg :: Ptr CFqZechPolyFactor -> Ptr CFqZechPoly -> CLong -> Ptr CFqZechCtx -> IO ()
foreign import ccall "fq_zech_poly_factor.h fq_zech_poly_factor_split_single"
fq_zech_poly_factor_split_single :: Ptr CFqZechPoly -> Ptr CFqZechPoly -> Ptr CFqZechCtx -> IO ()
foreign import ccall "fq_zech_poly_factor.h fq_zech_poly_factor_distinct_deg"
fq_zech_poly_factor_distinct_deg :: Ptr CFqZechPolyFactor -> Ptr CFqZechPoly -> Ptr (Ptr CLong) -> Ptr CFqZechCtx -> IO ()
foreign import ccall "fq_zech_poly_factor.h fq_zech_poly_factor_squarefree"
fq_zech_poly_factor_squarefree :: Ptr CFqZechPolyFactor -> Ptr CFqZechPoly -> Ptr CFqZechCtx -> IO ()
foreign import ccall "fq_zech_poly_factor.h fq_zech_poly_factor"
fq_zech_poly_factor :: Ptr CFqZechPolyFactor -> Ptr CFqZech -> Ptr CFqZechPoly -> Ptr CFqZechCtx -> IO ()
foreign import ccall "fq_zech_poly_factor.h fq_zech_poly_factor_cantor_zassenhaus"
fq_zech_poly_factor_cantor_zassenhaus :: Ptr CFqZechPolyFactor -> Ptr CFqZechPoly -> Ptr CFqZechCtx -> IO ()
foreign import ccall "fq_zech_poly_factor.h fq_zech_poly_factor_kaltofen_shoup"
fq_zech_poly_factor_kaltofen_shoup :: Ptr CFqZechPolyFactor -> Ptr CFqZechPoly -> Ptr CFqZechCtx -> IO ()
foreign import ccall "fq_zech_poly_factor.h fq_zech_poly_factor_berlekamp"
fq_zech_poly_factor_berlekamp :: Ptr CFqZechPolyFactor -> Ptr CFqZechPoly -> Ptr CFqZechCtx -> IO ()
foreign import ccall "fq_zech_poly_factor.h fq_zech_poly_factor_with_berlekamp"
fq_zech_poly_factor_with_berlekamp :: Ptr CFqZechPolyFactor -> Ptr CFqZech -> Ptr CFqZechPoly -> Ptr CFqZechCtx -> IO ()
foreign import ccall "fq_zech_poly_factor.h fq_zech_poly_factor_with_cantor_zassenhaus"
fq_zech_poly_factor_with_cantor_zassenhaus :: Ptr CFqZechPolyFactor -> Ptr CFqZech -> Ptr CFqZechPoly -> Ptr CFqZechCtx -> IO ()
foreign import ccall "fq_zech_poly_factor.h fq_zech_poly_factor_with_kaltofen_shoup"
fq_zech_poly_factor_with_kaltofen_shoup :: Ptr CFqZechPolyFactor -> Ptr CFqZech -> Ptr CFqZechPoly -> Ptr CFqZechCtx -> IO ()
foreign import ccall "fq_zech_poly_factor.h fq_zech_poly_iterated_frobenius_preinv"
fq_zech_poly_iterated_frobenius_preinv :: Ptr (Ptr CFqZechPoly) -> CLong -> Ptr CFqZechPoly -> Ptr CFqZechPoly -> Ptr CFqZechCtx -> IO ()
foreign import ccall "fq_zech_poly_factor.h fq_zech_poly_roots"
fq_zech_poly_roots :: Ptr CFqZechPolyFactor -> Ptr CFqZechPoly -> CInt -> Ptr CFqZechCtx -> IO ()