{-# LINE 1 "src/Data/Number/Flint/Padic/Poly/FFI.hsc" #-}
module Data.Number.Flint.Padic.Poly.FFI (
PadicPoly (..)
, CPadicPoly (..)
, newPadicPoly
, withPadicPoly
, withNewPadicPoly
, padic_poly_init
, padic_poly_init2
, padic_poly_realloc
, padic_poly_fit_length
, _padic_poly_set_length
, padic_poly_clear
, _padic_poly_normalise
, _padic_poly_canonicalise
, padic_poly_reduce
, padic_poly_truncate
, padic_poly_degree
, padic_poly_length
, padic_poly_val
, padic_poly_randtest
, padic_poly_randtest_not_zero
, padic_poly_randtest_val
, padic_poly_set_padic
, padic_poly_set
, padic_poly_set_si
, padic_poly_set_ui
, padic_poly_set_fmpz
, padic_poly_set_fmpq
, padic_poly_set_fmpz_poly
, padic_poly_set_fmpq_poly
, padic_poly_get_fmpz_poly
, padic_poly_get_fmpq_poly
, padic_poly_zero
, padic_poly_one
, padic_poly_swap
, padic_poly_get_coeff_padic
, padic_poly_set_coeff_padic
, padic_poly_equal
, padic_poly_is_zero
, padic_poly_is_one
, _padic_poly_add
, padic_poly_add
, _padic_poly_sub
, padic_poly_sub
, padic_poly_neg
, _padic_poly_scalar_mul_padic
, padic_poly_scalar_mul_padic
, _padic_poly_mul
, padic_poly_mul
, _padic_poly_pow
, padic_poly_pow
, padic_poly_inv_series
, _padic_poly_derivative
, padic_poly_derivative
, padic_poly_shift_left
, padic_poly_shift_right
, _padic_poly_evaluate_padic
, padic_poly_evaluate_padic
, _padic_poly_compose
, padic_poly_compose
, _padic_poly_compose_pow
, padic_poly_compose_pow
, padic_poly_debug
, _padic_poly_fprint
, padic_poly_fprint
, _padic_poly_print
, padic_poly_print
, _padic_poly_fprint_pretty
, padic_poly_fprint_pretty
, _padic_poly_print_pretty
, padic_poly_print_pretty
, padic_poly_get_str_pretty
, padic_poly_get_str
, _padic_poly_is_canonical
) where
import Control.Monad
import Foreign.C.String
import Foreign.C.Types
import Foreign.ForeignPtr
import Foreign.Ptr ( Ptr, FunPtr, nullPtr, plusPtr, castPtr )
import Foreign.Storable
import Foreign.Marshal ( free )
import Data.Number.Flint.Flint
import Data.Number.Flint.Fmpz
import Data.Number.Flint.Fmpz.Poly
import Data.Number.Flint.Fmpq
import Data.Number.Flint.Fmpq.Poly
import Data.Number.Flint.Padic
data PadicPoly = PadicPoly {-# UNPACK #-} !(ForeignPtr CPadicPoly)
data CPadicPoly = CPadicPoly (Ptr CFmpz) CLong CLong CLong CLong
instance Storable CPadicPoly where
{-# INLINE sizeOf #-}
sizeOf :: CPadicPoly -> Int
sizeOf CPadicPoly
_ = (Int
40)
{-# LINE 132 "src/Data/Number/Flint/Padic/Poly/FFI.hsc" #-}
{-# INLINE alignment #-}
alignment :: CPadicPoly -> Int
alignment CPadicPoly
_ = Int
8
{-# LINE 134 "src/Data/Number/Flint/Padic/Poly/FFI.hsc" #-}
peek ptr = return CPadicPoly
`ap` (return $ castPtr ptr)
`ap` (\hsc_ptr -> peekByteOff hsc_ptr 8) ptr
{-# LINE 137 "src/Data/Number/Flint/Padic/Poly/FFI.hsc" #-}
`ap` (\hsc_ptr -> peekByteOff hsc_ptr 16) ptr
{-# LINE 138 "src/Data/Number/Flint/Padic/Poly/FFI.hsc" #-}
`ap` (\hsc_ptr -> peekByteOff hsc_ptr 24) ptr
{-# LINE 139 "src/Data/Number/Flint/Padic/Poly/FFI.hsc" #-}
`ap` (\hsc_ptr -> peekByteOff hsc_ptr 32) ptr
{-# LINE 140 "src/Data/Number/Flint/Padic/Poly/FFI.hsc" #-}
poke ptr (CPadicPoly coeffs alloc length val n) = do
((\hsc_ptr -> pokeByteOff hsc_ptr 0)) ptr coeffs
{-# LINE 142 "src/Data/Number/Flint/Padic/Poly/FFI.hsc" #-}
((\hsc_ptr -> pokeByteOff hsc_ptr 8)) ptr alloc
{-# LINE 143 "src/Data/Number/Flint/Padic/Poly/FFI.hsc" #-}
((\hsc_ptr -> pokeByteOff hsc_ptr 16)) ptr length
{-# LINE 144 "src/Data/Number/Flint/Padic/Poly/FFI.hsc" #-}
((\hsc_ptr -> pokeByteOff hsc_ptr 24)) ptr val
{-# LINE 145 "src/Data/Number/Flint/Padic/Poly/FFI.hsc" #-}
((\hsc_ptr -> pokeByteOff hsc_ptr 32)) ptr n
{-# LINE 146 "src/Data/Number/Flint/Padic/Poly/FFI.hsc" #-}
newPadicPoly :: IO PadicPoly
newPadicPoly = do
ForeignPtr CPadicPoly
x <- IO (ForeignPtr CPadicPoly)
forall a. Storable a => IO (ForeignPtr a)
mallocForeignPtr
ForeignPtr CPadicPoly -> (Ptr CPadicPoly -> IO ()) -> IO ()
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr CPadicPoly
x Ptr CPadicPoly -> IO ()
padic_poly_init
FinalizerPtr CPadicPoly -> ForeignPtr CPadicPoly -> IO ()
forall a. FinalizerPtr a -> ForeignPtr a -> IO ()
addForeignPtrFinalizer FinalizerPtr CPadicPoly
p_padic_poly_clear ForeignPtr CPadicPoly
x
PadicPoly -> IO PadicPoly
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (PadicPoly -> IO PadicPoly) -> PadicPoly -> IO PadicPoly
forall a b. (a -> b) -> a -> b
$ ForeignPtr CPadicPoly -> PadicPoly
PadicPoly ForeignPtr CPadicPoly
x
{-# INLINE withPadicPoly #-}
withPadicPoly :: PadicPoly -> (Ptr CPadicPoly -> IO a) -> IO (PadicPoly, a)
withPadicPoly (PadicPoly ForeignPtr CPadicPoly
x) Ptr CPadicPoly -> IO a
f = do
ForeignPtr CPadicPoly
-> (Ptr CPadicPoly -> IO (PadicPoly, a)) -> IO (PadicPoly, a)
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr CPadicPoly
x ((Ptr CPadicPoly -> IO (PadicPoly, a)) -> IO (PadicPoly, a))
-> (Ptr CPadicPoly -> IO (PadicPoly, a)) -> IO (PadicPoly, a)
forall a b. (a -> b) -> a -> b
$ \Ptr CPadicPoly
px -> Ptr CPadicPoly -> IO a
f Ptr CPadicPoly
px IO a -> (a -> IO (PadicPoly, a)) -> IO (PadicPoly, a)
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (PadicPoly, a) -> IO (PadicPoly, a)
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return ((PadicPoly, a) -> IO (PadicPoly, a))
-> (a -> (PadicPoly, a)) -> a -> IO (PadicPoly, a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ForeignPtr CPadicPoly -> PadicPoly
PadicPoly ForeignPtr CPadicPoly
x,)
{-# INLINE withNewPadicPoly #-}
withNewPadicPoly :: (Ptr CPadicPoly -> IO a) -> IO (PadicPoly, a)
withNewPadicPoly Ptr CPadicPoly -> IO a
f = do
PadicPoly
x <- IO PadicPoly
newPadicPoly
PadicPoly -> (Ptr CPadicPoly -> IO a) -> IO (PadicPoly, a)
forall {a}.
PadicPoly -> (Ptr CPadicPoly -> IO a) -> IO (PadicPoly, a)
withPadicPoly PadicPoly
x Ptr CPadicPoly -> IO a
f
foreign import ccall "padic_poly.h padic_poly_init"
padic_poly_init :: Ptr CPadicPoly -> IO ()
foreign import ccall "padic_poly.h padic_poly_init2"
padic_poly_init2 :: Ptr CPadicPoly -> CLong -> CLong -> IO ()
foreign import ccall "padic_poly.h padic_poly_realloc"
padic_poly_realloc :: Ptr CPadicPoly -> CLong -> Ptr CFmpz -> IO ()
foreign import ccall "padic_poly.h padic_poly_fit_length"
padic_poly_fit_length :: Ptr CPadicPoly -> CLong -> IO ()
foreign import ccall "padic_poly.h _padic_poly_set_length"
_padic_poly_set_length :: Ptr CPadicPoly -> CLong -> IO ()
foreign import ccall "padic_poly.h padic_poly_clear"
padic_poly_clear :: Ptr CPadicPoly -> IO ()
foreign import ccall "padic_poly.h &padic_poly_clear"
p_padic_poly_clear :: FunPtr (Ptr CPadicPoly -> IO ())
foreign import ccall "padic_poly.h _padic_poly_normalise"
_padic_poly_normalise :: Ptr CPadicPoly -> IO ()
foreign import ccall "padic_poly.h _padic_poly_canonicalise"
_padic_poly_canonicalise :: Ptr CFmpz -> Ptr CLong -> CLong -> Ptr CFmpz -> IO ()
foreign import ccall "padic_poly.h padic_poly_reduce"
padic_poly_reduce :: Ptr CPadicPoly -> Ptr CPadicCtx -> IO ()
foreign import ccall "padic_poly.h padic_poly_truncate"
padic_poly_truncate :: Ptr CPadicPoly -> CLong -> Ptr CFmpz -> IO ()
foreign import ccall "padic_poly.h padic_poly_degree"
padic_poly_degree :: Ptr CPadicPoly -> IO CLong
foreign import ccall "padic_poly.h padic_poly_length"
padic_poly_length :: Ptr CPadicPoly -> IO CLong
foreign import ccall "padic_poly.h padic_poly_val"
padic_poly_val :: Ptr CPadicPoly -> IO CLong
foreign import ccall "padic_poly.h padic_poly_randtest"
padic_poly_randtest :: Ptr CPadicPoly -> Ptr CFRandState -> CLong -> Ptr CPadicCtx -> IO ()
foreign import ccall "padic_poly.h padic_poly_randtest_not_zero"
padic_poly_randtest_not_zero :: Ptr CPadicPoly -> Ptr CFRandState -> CLong -> Ptr CPadicCtx -> IO ()
foreign import ccall "padic_poly.h padic_poly_randtest_val"
padic_poly_randtest_val :: Ptr CPadicPoly -> Ptr CFRandState -> CLong -> CLong -> Ptr CPadicCtx -> IO ()
foreign import ccall "padic_poly.h padic_poly_set_padic"
padic_poly_set_padic :: Ptr CPadicPoly -> Ptr CPadic -> Ptr CPadicCtx -> IO ()
foreign import ccall "padic_poly.h padic_poly_set"
padic_poly_set :: Ptr CPadicPoly -> Ptr CPadicPoly -> Ptr CPadicCtx -> IO ()
foreign import ccall "padic_poly.h padic_poly_set_si"
padic_poly_set_si :: Ptr CPadicPoly -> CLong -> Ptr CPadicCtx -> IO ()
foreign import ccall "padic_poly.h padic_poly_set_ui"
padic_poly_set_ui :: Ptr CPadicPoly -> CULong -> Ptr CPadicCtx -> IO ()
foreign import ccall "padic_poly.h padic_poly_set_fmpz"
padic_poly_set_fmpz :: Ptr CPadicPoly -> Ptr CFmpz -> Ptr CPadicCtx -> IO ()
foreign import ccall "padic_poly.h padic_poly_set_fmpq"
padic_poly_set_fmpq :: Ptr CPadicPoly -> Ptr CFmpq -> Ptr CPadicCtx -> IO ()
foreign import ccall "padic_poly.h padic_poly_set_fmpz_poly"
padic_poly_set_fmpz_poly :: Ptr CPadicPoly -> Ptr CFmpzPoly -> Ptr CPadicCtx -> IO ()
foreign import ccall "padic_poly.h padic_poly_set_fmpq_poly"
padic_poly_set_fmpq_poly :: Ptr CPadicPoly -> Ptr CFmpqPoly -> Ptr CPadicCtx -> IO ()
foreign import ccall "padic_poly.h padic_poly_get_fmpz_poly"
padic_poly_get_fmpz_poly :: Ptr CFmpzPoly -> Ptr CPadicPoly -> Ptr CPadicCtx -> IO CInt
foreign import ccall "padic_poly.h padic_poly_get_fmpq_poly"
padic_poly_get_fmpq_poly :: Ptr CFmpqPoly -> Ptr CPadicPoly -> Ptr CPadicCtx -> IO ()
foreign import ccall "padic_poly.h padic_poly_zero"
padic_poly_zero :: Ptr CPadicPoly -> IO ()
foreign import ccall "padic_poly.h padic_poly_one"
padic_poly_one :: Ptr CPadicPoly -> IO ()
foreign import ccall "padic_poly.h padic_poly_swap"
padic_poly_swap :: Ptr CPadicPoly -> Ptr CPadicPoly -> IO ()
foreign import ccall "padic_poly.h padic_poly_get_coeff_padic"
padic_poly_get_coeff_padic :: Ptr CPadic -> Ptr CPadicPoly -> CLong -> Ptr CPadicCtx -> IO ()
foreign import ccall "padic_poly.h padic_poly_set_coeff_padic"
padic_poly_set_coeff_padic :: Ptr CPadicPoly -> CLong -> Ptr CPadic -> Ptr CPadicCtx -> IO ()
foreign import ccall "padic_poly.h padic_poly_equal"
padic_poly_equal :: Ptr CPadicPoly -> Ptr CPadicPoly -> IO CInt
foreign import ccall "padic_poly.h padic_poly_is_zero"
padic_poly_is_zero :: Ptr CPadicPoly -> IO CInt
foreign import ccall "padic_poly.h padic_poly_is_one"
padic_poly_is_one :: Ptr CPadicPoly -> Ptr CPadicCtx -> IO CInt
foreign import ccall "padic_poly.h _padic_poly_add"
_padic_poly_add :: Ptr CFmpz -> Ptr CLong -> CLong -> Ptr CFmpz -> CLong -> CLong -> CLong -> Ptr CFmpz -> CLong -> CLong -> CLong -> Ptr CPadicCtx -> IO ()
foreign import ccall "padic_poly.h padic_poly_add"
padic_poly_add :: Ptr CPadicPoly -> Ptr CPadicPoly -> Ptr CPadicPoly -> Ptr CPadicCtx -> IO ()
foreign import ccall "padic_poly.h _padic_poly_sub"
_padic_poly_sub :: Ptr CFmpz -> Ptr CLong -> Ptr CFmpz -> CLong -> CLong -> Ptr CFmpz -> CLong -> CLong -> Ptr CPadicCtx -> IO ()
foreign import ccall "padic_poly.h padic_poly_sub"
padic_poly_sub :: Ptr CPadicPoly -> Ptr CPadicPoly -> Ptr CPadicPoly -> Ptr CPadicCtx -> IO ()
foreign import ccall "padic_poly.h padic_poly_neg"
padic_poly_neg :: Ptr CPadicPoly -> Ptr CPadicPoly -> Ptr CPadicCtx -> IO ()
foreign import ccall "padic_poly.h _padic_poly_scalar_mul_padic"
_padic_poly_scalar_mul_padic :: Ptr CFmpz -> Ptr CLong -> Ptr CFmpz -> CLong -> CLong -> Ptr CPadic -> Ptr CPadicCtx -> IO ()
foreign import ccall "padic_poly.h padic_poly_scalar_mul_padic"
padic_poly_scalar_mul_padic :: Ptr CPadicPoly -> Ptr CPadicPoly -> Ptr CPadic -> Ptr CPadicCtx -> IO ()
foreign import ccall "padic_poly.h _padic_poly_mul"
_padic_poly_mul :: Ptr CFmpz -> Ptr CLong -> CLong -> Ptr CFmpz -> CLong -> CLong -> Ptr CFmpz -> CLong -> CLong -> Ptr CPadicCtx -> IO ()
foreign import ccall "padic_poly.h padic_poly_mul"
padic_poly_mul :: Ptr CPadicPoly -> Ptr CPadicPoly -> Ptr CPadicPoly -> Ptr CPadicCtx -> IO ()
foreign import ccall "padic_poly.h _padic_poly_pow"
_padic_poly_pow :: Ptr CFmpz -> Ptr CLong -> CLong -> Ptr CFmpz -> CLong -> CLong -> CULong -> Ptr CPadicCtx -> IO ()
foreign import ccall "padic_poly.h padic_poly_pow"
padic_poly_pow :: Ptr CPadicPoly -> Ptr CPadicPoly -> CULong -> Ptr CPadicCtx -> IO ()
foreign import ccall "padic_poly.h padic_poly_inv_series"
padic_poly_inv_series :: Ptr CPadicPoly -> Ptr CPadicPoly -> CLong -> Ptr CPadicCtx -> IO ()
foreign import ccall "padic_poly.h _padic_poly_derivative"
_padic_poly_derivative :: Ptr CFmpz -> Ptr CLong -> CLong -> Ptr CFmpz -> CLong -> CLong -> Ptr CPadicCtx -> IO ()
foreign import ccall "padic_poly.h padic_poly_derivative"
padic_poly_derivative :: Ptr CPadicPoly -> Ptr CPadicPoly -> Ptr CPadicCtx -> IO ()
foreign import ccall "padic_poly.h padic_poly_shift_left"
padic_poly_shift_left :: Ptr CPadicPoly -> Ptr CPadicPoly -> CLong -> Ptr CPadicCtx -> IO ()
foreign import ccall "padic_poly.h padic_poly_shift_right"
padic_poly_shift_right :: Ptr CPadicPoly -> Ptr CPadicPoly -> CLong -> IO ()
foreign import ccall "padic_poly.h _padic_poly_evaluate_padic"
_padic_poly_evaluate_padic :: Ptr CFmpz -> Ptr CLong -> CLong -> Ptr CFmpz -> CLong -> CLong -> Ptr CFmpz -> CLong -> Ptr CPadicCtx -> IO ()
foreign import ccall "flint/padic_poly.h padic_poly_evaluate_padic"
padic_poly_evaluate_padic :: Ptr CPadic -> Ptr CPadicPoly -> Ptr CPadic -> Ptr CPadicCtx -> IO ()
foreign import ccall "padic_poly.h _padic_poly_compose"
_padic_poly_compose :: Ptr CFmpz -> Ptr CLong -> CLong -> Ptr CFmpz -> CLong -> CLong -> Ptr CFmpz -> CLong -> CLong -> Ptr CPadicCtx -> IO ()
foreign import ccall "padic_poly.h padic_poly_compose"
padic_poly_compose :: Ptr CPadicPoly -> Ptr CPadicPoly -> Ptr CPadicPoly -> Ptr CPadicCtx -> IO ()
foreign import ccall "padic_poly.h _padic_poly_compose_pow"
_padic_poly_compose_pow :: Ptr CFmpz -> Ptr CLong -> CLong -> Ptr CFmpz -> CLong -> CLong -> CLong -> Ptr CPadicCtx -> IO ()
foreign import ccall "padic_poly.h padic_poly_compose_pow"
padic_poly_compose_pow :: Ptr CPadicPoly -> Ptr CPadicPoly -> CLong -> Ptr CPadicCtx -> IO ()
foreign import ccall "padic_poly.h padic_poly_debug"
padic_poly_debug :: Ptr CPadicPoly -> IO CInt
foreign import ccall "padic_poly.h _padic_poly_fprint"
_padic_poly_fprint :: Ptr CFile -> Ptr CFmpz -> CLong -> CLong -> Ptr CPadicCtx -> IO CInt
foreign import ccall "flint/padic_poly.h padic_poly_fprint"
padic_poly_fprint :: Ptr CFile -> Ptr CPadicPoly -> Ptr CPadicCtx -> IO CInt
foreign import ccall "padic_poly.h _padic_poly_print"
_padic_poly_print :: Ptr CFmpz -> CLong -> CLong -> Ptr CPadicCtx -> IO CInt
padic_poly_print :: Ptr CPadicPoly -> Ptr CPadicCtx -> IO CInt
padic_poly_print :: Ptr CPadicPoly -> Ptr CPadicCtx -> IO CInt
padic_poly_print Ptr CPadicPoly
poly Ptr CPadicCtx
ctx = do
CString
cs <- CString -> Ptr CPadicPoly -> Ptr CPadicCtx -> IO CString
padic_poly_get_str CString
forall a. Ptr a
nullPtr Ptr CPadicPoly
poly Ptr CPadicCtx
ctx
String
s <- CString -> IO String
peekCString CString
cs
CString -> IO ()
forall a. Ptr a -> IO ()
free CString
cs
String -> IO ()
putStr String
s
CInt -> IO CInt
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (CInt
1 :: CInt)
foreign import ccall "padic_poly.h _padic_poly_fprint_pretty"
_padic_poly_fprint_pretty :: Ptr CFile -> Ptr CFmpz -> CLong -> CLong -> CString -> Ptr CPadicCtx -> IO CInt
foreign import ccall "flint/padic_poly.h _padic_poly_print_pretty"
_padic_poly_print_pretty :: Ptr CFmpz -> CLong -> CLong -> CString -> Ptr CPadicCtx -> IO CInt
foreign import ccall "flint/padic_poly.h padic_poly_fprint_pretty"
padic_poly_fprint_pretty :: Ptr CFile -> Ptr CPadicPoly -> CString -> Ptr CPadicCtx -> IO CInt
padic_poly_print_pretty :: Ptr CPadicPoly -> CString -> Ptr CPadicCtx -> IO CInt
padic_poly_print_pretty :: Ptr CPadicPoly -> CString -> Ptr CPadicCtx -> IO CInt
padic_poly_print_pretty Ptr CPadicPoly
poly CString
var Ptr CPadicCtx
ctx = do
CString
cs <- Ptr CPadicPoly -> CString -> Ptr CPadicCtx -> IO CString
padic_poly_get_str_pretty Ptr CPadicPoly
poly CString
var Ptr CPadicCtx
ctx
String
s <- CString -> IO String
peekCString CString
cs
CString -> IO ()
forall a. Ptr a -> IO ()
free CString
cs
String -> IO ()
putStr String
s
CInt -> IO CInt
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (CInt
1 :: CInt)
foreign import ccall "padic_poly_get_str"
padic_poly_get_str :: CString -> Ptr CPadicPoly -> Ptr CPadicCtx -> IO CString
foreign import ccall "padic_poly_get_str_pretty"
padic_poly_get_str_pretty :: Ptr CPadicPoly -> CString -> Ptr CPadicCtx -> IO CString
foreign import ccall "padic_poly.h _padic_poly_is_canonical"
_padic_poly_is_canonical :: Ptr CFmpz -> CLong -> CLong -> Ptr CPadicCtx -> IO CInt
foreign import ccall "flint/padic_poly.h padic_poly_is_canonical"
padic_poly_is_canonical :: Ptr CPadicPoly -> Ptr CPadicCtx -> IO CInt
foreign import ccall "flint/padic_poly.h _padic_poly_is_reduced"
_padic_poly_is_reduced :: Ptr CFmpz -> CLong -> CLong -> Ptr CPadicCtx -> IO CInt
foreign import ccall "flint/padic_poly.h padic_poly_is_reduced"
padic_poly_is_reduced :: Ptr CPadicPoly -> Ptr CPadicCtx -> IO CInt