TRIQS/TRIQS 4.0.0
Researching Interacting Quantum Systems
Loading...
Searching...
No Matches
legendre.cpp
Go to the documentation of this file.
1// Copyright (c) 2019-2023 Simons Foundation
2//
3// This program is free software: you can redistribute it and/or modify
4// it under the terms of the GNU General Public License as published by
5// the Free Software Foundation, either version 3 of the License, or
6// (at your option) any later version.
7//
8// This program is distributed in the hope that it will be useful,
9// but WITHOUT ANY WARRANTY; without even the implied warranty of
10// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11// GNU General Public License for more details.
12//
13// You may obtain a copy of the License at
14// https://www.gnu.org/licenses/gpl-3.0.txt
15//
16// Authors: Nils Wentzell
17
22
23#include "./legendre.hpp"
24
25#include <boost/math/special_functions/bessel.hpp>
26
27#include <cassert>
28#include <cmath>
29#include <complex>
30#include <numbers>
31
32namespace triqs::utility {
33
34 using namespace std::complex_literals;
35 using std::numbers::pi;
36
37 std::complex<double> legendre_T(int n, int l) {
38 bool neg_n = false;
39 if (n < 0) {
40 neg_n = true;
41 n = std::abs(n + 1);
42 }
43
44 // cyl_bessel_j(l,x) gives the Bessel functions of the first kind J_l(x) which is related to the spherical Bessel
45 // function by j_l(x) = \sqrt{\pi / (2x)} J_{l+0.5}(x)
46 std::complex<double> res = (std::sqrt(2 * l + 1) / std::sqrt(2 * n + 1)) * std::exp(1i * (n + 0.5) * pi) * std::pow(1i, l)
47 * boost::math::cyl_bessel_j(l + 0.5, (n + 0.5) * pi);
48
49 // T_{-nl} = T_{nl}^*
50 return neg_n ? std::conj(res) : res;
51 }
52
53 double legendre_t(int l, int p) {
54 // p is the 1/omega power, it can't be negative
55 assert(p > 0);
56
57 // early return for special cases
58 if ((l + p) % 2 == 0 || p > l + 1) return 0.0;
59
60 // factorials
61 double f = 1;
62 for (int i = l + p - 1; (i > l - p + 1) && (i > 1); i--) f *= i;
63 for (int i = p - 1; i > 1; i--) f /= i;
64
65 return std::pow(double(-1), double(p)) * 2 * std::sqrt(2 * l + 1) * f;
66 }
67
68 double mod_cyl_bessel_i(int n, double x) {
69 if (x == 0) return (n == 0 ? 1.0 : 0);
70 return std::sqrt(pi / (2 * x)) * boost::math::cyl_bessel_i(n + 0.5, x);
71 }
72
73} // namespace triqs::utility
std::complex< double > legendre_T(int n, int l)
Get the quantity from Eq.(E2) in the paper https://doi.org/10.1103/PhysRevB.84.075145.
Definition legendre.cpp:37
double mod_cyl_bessel_i(int n, double x)
Get the modified spherical bessel function of the first kind of order evaluated at .
Definition legendre.cpp:68
double legendre_t(int l, int p)
Get the quantity from Eq.(E8) in the paper https://doi.org/10.1103/PhysRevB.84.075145.
Definition legendre.cpp:53
Provides Legendre polynomials and related functions.