polylog/
li.rs

1use num::complex::Complex;
2mod eta;
3mod fac;
4mod harmonic;
5mod zeta;
6mod cli;
7mod rli;
8
9/// Provides the n-th order polylogarithm function `li()` of a number of type `T`.
10pub trait Li<T> {
11    fn li(&self, n: i32) -> T;
12}
13
14impl Li<Complex<f64>> for Complex<f64> {
15    /// Returns the complex n-th order polylogarithm of a complex
16    /// number of type `Complex<f64>` for all integers `n`.
17    ///
18    /// The implementation for `n < 0` is an adaptation of
19    /// [[arxiv:2010.09860]].
20    ///
21    /// [arxiv:2010.09860]: https://arxiv.org/abs/2010.09860
22    ///
23    /// # Example:
24    /// ```
25    /// use num::complex::Complex;
26    /// use polylog::Li;
27    ///
28    /// assert!((Complex::new(1.0_f64, 1.0_f64).li(10) - Complex::new(0.9999619510320738_f64, 1.0019864330842581_f64)).norm() < 2.0_f64*std::f64::EPSILON);
29    /// ```
30    fn li(&self, n: i32) -> Complex<f64> {
31        cli::cli(n, *self)
32    }
33}
34
35impl Li<f64> for f64 {
36    /// Returns the real n-th order polylogarithm of a real number of
37    /// type `f64` for all integers `n`.
38    ///
39    /// The implementation for `n < 0` is an adaptation of
40    /// [[arxiv:2010.09860]].
41    ///
42    /// [arxiv:2010.09860]: https://arxiv.org/abs/2010.09860
43    ///
44    /// # Example:
45    /// ```
46    /// use polylog::Li;
47    ///
48    /// assert!((1.0_f64.li(10) - 1.0009945751278181_f64).abs() < std::f64::EPSILON);
49    /// ```
50    fn li(&self, n: i32) -> f64 {
51        rli::rli(n, *self)
52    }
53}