STLdoc
STLdocumentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Macros | Functions
poly_laguerre.tcc File Reference

Macros

#define _GLIBCXX_TR1_POLY_LAGUERRE_TCC   1
 

Functions

namespace std _GLIBCXX_VISIBILITY (default)
 

Detailed Description

This is an internal header file, included by other library headers. Do not attempt to use it directly. {tr1/cmath}

Macro Definition Documentation

#define _GLIBCXX_TR1_POLY_LAGUERRE_TCC   1

Function Documentation

namespace std _GLIBCXX_VISIBILITY ( default  )

This routine returns the associated Laguerre polynomial of order $ n $, degree $ \alpha $ for large n. Abramowitz & Stegun, 13.5.21

Parameters
__nThe order of the Laguerre function.
__alphaThe degree of the Laguerre function.
__xThe argument of the Laguerre function.
Returns
The value of the Laguerre function of order n, degree $ \alpha $, and argument x.

This is from the GNU Scientific Library.

Evaluate the polynomial based on the confluent hypergeometric function in a safe way, with no restriction on the arguments.

The associated Laguerre function is defined by

\[ L_n^\alpha(x) = \frac{(\alpha + 1)_n}{n!} _1F_1(-n; \alpha + 1; x) \]

where $ (\alpha)_n $ is the Pochhammer symbol and $ _1F_1(a; c; x) $ is the confluent hypergeometric function.

This function assumes x != 0.

This is from the GNU Scientific Library.

This routine returns the associated Laguerre polynomial of order $ n $, degree $ \alpha $: $ L_n^\alpha(x) $ by recursion.

The associated Laguerre function is defined by

\[ L_n^\alpha(x) = \frac{(\alpha + 1)_n}{n!} _1F_1(-n; \alpha + 1; x) \]

where $ (\alpha)_n $ is the Pochhammer symbol and $ _1F_1(a; c; x) $ is the confluent hypergeometric function.

The associated Laguerre polynomial is defined for integral $ \alpha = m $ by:

\[ L_n^m(x) = (-1)^m \frac{d^m}{dx^m} L_{n + m}(x) \]

where the Laguerre polynomial is defined by:

\[ L_n(x) = \frac{e^x}{n!} \frac{d^n}{dx^n} (x^ne^{-x}) \]

Parameters
__nThe order of the Laguerre function.
__alphaThe degree of the Laguerre function.
__xThe argument of the Laguerre function.
Returns
The value of the Laguerre function of order n, degree $ \alpha $, and argument x.

This routine returns the associated Laguerre polynomial of order n, degree $ \alpha $: $ L_n^alpha(x) $.

The associated Laguerre function is defined by

\[ L_n^\alpha(x) = \frac{(\alpha + 1)_n}{n!} _1F_1(-n; \alpha + 1; x) \]

where $ (\alpha)_n $ is the Pochhammer symbol and $ _1F_1(a; c; x) $ is the confluent hypergeometric function.

The associated Laguerre polynomial is defined for integral $ \alpha = m $ by:

\[ L_n^m(x) = (-1)^m \frac{d^m}{dx^m} L_{n + m}(x) \]

where the Laguerre polynomial is defined by:

\[ L_n(x) = \frac{e^x}{n!} \frac{d^n}{dx^n} (x^ne^{-x}) \]

Parameters
__nThe order of the Laguerre function.
__alphaThe degree of the Laguerre function.
__xThe argument of the Laguerre function.
Returns
The value of the Laguerre function of order n, degree $ \alpha $, and argument x.

This routine returns the associated Laguerre polynomial of order n, degree m: $ L_n^m(x) $.

The associated Laguerre polynomial is defined for integral $ \alpha = m $ by:

\[ L_n^m(x) = (-1)^m \frac{d^m}{dx^m} L_{n + m}(x) \]

where the Laguerre polynomial is defined by:

\[ L_n(x) = \frac{e^x}{n!} \frac{d^n}{dx^n} (x^ne^{-x}) \]

Parameters
__nThe order of the Laguerre polynomial.
__mThe degree of the Laguerre polynomial.
__xThe argument of the Laguerre polynomial.
Returns
The value of the associated Laguerre polynomial of order n, degree m, and argument x.

This routine returns the Laguerre polynomial of order n: $ L_n(x) $.

The Laguerre polynomial is defined by:

\[ L_n(x) = \frac{e^x}{n!} \frac{d^n}{dx^n} (x^ne^{-x}) \]

