module Data.Number.Flint.Fmpq.Mat.Instances where

import System.IO.Unsafe

import Foreign.C.String
import Foreign.Marshal.Alloc ( free )
import Foreign.Storable

import Data.Number.Flint.Fmpq.Mat

instance Show FmpqMat where
  show :: FmpqMat -> String
show FmpqMat
x = IO String -> String
forall a. IO a -> a
unsafePerformIO (IO String -> String) -> IO String -> String
forall a b. (a -> b) -> a -> b
$ do
    (FmpqMat
_, CString
cs) <- FmpqMat -> (Ptr CFmpqMat -> IO CString) -> IO (FmpqMat, CString)
forall {a}. FmpqMat -> (Ptr CFmpqMat -> IO a) -> IO (FmpqMat, a)
withFmpqMat FmpqMat
x Ptr CFmpqMat -> IO CString
fmpq_mat_get_str
    String
s <- CString -> IO String
peekCString CString
cs
    CString -> IO ()
forall a. Ptr a -> IO ()
free CString
cs
    String -> IO String
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return String
s
      
instance Eq FmpqMat where
  == :: FmpqMat -> FmpqMat -> Bool
(==) FmpqMat
x FmpqMat
y = IO Bool -> Bool
forall a. IO a -> a
unsafePerformIO (IO Bool -> Bool) -> IO Bool -> Bool
forall a b. (a -> b) -> a -> b
$ do
    (FmpqMat
_, (FmpqMat
_, CInt
flag)) <- FmpqMat
-> (Ptr CFmpqMat -> IO (FmpqMat, CInt))
-> IO (FmpqMat, (FmpqMat, CInt))
forall {a}. FmpqMat -> (Ptr CFmpqMat -> IO a) -> IO (FmpqMat, a)
withFmpqMat FmpqMat
x ((Ptr CFmpqMat -> IO (FmpqMat, CInt))
 -> IO (FmpqMat, (FmpqMat, CInt)))
-> (Ptr CFmpqMat -> IO (FmpqMat, CInt))
-> IO (FmpqMat, (FmpqMat, CInt))
forall a b. (a -> b) -> a -> b
$ \Ptr CFmpqMat
x -> do
      FmpqMat -> (Ptr CFmpqMat -> IO CInt) -> IO (FmpqMat, CInt)
forall {a}. FmpqMat -> (Ptr CFmpqMat -> IO a) -> IO (FmpqMat, a)
withFmpqMat FmpqMat
y ((Ptr CFmpqMat -> IO CInt) -> IO (FmpqMat, CInt))
-> (Ptr CFmpqMat -> IO CInt) -> IO (FmpqMat, CInt)
forall a b. (a -> b) -> a -> b
$ \Ptr CFmpqMat
y -> do
        Ptr CFmpqMat -> Ptr CFmpqMat -> IO CInt
fmpq_mat_equal Ptr CFmpqMat
x Ptr CFmpqMat
y
    Bool -> IO Bool
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Bool -> IO Bool) -> Bool -> IO Bool
forall a b. (a -> b) -> a -> b
$ CInt
flag CInt -> CInt -> Bool
forall a. Eq a => a -> a -> Bool
== CInt
1

instance Num FmpqMat where
  + :: FmpqMat -> FmpqMat -> FmpqMat
(+) = (Ptr CFmpqMat -> Ptr CFmpqMat -> Ptr CFmpqMat -> IO ())
-> FmpqMat -> FmpqMat -> FmpqMat
forall {a}.
(Ptr CFmpqMat -> Ptr CFmpqMat -> Ptr CFmpqMat -> IO a)
-> FmpqMat -> FmpqMat -> FmpqMat
lift2 Ptr CFmpqMat -> Ptr CFmpqMat -> Ptr CFmpqMat -> IO ()
fmpq_mat_add
  (-) = (Ptr CFmpqMat -> Ptr CFmpqMat -> Ptr CFmpqMat -> IO ())
-> FmpqMat -> FmpqMat -> FmpqMat
forall {a}.
(Ptr CFmpqMat -> Ptr CFmpqMat -> Ptr CFmpqMat -> IO a)
-> FmpqMat -> FmpqMat -> FmpqMat
lift2 Ptr CFmpqMat -> Ptr CFmpqMat -> Ptr CFmpqMat -> IO ()
fmpq_mat_sub
  * :: FmpqMat -> FmpqMat -> FmpqMat
