Chris@16: Chris@16: // (C) Copyright John Maddock 2006. Chris@16: // Use, modification and distribution are subject to the Chris@16: // Boost Software License, Version 1.0. (See accompanying file Chris@16: // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) Chris@16: Chris@16: #ifndef BOOST_MATH_SPECIAL_LAGUERRE_HPP Chris@16: #define BOOST_MATH_SPECIAL_LAGUERRE_HPP Chris@16: Chris@16: #ifdef _MSC_VER Chris@16: #pragma once Chris@16: #endif Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@16: namespace boost{ Chris@16: namespace math{ Chris@16: Chris@16: // Recurrance relation for Laguerre polynomials: Chris@16: template Chris@16: inline typename tools::promote_args::type Chris@16: laguerre_next(unsigned n, T1 x, T2 Ln, T3 Lnm1) Chris@16: { Chris@16: typedef typename tools::promote_args::type result_type; Chris@16: return ((2 * n + 1 - result_type(x)) * result_type(Ln) - n * result_type(Lnm1)) / (n + 1); Chris@16: } Chris@16: Chris@16: namespace detail{ Chris@16: Chris@16: // Implement Laguerre polynomials via recurrance: Chris@16: template Chris@16: T laguerre_imp(unsigned n, T x) Chris@16: { Chris@16: T p0 = 1; Chris@16: T p1 = 1 - x; Chris@16: Chris@16: if(n == 0) Chris@16: return p0; Chris@16: Chris@16: unsigned c = 1; Chris@16: Chris@16: while(c < n) Chris@16: { Chris@16: std::swap(p0, p1); Chris@16: p1 = laguerre_next(c, x, p0, p1); Chris@16: ++c; Chris@16: } Chris@16: return p1; Chris@16: } Chris@16: Chris@16: template Chris@16: inline typename tools::promote_args::type Chris@16: laguerre(unsigned n, T x, const Policy&, const mpl::true_&) Chris@16: { Chris@16: typedef typename tools::promote_args::type result_type; Chris@16: typedef typename policies::evaluation::type value_type; Chris@16: return policies::checked_narrowing_cast(detail::laguerre_imp(n, static_cast(x)), "boost::math::laguerre<%1%>(unsigned, %1%)"); Chris@16: } Chris@16: Chris@16: template Chris@16: inline typename tools::promote_args::type Chris@16: laguerre(unsigned n, unsigned m, T x, const mpl::false_&) Chris@16: { Chris@16: return boost::math::laguerre(n, m, x, policies::policy<>()); Chris@16: } Chris@16: Chris@16: } // namespace detail Chris@16: Chris@16: template Chris@16: inline typename tools::promote_args::type Chris@16: laguerre(unsigned n, T x) Chris@16: { Chris@16: return laguerre(n, x, policies::policy<>()); Chris@16: } Chris@16: Chris@16: // Recurrence for associated polynomials: Chris@16: template Chris@16: inline typename tools::promote_args::type Chris@16: laguerre_next(unsigned n, unsigned l, T1 x, T2 Pl, T3 Plm1) Chris@16: { Chris@16: typedef typename tools::promote_args::type result_type; Chris@16: return ((2 * n + l + 1 - result_type(x)) * result_type(Pl) - (n + l) * result_type(Plm1)) / (n+1); Chris@16: } Chris@16: Chris@16: namespace detail{ Chris@16: // Laguerre Associated Polynomial: Chris@16: template Chris@16: T laguerre_imp(unsigned n, unsigned m, T x, const Policy& pol) Chris@16: { Chris@16: // Special cases: Chris@16: if(m == 0) Chris@16: return boost::math::laguerre(n, x, pol); Chris@16: Chris@16: T p0 = 1; Chris@16: Chris@16: if(n == 0) Chris@16: return p0; Chris@16: Chris@16: T p1 = m + 1 - x; Chris@16: Chris@16: unsigned c = 1; Chris@16: Chris@16: while(c < n) Chris@16: { Chris@16: std::swap(p0, p1); Chris@16: p1 = laguerre_next(c, m, x, p0, p1); Chris@16: ++c; Chris@16: } Chris@16: return p1; Chris@16: } Chris@16: Chris@16: } Chris@16: Chris@16: template Chris@16: inline typename tools::promote_args::type Chris@16: laguerre(unsigned n, unsigned m, T x, const Policy& pol) Chris@16: { Chris@16: typedef typename tools::promote_args::type result_type; Chris@16: typedef typename policies::evaluation::type value_type; Chris@16: return policies::checked_narrowing_cast(detail::laguerre_imp(n, m, static_cast(x), pol), "boost::math::laguerre<%1%>(unsigned, unsigned, %1%)"); Chris@16: } Chris@16: Chris@16: template Chris@16: inline typename laguerre_result::type Chris@16: laguerre(unsigned n, T1 m, T2 x) Chris@16: { Chris@16: typedef typename policies::is_policy::type tag_type; Chris@16: return detail::laguerre(n, m, x, tag_type()); Chris@16: } Chris@16: Chris@16: } // namespace math Chris@16: } // namespace boost Chris@16: Chris@16: #endif // BOOST_MATH_SPECIAL_LAGUERRE_HPP Chris@16: Chris@16: Chris@16: