diff options
author | Alberto Ruiz <aruiz@um.es> | 2010-10-20 07:19:06 +0000 |
---|---|---|
committer | Alberto Ruiz <aruiz@um.es> | 2010-10-20 07:19:06 +0000 |
commit | 7cfba6b4eb311590986a888255cd1dc594bd7264 (patch) | |
tree | b01b83260b9d959cd8b32fe4021553bb1aadc8d4 /packages/special/lib | |
parent | ceb049de0898a2cc58fac8191a049e65bad7a2f6 (diff) |
mkComplex_e and other complex special functions
Diffstat (limited to 'packages/special/lib')
-rw-r--r-- | packages/special/lib/Numeric/GSL/Special.hs | 32 | ||||
-rw-r--r-- | packages/special/lib/Numeric/GSL/Special/Gamma.hs | 5 | ||||
-rw-r--r-- | packages/special/lib/Numeric/GSL/Special/Internal.hsc | 3 | ||||
-rw-r--r-- | packages/special/lib/Numeric/GSL/Special/Log.hs | 5 | ||||
-rw-r--r-- | packages/special/lib/Numeric/GSL/Special/Psi.hs | 5 | ||||
-rw-r--r-- | packages/special/lib/Numeric/GSL/Special/Trig.hs | 25 |
6 files changed, 57 insertions, 18 deletions
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. | |||
15 | ----------------------------------------------------------------------------- | 15 | ----------------------------------------------------------------------------- |
16 | 16 | ||
17 | module Numeric.GSL.Special ( | 17 | module Numeric.GSL.Special ( |
18 | -- * Functions | ||
18 | module Numeric.GSL.Special.Airy | 19 | module Numeric.GSL.Special.Airy |
19 | , module Numeric.GSL.Special.Bessel | 20 | , module Numeric.GSL.Special.Bessel |
20 | , module Numeric.GSL.Special.Clausen | 21 | , module Numeric.GSL.Special.Clausen |
@@ -43,9 +44,12 @@ module Numeric.GSL.Special ( | |||
43 | , module Numeric.GSL.Special.Transport | 44 | , module Numeric.GSL.Special.Transport |
44 | , module Numeric.GSL.Special.Trig | 45 | , module Numeric.GSL.Special.Trig |
45 | , module Numeric.GSL.Special.Zeta | 46 | , module Numeric.GSL.Special.Zeta |
47 | -- * Util | ||
48 | , mkComplex_e | ||
46 | ) | 49 | ) |
47 | where | 50 | where |
48 | 51 | ||
52 | |||
49 | import Numeric.GSL.Special.Airy | 53 | import Numeric.GSL.Special.Airy |
50 | import Numeric.GSL.Special.Bessel | 54 | import Numeric.GSL.Special.Bessel |
51 | import Numeric.GSL.Special.Clausen | 55 | import Numeric.GSL.Special.Clausen |
@@ -74,3 +78,31 @@ import Numeric.GSL.Special.Synchrotron | |||
74 | import Numeric.GSL.Special.Transport | 78 | import Numeric.GSL.Special.Transport |
75 | import Numeric.GSL.Special.Trig | 79 | import Numeric.GSL.Special.Trig |
76 | import Numeric.GSL.Special.Zeta | 80 | import Numeric.GSL.Special.Zeta |
81 | |||
82 | import Data.Complex | ||
83 | |||
84 | ---------------------------------------------------------------- | ||
85 | |||
86 | {- | 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: | ||
87 | |||
88 | > > import Numeric.GSL.Special.Dilog | ||
89 | |||
90 | > > complex_dilog_xy_e 1 1 | ||
91 | > ((0.6168502750680847,1.1097853812294034e-14),(1.4603621167531193,1.1855504863267322e-14)) | ||
92 | |||
93 | We can use @mkComplex_e@ to work with \"normal\" complex numbers: | ||
94 | |||
95 | > > import Numeric.GSL.Special(mkComplex_e) | ||
96 | > > import Data.Complex | ||
97 | |||
98 | > > let dilogC = fst . mkComplex_e complex_dilog_xy_e | ||
99 | |||
100 | > > dilogC (1 :+ 1) | ||
101 | > 0.6168502750680847 :+ 1.4603621167531193 | ||
102 | |||
103 | -} | ||
104 | mkComplex_e :: (Double -> Double -> ((Double, Double), (Double, Double))) | ||
105 | -> Complex Double -> (Complex Double, Complex Double) | ||
106 | mkComplex_e f (x :+ y) = (zr :+ zi, er :+ ei) | ||
107 | where ((zr,er),(zi,ei)) = f x y | ||
108 | |||
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( | |||
21 | , gammastar | 21 | , gammastar |
22 | , gammainv_e | 22 | , gammainv_e |
23 | , gammainv | 23 | , gammainv |
24 | , lngamma_complex_e | ||
24 | , taylorcoeff_e | 25 | , taylorcoeff_e |
25 | , taylorcoeff | 26 | , taylorcoeff |
26 | , fact_e | 27 | , fact_e |
@@ -95,8 +96,8 @@ gammainv :: Double -> Double | |||
95 | gammainv = gsl_sf_gammainv | 96 | gammainv = gsl_sf_gammainv |
96 | foreign import ccall SAFE_CHEAP "gsl_sf_gammainv" gsl_sf_gammainv :: Double -> Double | 97 | foreign import ccall SAFE_CHEAP "gsl_sf_gammainv" gsl_sf_gammainv :: Double -> Double |
97 | 98 | ||
98 | lngamma_complex_e :: Double -> Double -> Ptr () -> (Double,Double) | 99 | lngamma_complex_e :: Double -> Double -> ((Double,Double),(Double,Double)) |
99 | lngamma_complex_e zr zi lnr = createSFR "lngamma_complex_e" $ gsl_sf_lngamma_complex_e zr zi lnr | 100 | lngamma_complex_e zr zi = create2SFR "lngamma_complex_e" $ gsl_sf_lngamma_complex_e zr zi |
100 | foreign import ccall SAFE_CHEAP "gsl_sf_lngamma_complex_e" gsl_sf_lngamma_complex_e :: Double -> Double -> Ptr () -> Ptr () -> IO CInt | 101 | foreign import ccall SAFE_CHEAP "gsl_sf_lngamma_complex_e" gsl_sf_lngamma_complex_e :: Double -> Double -> Ptr () -> Ptr () -> IO CInt |
101 | 102 | ||
102 | taylorcoeff_e :: CInt -> Double -> (Double,Double) | 103 | 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 | |||
33 | import Data.Packed.Development(check,(//)) | 33 | import Data.Packed.Development(check,(//)) |
34 | import Foreign.C.Types(CSize,CInt) | 34 | import Foreign.C.Types(CSize,CInt) |
35 | 35 | ||
36 | |||
37 | data Precision = PrecDouble | PrecSingle | PrecApprox | 36 | data Precision = PrecDouble | PrecSingle | PrecApprox |
38 | 37 | ||
39 | precCode :: Precision -> Int | 38 | precCode :: Precision -> Int |
@@ -90,7 +89,7 @@ createSFR s f = unsafePerformIO $ do | |||
90 | return (val,err) | 89 | return (val,err) |
91 | 90 | ||
92 | ---------------------------------------------------------------- | 91 | ---------------------------------------------------------------- |
93 | -- | access to two sf_result | 92 | -- | access to two sf_result's |
94 | create2SFR :: String -> (Ptr a -> Ptr a -> IO CInt) -> ((Double, Double),(Double, Double)) | 93 | create2SFR :: String -> (Ptr a -> Ptr a -> IO CInt) -> ((Double, Double),(Double, Double)) |
95 | create2SFR s f = unsafePerformIO $ do | 94 | create2SFR s f = unsafePerformIO $ do |
96 | p1 <- malloc :: IO (Ptr Gsl_sf_result) | 95 | 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( | |||
17 | , Numeric.GSL.Special.Log.log | 17 | , Numeric.GSL.Special.Log.log |
18 | , log_abs_e | 18 | , log_abs_e |
19 | , log_abs | 19 | , log_abs |
20 | , complex_log_e | ||
20 | , log_1plusx_e | 21 | , log_1plusx_e |
21 | , log_1plusx | 22 | , log_1plusx |
22 | , log_1plusx_mx_e | 23 | , log_1plusx_mx_e |
@@ -43,8 +44,8 @@ log_abs :: Double -> Double | |||
43 | log_abs = gsl_sf_log_abs | 44 | log_abs = gsl_sf_log_abs |
44 | foreign import ccall SAFE_CHEAP "gsl_sf_log_abs" gsl_sf_log_abs :: Double -> Double | 45 | foreign import ccall SAFE_CHEAP "gsl_sf_log_abs" gsl_sf_log_abs :: Double -> Double |
45 | 46 | ||
46 | complex_log_e :: Double -> Double -> Ptr () -> (Double,Double) | 47 | complex_log_e :: Double -> Double -> ((Double,Double),(Double,Double)) |
47 | complex_log_e zr zi lnr = createSFR "complex_log_e" $ gsl_sf_complex_log_e zr zi lnr | 48 | complex_log_e zr zi = create2SFR "complex_log_e" $ gsl_sf_complex_log_e zr zi |
48 | foreign import ccall SAFE_CHEAP "gsl_sf_complex_log_e" gsl_sf_complex_log_e :: Double -> Double -> Ptr () -> Ptr () -> IO CInt | 49 | foreign import ccall SAFE_CHEAP "gsl_sf_complex_log_e" gsl_sf_complex_log_e :: Double -> Double -> Ptr () -> Ptr () -> IO CInt |
49 | 50 | ||
50 | log_1plusx_e :: Double -> (Double,Double) | 51 | 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( | |||
19 | , psi | 19 | , psi |
20 | , psi_1piy_e | 20 | , psi_1piy_e |
21 | , psi_1piy | 21 | , psi_1piy |
22 | , complex_psi_e | ||
22 | , psi_1_int_e | 23 | , psi_1_int_e |
23 | , psi_1_int | 24 | , psi_1_int |
24 | , psi_1_e | 25 | , psi_1_e |
@@ -55,8 +56,8 @@ psi_1piy :: Double -> Double | |||
55 | psi_1piy = gsl_sf_psi_1piy | 56 | psi_1piy = gsl_sf_psi_1piy |
56 | foreign import ccall SAFE_CHEAP "gsl_sf_psi_1piy" gsl_sf_psi_1piy :: Double -> Double | 57 | foreign import ccall SAFE_CHEAP "gsl_sf_psi_1piy" gsl_sf_psi_1piy :: Double -> Double |
57 | 58 | ||
58 | complex_psi_e :: Double -> Double -> Ptr () -> (Double,Double) | 59 | complex_psi_e :: Double -> Double -> ((Double,Double),(Double,Double)) |
59 | complex_psi_e x y result_re = createSFR "complex_psi_e" $ gsl_sf_complex_psi_e x y result_re | 60 | complex_psi_e x y = create2SFR "complex_psi_e" $ gsl_sf_complex_psi_e x y |
60 | foreign import ccall SAFE_CHEAP "gsl_sf_complex_psi_e" gsl_sf_complex_psi_e :: Double -> Double -> Ptr () -> Ptr () -> IO CInt | 61 | foreign import ccall SAFE_CHEAP "gsl_sf_complex_psi_e" gsl_sf_complex_psi_e :: Double -> Double -> Ptr () -> Ptr () -> IO CInt |
61 | 62 | ||
62 | psi_1_int_e :: CInt -> (Double,Double) | 63 | 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( | |||
19 | , Numeric.GSL.Special.Trig.cos | 19 | , Numeric.GSL.Special.Trig.cos |
20 | , hypot_e | 20 | , hypot_e |
21 | , hypot | 21 | , hypot |
22 | , complex_sin_e | ||
23 | , complex_cos_e | ||
24 | , complex_logsin_e | ||
22 | , sinc_e | 25 | , sinc_e |
23 | , sinc | 26 | , sinc |
24 | , lnsinh_e | 27 | , lnsinh_e |
25 | , lnsinh | 28 | , lnsinh |
26 | , lncosh_e | 29 | , lncosh_e |
27 | , lncosh | 30 | , lncosh |
31 | , polar_to_rect | ||
32 | , rect_to_polar | ||
28 | , sin_err_e | 33 | , sin_err_e |
29 | , cos_err_e | 34 | , cos_err_e |
30 | , angle_restrict_symm | 35 | , angle_restrict_symm |
@@ -61,16 +66,16 @@ hypot :: Double -> Double -> Double | |||
61 | hypot = gsl_sf_hypot | 66 | hypot = gsl_sf_hypot |
62 | foreign import ccall SAFE_CHEAP "gsl_sf_hypot" gsl_sf_hypot :: Double -> Double -> Double | 67 | foreign import ccall SAFE_CHEAP "gsl_sf_hypot" gsl_sf_hypot :: Double -> Double -> Double |
63 | 68 | ||
64 | complex_sin_e :: Double -> Double -> Ptr () -> (Double,Double) | 69 | complex_sin_e :: Double -> Double -> ((Double,Double),(Double,Double)) |
65 | complex_sin_e zr zi szr = createSFR "complex_sin_e" $ gsl_sf_complex_sin_e zr zi szr | 70 | complex_sin_e zr zi = create2SFR "complex_sin_e" $ gsl_sf_complex_sin_e zr zi |
66 | foreign import ccall SAFE_CHEAP "gsl_sf_complex_sin_e" gsl_sf_complex_sin_e :: Double -> Double -> Ptr () -> Ptr () -> IO CInt | 71 | foreign import ccall SAFE_CHEAP "gsl_sf_complex_sin_e" gsl_sf_complex_sin_e :: Double -> Double -> Ptr () -> Ptr () -> IO CInt |
67 | 72 | ||
68 | complex_cos_e :: Double -> Double -> Ptr () -> (Double,Double) | 73 | complex_cos_e :: Double -> Double -> ((Double,Double),(Double,Double)) |
69 | complex_cos_e zr zi czr = createSFR "complex_cos_e" $ gsl_sf_complex_cos_e zr zi czr | 74 | complex_cos_e zr zi = create2SFR "complex_cos_e" $ gsl_sf_complex_cos_e zr zi |
70 | foreign import ccall SAFE_CHEAP "gsl_sf_complex_cos_e" gsl_sf_complex_cos_e :: Double -> Double -> Ptr () -> Ptr () -> IO CInt | 75 | foreign import ccall SAFE_CHEAP "gsl_sf_complex_cos_e" gsl_sf_complex_cos_e :: Double -> Double -> Ptr () -> Ptr () -> IO CInt |
71 | 76 | ||
72 | complex_logsin_e :: Double -> Double -> Ptr () -> (Double,Double) | 77 | complex_logsin_e :: Double -> Double -> ((Double,Double),(Double,Double)) |
73 | complex_logsin_e zr zi lszr = createSFR "complex_logsin_e" $ gsl_sf_complex_logsin_e zr zi lszr | 78 | complex_logsin_e zr zi = create2SFR "complex_logsin_e" $ gsl_sf_complex_logsin_e zr zi |
74 | foreign import ccall SAFE_CHEAP "gsl_sf_complex_logsin_e" gsl_sf_complex_logsin_e :: Double -> Double -> Ptr () -> Ptr () -> IO CInt | 79 | foreign import ccall SAFE_CHEAP "gsl_sf_complex_logsin_e" gsl_sf_complex_logsin_e :: Double -> Double -> Ptr () -> Ptr () -> IO CInt |
75 | 80 | ||
76 | sinc_e :: Double -> (Double,Double) | 81 | sinc_e :: Double -> (Double,Double) |
@@ -97,12 +102,12 @@ lncosh :: Double -> Double | |||
97 | lncosh = gsl_sf_lncosh | 102 | lncosh = gsl_sf_lncosh |
98 | foreign import ccall SAFE_CHEAP "gsl_sf_lncosh" gsl_sf_lncosh :: Double -> Double | 103 | foreign import ccall SAFE_CHEAP "gsl_sf_lncosh" gsl_sf_lncosh :: Double -> Double |
99 | 104 | ||
100 | polar_to_rect :: Double -> Double -> Ptr () -> (Double,Double) | 105 | polar_to_rect :: Double -> Double -> ((Double,Double),(Double,Double)) |
101 | polar_to_rect r theta x = createSFR "polar_to_rect" $ gsl_sf_polar_to_rect r theta x | 106 | polar_to_rect r theta = create2SFR "polar_to_rect" $ gsl_sf_polar_to_rect r theta |
102 | foreign import ccall SAFE_CHEAP "gsl_sf_polar_to_rect" gsl_sf_polar_to_rect :: Double -> Double -> Ptr () -> Ptr () -> IO CInt | 107 | foreign import ccall SAFE_CHEAP "gsl_sf_polar_to_rect" gsl_sf_polar_to_rect :: Double -> Double -> Ptr () -> Ptr () -> IO CInt |
103 | 108 | ||
104 | rect_to_polar :: Double -> Double -> Ptr () -> (Double,Double) | 109 | rect_to_polar :: Double -> Double -> ((Double,Double),(Double,Double)) |
105 | rect_to_polar x y r = createSFR "rect_to_polar" $ gsl_sf_rect_to_polar x y r | 110 | rect_to_polar x y = create2SFR "rect_to_polar" $ gsl_sf_rect_to_polar x y |
106 | foreign import ccall SAFE_CHEAP "gsl_sf_rect_to_polar" gsl_sf_rect_to_polar :: Double -> Double -> Ptr () -> Ptr () -> IO CInt | 111 | foreign import ccall SAFE_CHEAP "gsl_sf_rect_to_polar" gsl_sf_rect_to_polar :: Double -> Double -> Ptr () -> Ptr () -> IO CInt |
107 | 112 | ||
108 | sin_err_e :: Double -> Double -> (Double,Double) | 113 | sin_err_e :: Double -> Double -> (Double,Double) |