From 7cfba6b4eb311590986a888255cd1dc594bd7264 Mon Sep 17 00:00:00 2001 From: Alberto Ruiz Date: Wed, 20 Oct 2010 07:19:06 +0000 Subject: mkComplex_e and other complex special functions --- packages/special/lib/Numeric/GSL/Special.hs | 32 ++++++++++++++++++++++ packages/special/lib/Numeric/GSL/Special/Gamma.hs | 5 ++-- .../special/lib/Numeric/GSL/Special/Internal.hsc | 3 +- packages/special/lib/Numeric/GSL/Special/Log.hs | 5 ++-- packages/special/lib/Numeric/GSL/Special/Psi.hs | 5 ++-- packages/special/lib/Numeric/GSL/Special/Trig.hs | 25 ++++++++++------- 6 files changed, 57 insertions(+), 18 deletions(-) (limited to 'packages/special/lib') diff --git a/packages/special/lib/Numeric/GSL/Special.hs b/packages/special/lib/Numeric/GSL/Special.hs index a8bbaf6..2994efb 100644 --- a/packages/special/lib/Numeric/GSL/Special.hs +++ b/packages/special/lib/Numeric/GSL/Special.hs @@ -15,6 +15,7 @@ Wrappers for selected special functions. ----------------------------------------------------------------------------- module Numeric.GSL.Special ( + -- * Functions module Numeric.GSL.Special.Airy , module Numeric.GSL.Special.Bessel , module Numeric.GSL.Special.Clausen @@ -43,9 +44,12 @@ module Numeric.GSL.Special ( , module Numeric.GSL.Special.Transport , module Numeric.GSL.Special.Trig , module Numeric.GSL.Special.Zeta +-- * Util +, mkComplex_e ) where + import Numeric.GSL.Special.Airy import Numeric.GSL.Special.Bessel import Numeric.GSL.Special.Clausen @@ -74,3 +78,31 @@ import Numeric.GSL.Special.Synchrotron import Numeric.GSL.Special.Transport import Numeric.GSL.Special.Trig import Numeric.GSL.Special.Zeta + +import Data.Complex + +---------------------------------------------------------------- + +{- | Some GSL complex functions work with separate real and imaginary parts stored in real variables, obtaining tuples (value, error) for the real and imaginary parts of the result: + +> > import Numeric.GSL.Special.Dilog + +> > complex_dilog_xy_e 1 1 +> ((0.6168502750680847,1.1097853812294034e-14),(1.4603621167531193,1.1855504863267322e-14)) + +We can use @mkComplex_e@ to work with \"normal\" complex numbers: + +> > import Numeric.GSL.Special(mkComplex_e) +> > import Data.Complex + +> > let dilogC = fst . mkComplex_e complex_dilog_xy_e + +> > dilogC (1 :+ 1) +> 0.6168502750680847 :+ 1.4603621167531193 + +-} +mkComplex_e :: (Double -> Double -> ((Double, Double), (Double, Double))) + -> Complex Double -> (Complex Double, Complex Double) +mkComplex_e f (x :+ y) = (zr :+ zi, er :+ ei) + where ((zr,er),(zi,ei)) = f x y + diff --git a/packages/special/lib/Numeric/GSL/Special/Gamma.hs b/packages/special/lib/Numeric/GSL/Special/Gamma.hs index 03b39c4..1a4ed4e 100644 --- a/packages/special/lib/Numeric/GSL/Special/Gamma.hs +++ b/packages/special/lib/Numeric/GSL/Special/Gamma.hs @@ -21,6 +21,7 @@ module Numeric.GSL.Special.Gamma( , gammastar , gammainv_e , gammainv +, lngamma_complex_e , taylorcoeff_e , taylorcoeff , fact_e @@ -95,8 +96,8 @@ gammainv :: Double -> Double gammainv = gsl_sf_gammainv foreign import ccall SAFE_CHEAP "gsl_sf_gammainv" gsl_sf_gammainv :: Double -> Double -lngamma_complex_e :: Double -> Double -> Ptr () -> (Double,Double) -lngamma_complex_e zr zi lnr = createSFR "lngamma_complex_e" $ gsl_sf_lngamma_complex_e zr zi lnr +lngamma_complex_e :: Double -> Double -> ((Double,Double),(Double,Double)) +lngamma_complex_e zr zi = create2SFR "lngamma_complex_e" $ gsl_sf_lngamma_complex_e zr zi foreign import ccall SAFE_CHEAP "gsl_sf_lngamma_complex_e" gsl_sf_lngamma_complex_e :: Double -> Double -> Ptr () -> Ptr () -> IO CInt taylorcoeff_e :: CInt -> Double -> (Double,Double) diff --git a/packages/special/lib/Numeric/GSL/Special/Internal.hsc b/packages/special/lib/Numeric/GSL/Special/Internal.hsc index d1a9c57..ae735df 100644 --- a/packages/special/lib/Numeric/GSL/Special/Internal.hsc +++ b/packages/special/lib/Numeric/GSL/Special/Internal.hsc @@ -33,7 +33,6 @@ import Foreign import Data.Packed.Development(check,(//)) import Foreign.C.Types(CSize,CInt) - data Precision = PrecDouble | PrecSingle | PrecApprox precCode :: Precision -> Int @@ -90,7 +89,7 @@ createSFR s f = unsafePerformIO $ do return (val,err) ---------------------------------------------------------------- --- | access to two sf_result +-- | access to two sf_result's create2SFR :: String -> (Ptr a -> Ptr a -> IO CInt) -> ((Double, Double),(Double, Double)) create2SFR s f = unsafePerformIO $ do p1 <- malloc :: IO (Ptr Gsl_sf_result) diff --git a/packages/special/lib/Numeric/GSL/Special/Log.hs b/packages/special/lib/Numeric/GSL/Special/Log.hs index a57b67a..7f3f9d6 100644 --- a/packages/special/lib/Numeric/GSL/Special/Log.hs +++ b/packages/special/lib/Numeric/GSL/Special/Log.hs @@ -17,6 +17,7 @@ module Numeric.GSL.Special.Log( , Numeric.GSL.Special.Log.log , log_abs_e , log_abs +, complex_log_e , log_1plusx_e , log_1plusx , log_1plusx_mx_e @@ -43,8 +44,8 @@ log_abs :: Double -> Double log_abs = gsl_sf_log_abs foreign import ccall SAFE_CHEAP "gsl_sf_log_abs" gsl_sf_log_abs :: Double -> Double -complex_log_e :: Double -> Double -> Ptr () -> (Double,Double) -complex_log_e zr zi lnr = createSFR "complex_log_e" $ gsl_sf_complex_log_e zr zi lnr +complex_log_e :: Double -> Double -> ((Double,Double),(Double,Double)) +complex_log_e zr zi = create2SFR "complex_log_e" $ gsl_sf_complex_log_e zr zi foreign import ccall SAFE_CHEAP "gsl_sf_complex_log_e" gsl_sf_complex_log_e :: Double -> Double -> Ptr () -> Ptr () -> IO CInt log_1plusx_e :: Double -> (Double,Double) diff --git a/packages/special/lib/Numeric/GSL/Special/Psi.hs b/packages/special/lib/Numeric/GSL/Special/Psi.hs index 4655b8c..cb4c756 100644 --- a/packages/special/lib/Numeric/GSL/Special/Psi.hs +++ b/packages/special/lib/Numeric/GSL/Special/Psi.hs @@ -19,6 +19,7 @@ module Numeric.GSL.Special.Psi( , psi , psi_1piy_e , psi_1piy +, complex_psi_e , psi_1_int_e , psi_1_int , psi_1_e @@ -55,8 +56,8 @@ psi_1piy :: Double -> Double psi_1piy = gsl_sf_psi_1piy foreign import ccall SAFE_CHEAP "gsl_sf_psi_1piy" gsl_sf_psi_1piy :: Double -> Double -complex_psi_e :: Double -> Double -> Ptr () -> (Double,Double) -complex_psi_e x y result_re = createSFR "complex_psi_e" $ gsl_sf_complex_psi_e x y result_re +complex_psi_e :: Double -> Double -> ((Double,Double),(Double,Double)) +complex_psi_e x y = create2SFR "complex_psi_e" $ gsl_sf_complex_psi_e x y foreign import ccall SAFE_CHEAP "gsl_sf_complex_psi_e" gsl_sf_complex_psi_e :: Double -> Double -> Ptr () -> Ptr () -> IO CInt psi_1_int_e :: CInt -> (Double,Double) diff --git a/packages/special/lib/Numeric/GSL/Special/Trig.hs b/packages/special/lib/Numeric/GSL/Special/Trig.hs index 4b7ae67..91c264a 100644 --- a/packages/special/lib/Numeric/GSL/Special/Trig.hs +++ b/packages/special/lib/Numeric/GSL/Special/Trig.hs @@ -19,12 +19,17 @@ module Numeric.GSL.Special.Trig( , Numeric.GSL.Special.Trig.cos , hypot_e , hypot +, complex_sin_e +, complex_cos_e +, complex_logsin_e , sinc_e , sinc , lnsinh_e , lnsinh , lncosh_e , lncosh +, polar_to_rect +, rect_to_polar , sin_err_e , cos_err_e , angle_restrict_symm @@ -61,16 +66,16 @@ hypot :: Double -> Double -> Double hypot = gsl_sf_hypot foreign import ccall SAFE_CHEAP "gsl_sf_hypot" gsl_sf_hypot :: Double -> Double -> Double -complex_sin_e :: Double -> Double -> Ptr () -> (Double,Double) -complex_sin_e zr zi szr = createSFR "complex_sin_e" $ gsl_sf_complex_sin_e zr zi szr +complex_sin_e :: Double -> Double -> ((Double,Double),(Double,Double)) +complex_sin_e zr zi = create2SFR "complex_sin_e" $ gsl_sf_complex_sin_e zr zi foreign import ccall SAFE_CHEAP "gsl_sf_complex_sin_e" gsl_sf_complex_sin_e :: Double -> Double -> Ptr () -> Ptr () -> IO CInt -complex_cos_e :: Double -> Double -> Ptr () -> (Double,Double) -complex_cos_e zr zi czr = createSFR "complex_cos_e" $ gsl_sf_complex_cos_e zr zi czr +complex_cos_e :: Double -> Double -> ((Double,Double),(Double,Double)) +complex_cos_e zr zi = create2SFR "complex_cos_e" $ gsl_sf_complex_cos_e zr zi foreign import ccall SAFE_CHEAP "gsl_sf_complex_cos_e" gsl_sf_complex_cos_e :: Double -> Double -> Ptr () -> Ptr () -> IO CInt -complex_logsin_e :: Double -> Double -> Ptr () -> (Double,Double) -complex_logsin_e zr zi lszr = createSFR "complex_logsin_e" $ gsl_sf_complex_logsin_e zr zi lszr +complex_logsin_e :: Double -> Double -> ((Double,Double),(Double,Double)) +complex_logsin_e zr zi = create2SFR "complex_logsin_e" $ gsl_sf_complex_logsin_e zr zi foreign import ccall SAFE_CHEAP "gsl_sf_complex_logsin_e" gsl_sf_complex_logsin_e :: Double -> Double -> Ptr () -> Ptr () -> IO CInt sinc_e :: Double -> (Double,Double) @@ -97,12 +102,12 @@ lncosh :: Double -> Double lncosh = gsl_sf_lncosh foreign import ccall SAFE_CHEAP "gsl_sf_lncosh" gsl_sf_lncosh :: Double -> Double -polar_to_rect :: Double -> Double -> Ptr () -> (Double,Double) -polar_to_rect r theta x = createSFR "polar_to_rect" $ gsl_sf_polar_to_rect r theta x +polar_to_rect :: Double -> Double -> ((Double,Double),(Double,Double)) +polar_to_rect r theta = create2SFR "polar_to_rect" $ gsl_sf_polar_to_rect r theta foreign import ccall SAFE_CHEAP "gsl_sf_polar_to_rect" gsl_sf_polar_to_rect :: Double -> Double -> Ptr () -> Ptr () -> IO CInt -rect_to_polar :: Double -> Double -> Ptr () -> (Double,Double) -rect_to_polar x y r = createSFR "rect_to_polar" $ gsl_sf_rect_to_polar x y r +rect_to_polar :: Double -> Double -> ((Double,Double),(Double,Double)) +rect_to_polar x y = create2SFR "rect_to_polar" $ gsl_sf_rect_to_polar x y foreign import ccall SAFE_CHEAP "gsl_sf_rect_to_polar" gsl_sf_rect_to_polar :: Double -> Double -> Ptr () -> Ptr () -> IO CInt sin_err_e :: Double -> Double -> (Double,Double) -- cgit v1.2.3