module Data.Number.Flint.Acb.Poly.Instances ( AcbPoly (..) , module GHC.Exts ) where import Test.QuickCheck import GHC.Exts import System.IO.Unsafe import Control.Monad import Foreign.Ptr import Foreign.C.String import Foreign.Storable import Foreign.Marshal.Alloc (free) import Foreign.Marshal.Array (advancePtr) import Data.Number.Flint.Acb import Data.Number.Flint.Acb.Instances import Data.Number.Flint.Acb.Poly import Data.Number.Flint.UFD instance Show AcbPoly where show :: AcbPoly -> String show AcbPoly p = forall a b. (a, b) -> b snd forall a b. (a -> b) -> a -> b $ forall a. IO a -> a unsafePerformIO forall a b. (a -> b) -> a -> b $ do forall {a}. AcbPoly -> (Ptr CAcbPoly -> IO a) -> IO (AcbPoly, a) withAcbPoly AcbPoly p forall a b. (a -> b) -> a -> b $ \Ptr CAcbPoly p -> do CString cs <- Ptr CAcbPoly -> CLong -> IO CString acb_poly_get_strd Ptr CAcbPoly p CLong 16 String s <- CString -> IO String peekCString CString cs forall a. Ptr a -> IO () free CString cs forall (m :: * -> *) a. Monad m => a -> m a return String s instance IsList AcbPoly where type Item AcbPoly = Acb fromList :: [Item AcbPoly] -> AcbPoly fromList [Item AcbPoly] c = forall a. IO a -> a unsafePerformIO forall a b. (a -> b) -> a -> b $ do AcbPoly p <- IO AcbPoly newAcbPoly forall {a}. AcbPoly -> (Ptr CAcbPoly -> IO a) -> IO (AcbPoly, a) withAcbPoly AcbPoly p forall a b. (a -> b) -> a -> b $ \Ptr CAcbPoly p -> forall (t :: * -> *) (m :: * -> *) a b. (Foldable t, Monad m) => t a -> (a -> m b) -> m () forM_ [Int 0..forall (t :: * -> *) a. Foldable t => t a -> Int length [Item AcbPoly] cforall a. Num a => a -> a -> a -Int 1] forall a b. (a -> b) -> a -> b $ \Int j -> forall {a}. Acb -> (Ptr CAcb -> IO a) -> IO (Acb, a) withAcb ([Item AcbPoly] cforall a. [a] -> Int -> a !!Int j) forall a b. (a -> b) -> a -> b $ \Ptr CAcb a -> Ptr CAcbPoly -> CLong -> Ptr CAcb -> IO () acb_poly_set_coeff_acb Ptr CAcbPoly p (forall a b. (Integral a, Num b) => a -> b fromIntegral Int j) Ptr CAcb a forall (m :: * -> *) a. Monad m => a -> m a return AcbPoly p toList :: AcbPoly -> [Item AcbPoly] toList AcbPoly p = forall a b. (a, b) -> b snd forall a b. (a -> b) -> a -> b $ forall a. IO a -> a unsafePerformIO forall a b. (a -> b) -> a -> b $ forall {a}. AcbPoly -> (Ptr CAcbPoly -> IO a) -> IO (AcbPoly, a) withAcbPoly AcbPoly p forall a b. (a -> b) -> a -> b $ \Ptr CAcbPoly p -> do CLong d <- Ptr CAcbPoly -> IO CLong acb_poly_degree Ptr CAcbPoly p forall (t :: * -> *) (m :: * -> *) a b. (Traversable t, Monad m) => t a -> (a -> m b) -> m (t b) forM [CLong 0..CLong d] forall a b. (a -> b) -> a -> b $ \CLong j -> do Acb c <- IO Acb newAcb forall {a}. Acb -> (Ptr CAcb -> IO a) -> IO (Acb, a) withAcb Acb c forall a b. (a -> b) -> a -> b $ \Ptr CAcb c -> Ptr CAcb -> Ptr CAcbPoly -> CLong -> IO () acb_poly_get_coeff_acb Ptr CAcb c Ptr CAcbPoly p CLong j forall (m :: * -> *) a. Monad m => a -> m a return Acb c lift2 :: (Ptr CAcbPoly -> Ptr CAcbPoly -> Ptr CAcbPoly -> IO a) -> AcbPoly -> AcbPoly -> AcbPoly lift2 Ptr CAcbPoly -> Ptr CAcbPoly -> Ptr CAcbPoly -> IO a f AcbPoly x AcbPoly y = forall a. IO a -> a unsafePerformIO forall a b. (a -> b) -> a -> b $ do AcbPoly result <- IO AcbPoly newAcbPoly forall {a}. AcbPoly -> (Ptr CAcbPoly -> IO a) -> IO (AcbPoly, a) withAcbPoly AcbPoly result forall a b. (a -> b) -> a -> b $ \Ptr CAcbPoly result -> do forall {a}. AcbPoly -> (Ptr CAcbPoly -> IO a) -> IO (AcbPoly, a) withAcbPoly AcbPoly x forall a b. (a -> b) -> a -> b $ \Ptr CAcbPoly x -> do forall {a}. AcbPoly -> (Ptr CAcbPoly -> IO a) -> IO (AcbPoly, a) withAcbPoly AcbPoly y forall a b. (a -> b) -> a -> b $ \Ptr CAcbPoly y -> do Ptr CAcbPoly -> Ptr CAcbPoly -> Ptr CAcbPoly -> IO a f Ptr CAcbPoly result Ptr CAcbPoly x Ptr CAcbPoly y forall (m :: * -> *) a. Monad m => a -> m a return AcbPoly result lift1 :: (Ptr CAcbPoly -> Ptr CAcbPoly -> IO a) -> AcbPoly -> AcbPoly lift1 Ptr CAcbPoly -> Ptr CAcbPoly -> IO a f AcbPoly x = forall a. IO a -> a unsafePerformIO forall a b. (a -> b) -> a -> b $ do AcbPoly result <- IO AcbPoly newAcbPoly forall {a}. AcbPoly -> (Ptr CAcbPoly -> IO a) -> IO (AcbPoly, a) withAcbPoly AcbPoly result forall a b. (a -> b) -> a -> b $ \Ptr CAcbPoly result -> forall {a}. AcbPoly -> (Ptr CAcbPoly -> IO a) -> IO (AcbPoly, a) withAcbPoly AcbPoly x forall a b. (a -> b) -> a -> b $ \Ptr CAcbPoly x -> Ptr CAcbPoly -> Ptr CAcbPoly -> IO a f Ptr CAcbPoly result Ptr CAcbPoly x forall (m :: * -> *) a. Monad m => a -> m a return AcbPoly result