为什么 scipy.special.comb 和 math.comb 有区别?

Why is there a difference between scipy.special.comb and math.comb?

有人可以解释一下为什么这不相等吗?

import scipy
import math
sum(math.comb(250, i) for i in range(0, 251)) == sum(scipy.special.comb(250, i) for i in range(0, 251))

但是,例如,是吗?

sum(math.comb(25, i) for i in range(0, 26)) == sum(scipy.special.comb(25, i) for i in range(0, 26))

谢谢:)

从您发现的 documentation 中,您必须像这样将 'exact' 标志设置为 True:

scipy.special.comb(250, i, exact=True)

您的代码将显示为

import scipy.special as ssp
import math
print(sum(math.comb(250, i) for i in range(0, 251)) == sum(ssp.comb(250, i, exact=True) for i in range(0, 251)))

并输出'True'.

文档说

exactbool, optional

If exact is False, then floating point precision is used, otherwise exact long integer is computed.