module Data.Number.Flint.Arb.RealField (
  RF(..)
, RF'(..)
, Special (..)
, fromDouble
, toDouble
) where

import GHC.TypeLits
import Data.Proxy

import GHC.Read 
import qualified Text.Read.Lex as Lex
import Text.ParserCombinators.ReadPrec hiding (prec)

import Data.Ratio

import System.IO.Unsafe
import Control.Monad

import Foreign.C.String
import Foreign.C.Types
import Foreign.ForeignPtr
import Foreign.Ptr ( Ptr, FunPtr )
import Foreign.Storable
import Foreign.Marshal (free)

import Data.Number.Flint.Fmpz
import Data.Number.Flint.Fmpz.Instances
import Data.Number.Flint.Arb
import Data.Number.Flint.Arb.Arf
import Data.Number.Flint.Arb.Mag
import Data.Number.Flint.Arb.Types
import Data.Number.Flint.Arb.Hypgeom
import Data.Number.Flint.Support.D.Interval

newtype RF (n :: Nat) = RF Arb

instance forall n. KnownNat n => Eq (RF n) where
  {-# INLINE (==) #-}
  == :: RF n -> RF n -> Bool
(==) = Cmp -> RF n -> RF n -> Bool
forall (n :: Nat). KnownNat n => Cmp -> RF n -> RF n -> Bool
liftCmp Cmp
arb_eq
  {-# INLINE (/=) #-}
  /= :: RF n -> RF n -> Bool
(/=) = Cmp -> RF n -> RF n -> Bool
forall (n :: Nat). KnownNat n => Cmp -> RF n -> RF n -> Bool
liftCmp Cmp
arb_ne

instance forall n. KnownNat n => Ord (RF n) where
  {-# INLINE (<) #-}
  < :: RF n -> RF n -> Bool
(<) = Cmp -> RF n -> RF n -> Bool
forall (n :: Nat). KnownNat n => Cmp -> RF n -> RF n -> Bool
liftCmp Cmp
arb_lt
  {-# INLINE (<=) #-}
  <= :: RF n -> RF n -> Bool
(<=) = Cmp -> RF n -> RF n -> Bool
forall (n :: Nat). KnownNat n => Cmp -> RF n -> RF n -> Bool
liftCmp Cmp
arb_le
  {-# INLINE (>) #-}
  > :: RF n -> RF n -> Bool
(>) = Cmp -> RF n -> RF n -> Bool
forall (n :: Nat). KnownNat n => Cmp -> RF n -> RF n -> Bool
liftCmp Cmp
arb_gt
  {-# INLINE (>=) #-}
  >= :: RF n -> RF n -> Bool
(>=) = Cmp -> RF n -> RF n -> Bool
forall (n :: Nat). KnownNat n => Cmp -> RF n -> RF n -> Bool
liftCmp Cmp
arb_ge
  {-# INLINE max #-}
  max :: RF n -> RF n -> RF n
max = Binary -> RF n -> RF n -> RF n
forall (n :: Nat). KnownNat n => Binary -> RF n -> RF n -> RF n
lift2 Binary
arb_max
  {-# INLINE min #-}
  min :: RF n -> RF n -> RF n
min = Binary -> RF n -> RF n -> RF n
forall (n :: Nat). KnownNat n => Binary -> RF n -> RF n -> RF n
lift2 Binary
arb_min
  
instance forall n. KnownNat n => Num (RF n) where
  {-# INLINE (+) #-}
  + :: RF n -> RF n -> RF n
(+) = Binary -> RF n -> RF n -> RF n
forall (n :: Nat). KnownNat n => Binary -> RF n -> RF n -> RF n
lift2 Binary
arb_add
  {-# INLINE (-) #-}
  (-) = Binary -> RF n -> RF n -> RF n
forall (n :: Nat). KnownNat n => Binary -> RF n -> RF n -> RF n
lift2 Binary
arb_sub
  {-# INLINE (*) #-}
  * :: RF n -> RF n -> RF n
(*) = Binary -> RF n -> RF n -> RF n
forall (n :: Nat). KnownNat n => Binary -> RF n -> RF n -> RF n
lift2 Binary
arb_mul
  {-# INLINE negate #-}
  negate :: RF n -> RF n
negate = Function -> RF n -> RF n
forall (n :: Nat). KnownNat n => Function -> RF n -> RF n
lift1 Function
arb_neg
  {-# INLINE abs #-}
  abs :: RF n -> RF n
abs = Function -> RF n -> RF n
forall (n :: Nat). KnownNat n => Function -> RF n -> RF n
lift1 Function
arb_abs
  {-# INLINE fromInteger #-}
  fromInteger :: Integer -> RF n
fromInteger Integer
x = IO (RF n) -> RF n
forall a. IO a -> a
unsafePerformIO (IO (RF n) -> RF n) -> IO (RF n) -> RF n
forall a b. (a -> b) -> a -> b
$ do
    let prec :: CLong
prec = Integer -> CLong
forall a. Num a => Integer -> a
fromInteger (Integer -> CLong) -> Integer -> CLong
forall a b. (a -> b) -> a -> b
$ Proxy n -> Integer
forall (n :: Nat) (proxy :: Nat -> *).
KnownNat n =>
proxy n -> Integer
natVal (Proxy n
forall {k} (t :: k). Proxy t
Proxy :: Proxy n)
    Arb
result <- IO Arb
newArb
    Arb -> (Ptr CArb -> IO ()) -> IO (Arb, ())
forall {a}. Arb -> (Ptr CArb -> IO a) -> IO (Arb, a)
withArb Arb
result ((Ptr CArb -> IO ()) -> IO (Arb, ()))
-> (Ptr CArb -> IO ()) -> IO (Arb, ())
forall a b. (a -> b) -> a -> b
$ \Ptr CArb
result -> do
      String -> (CString -> IO ()) -> IO ()
forall a. String -> (CString -> IO a) -> IO a
withCString (Integer -> String
forall a. Show a => a -> String
show Integer
x) ((CString -> IO ()) -> IO ()) -> (CString -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \CString
s -> do
        CInt
flag <- Ptr CArb -> CString -> CLong -> IO CInt
arb_set_str Ptr CArb
result CString
s CLong
prec
        Bool -> IO () -> IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (CInt
flag CInt -> CInt -> Bool
forall a. Eq a => a -> a -> Bool
/= CInt
0) (IO () -> IO ()) -> IO () -> IO ()
forall a b. (a -> b) -> a -> b
$
          String -> IO ()
forall a. HasCallStack => String -> a
error (String -> IO ()) -> String -> IO ()
forall a b. (a -> b) -> a -> b
$ String
"Could not create RF " String -> String -> String
forall a. [a] -> [a] -> [a]
++ CLong -> String
forall a. Show a => a -> String
show CLong
prec String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
" from " String -> String -> String
forall a. [a] -> [a] -> [a]
++ Integer -> String
forall a. Show a => a -> String
show Integer
x
    RF n -> IO (RF n)
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Arb -> RF n
forall (n :: Nat). Arb -> RF n
RF Arb
result)
  {-# INLINE signum #-}
  signum :: RF n -> RF n
signum = Function -> RF n -> RF n
forall (n :: Nat). KnownNat n => Function -> RF n -> RF n
lift1 Function
arb_sgn
  
instance forall n. KnownNat n => Fractional (RF n) where
  {-# INLINE (/) #-}
  / :: RF n -> RF n -> RF n
(/) = Binary -> RF n -> RF n -> RF n
forall (n :: Nat). KnownNat n => Binary -> RF n -> RF n -> RF n
lift2 Binary
arb_div
  fromRational :: Rational -> RF n
fromRational Rational
x = RF n
p RF n -> RF n -> RF n
forall a. Fractional a => a -> a -> a
/ RF n
q where
    p :: RF n
p = Integer -> RF n
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Rational -> Integer
forall a. Ratio a -> a
numerator Rational
x) :: RF n
    q :: RF n
q = Integer -> RF n
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Rational -> Integer
forall a. Ratio a -> a
denominator Rational
x) :: RF n

instance forall n. KnownNat n => RealFloat (RF n) where
  isNaN :: RF n -> Bool
isNaN = Bool -> Bool
not (Bool -> Bool) -> (RF n -> Bool) -> RF n -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Ptr CArb -> IO CInt) -> RF n -> Bool
forall (n :: Nat).
KnownNat n =>
(Ptr CArb -> IO CInt) -> RF n -> Bool
liftProp Ptr CArb -> IO CInt
arb_is_finite
  isInfinite :: RF n -> Bool
isInfinite = Bool -> Bool
not (Bool -> Bool) -> (RF n -> Bool) -> RF n -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Ptr CArb -> IO CInt) -> RF n -> Bool
forall (n :: Nat).
KnownNat n =>
(Ptr CArb -> IO CInt) -> RF n -> Bool
liftProp Ptr CArb -> IO CInt
arb_is_finite
  floatRadix :: RF n -> Integer
floatRadix RF n
_ = Integer
2
  floatDigits :: RF n -> Int
floatDigits RF n
_ = Integer -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Integer -> Int) -> Integer -> Int
forall a b. (a -> b) -> a -> b
$ Proxy n -> Integer
forall (n :: Nat) (proxy :: Nat -> *).
KnownNat n =>
proxy n -> Integer
natVal (Proxy n
forall {k} (t :: k). Proxy t
Proxy :: Proxy n)
  floatRange :: RF n -> (Int, Int)
floatRange RF n
_ = (Int
forall a. Bounded a => a
minBound :: Int, Int
forall a. Bounded a => a
maxBound :: Int)
  decodeFloat :: RF n -> (Integer, Int)
decodeFloat (RF Arb
x) = IO (Integer, Int) -> (Integer, Int)
forall a. IO a -> a
unsafePerformIO (IO (Integer, Int) -> (Integer, Int))
-> IO (Integer, Int) -> (Integer, Int)
forall a b. (a -> b) -> a -> b
$ do
    Fmpz
man <- IO Fmpz
newFmpz
    Fmpz
exp <- IO Fmpz
newFmpz 
    Arb
-> (Ptr CArb -> IO (Fmpz, (Fmpz, ())))
-> IO (Arb, (Fmpz, (Fmpz, ())))
forall {a}. Arb -> (Ptr CArb -> IO a) -> IO (Arb, a)
withArb Arb
x ((Ptr CArb -> IO (Fmpz, (Fmpz, ())))
 -> IO (Arb, (Fmpz, (Fmpz, ()))))
-> (Ptr CArb -> IO (Fmpz, (Fmpz, ())))
-> IO (Arb, (Fmpz, (Fmpz, ())))
forall a b. (a -> b) -> a -> b
$ \Ptr CArb
a -> do
      Fmpz -> (Ptr CFmpz -> IO (Fmpz, ())) -> IO (Fmpz, (Fmpz, ()))
forall {a}. Fmpz -> (Ptr CFmpz -> IO a) -> IO (Fmpz, a)
withFmpz Fmpz
man ((Ptr CFmpz -> IO (Fmpz, ())) -> IO (Fmpz, (Fmpz, ())))
-> (Ptr CFmpz -> IO (Fmpz, ())) -> IO (Fmpz, (Fmpz, ()))
forall a b. (a -> b) -> a -> b
$ \Ptr CFmpz
man -> do
        Fmpz -> (Ptr CFmpz -> IO ()) -> IO (Fmpz, ())
forall {a}. Fmpz -> (Ptr CFmpz -> IO a) -> IO (Fmpz, a)
withFmpz Fmpz
exp ((Ptr CFmpz -> IO ()) -> IO (Fmpz, ()))
-> (Ptr CFmpz -> IO ()) -> IO (Fmpz, ())
forall a b. (a -> b) -> a -> b
$ \Ptr CFmpz
exp -> do
          Ptr CFmpz -> Ptr CFmpz -> Ptr CArf -> IO ()
arf_get_fmpz_2exp Ptr CFmpz
man Ptr CFmpz
exp (Ptr CArb -> Ptr CArf
arb_midref Ptr CArb
a)
    (Integer, Int) -> IO (Integer, Int)
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Fmpz -> Integer
forall a. Integral a => a -> Integer
toInteger Fmpz
man, Fmpz -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Fmpz
exp)
  encodeFloat :: Integer -> Int -> RF n
encodeFloat Integer
man Int
exp = IO (RF n) -> RF n
forall a. IO a -> a
unsafePerformIO (IO (RF n) -> RF n) -> IO (RF n) -> RF n
forall a b. (a -> b) -> a -> b
$ do
    let prec :: CLong
prec = Integer -> CLong
forall a. Num a => Integer -> a
fromInteger (Integer -> CLong) -> Integer -> CLong
forall a b. (a -> b) -> a -> b
$ Proxy n -> Integer
forall (n :: Nat) (proxy :: Nat -> *).
KnownNat n =>
proxy n -> Integer
natVal (Proxy n
forall {k} (t :: k). Proxy t
Proxy :: Proxy n)
        m :: Fmpz
m = Integer -> Fmpz
forall a b. (Integral a, Num b) => a -> b
fromIntegral Integer
man :: Fmpz
        e :: Fmpz
e = Int -> Fmpz
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
exp :: Fmpz
    Arb
res <- IO Arb
newArb
    Arb
-> (Ptr CArb -> IO (Fmpz, (Fmpz, (Arf, ()))))
-> IO (Arb, (Fmpz, (Fmpz, (Arf, ()))))
forall {a}. Arb -> (Ptr CArb -> IO a) -> IO (Arb, a)
withArb Arb
res ((Ptr CArb -> IO (Fmpz, (Fmpz, (Arf, ()))))
 -> IO (Arb, (Fmpz, (Fmpz, (Arf, ())))))
-> (Ptr CArb -> IO (Fmpz, (Fmpz, (Arf, ()))))
-> IO (Arb, (Fmpz, (Fmpz, (Arf, ()))))
forall a b. (a -> b) -> a -> b
$ \Ptr CArb
res -> do 
      Fmpz
-> (Ptr CFmpz -> IO (Fmpz, (Arf, ())))
-> IO (Fmpz, (Fmpz, (Arf, ())))
forall {a}. Fmpz -> (Ptr CFmpz -> IO a) -> IO (Fmpz, a)
withFmpz Fmpz
m ((Ptr CFmpz -> IO (Fmpz, (Arf, ())))
 -> IO (Fmpz, (Fmpz, (Arf, ()))))
-> (Ptr CFmpz -> IO (Fmpz, (Arf, ())))
-> IO (Fmpz, (Fmpz, (Arf, ())))
forall a b. (a -> b) -> a -> b
$ \Ptr CFmpz
m -> do
        Fmpz -> (Ptr CFmpz -> IO (Arf, ())) -> IO (Fmpz, (Arf, ()))
forall {a}. Fmpz -> (Ptr CFmpz -> IO a) -> IO (Fmpz, a)
withFmpz Fmpz
e ((Ptr CFmpz -> IO (Arf, ())) -> IO (Fmpz, (Arf, ())))
-> (Ptr CFmpz -> IO (Arf, ())) -> IO (Fmpz, (Arf, ()))
forall a b. (a -> b) -> a -> b
$ \Ptr CFmpz
e -> do
          (Ptr CArf -> IO ()) -> IO (Arf, ())
forall {a}. (Ptr CArf -> IO a) -> IO (Arf, a)
withNewArf ((Ptr CArf -> IO ()) -> IO (Arf, ()))
-> (Ptr CArf -> IO ()) -> IO (Arf, ())
forall a b. (a -> b) -> a -> b
$ \ Ptr CArf
arf -> do
            Ptr CArf -> Ptr CFmpz -> Ptr CFmpz -> CLong -> ArfRnd -> IO CInt
arf_set_round_fmpz_2exp Ptr CArf
arf Ptr CFmpz
m Ptr CFmpz
e CLong
prec ArfRnd
arf_rnd_near
            Ptr CArb -> Ptr CArf -> IO ()
arb_set_arf Ptr CArb
res Ptr CArf
arf
    RF n -> IO (RF n)
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (RF n -> IO (RF n)) -> RF n -> IO (RF n)
forall a b. (a -> b) -> a -> b
$ Arb -> RF n
forall (n :: Nat). Arb -> RF n
RF Arb
res
  isDenormalized :: RF n -> Bool
isDenormalized = String -> RF n -> Bool
forall a. HasCallStack => String -> a
error String
"isDenormalized: not defined"
  isNegativeZero :: RF n -> Bool
isNegativeZero = String -> RF n -> Bool
forall a. HasCallStack => String -> a
error String
"isNegativeZero: not defined"
  isIEEE :: RF n -> Bool
isIEEE RF n
_ = Bool
False
  atan2 :: RF n -> RF n -> RF n
atan2 = Binary -> RF n -> RF n -> RF n
forall (n :: Nat). KnownNat n => Binary -> RF n -> RF n -> RF n
lift2 Binary
arb_atan2

instance forall n. KnownNat n => Real (RF n) where
  toRational :: RF n -> Rational
toRational RF n
x =
    case RF n -> (Integer, Int)
forall a. RealFloat a => a -> (Integer, Int)
decodeFloat RF n
x of
      (Integer
m, Int
n) -> if Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
0 then (Integer
mInteger -> Integer -> Integer
forall a. Num a => a -> a -> a
*Integer
2Integer -> Int -> Integer
forall a b. (Num a, Integral b) => a -> b -> a
^Int
n)Integer -> Integer -> Rational
forall a. Integral a => a -> a -> Ratio a
%Integer
1 else Integer
m Integer -> Integer -> Rational
forall a. Integral a => a -> a -> Ratio a
% (Integer
2Integer -> Int -> Integer
forall a b. (Num a, Integral b) => a -> b -> a
^(-Int
n))

instance forall n. KnownNat n => RealFrac (RF n) where
  properFraction :: forall b. Integral b => RF n -> (b, RF n)
properFraction RF n
x
    = case (RF n -> (Integer, Int)
forall a. RealFloat a => a -> (Integer, Int)
decodeFloat RF n
x) of { (Integer
m,Int
n) ->
      if Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
0 then
          (Integer -> b
forall a. Num a => Integer -> a
fromInteger Integer
m b -> b -> b
forall a. Num a => a -> a -> a
* b
2 b -> Int -> b
forall a b. (Num a, Integral b) => a -> b -> a
^ Int
n, RF n
0.0)
      else
          case (Integer -> Integer -> (Integer, Integer)
forall a. Integral a => a -> a -> (a, a)
quotRem Integer
m (Integer
2Integer -> Int -> Integer
forall a b. (Num a, Integral b) => a -> b -> a
^(Int -> Int
forall a. Num a => a -> a
negate Int
n))) of { (Integer
w,Integer
r) ->
          (Integer -> b
forall a. Num a => Integer -> a
fromInteger Integer
w, Integer -> Int -> RF n
forall a. RealFloat a => Integer -> Int -> a
encodeFloat Integer
r Int
n)
          }
      }

instance forall n. KnownNat n => Floating (RF n) where
  pi :: RF n
pi = (Ptr CArb -> CLong -> IO ()) -> RF n
forall (n :: Nat).
KnownNat n =>
(Ptr CArb -> CLong -> IO ()) -> RF n
liftConstant Ptr CArb -> CLong -> IO ()
arb_const_pi
  exp :: RF n -> RF n
exp = (Ptr CArb -> Ptr CArb -> CLong -> IO ()) -> RF n -> RF n
forall (n :: Nat).
KnownNat n =>
(Ptr CArb -> Ptr CArb -> CLong -> IO ()) -> RF n -> RF n
liftF1 Ptr CArb -> Ptr CArb -> CLong -> IO ()
arb_exp
  log :: RF n -> RF n
log = (Ptr CArb -> Ptr CArb -> CLong -> IO ()) -> RF n -> RF n
forall (n :: Nat).
KnownNat n =>
(Ptr CArb -> Ptr CArb -> CLong -> IO ()) -> RF n -> RF n
liftF1 Ptr CArb -> Ptr CArb -> CLong -> IO ()
arb_log
  sqrt :: RF n -> RF n
sqrt = (Ptr CArb -> Ptr CArb -> CLong -> IO ()) -> RF n -> RF n
forall (n :: Nat).
KnownNat n =>
(Ptr CArb -> Ptr CArb -> CLong -> IO ()) -> RF n -> RF n
liftF1 Ptr CArb -> Ptr CArb -> CLong -> IO ()
arb_sqrt
  sin :: RF n -> RF n
sin = (Ptr CArb -> Ptr CArb -> CLong -> IO ()) -> RF n -> RF n
forall (n :: Nat).
KnownNat n =>
(Ptr CArb -> Ptr CArb -> CLong -> IO ()) -> RF n -> RF n
liftF1 Ptr CArb -> Ptr CArb -> CLong -> IO ()
arb_sin
  cos :: RF n -> RF n
cos = (Ptr CArb -> Ptr CArb -> CLong -> IO ()) -> RF n -> RF n
forall (n :: Nat).
KnownNat n =>
(Ptr CArb -> Ptr CArb -> CLong -> IO ()) -> RF n -> RF n
liftF1 Ptr CArb -> Ptr CArb -> CLong -> IO ()
arb_cos
  tan :: RF n -> RF n
tan = (Ptr CArb -> Ptr CArb -> CLong -> IO ()) -> RF n -> RF n
forall (n :: Nat).
KnownNat n =>
(Ptr CArb -> Ptr CArb -> CLong -> IO ()) -> RF n -> RF n
liftF1 Ptr CArb -> Ptr CArb -> CLong -> IO ()
arb_tan
  asin :: RF n -> RF n
asin = (Ptr CArb -> Ptr CArb -> CLong -> IO ()) -> RF n -> RF n
forall (n :: Nat).
KnownNat n =>
(Ptr CArb -> Ptr CArb -> CLong -> IO ()) -> RF n -> RF n
liftF1 Ptr CArb -> Ptr CArb -> CLong -> IO ()
arb_asin
  acos :: RF n -> RF n
acos = (Ptr CArb -> Ptr CArb -> CLong -> IO ()) -> RF n -> RF n
forall (n :: Nat).
KnownNat n =>
(Ptr CArb -> Ptr CArb -> CLong -> IO ()) -> RF n -> RF n
liftF1 Ptr CArb -> Ptr CArb -> CLong -> IO ()
arb_acos
  atan :: RF n -> RF n
atan = (Ptr CArb -> Ptr CArb -> CLong -> IO ()) -> RF n -> RF n
forall (n :: Nat).
KnownNat n =>
(Ptr CArb -> Ptr CArb -> CLong -> IO ()) -> RF n -> RF n
liftF1 Ptr CArb -> Ptr CArb -> CLong -> IO ()
arb_atan
  sinh :: RF n -> RF n
sinh = (Ptr CArb -> Ptr CArb -> CLong -> IO ()) -> RF n -> RF n
forall (n :: Nat).
KnownNat n =>
(Ptr CArb -> Ptr CArb -> CLong -> IO ()) -> RF n -> RF n
liftF1 Ptr CArb -> Ptr CArb -> CLong -> IO ()
arb_sinh
  cosh :: RF n -> RF n
cosh = (Ptr CArb -> Ptr CArb -> CLong -> IO ()) -> RF n -> RF n
forall (n :: Nat).
KnownNat n =>
(Ptr CArb -> Ptr CArb -> CLong -> IO ()) -> RF n -> RF n
liftF1 Ptr CArb -> Ptr CArb -> CLong -> IO ()
arb_cosh
  tanh :: RF n -> RF n
tanh = (Ptr CArb -> Ptr CArb -> CLong -> IO ()) -> RF n -> RF n
forall (n :: Nat).
KnownNat n =>
(Ptr CArb -> Ptr CArb -> CLong -> IO ()) -> RF n -> RF n
liftF1 Ptr CArb -> Ptr CArb -> CLong -> IO ()
arb_tanh
  asinh :: RF n -> RF n
asinh = (Ptr CArb -> Ptr CArb -> CLong -> IO ()) -> RF n -> RF n
forall (n :: Nat).
KnownNat n =>
(Ptr CArb -> Ptr CArb -> CLong -> IO ()) -> RF n -> RF n
liftF1 Ptr CArb -> Ptr CArb -> CLong -> IO ()
arb_asinh
  acosh :: RF n -> RF n
acosh = (Ptr CArb -> Ptr CArb -> CLong -> IO ()) -> RF n -> RF n
forall (n :: Nat).
KnownNat n =>
(Ptr CArb -> Ptr CArb -> CLong -> IO ()) -> RF n -> RF n
liftF1 Ptr CArb -> Ptr CArb -> CLong -> IO ()
arb_acosh
  atanh :: RF n -> RF n
atanh = (Ptr CArb -> Ptr CArb -> CLong -> IO ()) -> RF n -> RF n
forall (n :: Nat).
KnownNat n =>
(Ptr CArb -> Ptr CArb -> CLong -> IO ()) -> RF n -> RF n
liftF1 Ptr CArb -> Ptr CArb -> CLong -> IO ()
arb_atanh
  
instance forall n. KnownNat n => Show (RF n) where
  show :: RF n -> String
show (RF Arb
x) = IO String -> String
forall a. IO a -> a
unsafePerformIO (IO String -> String) -> IO String -> String
forall a b. (a -> b) -> a -> b
$ do
    let prec :: Integer
prec = Integer -> Integer
forall a. Num a => Integer -> a
fromInteger (Integer -> Integer) -> Integer -> Integer
forall a b. (a -> b) -> a -> b
$ Proxy n -> Integer
forall (n :: Nat) (proxy :: Nat -> *).
KnownNat n =>
proxy n -> Integer
natVal (Proxy n
forall {k} (t :: k). Proxy t
Proxy :: Proxy n)
        digits :: Integer
digits = Double -> Integer
forall b. Integral b => Double -> b
forall a b. (RealFrac a, Integral b) => a -> b
floor (Integer -> Double
forall a b. (Integral a, Num b) => a -> b
fromIntegral Integer
prec Double -> Double -> Double
forall a. Num a => a -> a -> a
* Double -> Double -> Double
forall a. Floating a => a -> a -> a
logBase Double
10 Double
2)
    (Arb
_, CString
cstr) <- Arb -> (Ptr CArb -> IO CString) -> IO (Arb, CString)
forall {a}. Arb -> (Ptr CArb -> IO a) -> IO (Arb, a)
withArb Arb
x ((Ptr CArb -> IO CString) -> IO (Arb, CString))
-> (Ptr CArb -> IO CString) -> IO (Arb, CString)
forall a b. (a -> b) -> a -> b
$ \Ptr CArb
p ->
      Ptr CArb -> CLong -> ArbStrOption -> IO CString
arb_get_str Ptr CArb
p (Integer -> CLong
forall a b. (Integral a, Num b) => a -> b
fromIntegral Integer
digits) ArbStrOption
arb_str_no_radius
    String
str <- CString -> IO String
peekCString CString
cstr
    String -> IO String
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return String
str

instance forall n. KnownNat n => Read (RF n) where
  readPrec :: ReadPrec (RF n)
readPrec     = (Lexeme -> ReadPrec (RF n)) -> ReadPrec (RF n)
forall a. Num a => (Lexeme -> ReadPrec a) -> ReadPrec a
readNumber Lexeme -> ReadPrec (RF n)
forall a. RealFloat a => Lexeme -> ReadPrec a
convertFrac
  readListPrec :: ReadPrec [RF n]
readListPrec = ReadPrec [RF n]
forall a. Read a => ReadPrec [a]
readListPrecDefault
  readList :: ReadS [RF n]
readList     = ReadS [RF n]
forall a. Read a => ReadS [a]
readListDefault

convertFrac :: RealFloat a => Lex.Lexeme -> ReadPrec a
convertFrac :: forall a. RealFloat a => Lexeme -> ReadPrec a
convertFrac (Lex.Ident String
"NaN")      = a -> ReadPrec a
forall a. a -> ReadPrec a
forall (m :: * -> *) a. Monad m => a -> m a
return (a
0 a -> a -> a
forall a. Fractional a => a -> a -> a
/ a
0)
convertFrac (Lex.Ident String
"Infinity") = a -> ReadPrec a
forall a. a -> ReadPrec a
forall (m :: * -> *) a. Monad m => a -> m a
return (a
1 a -> a -> a
forall a. Fractional a => a -> a -> a
/ a
0)
convertFrac (Lex.Number Number
n) = let resRange :: (Int, Int)
resRange = Double -> (Int, Int)
forall a. RealFloat a => a -> (Int, Int)
floatRange (a
forall {a}. a
forall a. HasCallStack => a
undefined :: a)
                           in case (Int, Int) -> Number -> Maybe Rational
Lex.numberToRangedRational (Int, Int)
resRange Number
n of
                              Maybe Rational
Nothing -> a -> ReadPrec a
forall a. a -> ReadPrec a
forall (m :: * -> *) a. Monad m => a -> m a
return (a
1 a -> a -> a
forall a. Fractional a => a -> a -> a
/ a
0)
                              Just Rational
rat -> a -> ReadPrec a
forall a. a -> ReadPrec a
forall (m :: * -> *) a. Monad m => a -> m a
return (a -> ReadPrec a) -> a -> ReadPrec a
forall a b. (a -> b) -> a -> b
$ Rational -> a
forall a. Fractional a => Rational -> a
fromRational Rational
rat
convertFrac Lexeme
_            = ReadPrec a
forall a. ReadPrec a
pfail

------------------------------------------------------------------------

instance forall n. KnownNat n => Special (RF n) where
  gamma :: RF n -> RF n
gamma = (Ptr CArb -> Ptr CArb -> CLong -> IO ()) -> RF n -> RF n
forall (n :: Nat).
KnownNat n =>
(Ptr CArb -> Ptr CArb -> CLong -> IO ()) -> RF n -> RF n
liftF1 Ptr CArb -> Ptr CArb -> CLong -> IO ()
arb_gamma
  digamma :: RF n -> RF n
digamma = (Ptr CArb -> Ptr CArb -> CLong -> IO ()) -> RF n -> RF n
forall (n :: Nat).
KnownNat n =>
(Ptr CArb -> Ptr CArb -> CLong -> IO ()) -> RF n -> RF n
liftF1 Ptr CArb -> Ptr CArb -> CLong -> IO ()
arb_digamma
  lgamma :: RF n -> RF n
lgamma = (Ptr CArb -> Ptr CArb -> CLong -> IO ()) -> RF n -> RF n
forall (n :: Nat).
KnownNat n =>
(Ptr CArb -> Ptr CArb -> CLong -> IO ()) -> RF n -> RF n
liftF1 Ptr CArb -> Ptr CArb -> CLong -> IO ()
arb_hypgeom_lgamma
  zeta :: RF n -> RF n
zeta = (Ptr CArb -> Ptr CArb -> CLong -> IO ()) -> RF n -> RF n
forall (n :: Nat).
KnownNat n =>
(Ptr CArb -> Ptr CArb -> CLong -> IO ()) -> RF n -> RF n
liftF1 Ptr CArb -> Ptr CArb -> CLong -> IO ()
arb_zeta
  erf :: RF n -> RF n
erf = (Ptr CArb -> Ptr CArb -> CLong -> IO ()) -> RF n -> RF n
forall (n :: Nat).
KnownNat n =>
(Ptr CArb -> Ptr CArb -> CLong -> IO ()) -> RF n -> RF n
liftF1 Ptr CArb -> Ptr CArb -> CLong -> IO ()
arb_hypgeom_erf
  airy :: RF n -> (RF n, RF n, RF n, RF n)
airy (RF Arb
x) = IO (RF n, RF n, RF n, RF n) -> (RF n, RF n, RF n, RF n)
forall a. IO a -> a
unsafePerformIO (IO (RF n, RF n, RF n, RF n) -> (RF n, RF n, RF n, RF n))
-> IO (RF n, RF n, RF n, RF n) -> (RF n, RF n, RF n, RF n)
forall a b. (a -> b) -> a -> b
$ do
    let prec :: CLong
prec = Integer -> CLong
forall a. Num a => Integer -> a
fromInteger (Integer -> CLong) -> Integer -> CLong
forall a b. (a -> b) -> a -> b
$ Proxy n -> Integer
forall (n :: Nat) (proxy :: Nat -> *).
KnownNat n =>
proxy n -> Integer
natVal (Proxy n
forall {k} (t :: k). Proxy t
Proxy :: Proxy n)
    Arb
ai <- IO Arb
newArb
    Arb
ai' <- IO Arb
newArb
    Arb
bi <- IO Arb
newArb
    Arb
bi' <- IO Arb
newArb
    Arb
-> (Ptr CArb -> IO (Arb, (Arb, (Arb, (Arb, ())))))
-> IO (Arb, (Arb, (Arb, (Arb, (Arb, ())))))
forall {a}. Arb -> (Ptr CArb -> IO a) -> IO (Arb, a)
withArb Arb
x ((Ptr CArb -> IO (Arb, (Arb, (Arb, (Arb, ())))))
 -> IO (Arb, (Arb, (Arb, (Arb, (Arb, ()))))))
-> (Ptr CArb -> IO (Arb, (Arb, (Arb, (Arb, ())))))
-> IO (Arb, (Arb, (Arb, (Arb, (Arb, ())))))
forall a b. (a -> b) -> a -> b
$ \Ptr CArb
x -> 
      Arb
-> (Ptr CArb -> IO (Arb, (Arb, (Arb, ()))))
-> IO (Arb, (Arb, (Arb, (Arb, ()))))
forall {a}. Arb -> (Ptr CArb -> IO a) -> IO (Arb, a)
withArb Arb
ai ((Ptr CArb -> IO (Arb, (Arb, (Arb, ()))))
 -> IO (Arb, (Arb, (Arb, (Arb, ())))))
-> (Ptr CArb -> IO (Arb, (Arb, (Arb, ()))))
-> IO (Arb, (Arb, (Arb, (Arb, ()))))
forall a b. (a -> b) -> a -> b
$ \Ptr CArb
ai -> 
        Arb
-> (Ptr CArb -> IO (Arb, (Arb, ()))) -> IO (Arb, (Arb, (Arb, ())))
forall {a}. Arb -> (Ptr CArb -> IO a) -> IO (Arb, a)
withArb Arb
ai' ((Ptr CArb -> IO (Arb, (Arb, ()))) -> IO (Arb, (Arb, (Arb, ()))))
-> (Ptr CArb -> IO (Arb, (Arb, ()))) -> IO (Arb, (Arb, (Arb, ())))
forall a b. (a -> b) -> a -> b
$ \Ptr CArb
ai' ->
          Arb -> (Ptr CArb -> IO (Arb, ())) -> IO (Arb, (Arb, ()))
forall {a}. Arb -> (Ptr CArb -> IO a) -> IO (Arb, a)
withArb Arb
bi ((Ptr CArb -> IO (Arb, ())) -> IO (Arb, (Arb, ())))
-> (Ptr CArb -> IO (Arb, ())) -> IO (Arb, (Arb, ()))
forall a b. (a -> b) -> a -> b
$ \Ptr CArb
bi ->
            Arb -> (Ptr CArb -> IO ()) -> IO (Arb, ())
forall {a}. Arb -> (Ptr CArb -> IO a) -> IO (Arb, a)
withArb Arb
bi' ((Ptr CArb -> IO ()) -> IO (Arb, ()))
-> (Ptr CArb -> IO ()) -> IO (Arb, ())
forall a b. (a -> b) -> a -> b
$ \Ptr CArb
bi' ->
              Ptr CArb -> Ptr CArb -> Binary
arb_hypgeom_airy Ptr CArb
ai Ptr CArb
ai' Ptr CArb
bi Ptr CArb
bi' Ptr CArb
x CLong
prec
    (RF n, RF n, RF n, RF n) -> IO (RF n, RF n, RF n, RF n)
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return ((RF n, RF n, RF n, RF n) -> IO (RF n, RF n, RF n, RF n))
-> (RF n, RF n, RF n, RF n) -> IO (RF n, RF n, RF n, RF n)
forall a b. (a -> b) -> a -> b
$ (Arb -> RF n
forall (n :: Nat). Arb -> RF n
RF Arb
ai, Arb -> RF n
forall (n :: Nat). Arb -> RF n
RF Arb
ai', Arb -> RF n
forall (n :: Nat). Arb -> RF n
RF Arb
bi, Arb -> RF n
forall (n :: Nat). Arb -> RF n
RF Arb
bi')
  airyZeros :: Fmpz -> (RF n, RF n, RF n, RF n)
airyZeros Fmpz
k = IO (RF n, RF n, RF n, RF n) -> (RF n, RF n, RF n, RF n)
forall a. IO a -> a
unsafePerformIO (IO (RF n, RF n, RF n, RF n) -> (RF n, RF n, RF n, RF n))
-> IO (RF n, RF n, RF n, RF n) -> (RF n, RF n, RF n, RF n)
forall a b. (a -> b) -> a -> b
$ do
    let prec :: CLong
prec = Integer -> CLong
forall a. Num a => Integer -> a
fromInteger (Integer -> CLong) -> Integer -> CLong
forall a b. (a -> b) -> a -> b
$ Proxy n -> Integer
forall (n :: Nat) (proxy :: Nat -> *).
KnownNat n =>
proxy n -> Integer
natVal (Proxy n
forall {k} (t :: k). Proxy t
Proxy :: Proxy n)
    Arb
ai <- IO Arb
newArb
    Arb
ai' <- IO Arb
newArb
    Arb
bi <- IO Arb
newArb
    Arb
bi' <- IO Arb
newArb
    Fmpz
-> (Ptr CFmpz -> IO (Arb, (Arb, (Arb, (Arb, ())))))
-> IO (Fmpz, (Arb, (Arb, (Arb, (Arb, ())))))
forall {a}. Fmpz -> (Ptr CFmpz -> IO a) -> IO (Fmpz, a)
withFmpz Fmpz
k ((Ptr CFmpz -> IO (Arb, (Arb, (Arb, (Arb, ())))))
 -> IO (Fmpz, (Arb, (Arb, (Arb, (Arb, ()))))))
-> (Ptr CFmpz -> IO (Arb, (Arb, (Arb, (Arb, ())))))
-> IO (Fmpz, (Arb, (Arb, (Arb, (Arb, ())))))
forall a b. (a -> b) -> a -> b
$ \Ptr CFmpz
k -> 
      Arb
-> (Ptr CArb -> IO (Arb, (Arb, (Arb, ()))))
-> IO (Arb, (Arb, (Arb, (Arb, ()))))
forall {a}. Arb -> (Ptr CArb -> IO a) -> IO (Arb, a)
withArb Arb
ai ((Ptr CArb -> IO (Arb, (Arb, (Arb, ()))))
 -> IO (Arb, (Arb, (Arb, (Arb, ())))))
-> (Ptr CArb -> IO (Arb, (Arb, (Arb, ()))))
-> IO (Arb, (Arb, (Arb, (Arb, ()))))
forall a b. (a -> b) -> a -> b
$ \Ptr CArb
ai -> 
        Arb
-> (Ptr CArb -> IO (Arb, (Arb, ()))) -> IO (Arb, (Arb, (Arb, ())))
forall {a}. Arb -> (Ptr CArb -> IO a) -> IO (Arb, a)
withArb Arb
ai' ((Ptr CArb -> IO (Arb, (Arb, ()))) -> IO (Arb, (Arb, (Arb, ()))))
-> (Ptr CArb -> IO (Arb, (Arb, ()))) -> IO (Arb, (Arb, (Arb, ())))
forall a b. (a -> b) -> a -> b
$ \Ptr CArb
ai' ->
          Arb -> (Ptr CArb -> IO (Arb, ())) -> IO (Arb, (Arb, ()))
forall {a}. Arb -> (Ptr CArb -> IO a) -> IO (Arb, a)
withArb Arb
bi ((Ptr CArb -> IO (Arb, ())) -> IO (Arb, (Arb, ())))
-> (Ptr CArb -> IO (Arb, ())) -> IO (Arb, (Arb, ()))
forall a b. (a -> b) -> a -> b
$ \Ptr CArb
bi ->
            Arb -> (Ptr CArb -> IO ()) -> IO (Arb, ())
forall {a}. Arb -> (Ptr CArb -> IO a) -> IO (Arb, a)
withArb Arb
bi' ((Ptr CArb -> IO ()) -> IO (Arb, ()))
-> (Ptr CArb -> IO ()) -> IO (Arb, ())
forall a b. (a -> b) -> a -> b
$ \Ptr CArb
bi' ->
              Ptr CArb
-> Ptr CArb -> Ptr CArb -> Ptr CArb -> Ptr CFmpz -> CLong -> IO ()
arb_hypgeom_airy_zero Ptr CArb
ai Ptr CArb
ai' Ptr CArb
bi Ptr CArb
bi' Ptr CFmpz
k CLong
prec
    (RF n, RF n, RF n, RF n) -> IO (RF n, RF n, RF n, RF n)
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return ((RF n, RF n, RF n, RF n) -> IO (RF n, RF n, RF n, RF n))
-> (RF n, RF n, RF n, RF n) -> IO (RF n, RF n, RF n, RF n)
forall a b. (a -> b) -> a -> b
$ (Arb -> RF n
forall (n :: Nat). Arb -> RF n
RF Arb
ai, Arb -> RF n
forall (n :: Nat). Arb -> RF n
RF Arb
ai', Arb -> RF n
forall (n :: Nat). Arb -> RF n
RF Arb
bi, Arb -> RF n
forall (n :: Nat). Arb -> RF n
RF Arb
bi')
  besselJ :: RF n -> RF n -> RF n
besselJ = Binary -> RF n -> RF n -> RF n
forall (n :: Nat). KnownNat n => Binary -> RF n -> RF n -> RF n
lift2 Binary
arb_hypgeom_bessel_j
  besselY :: RF n -> RF n -> RF n
besselY = Binary -> RF n -> RF n -> RF n
forall (n :: Nat). KnownNat n => Binary -> RF n -> RF n -> RF n
lift2 Binary
arb_hypgeom_bessel_y
  besselI :: RF n -> RF n -> RF n
besselI = Binary -> RF n -> RF n -> RF n
forall (n :: Nat). KnownNat n => Binary -> RF n -> RF n -> RF n
lift2 Binary
arb_hypgeom_bessel_i
  besselK :: RF n -> RF n -> RF n
besselK = Binary -> RF n -> RF n -> RF n
forall (n :: Nat). KnownNat n => Binary -> RF n -> RF n -> RF n
lift2 Binary
arb_hypgeom_bessel_k
  modj :: RF n -> RF n
modj = RF n -> RF n
forall a. HasCallStack => a
undefined
  modjq :: RF n -> RF n
modjq = RF n -> RF n
forall a. HasCallStack => a
undefined
  modeta :: RF n -> RF n
modeta = RF n -> RF n
forall a. HasCallStack => a
undefined
  modetaq :: RF n -> RF n
modetaq = RF n -> RF n
forall a. HasCallStack => a
undefined
  modlambda :: RF n -> RF n
modlambda = RF n -> RF n
forall a. HasCallStack => a
undefined
  modlambdaq :: RF n -> RF n
modlambdaq = RF n -> RF n
forall a. HasCallStack => a
undefined
  ellipp :: RF n -> RF n -> RF n
ellipp = RF n -> RF n -> RF n
forall a. HasCallStack => a
undefined
  ellipzeta :: RF n -> RF n -> RF n
ellipzeta = RF n -> RF n -> RF n
forall a. HasCallStack => a
undefined
  ellipsigma :: RF n -> RF n -> RF n
ellipsigma = RF n -> RF n -> RF n
forall a. HasCallStack => a
undefined
  barnesg :: RF n -> RF n
barnesg = RF n -> RF n
forall a. HasCallStack => a
undefined
  agm :: RF n -> RF n -> RF n
agm = RF n -> RF n -> RF n
forall a. HasCallStack => a
undefined
  fresnels :: RF n -> RF n
fresnels = RF n -> RF n
forall a. HasCallStack => a
undefined
  fresnelc :: RF n -> RF n
fresnelc = RF n -> RF n
forall a. HasCallStack => a
undefined
  
class RF' a where
  euler :: a
  glaisher :: a
  catalan :: a
  khinchin :: a
  polylog :: a -> a -> a
  midPoint :: a -> a
  
instance forall n. KnownNat n => RF' (RF n) where
  euler :: RF n
euler = (Ptr CArb -> CLong -> IO ()) -> RF n
forall (n :: Nat).
KnownNat n =>
(Ptr CArb -> CLong -> IO ()) -> RF n
liftConstant Ptr CArb -> CLong -> IO ()
arb_const_euler
  glaisher :: RF n
glaisher = (Ptr CArb -> CLong -> IO ()) -> RF n
forall (n :: Nat).
KnownNat n =>
(Ptr CArb -> CLong -> IO ()) -> RF n
liftConstant Ptr CArb -> CLong -> IO ()
arb_const_glaisher
  catalan :: RF n
catalan = (Ptr CArb -> CLong -> IO ()) -> RF n
forall (n :: Nat).
KnownNat n =>
(Ptr CArb -> CLong -> IO ()) -> RF n
liftConstant Ptr CArb -> CLong -> IO ()
arb_const_catalan
  khinchin :: RF n
khinchin = (Ptr CArb -> CLong -> IO ()) -> RF n
forall (n :: Nat).
KnownNat n =>
(Ptr CArb -> CLong -> IO ()) -> RF n
liftConstant Ptr CArb -> CLong -> IO ()
arb_const_khinchin
  polylog :: RF n -> RF n -> RF n
polylog = Binary -> RF n -> RF n -> RF n
forall (n :: Nat). KnownNat n => Binary -> RF n -> RF n -> RF n
lift2 Binary
arb_polylog
  midPoint :: RF n -> RF n
midPoint = Function -> RF n -> RF n
forall (n :: Nat). KnownNat n => Function -> RF n -> RF n
lift1 Function
arb_get_mid_arb

fromDouble ::  forall n. KnownNat n => Double -> RF n
fromDouble :: forall (n :: Nat). KnownNat n => Double -> RF n
fromDouble Double
x = IO (RF n) -> RF n
forall a. IO a -> a
unsafePerformIO (IO (RF n) -> RF n) -> IO (RF n) -> RF n
forall a b. (a -> b) -> a -> b
$ do
  Arb
res <- IO Arb
newArb
  Arb -> (Ptr CArb -> IO ()) -> IO (Arb, ())
forall {a}. Arb -> (Ptr CArb -> IO a) -> IO (Arb, a)
withArb Arb
res ((Ptr CArb -> IO ()) -> IO (Arb, ()))
-> (Ptr CArb -> IO ()) -> IO (Arb, ())
forall a b. (a -> b) -> a -> b
$ \Ptr CArb
res -> Ptr CArb -> CDouble -> IO ()
arb_set_d Ptr CArb
res (Double -> CDouble
forall a b. (Real a, Fractional b) => a -> b
realToFrac Double
x)
  RF n -> IO (RF n)
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (RF n -> IO (RF n)) -> RF n -> IO (RF n)
forall a b. (a -> b) -> a -> b
$ Arb -> RF n
forall (n :: Nat). Arb -> RF n
RF Arb
res
  
toDouble :: forall n. KnownNat n => RF n -> Double
toDouble :: forall (n :: Nat). KnownNat n => RF n -> Double
toDouble RF n
x = Rational -> Double
forall a. Fractional a => Rational -> a
fromRational (Rational -> Double) -> Rational -> Double
forall a b. (a -> b) -> a -> b
$ RF n -> Rational
forall a. Real a => a -> Rational
toRational RF n
x
    
-- lifting -------------------------------------------------------------

type Binary = Ptr CArb -> Ptr CArb -> Ptr CArb -> CLong -> IO ()
type Cmp = Ptr CArb -> Ptr CArb -> IO CInt
type Function = Ptr CArb -> Ptr CArb -> IO ()

lift2 :: forall n. KnownNat n => Binary -> RF n -> RF n -> RF n
lift2 :: forall (n :: Nat). KnownNat n => Binary -> RF n -> RF n -> RF n
lift2 Binary
f (RF Arb
a) (RF Arb
b) = IO (RF n) -> RF n
forall a. IO a -> a
unsafePerformIO (IO (RF n) -> RF n) -> IO (RF n) -> RF n
forall a b. (a -> b) -> a -> b
$ do
  let prec :: Int64
prec = Integer -> Int64
forall a. Num a => Integer -> a
fromInteger (Integer -> Int64) -> Integer -> Int64
forall a b. (a -> b) -> a -> b
$ Proxy n -> Integer
forall (n :: Nat) (proxy :: Nat -> *).
KnownNat n =>
proxy n -> Integer
natVal (Proxy n
forall {k} (t :: k). Proxy t
Proxy :: Proxy n)
  Arb
c <- IO Arb
newArb
  Arb
-> (Ptr CArb -> IO (Arb, (Arb, ()))) -> IO (Arb, (Arb, (Arb, ())))
forall {a}. Arb -> (Ptr CArb -> IO a) -> IO (Arb, a)
withArb Arb
a ((Ptr CArb -> IO (Arb, (Arb, ()))) -> IO (Arb, (Arb, (Arb, ()))))
-> (Ptr CArb -> IO (Arb, (Arb, ()))) -> IO (Arb, (Arb, (Arb, ())))
forall a b. (a -> b) -> a -> b
$ \Ptr CArb
a ->
    Arb -> (Ptr CArb -> IO (Arb, ())) -> IO (Arb, (Arb, ()))
forall {a}. Arb -> (Ptr CArb -> IO a) -> IO (Arb, a)
withArb Arb
b ((Ptr CArb -> IO (Arb, ())) -> IO (Arb, (Arb, ())))
-> (Ptr CArb -> IO (Arb, ())) -> IO (Arb, (Arb, ()))
forall a b. (a -> b) -> a -> b
$ \Ptr CArb
b ->
      Arb -> (Ptr CArb -> IO ()) -> IO (Arb, ())
forall {a}. Arb -> (Ptr CArb -> IO a) -> IO (Arb, a)
withArb Arb
c ((Ptr CArb -> IO ()) -> IO (Arb, ()))
-> (Ptr CArb -> IO ()) -> IO (Arb, ())
forall a b. (a -> b) -> a -> b
$ \Ptr CArb
c ->
        Binary
f Ptr CArb
c Ptr CArb
a Ptr CArb
b (Int64 -> CLong
CLong Int64
prec)
  RF n -> IO (RF n)
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Arb -> RF n
forall (n :: Nat). Arb -> RF n
RF Arb
c)

lift1 :: forall n. KnownNat n => Function -> RF n -> RF n
lift1 :: forall (n :: Nat). KnownNat n => Function -> RF n -> RF n
lift1 Function
f (RF Arb
x) = IO (RF n) -> RF n
forall a. IO a -> a
unsafePerformIO (IO (RF n) -> RF n) -> IO (RF n) -> RF n
forall a b. (a -> b) -> a -> b
$ do
  Arb
y <- IO Arb
newArb
  Arb -> (Ptr CArb -> IO (Arb, ())) -> IO (Arb, (Arb, ()))
forall {a}. Arb -> (Ptr CArb -> IO a) -> IO (Arb, a)
withArb Arb
x ((Ptr CArb -> IO (Arb, ())) -> IO (Arb, (Arb, ())))
-> (Ptr CArb -> IO (Arb, ())) -> IO (Arb, (Arb, ()))
forall a b. (a -> b) -> a -> b
$ \Ptr CArb
x -> Arb -> (Ptr CArb -> IO ()) -> IO (Arb, ())
forall {a}. Arb -> (Ptr CArb -> IO a) -> IO (Arb, a)
withArb Arb
y ((Ptr CArb -> IO ()) -> IO (Arb, ()))
-> (Ptr CArb -> IO ()) -> IO (Arb, ())
forall a b. (a -> b) -> a -> b
$ \Ptr CArb
y -> Function
f Ptr CArb
y Ptr CArb
x
  RF n -> IO (RF n)
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Arb -> RF n
forall (n :: Nat). Arb -> RF n
RF Arb
y)
  
lift0 :: (Ptr CArb -> p -> IO b) -> p -> RF n
lift0 Ptr CArb -> p -> IO b
f p
x = Arb -> RF n
forall (n :: Nat). Arb -> RF n
RF (Arb -> RF n) -> Arb -> RF n
forall a b. (a -> b) -> a -> b
$ IO Arb -> Arb
forall a. IO a -> a
unsafePerformIO (IO Arb -> Arb) -> IO Arb -> Arb
forall a b. (a -> b) -> a -> b
$ (Arb, b) -> Arb
forall a b. (a, b) -> a
fst ((Arb, b) -> Arb) -> IO (Arb, b) -> IO Arb
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Ptr CArb -> IO b) -> IO (Arb, b)
forall {a}. (Ptr CArb -> IO a) -> IO (Arb, a)
withNewArb (Ptr CArb -> p -> IO b
`f` p
x)
  
liftF1 :: forall n. KnownNat n =>
  (Ptr CArb -> Ptr CArb -> CLong -> IO ()) -> RF n -> RF n
liftF1 :: forall (n :: Nat).
KnownNat n =>
(Ptr CArb -> Ptr CArb -> CLong -> IO ()) -> RF n -> RF n
liftF1 Ptr CArb -> Ptr CArb -> CLong -> IO ()
f (RF Arb
x) = IO (RF n) -> RF n
forall a. IO a -> a
unsafePerformIO (IO (RF n) -> RF n) -> IO (RF n) -> RF n
forall a b. (a -> b) -> a -> b
$ do
  let prec :: Int64
prec = Integer -> Int64
forall a. Num a => Integer -> a
fromInteger (Integer -> Int64) -> Integer -> Int64
forall a b. (a -> b) -> a -> b
$ Proxy n -> Integer
forall (n :: Nat) (proxy :: Nat -> *).
KnownNat n =>
proxy n -> Integer
natVal (Proxy n
forall {k} (t :: k). Proxy t
Proxy :: Proxy n)
  Arb
y <- IO Arb
newArb
  Arb -> (Ptr CArb -> IO (Arb, ())) -> IO (Arb, (Arb, ()))
forall {a}. Arb -> (Ptr CArb -> IO a) -> IO (Arb, a)
withArb Arb
x ((Ptr CArb -> IO (Arb, ())) -> IO (Arb, (Arb, ())))
-> (Ptr CArb -> IO (Arb, ())) -> IO (Arb, (Arb, ()))
forall a b. (a -> b) -> a -> b
$ \Ptr CArb
x -> Arb -> (Ptr CArb -> IO ()) -> IO (Arb, ())
forall {a}. Arb -> (Ptr CArb -> IO a) -> IO (Arb, a)
withArb Arb
y ((Ptr CArb -> IO ()) -> IO (Arb, ()))
-> (Ptr CArb -> IO ()) -> IO (Arb, ())
forall a b. (a -> b) -> a -> b
$ \Ptr CArb
y -> Ptr CArb -> Ptr CArb -> CLong -> IO ()
f Ptr CArb
y Ptr CArb
x (Int64 -> CLong
CLong Int64
prec)
  RF n -> IO (RF n)
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Arb -> RF n
forall (n :: Nat). Arb -> RF n
RF Arb
y)

liftCmp :: forall n. KnownNat n => Cmp -> RF n -> RF n -> Bool
liftCmp :: forall (n :: Nat). KnownNat n => Cmp -> RF n -> RF n -> Bool
liftCmp Cmp
f (RF Arb
x) (RF Arb
y) = IO Bool -> Bool
forall a. IO a -> a
unsafePerformIO (IO Bool -> Bool) -> IO Bool -> Bool
forall a b. (a -> b) -> a -> b
$ do
  (Arb
_, (Arb
_, CInt
cmp)) <- Arb -> (Ptr CArb -> IO (Arb, CInt)) -> IO (Arb, (Arb, CInt))
forall {a}. Arb -> (Ptr CArb -> IO a) -> IO (Arb, a)
withArb Arb
x ((Ptr CArb -> IO (Arb, CInt)) -> IO (Arb, (Arb, CInt)))
-> (Ptr CArb -> IO (Arb, CInt)) -> IO (Arb, (Arb, CInt))
forall a b. (a -> b) -> a -> b
$ \Ptr CArb
x -> Arb -> (Ptr CArb -> IO CInt) -> IO (Arb, CInt)
forall {a}. Arb -> (Ptr CArb -> IO a) -> IO (Arb, a)
withArb Arb
y ((Ptr CArb -> IO CInt) -> IO (Arb, CInt))
-> (Ptr CArb -> IO CInt) -> IO (Arb, CInt)
forall a b. (a -> b) -> a -> b
$ \Ptr CArb
y -> Cmp
f Ptr CArb
x Ptr CArb
y
  Bool -> IO Bool
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (CInt
cmp CInt -> CInt -> Bool
forall a. Eq a => a -> a -> Bool
== CInt
1)

liftProp :: forall n. KnownNat n => (Ptr CArb -> IO CInt) -> RF n -> Bool
liftProp :: forall (n :: Nat).
KnownNat n =>
(Ptr CArb -> IO CInt) -> RF n -> Bool
liftProp Ptr CArb -> IO CInt
f (RF Arb
x)  = IO Bool -> Bool
forall a. IO a -> a
unsafePerformIO (IO Bool -> Bool) -> IO Bool -> Bool
forall a b. (a -> b) -> a -> b
$ do
  (Arb
_, CInt
prop) <- Arb -> (Ptr CArb -> IO CInt) -> IO (Arb, CInt)
forall {a}. Arb -> (Ptr CArb -> IO a) -> IO (Arb, a)
withArb Arb
x ((Ptr CArb -> IO CInt) -> IO (Arb, CInt))
-> (Ptr CArb -> IO CInt) -> IO (Arb, CInt)
forall a b. (a -> b) -> a -> b
$ \Ptr CArb
x -> Ptr CArb -> IO CInt
f Ptr CArb
x
  Bool -> IO Bool
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (CInt
prop CInt -> CInt -> Bool
forall a. Eq a => a -> a -> Bool
== CInt
1)

liftConstant :: forall n. KnownNat n => (Ptr CArb -> CLong -> IO ()) -> RF n
liftConstant :: forall (n :: Nat).
KnownNat n =>
(Ptr CArb -> CLong -> IO ()) -> RF n
liftConstant Ptr CArb -> CLong -> IO ()
f = Arb -> RF n
forall (n :: Nat). Arb -> RF n
RF (Arb -> RF n) -> Arb -> RF n
forall a b. (a -> b) -> a -> b
$ IO Arb -> Arb
forall a. IO a -> a
unsafePerformIO (IO Arb -> Arb) -> IO Arb -> Arb
forall a b. (a -> b) -> a -> b
$ do
  let prec :: Int64
prec = Integer -> Int64
forall a. Num a => Integer -> a
fromInteger (Integer -> Int64) -> Integer -> Int64
forall a b. (a -> b) -> a -> b
$ Proxy n -> Integer
forall (n :: Nat) (proxy :: Nat -> *).
KnownNat n =>
proxy n -> Integer
natVal (Proxy n
forall {k} (t :: k). Proxy t
Proxy :: Proxy n)
  (Arb, ()) -> Arb
forall a b. (a, b) -> a
fst ((Arb, ()) -> Arb) -> IO (Arb, ()) -> IO Arb
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Ptr CArb -> IO ()) -> IO (Arb, ())
forall {a}. (Ptr CArb -> IO a) -> IO (Arb, a)
withNewArb (Ptr CArb -> CLong -> IO ()
`f` Int64 -> CLong
CLong Int64
prec)

class Special a where
  gamma :: a -> a
  digamma :: a -> a
  lgamma :: a -> a
  zeta :: a -> a
  erf :: a -> a
  airy :: a -> (a, a, a, a)
  airyZeros :: Fmpz -> (a, a, a, a)
  besselJ :: a -> a -> a
  besselY :: a -> a -> a
  besselI :: a -> a -> a
  besselK :: a -> a -> a
  modj :: a -> a
  modjq :: a -> a
  modeta :: a -> a
  modetaq :: a -> a
  modlambda :: a -> a
  modlambdaq :: a -> a
  ellipp :: a -> a -> a
  ellipzeta :: a -> a -> a
  ellipsigma :: a -> a -> a
  barnesg :: a -> a
  agm :: a -> a -> a
  fresnels :: a -> a
  fresnelc :: a -> a