2 // (C) Copyright John Maddock 2006.
3 // Use, modification and distribution are subject to the
4 // Boost Software License, Version 1.0. (See accompanying file
5 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 #ifndef BOOST_MATH_SPECIAL_LAGUERRE_HPP
8 #define BOOST_MATH_SPECIAL_LAGUERRE_HPP
14 #include <boost/math/special_functions/math_fwd.hpp>
15 #include <boost/math/tools/config.hpp>
16 #include <boost/math/policies/error_handling.hpp>
21 // Recurrance relation for Laguerre polynomials:
22 template <class T1, class T2, class T3>
23 inline typename tools::promote_args<T1, T2, T3>::type
24 laguerre_next(unsigned n, T1 x, T2 Ln, T3 Lnm1)
26 typedef typename tools::promote_args<T1, T2, T3>::type result_type;
27 return ((2 * n + 1 - result_type(x)) * result_type(Ln) - n * result_type(Lnm1)) / (n + 1);
32 // Implement Laguerre polynomials via recurrance:
34 T laguerre_imp(unsigned n, T x)
47 p1 = laguerre_next(c, x, p0, p1);
53 template <class T, class Policy>
54 inline typename tools::promote_args<T>::type
55 laguerre(unsigned n, T x, const Policy&, const mpl::true_&)
57 typedef typename tools::promote_args<T>::type result_type;
58 typedef typename policies::evaluation<result_type, Policy>::type value_type;
59 return policies::checked_narrowing_cast<result_type, Policy>(detail::laguerre_imp(n, static_cast<value_type>(x)), "boost::math::laguerre<%1%>(unsigned, %1%)");
63 inline typename tools::promote_args<T>::type
64 laguerre(unsigned n, unsigned m, T x, const mpl::false_&)
66 return boost::math::laguerre(n, m, x, policies::policy<>());
72 inline typename tools::promote_args<T>::type
73 laguerre(unsigned n, T x)
75 return laguerre(n, x, policies::policy<>());
78 // Recurrence for associated polynomials:
79 template <class T1, class T2, class T3>
80 inline typename tools::promote_args<T1, T2, T3>::type
81 laguerre_next(unsigned n, unsigned l, T1 x, T2 Pl, T3 Plm1)
83 typedef typename tools::promote_args<T1, T2, T3>::type result_type;
84 return ((2 * n + l + 1 - result_type(x)) * result_type(Pl) - (n + l) * result_type(Plm1)) / (n+1);
88 // Laguerre Associated Polynomial:
89 template <class T, class Policy>
90 T laguerre_imp(unsigned n, unsigned m, T x, const Policy& pol)
94 return boost::math::laguerre(n, x, pol);
108 p1 = laguerre_next(c, m, x, p0, p1);
116 template <class T, class Policy>
117 inline typename tools::promote_args<T>::type
118 laguerre(unsigned n, unsigned m, T x, const Policy& pol)
120 typedef typename tools::promote_args<T>::type result_type;
121 typedef typename policies::evaluation<result_type, Policy>::type value_type;
122 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%)");
125 template <class T1, class T2>
126 inline typename laguerre_result<T1, T2>::type
127 laguerre(unsigned n, T1 m, T2 x)
129 typedef typename policies::is_policy<T2>::type tag_type;
130 return detail::laguerre(n, m, x, tag_type());
136 #endif // BOOST_MATH_SPECIAL_LAGUERRE_HPP