(*) = (Ptr CFmpqMat -> Ptr CFmpqMat -> Ptr CFmpqMat -> IO ())
-> FmpqMat -> FmpqMat -> FmpqMat
forall {a}.
(Ptr CFmpqMat -> Ptr CFmpqMat -> Ptr CFmpqMat -> IO a)
-> FmpqMat -> FmpqMat -> FmpqMat
lift2 Ptr CFmpqMat -> Ptr CFmpqMat -> Ptr CFmpqMat -> IO ()
fmpq_mat_mul
  negate :: FmpqMat -> FmpqMat
negate = (Ptr CFmpqMat -> Ptr CFmpqMat -> IO ()) -> FmpqMat -> FmpqMat
forall {a}.
(Ptr CFmpqMat -> Ptr CFmpqMat -> IO a) -> FmpqMat -> FmpqMat
lift1 Ptr CFmpqMat -> Ptr CFmpqMat -> IO ()
fmpq_mat_neg
  fromInteger :: Integer -> FmpqMat
fromInteger = Integer -> FmpqMat
forall a. HasCallStack => a
undefined
  signum :: FmpqMat -> FmpqMat
signum = FmpqMat -> FmpqMat
forall a. HasCallStack => a
undefined
  abs :: FmpqMat -> FmpqMat
abs = FmpqMat -> FmpqMat
forall a. HasCallStack => a
undefined

instance Fractional FmpqMat where
  recip :: FmpqMat -> FmpqMat
recip FmpqMat
x = IO FmpqMat -> FmpqMat
forall a. IO a -> a
unsafePerformIO (IO FmpqMat -> FmpqMat) -> IO FmpqMat -> FmpqMat
forall a b. (a -> b) -> a -> b
$ do
    (FmpqMat
_, (CLong
nx, CLong
mx)) <- FmpqMat
-> (Ptr CFmpqMat -> IO (CLong, CLong))
-> IO (FmpqMat, (CLong, CLong))
forall {a}. FmpqMat -> (Ptr CFmpqMat -> IO a) -> IO (FmpqMat, a)
withFmpqMat FmpqMat
x ((Ptr CFmpqMat -> IO (CLong, CLong))
 -> IO (FmpqMat, (CLong, CLong)))
-> (Ptr CFmpqMat -> IO (CLong, CLong))
-> IO (FmpqMat, (CLong, CLong))
forall a b. (a -> b) -> a -> b
$ \Ptr CFmpqMat
x -> do
      CFmpqMat Ptr CFmpq
_ CLong
nx CLong
mx Ptr (Ptr CFmpq)
_ <- Ptr CFmpqMat -> IO CFmpqMat
forall a. Storable a => Ptr a -> IO a
peek Ptr CFmpqMat
x
      (CLong, CLong) -> IO (CLong, CLong)
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (CLong
nx, CLong
mx)
    FmpqMat
result <- CLong -> CLong -> IO FmpqMat
newFmpqMat CLong
nx CLong
mx
    (FmpqMat
_, (FmpqMat
_, CInt
flag)) <- FmpqMat
-> (Ptr CFmpqMat -> IO (FmpqMat, CInt))
-> IO (FmpqMat, (FmpqMat, CInt))
forall {a}. FmpqMat -> (Ptr CFmpqMat -> IO a) -> IO (FmpqMat, a)
withFmpqMat FmpqMat
x ((Ptr CFmpqMat -> IO (FmpqMat, CInt))
 -> IO (FmpqMat, (FmpqMat, CInt)))
-> (Ptr CFmpqMat -> IO (FmpqMat, CInt))
-> IO (FmpqMat, (FmpqMat, CInt))
forall a b. (a -> b) -> a -> b
$ \Ptr CFmpqMat
x -> do
      FmpqMat -> (Ptr CFmpqMat -> IO CInt) -> IO (FmpqMat, CInt)
forall {a}. FmpqMat -> (Ptr CFmpqMat -> IO a) -> IO (FmpqMat, a)
withFmpqMat FmpqMat
result ((Ptr CFmpqMat -> IO CInt) -> IO (FmpqMat, CInt))
-> (Ptr CFmpqMat -> IO CInt) -> IO (FmpqMat, CInt)
forall a b. (a -> b) -> a -> b
$ \Ptr CFmpqMat
result -> do
        CInt
flag <- Ptr CFmpqMat -> Ptr CFmpqMat -> IO CInt
fmpq_mat_inv Ptr CFmpqMat
result Ptr CFmpqMat
x
        CInt -> IO CInt
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return CInt
flag
    FmpqMat -> IO FmpqMat
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return FmpqMat
result
  fromRational :: Rational -> FmpqMat
fromRational = Rational -> FmpqMat
forall a. HasCallStack => a
undefined

instance Semigroup FmpqMat where
  <> :: FmpqMat -> FmpqMat -> FmpqMat
(<>) = FmpqMat -> FmpqMat -> FmpqMat
forall a. Num a => a -> a -> a
(*)
  
lift1 :: (Ptr CFmpqMat -> Ptr CFmpqMat -> IO a) -> FmpqMat -> FmpqMat
lift1 Ptr CFmpqMat -> Ptr CFmpqMat -> IO a
f FmpqMat
x = IO FmpqMat -> FmpqMat
forall a. IO a -> a
unsafePerformIO (IO FmpqMat -> FmpqMat) -> IO FmpqMat -> FmpqMat
forall a b. (a -> b) -> a -> b
$ do
  (FmpqMat
_, (CLong
nx, CLong
mx)) <- FmpqMat
-> (Ptr CFmpqMat -> IO (CLong, CLong))
-> IO (FmpqMat, (CLong, CLong))
forall {a}. FmpqMat -> (Ptr CFmpqMat -> IO a) -> IO (FmpqMat, a)
withFmpqMat FmpqMat
x ((Ptr CFmpqMat -> IO (CLong, CLong))
 -> IO (FmpqMat, (CLong, CLong)))
-> (Ptr CFmpqMat -> IO (CLong, CLong))
-> IO (FmpqMat, (CLong, CLong))
forall a b. (a -> b) -> a -> b
$ \Ptr CFmpqMat
x -> do
    CFmpqMat Ptr CFmpq
_ CLong
nx CLong
mx Ptr (Ptr CFmpq)
_ <- Ptr CFmpqMat -> IO CFmpqMat
forall a. Storable a => Ptr a -> IO a
peek Ptr CFmpqMat
x
    (CLong, CLong) -> IO (CLong, CLong)
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (CLong
nx, CLong
mx)
  FmpqMat
result <- CLong -> CLong -> IO FmpqMat
newFmpqMat CLong
nx CLong
mx
  FmpqMat
-> (Ptr CFmpqMat -> IO (FmpqMat, a)) -> IO (FmpqMat, (FmpqMat, a))
forall {a}. FmpqMat -> (Ptr CFmpqMat -> IO a) -> IO (FmpqMat, a)
withFmpqMat FmpqMat
x ((Ptr CFmpqMat -> IO (FmpqMat, a)) -> IO (FmpqMat, (FmpqMat, a)))
-> (Ptr CFmpqMat -> IO (FmpqMat, a)) -> IO (FmpqMat, (FmpqMat, a))
forall a b. (a -> b) -> a -> b
$ \Ptr CFmpqMat
x -> do
    FmpqMat -> (Ptr CFmpqMat -> IO a) -> IO (FmpqMat, a)
forall {a}. FmpqMat -> (Ptr CFmpqMat -> IO a) -> IO (FmpqMat, a)
withFmpqMat FmpqMat
result ((Ptr CFmpqMat -> IO a) -> IO (FmpqMat, a))
-> (Ptr CFmpqMat -> IO a) -> IO (FmpqMat, a)
forall a b. (a -> b) -> a -> b
$ \Ptr CFmpqMat
result -> do
      Ptr CFmpqMat -> Ptr CFmpqMat -> IO a
f Ptr CFmpqMat
result Ptr CFmpqMat
x
  FmpqMat -> IO FmpqMat
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return FmpqMat
result
    
lift2 :: (Ptr CFmpqMat -> Ptr CFmpqMat -> Ptr CFmpqMat -> IO a)
-> FmpqMat -> FmpqMat -> FmpqMat
lift2 Ptr CFmpqMat -> Ptr CFmpqMat -> Ptr CFmpqMat -> IO a
f FmpqMat
x FmpqMat
y = IO FmpqMat -> FmpqMat
forall a. IO a -> a
unsafePerformIO (IO FmpqMat -> FmpqMat) -> IO FmpqMat -> FmpqMat
forall a b. (a -> b) -> a -> b
$ do
  (FmpqMat
_, (CLong
nx, CLong
mx)) <- FmpqMat
-> (Ptr CFmpqMat -> IO (CLong, CLong))
-> IO (FmpqMat, (CLong, CLong))
forall {a}. FmpqMat -> (Ptr CFmpqMat -> IO a) -> IO (FmpqMat, a)
withFmpqMat FmpqMat
x ((Ptr CFmpqMat -> IO (CLong, CLong))
 -> IO (FmpqMat, (CLong, CLong)))
