Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-17 08:36:13

0001 
0002 //  (C) Copyright John Maddock 2006.
0003 //  (C) Copyright Matt Borland 2024.
0004 //  Use, modification and distribution are subject to the
0005 //  Boost Software License, Version 1.0. (See accompanying file
0006 //  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0007 
0008 #ifndef BOOST_MATH_SPECIAL_HERMITE_HPP
0009 #define BOOST_MATH_SPECIAL_HERMITE_HPP
0010 
0011 #ifdef _MSC_VER
0012 #pragma once
0013 #endif
0014 
0015 #include <boost/math/tools/config.hpp>
0016 #include <boost/math/tools/promotion.hpp>
0017 #include <boost/math/special_functions/math_fwd.hpp>
0018 #include <boost/math/policies/error_handling.hpp>
0019 
0020 namespace boost{
0021 namespace math{
0022 
0023 // Recurrence relation for Hermite polynomials:
0024 template <class T1, class T2, class T3>
0025 BOOST_MATH_GPU_ENABLED inline typename tools::promote_args<T1, T2, T3>::type 
0026    hermite_next(unsigned n, T1 x, T2 Hn, T3 Hnm1)
0027 {
0028    using promoted_type = tools::promote_args_t<T1, T2, T3>;
0029    return (2 * promoted_type(x) * promoted_type(Hn) - 2 * n * promoted_type(Hnm1));
0030 }
0031 
0032 namespace detail{
0033 
0034 // Implement Hermite polynomials via recurrence:
0035 template <class T>
0036 BOOST_MATH_GPU_ENABLED T hermite_imp(unsigned n, T x)
0037 {
0038    T p0 = 1;
0039    T p1 = 2 * x;
0040 
0041    if(n == 0)
0042       return p0;
0043 
0044    unsigned c = 1;
0045 
0046    while(c < n)
0047    {
0048       BOOST_MATH_GPU_SAFE_SWAP(p0, p1);
0049       p1 = static_cast<T>(hermite_next(c, x, p0, p1));
0050       ++c;
0051    }
0052    return p1;
0053 }
0054 
0055 } // namespace detail
0056 
0057 template <class T, class Policy>
0058 BOOST_MATH_GPU_ENABLED inline typename tools::promote_args<T>::type 
0059    hermite(unsigned n, T x, const Policy&)
0060 {
0061    typedef typename tools::promote_args<T>::type result_type;
0062    typedef typename policies::evaluation<result_type, Policy>::type value_type;
0063    return policies::checked_narrowing_cast<result_type, Policy>(detail::hermite_imp(n, static_cast<value_type>(x)), "boost::math::hermite<%1%>(unsigned, %1%)");
0064 }
0065 
0066 template <class T>
0067 BOOST_MATH_GPU_ENABLED inline typename tools::promote_args<T>::type 
0068    hermite(unsigned n, T x)
0069 {
0070    return boost::math::hermite(n, x, policies::policy<>());
0071 }
0072 
0073 } // namespace math
0074 } // namespace boost
0075 
0076 #endif // BOOST_MATH_SPECIAL_HERMITE_HPP
0077 
0078 
0079