Parameters
__nThe order of the Laguerre polynomial.
__xThe argument of the Laguerre polynomial.
Returns
The value of the Laguerre polynomial of order n and argument x.
45 {
46 namespace tr1
47 {
48  // [5.2] Special functions
49 
50  // Implementation-space details.
51  namespace __detail
52  {
53  _GLIBCXX_BEGIN_NAMESPACE_VERSION
54 
68  template<typename _Tpa, typename _Tp>
69  _Tp
70  __poly_laguerre_large_n(unsigned __n, _Tpa __alpha1, _Tp __x)
71  {
72  const _Tp __a = -_Tp(__n);
73  const _Tp __b = _Tp(__alpha1) + _Tp(1);
74  const _Tp __eta = _Tp(2) * __b - _Tp(4) * __a;
75  const _Tp __cos2th = __x / __eta;
76  const _Tp __sin2th = _Tp(1) - __cos2th;
77  const _Tp __th = std::acos(std::sqrt(__cos2th));
78  const _Tp __pre_h = __numeric_constants<_Tp>::__pi_2()
79  * __numeric_constants<_Tp>::__pi_2()
80  * __eta * __eta * __cos2th * __sin2th;
81 
82 #if _GLIBCXX_USE_C99_MATH_TR1
83  const _Tp __lg_b = std::tr1::lgamma(_Tp(__n) + __b);
84  const _Tp __lnfact = std::tr1::lgamma(_Tp(__n + 1));
85 #else
86  const _Tp __lg_b = __log_gamma(_Tp(__n) + __b);
87  const _Tp __lnfact = __log_gamma(_Tp(__n + 1));
88 #endif
89 
90  _Tp __pre_term1 = _Tp(0.5L) * (_Tp(1) - __b)
91  * std::log(_Tp(0.25L) * __x * __eta);
92  _Tp __pre_term2 = _Tp(0.25L) * std::log(__pre_h);
93  _Tp __lnpre = __lg_b - __lnfact + _Tp(0.5L) * __x
94  + __pre_term1 - __pre_term2;
95  _Tp __ser_term1 = std::sin(__a * __numeric_constants<_Tp>::__pi());
96  _Tp __ser_term2 = std::sin(_Tp(0.25L) * __eta
97  * (_Tp(2) * __th
98  - std::sin(_Tp(2) * __th))
99  + __numeric_constants<_Tp>::__pi_4());
100  _Tp __ser = __ser_term1 + __ser_term2;
101 
102  return std::exp(__lnpre) * __ser;
103  }
104 
105 
122  template<typename _Tpa, typename _Tp>
123  _Tp
124  __poly_laguerre_hyperg(unsigned int __n, _Tpa __alpha1, _Tp __x)
125  {
126  const _Tp __b = _Tp(__alpha1) + _Tp(1);
127  const _Tp __mx = -__x;
128  const _Tp __tc_sgn = (__x < _Tp(0) ? _Tp(1)
129  : ((__n % 2 == 1) ? -_Tp(1) : _Tp(1)));
130  // Get |x|^n/n!
131  _Tp __tc = _Tp(1);
132  const _Tp __ax = std::abs(__x);
133  for (unsigned int __k = 1; __k <= __n; ++__k)
134  __tc *= (__ax / __k);
135 
136  _Tp __term = __tc * __tc_sgn;
137  _Tp __sum = __term;
138  for (int __k = int(__n) - 1; __k >= 0; --__k)
139  {
140  __term *= ((__b + _Tp(__k)) / _Tp(int(__n) - __k))
141  * _Tp(__k + 1) / __mx;
142  __sum += __term;
143  }
144 
145  return __sum;
146  }
147 
148 
178  template<typename _Tpa, typename _Tp>
179  _Tp
180  __poly_laguerre_recursion(unsigned int __n, _Tpa __alpha1, _Tp __x)
181  {
182  // Compute l_0.
183  _Tp __l_0 = _Tp(1);
184  if (__n == 0)
185  return __l_0;
186 
187  // Compute l_1^alpha.
188  _Tp __l_1 = -__x + _Tp(1) + _Tp(__alpha1);
189  if (__n == 1)
190  return __l_1;
191 
192  // Compute l_n^alpha by recursion on n.
193  _Tp __l_n2 = __l_0;
194  _Tp __l_n1 = __l_1;
195  _Tp __l_n = _Tp(0);
196  for (unsigned int __nn = 2; __nn <= __n; ++__nn)
197  {
198  __l_n = (_Tp(2 * __nn - 1) + _Tp(__alpha1) - __x)
199  * __l_n1 / _Tp(__nn)
200  - (_Tp(__nn - 1) + _Tp(__alpha1)) * __l_n2 / _Tp(__nn);
201  __l_n2 = __l_n1;
202  __l_n1 = __l_n;
203  }
204 
205  return __l_n;
206  }
207 
208 
237  template<typename _Tpa, typename _Tp>
238  _Tp
239  __poly_laguerre(unsigned int __n, _Tpa __alpha1, _Tp __x)
240  {
241  if (__x < _Tp(0))
242  std::__throw_domain_error(__N("Negative argument "
243  "in __poly_laguerre."));
244  // Return NaN on NaN input.
245  else if (__isnan(__x))
246  return std::numeric_limits<_Tp>::quiet_NaN();
247  else if (__n == 0)
248  return _Tp(1);
249  else if (__n == 1)
250  return _Tp(1) + _Tp(__alpha1) - __x;
251  else if (__x == _Tp(0))
252  {
253  _Tp __prod = _Tp(__alpha1) + _Tp(1);
254  for (unsigned int __k = 2; __k <= __n; ++__k)
255  __prod *= (_Tp(__alpha1) + _Tp(__k)) / _Tp(__k);
256  return __prod;
257  }
258  else if (__n > 10000000 && _Tp(__alpha1) > -_Tp(1)
259  && __x < _Tp(2) * (_Tp(__alpha1) + _Tp(1)) + _Tp(4 * __n))
260  return __poly_laguerre_large_n(__n, __alpha1, __x);
261  else if (_Tp(__alpha1) >= _Tp(0)
262  || (__x > _Tp(0) && _Tp(__alpha1) < -_Tp(__n + 1)))
263  return __poly_laguerre_recursion(__n, __alpha1, __x);
264  else
265  return __poly_laguerre_hyperg(__n, __alpha1, __x);
266  }
267 
268 
289  template<typename _Tp>
290  inline _Tp
291  __assoc_laguerre(unsigned int __n, unsigned int __m, _Tp __x)
292  { return __poly_laguerre<unsigned int, _Tp>(__n, __m, __x); }
293 
294 
309  template<typename _Tp>
310  inline _Tp
311  __laguerre(unsigned int __n, _Tp __x)
312  { return __poly_laguerre<unsigned int, _Tp>(__n, 0, __x); }
313 
314  _GLIBCXX_END_NAMESPACE_VERSION
315  } // namespace std::tr1::__detail
316 }
317 }