Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-07-02 08:16:58

0001 //  Copyright (c) 2013 Anton Bikineev
0002 //  Use, modification and distribution are subject to the
0003 //  Boost Software License, Version 1.0. (See accompanying file
0004 //  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0005 
0006 //
0007 // This is a partial header, do not include on it's own!!!
0008 //
0009 // Linear combination for bessel derivatives are defined here
0010 #ifndef BOOST_MATH_SF_DETAIL_BESSEL_DERIVATIVES_LINEAR_HPP
0011 #define BOOST_MATH_SF_DETAIL_BESSEL_DERIVATIVES_LINEAR_HPP
0012 #include <iostream>
0013 #ifdef _MSC_VER
0014 #pragma once
0015 #endif
0016 
0017 namespace boost{ namespace math{ namespace detail{
0018 
0019 template <class T, class Tag, class Policy>
0020 inline T bessel_j_derivative_linear(T v, T x, Tag tag, Policy pol)
0021 {
0022    return (boost::math::detail::cyl_bessel_j_imp<T>(v-1, x, tag, pol) - boost::math::detail::cyl_bessel_j_imp<T>(v+1, x, tag, pol)) / 2;
0023 }
0024 
0025 template <class T, class Policy>
0026 inline T bessel_j_derivative_linear(T v, T x, const bessel_int_tag& tag, Policy pol)
0027 {
0028    return (boost::math::detail::cyl_bessel_j_imp<T>(itrunc(v-1), x, tag, pol) - boost::math::detail::cyl_bessel_j_imp<T>(itrunc(v+1), x, tag, pol)) / 2;
0029 }
0030 
0031 template <class T, class Policy>
0032 inline T sph_bessel_j_derivative_linear(unsigned v, T x, Policy pol)
0033 {
0034    return (v / x) * boost::math::detail::sph_bessel_j_imp<T>(v, x, pol) - boost::math::detail::sph_bessel_j_imp<T>(v+1, x, pol);
0035 }
0036 
0037 template <class T, class Policy>
0038 inline T bessel_i_derivative_linear(T v, T x, Policy pol)
0039 {
0040    T result = boost::math::detail::cyl_bessel_i_imp<T>(v - 1, x, pol);
0041    if(result >= tools::max_value<T>())
0042       return result;  // result is infinite
0043    // Both experimentally, and based on https://www.wolframalpha.com/input?i=BesselI%5Bv%2C+x%5D%2FBesselI%5Bv%2B2%2C+x%5D
0044    // I[v + 1, x] < I[v-1, x], so this can't overflow:
0045    T result2 = boost::math::detail::cyl_bessel_i_imp<T>(v + 1, x, pol);
0046 
0047    return result / 2 + result2 / 2;
0048 }
0049 
0050 template <class T, class Tag, class Policy>
0051 inline T bessel_k_derivative_linear(T v, T x, Tag tag, Policy pol)
0052 {
0053    T result = boost::math::detail::cyl_bessel_k_imp<T>(v - 1, x, tag, pol);
0054    if(result >= tools::max_value<T>())
0055       return -result;  // result is infinite
0056    T result2 = boost::math::detail::cyl_bessel_k_imp<T>(v + 1, x, tag, pol);
0057    if(result2 >= tools::max_value<T>() + result)
0058       return -boost::math::policies::raise_overflow_error<T>("cyl_bessel_k_prime<%1>", 0, pol);  // result is infinite
0059    result /= -2;
0060    result2 /= -2;
0061    return result + result2;
0062 }
0063 
0064 template <class T, class Policy>
0065 inline T bessel_k_derivative_linear(T v, T x, const bessel_int_tag& tag, Policy pol)
0066 {
0067    T result = boost::math::detail::cyl_bessel_k_imp<T>(itrunc(v - 1), x, tag, pol);
0068    if (result >= tools::max_value<T>())
0069       return -result;  // result is infinite
0070    T result2 = boost::math::detail::cyl_bessel_k_imp<T>(itrunc(v + 1), x, tag, pol);
0071    if (result2 >= tools::max_value<T>() + result)
0072       return -boost::math::policies::raise_overflow_error<T>("cyl_bessel_k_prime<%1>", 0, pol);  // result is infinite
0073    result /= -2;
0074    result2 /= -2;
0075    return result + result2;
0076 }
0077 
0078 template <class T, class Policy>
0079 inline T bessel_k_derivative_linear(T v, T x, const bessel_maybe_int_tag&, Policy pol)
0080 {
0081    using std::floor;
0082    if (floor(v) == v)
0083       return bessel_k_derivative_linear(v, x, bessel_int_tag(), pol);
0084    return bessel_k_derivative_linear(v, x, bessel_no_int_tag(), pol);
0085 }
0086 
0087 template <class T, class Tag, class Policy>
0088 inline T bessel_y_derivative_linear(T v, T x, Tag tag, Policy pol)
0089 {
0090    return (boost::math::detail::cyl_neumann_imp<T>(v-1, x, tag, pol) - boost::math::detail::cyl_neumann_imp<T>(v+1, x, tag, pol)) / 2;
0091 }
0092 
0093 template <class T, class Policy>
0094 inline T bessel_y_derivative_linear(T v, T x, const bessel_int_tag& tag, Policy pol)
0095 {
0096    return (boost::math::detail::cyl_neumann_imp<T>(itrunc(v-1), x, tag, pol) - boost::math::detail::cyl_neumann_imp<T>(itrunc(v+1), x, tag, pol)) / 2;
0097 }
0098 
0099 template <class T, class Policy>
0100 inline T sph_neumann_derivative_linear(unsigned v, T x, Policy pol)
0101 {
0102    return (v / x) * boost::math::detail::sph_neumann_imp<T>(v, x, pol) - boost::math::detail::sph_neumann_imp<T>(v+1, x, pol);
0103 }
0104 
0105 }}} // namespaces
0106 
0107 #endif // BOOST_MATH_SF_DETAIL_BESSEL_DERIVATIVES_LINEAR_HPP