Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:40:15

0001 
0002 //  (C) Copyright John Maddock 2006.
0003 //  Use, modification and distribution are subject to the
0004 //  Boost Software License, Version 1.0. (See accompanying file
0005 //  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0006 
0007 #ifndef BOOST_MATH_SPECIAL_LAGUERRE_HPP
0008 #define BOOST_MATH_SPECIAL_LAGUERRE_HPP
0009 
0010 #ifdef _MSC_VER
0011 #pragma once
0012 #endif
0013 
0014 #include <boost/math/special_functions/math_fwd.hpp>
0015 #include <boost/math/tools/config.hpp>
0016 #include <boost/math/policies/error_handling.hpp>
0017 
0018 namespace boost{
0019 namespace math{
0020 
0021 // Recurrence relation for Laguerre polynomials:
0022 template <class T1, class T2, class T3>
0023 inline typename tools::promote_args<T1, T2, T3>::type  
0024    laguerre_next(unsigned n, T1 x, T2 Ln, T3 Lnm1)
0025 {
0026    typedef typename tools::promote_args<T1, T2, T3>::type result_type;
0027    return ((2 * n + 1 - result_type(x)) * result_type(Ln) - n * result_type(Lnm1)) / (n + 1);
0028 }
0029 
0030 namespace detail{
0031 
0032 // Implement Laguerre polynomials via recurrence:
0033 template <class T>
0034 T laguerre_imp(unsigned n, T x)
0035 {
0036    T p0 = 1;
0037    T p1 = 1 - x;
0038 
0039    if(n == 0)
0040       return p0;
0041 
0042    unsigned c = 1;
0043 
0044    while(c < n)
0045    {
0046       std::swap(p0, p1);
0047       p1 = laguerre_next(c, x, p0, p1);
0048       ++c;
0049    }
0050    return p1;
0051 }
0052 
0053 template <class T, class Policy>
0054 inline typename tools::promote_args<T>::type 
0055 laguerre(unsigned n, T x, const Policy&, const std::true_type&)
0056 {
0057    typedef typename tools::promote_args<T>::type result_type;
0058    typedef typename policies::evaluation<result_type, Policy>::type value_type;
0059    return policies::checked_narrowing_cast<result_type, Policy>(detail::laguerre_imp(n, static_cast<value_type>(x)), "boost::math::laguerre<%1%>(unsigned, %1%)");
0060 }
0061 
0062 template <class T>
0063 inline typename tools::promote_args<T>::type 
0064    laguerre(unsigned n, unsigned m, T x, const std::false_type&)
0065 {
0066    return boost::math::laguerre(n, m, x, policies::policy<>());
0067 }
0068 
0069 } // namespace detail
0070 
0071 template <class T>
0072 inline typename tools::promote_args<T>::type 
0073    laguerre(unsigned n, T x)
0074 {
0075    return laguerre(n, x, policies::policy<>());
0076 }
0077 
0078 // Recurrence for associated polynomials:
0079 template <class T1, class T2, class T3>
0080 inline typename tools::promote_args<T1, T2, T3>::type  
0081    laguerre_next(unsigned n, unsigned l, T1 x, T2 Pl, T3 Plm1)
0082 {
0083    typedef typename tools::promote_args<T1, T2, T3>::type result_type;
0084    return ((2 * n + l + 1 - result_type(x)) * result_type(Pl) - (n + l) * result_type(Plm1)) / (n+1);
0085 }
0086 
0087 namespace detail{
0088 // Laguerre Associated Polynomial:
0089 template <class T, class Policy>
0090 T laguerre_imp(unsigned n, unsigned m, T x, const Policy& pol)
0091 {
0092    // Special cases:
0093    if(m == 0)
0094       return boost::math::laguerre(n, x, pol);
0095 
0096    T p0 = 1;
0097    
0098    if(n == 0)
0099       return p0;
0100 
0101    T p1 = m + 1 - x;
0102 
0103    unsigned c = 1;
0104 
0105    while(c < n)
0106    {
0107       std::swap(p0, p1);
0108       p1 = static_cast<T>(laguerre_next(c, m, x, p0, p1));
0109       ++c;
0110    }
0111    return p1;
0112 }
0113 
0114 }
0115 
0116 template <class T, class Policy>
0117 inline typename tools::promote_args<T>::type 
0118    laguerre(unsigned n, unsigned m, T x, const Policy& pol)
0119 {
0120    typedef typename tools::promote_args<T>::type result_type;
0121    typedef typename policies::evaluation<result_type, Policy>::type value_type;
0122    return policies::checked_narrowing_cast<result_type, Policy>(detail::laguerre_imp(n, m, static_cast<value_type>(x), pol), "boost::math::laguerre<%1%>(unsigned, unsigned, %1%)");
0123 }
0124 
0125 template <class T1, class T2>
0126 inline typename laguerre_result<T1, T2>::type 
0127    laguerre(unsigned n, T1 m, T2 x)
0128 {
0129    typedef typename policies::is_policy<T2>::type tag_type;
0130    return detail::laguerre(n, m, x, tag_type());
0131 }
0132 
0133 } // namespace math
0134 } // namespace boost
0135 
0136 #endif // BOOST_MATH_SPECIAL_LAGUERRE_HPP
0137 
0138 
0139