def test_nsum():
    mp.dps = 15
    assert nsum(lambda x: x**2, [1, 3]) == 14
    assert nsum(lambda k: 1/factorial(k), [0, inf]).ae(e)
    assert nsum(lambda k: (-1)**(k+1) / k, [1, inf]).ae(log(2))
    assert nsum(lambda k: (-1)**(k+1) / k**2, [1, inf]).ae(pi**2 / 12)
    assert nsum(lambda k: (-1)**k / log(k), [2, inf]).ae(0.9242998972229388)
    assert nsum(lambda k: 1/k**2, [1, inf]).ae(pi**2 / 6)
    assert nsum(lambda k: fac(k)/2**k, [0, inf]).ae(exp(2))
    assert nsum(lambda k: 1/k**2, [4, inf], method='e').ae(0.2838229557371153)
dataset/ETHPy150Open fredrik-johansson/mpmath/mpmath/tests/test_summation.py/test_nsum/swapped operands of `/`