-> (Ptr CFmpqMat -> IO (CLong, CLong))
-> IO (FmpqMat, (CLong, CLong))
forall a b. (a -> b) -> a -> b
$ \Ptr CFmpqMat
x -> do
    CFmpqMat Ptr CFmpq
_ CLong
nx CLong
mx Ptr (Ptr CFmpq)
_ <- Ptr CFmpqMat -> IO CFmpqMat
forall a. Storable a => Ptr a -> IO a
peek Ptr CFmpqMat
x
    (CLong, CLong) -> IO (CLong, CLong)
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (CLong
nx, CLong
mx)
  (FmpqMat
_, (CLong
ny, CLong
my)) <- FmpqMat
-> (Ptr CFmpqMat -> IO (CLong, CLong))
-> IO (FmpqMat, (CLong, CLong))
forall {a}. FmpqMat -> (Ptr CFmpqMat -> IO a) -> IO (FmpqMat, a)
withFmpqMat FmpqMat
y ((Ptr CFmpqMat -> IO (CLong, CLong))
 -> IO (FmpqMat, (CLong, CLong)))
-> (Ptr CFmpqMat -> IO (CLong, CLong))
-> IO (FmpqMat, (CLong, CLong))
forall a b. (a -> b) -> a -> b
$ \Ptr CFmpqMat
y -> do 
     CFmpqMat Ptr CFmpq
_ CLong
ny CLong
my Ptr (Ptr CFmpq)
_ <- Ptr CFmpqMat -> IO CFmpqMat
forall a. Storable a => Ptr a -> IO a
peek Ptr CFmpqMat
y
     (CLong, CLong) -> IO (CLong, CLong)
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (CLong
ny, CLong
my)
  FmpqMat
result <- CLong -> CLong -> IO FmpqMat
newFmpqMat CLong
nx CLong
my
  FmpqMat
-> (Ptr CFmpqMat -> IO (FmpqMat, (FmpqMat, a)))
-> IO (FmpqMat, (FmpqMat, (FmpqMat, a)))
forall {a}. FmpqMat -> (Ptr CFmpqMat -> IO a) -> IO (FmpqMat, a)
withFmpqMat FmpqMat
result ((Ptr CFmpqMat -> IO (FmpqMat, (FmpqMat, a)))
 -> IO (FmpqMat, (FmpqMat, (FmpqMat, a))))
-> (Ptr CFmpqMat -> IO (FmpqMat, (FmpqMat, a)))
-> IO (FmpqMat, (FmpqMat, (FmpqMat, a)))
forall a b. (a -> b) -> a -> b
$ \Ptr CFmpqMat
z -> do
    FmpqMat
-> (Ptr CFmpqMat -> IO (FmpqMat, a)) -> IO (FmpqMat, (FmpqMat, a))
forall {a}. FmpqMat -> (Ptr CFmpqMat -> IO a) -> IO (FmpqMat, a)
withFmpqMat FmpqMat
x ((Ptr CFmpqMat -> IO (FmpqMat, a)) -> IO (FmpqMat, (FmpqMat, a)))
-> (Ptr CFmpqMat -> IO (FmpqMat, a)) -> IO (FmpqMat, (FmpqMat, a))
forall a b. (a -> b) -> a -> b
$ \Ptr CFmpqMat
x -> do
      FmpqMat -> (Ptr CFmpqMat -> IO a) -> IO (FmpqMat, a)
forall {a}. FmpqMat -> (Ptr CFmpqMat -> IO a) -> IO (FmpqMat, a)
withFmpqMat FmpqMat
y ((Ptr CFmpqMat -> IO a) -> IO (FmpqMat, a))
-> (Ptr CFmpqMat -> IO a) -> IO (FmpqMat, a)
forall a b. (a -> b) -> a -> b
$ \Ptr CFmpqMat
y -> do
        Ptr CFmpqMat -> Ptr CFmpqMat -> Ptr CFmpqMat -> IO a
f Ptr CFmpqMat
z Ptr CFmpqMat
x Ptr CFmpqMat
y
  FmpqMat -> IO FmpqMat
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return FmpqMat
result