helpers.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:quadpy 作者: nschloe 项目源码 文件源码
def integrate_monomial_over_unit_nsphere(alpha):
    '''
    Gerald B. Folland,
    How to Integrate a Polynomial over a Sphere,
    The American Mathematical Monthly,
    Vol. 108, No. 5 (May, 2001), pp. 446-448,
    <https://doi.org/10.2307/2695802>.
    '''
    if any(a % 2 == 1 for a in alpha):
        return 0
    # Use lgamma since other with ordinary gamma, numerator and denominator
    # might overflow.
    # return 2 * math.exp(
    #     math.fsum([math.lgamma(0.5*(a+1)) for a in alpha])
    #     - math.lgamma(math.fsum([0.5*(a+1) for a in alpha]))
    #     )

    # Explicitly cast a to int (from numpy.int64) to work around bug
    # <https://github.com/sympy/sympy/issues/13618>.
    return 2 * (
        prod([gamma(Rational(int(a)+1, 2)) for a in alpha])
        / gamma(sum([Rational(int(a)+1, 2) for a in alpha]))
        )
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号