rgsl/
psi.rs

1//
2// A rust binding for the GSL library by Guillaume Gomez (guillaume1.gomez@gmail.com)
3//
4
5/*!
6The polygamma functions of order n are defined by
7
8\psi^{(n)}(x) = (d/dx)^n \psi(x) = (d/dx)^{n+1} \log(\Gamma(x))
9
10where \psi(x) = \Gamma'(x)/\Gamma(x) is known as the digamma function.
11!*/
12
13pub mod diagamma {
14    use crate::{types, Value};
15    use std::mem::MaybeUninit;
16
17    /// This routine computes the digamma function \psi(n) for positive integer n. The digamma function is also called the Psi function.
18    #[doc(alias = "gsl_sf_psi_int")]
19    pub fn psi_int(n: i32) -> f64 {
20        unsafe { sys::gsl_sf_psi_int(n) }
21    }
22
23    /// This routine computes the digamma function \psi(n) for positive integer n. The digamma function is also called the Psi function.
24    #[doc(alias = "gsl_sf_psi_int_e")]
25    pub fn psi_int_e(n: i32) -> Result<types::Result, Value> {
26        let mut result = MaybeUninit::<sys::gsl_sf_result>::uninit();
27        let ret = unsafe { sys::gsl_sf_psi_int_e(n, result.as_mut_ptr()) };
28
29        result_handler!(ret, unsafe { result.assume_init() }.into())
30    }
31
32    /// This routine computes the digamma function \psi(x) for general x, x \ne 0.
33    #[doc(alias = "gsl_sf_psi")]
34    pub fn psi(x: f64) -> f64 {
35        unsafe { sys::gsl_sf_psi(x) }
36    }
37
38    /// This routine computes the digamma function \psi(x) for general x, x \ne 0.
39    #[doc(alias = "gsl_sf_psi_e")]
40    pub fn psi_e(x: f64) -> Result<types::Result, Value> {
41        let mut result = MaybeUninit::<sys::gsl_sf_result>::uninit();
42        let ret = unsafe { sys::gsl_sf_psi_e(x, result.as_mut_ptr()) };
43
44        result_handler!(ret, unsafe { result.assume_init() }.into())
45    }
46
47    /// This routine computes the real part of the digamma function on the line 1+i y, \Re[\psi(1 + i y)].
48    #[doc(alias = "gsl_sf_psi_1piy")]
49    pub fn psi_1piy(x: f64) -> f64 {
50        unsafe { sys::gsl_sf_psi_1piy(x) }
51    }
52
53    /// This routine computes the real part of the digamma function on the line 1+i y, \Re[\psi(1 + i y)].
54    #[doc(alias = "gsl_sf_psi_1piy_e")]
55    pub fn psi_1piy_e(x: f64) -> Result<types::Result, Value> {
56        let mut result = MaybeUninit::<sys::gsl_sf_result>::uninit();
57        let ret = unsafe { sys::gsl_sf_psi_1piy_e(x, result.as_mut_ptr()) };
58
59        result_handler!(ret, unsafe { result.assume_init() }.into())
60    }
61}
62
63pub mod trigamma {
64    use crate::{types, Value};
65    use std::mem::MaybeUninit;
66
67    /// This routine computes the Trigamma function \psi'(n) for positive integer n.
68    #[doc(alias = "gsl_sf_psi_1_int")]
69    pub fn psi_1_int(n: i32) -> f64 {
70        unsafe { sys::gsl_sf_psi_1_int(n) }
71    }
72
73    /// This routine computes the Trigamma function \psi'(n) for positive integer n.
74    #[doc(alias = "gsl_sf_psi_1_int_e")]
75    pub fn psi_1_int_e(n: i32) -> Result<types::Result, Value> {
76        let mut result = MaybeUninit::<sys::gsl_sf_result>::uninit();
77        let ret = unsafe { sys::gsl_sf_psi_1_int_e(n, result.as_mut_ptr()) };
78
79        result_handler!(ret, unsafe { result.assume_init() }.into())
80    }
81
82    /// This routine computes the Trigamma function \psi'(x) for general x.
83    #[doc(alias = "gsl_sf_psi_1")]
84    pub fn psi_1(x: f64) -> f64 {
85        unsafe { sys::gsl_sf_psi_1(x) }
86    }
87
88    /// This routine computes the Trigamma function \psi'(x) for general x.
89    #[doc(alias = "gsl_sf_psi_1_e")]
90    pub fn psi_1_e(x: f64) -> Result<types::Result, Value> {
91        let mut result = MaybeUninit::<sys::gsl_sf_result>::uninit();
92        let ret = unsafe { sys::gsl_sf_psi_1_e(x, result.as_mut_ptr()) };
93
94        result_handler!(ret, unsafe { result.assume_init() }.into())
95    }
96}
97
98pub mod polygamma {
99    use crate::{types, Value};
100    use std::mem::MaybeUninit;
101
102    /// This routine computes the polygamma function \psi^{(n)}(x) for n >= 0, x > 0.
103    #[doc(alias = "gsl_sf_psi_n")]
104    pub fn psi_n(n: i32, x: f64) -> f64 {
105        unsafe { sys::gsl_sf_psi_n(n, x) }
106    }
107
108    /// This routine computes the polygamma function \psi^{(n)}(x) for n >= 0, x > 0.
109    #[doc(alias = "gsl_sf_psi_n_e")]
110    pub fn psi_n_e(n: i32, x: f64) -> Result<types::Result, Value> {
111        let mut result = MaybeUninit::<sys::gsl_sf_result>::uninit();
112        let ret = unsafe { sys::gsl_sf_psi_n_e(n, x, result.as_mut_ptr()) };
113
114        result_handler!(ret, unsafe { result.assume_init() }.into())
115    }
116}