def test_floor():
    x = Symbol("x")
    y = Symbol("y")
    assert floor(nan) == nan
    assert floor(oo) == oo
    assert floor(-oo) == -oo
    assert floor(0) == 0
    assert floor(1) == 1
    assert floor(-1) == -1
    assert floor(E) == 2
    assert floor(pi) == 3
    assert floor(Rational(1, 2)) == 0
    assert floor(-Rational(1, 2)) == -1
    assert floor(Rational(7, 3)) == 2
    assert floor(-Rational(7, 3)) == -3
    assert floor(Float(17.0)) == 17
    assert floor(-Float(17.0)) == -17
    assert floor(Float(7.69)) == 7
    assert floor(-Float(7.69)) == -8
    assert floor(I) == I
    assert floor(-I) == -I
    assert floor(2 * I) == 2 * I
    assert floor(-2 * I) == -2 * I
    assert floor(E + pi) == floor(E + pi)
    assert floor(I + pi) == floor(I + pi)
    assert floor(floor(pi)) == 3
    assert floor(floor(y)) == floor(y)
    assert floor(floor(x)) == floor(floor(x))
    assert floor(x) == floor(x)
    assert floor(2 * x) == floor(2 * x)
def test_ceiling():
    x = Symbol("x")
    y = Symbol("y")
    assert ceiling(nan) == nan
    assert ceiling(oo) == oo
    assert ceiling(-oo) == -oo
    assert ceiling(0) == 0
    assert ceiling(1) == 1
    assert ceiling(-1) == -1
    assert ceiling(E) == 3
    assert ceiling(pi) == 4
    assert ceiling(Rational(1, 2)) == 1
    assert ceiling(-Rational(1, 2)) == 0
    assert ceiling(Rational(7, 3)) == 3
    assert ceiling(-Rational(7, 3)) == -2
    assert ceiling(Float(17.0)) == 17
    assert ceiling(-Float(17.0)) == -17
    assert ceiling(Float(7.69)) == 8
    assert ceiling(-Float(7.69)) == -7
    assert ceiling(I) == I
    assert ceiling(-I) == -I
    assert ceiling(2 * I) == 2 * I
    assert ceiling(-2 * I) == -2 * I
    assert ceiling(E + pi) == ceiling(E + pi)
    assert ceiling(I + pi) == ceiling(I + pi)
    assert ceiling(ceiling(pi)) == 4
    assert ceiling(ceiling(y)) == ceiling(y)
    assert ceiling(ceiling(x)) == ceiling(ceiling(x))
    assert ceiling(x) == ceiling(x)
    assert ceiling(2 * x) == ceiling(2 * x)
def test_polygamma():
    assert polygamma(0, -9) == zoo
    assert polygamma(0, -9) == zoo
    assert polygamma(0, -1) == zoo
    assert polygamma(0, 0) == zoo
    assert polygamma(0, 1) == -EulerGamma
    assert polygamma(0, 7) == Rational(49, 20) - EulerGamma
    assert polygamma(1, 1) == pi**2 / 6
    assert polygamma(1, 2) == pi**2 / 6 - 1
    assert polygamma(1, 3) == pi**2 / 6 - Rational(5, 4)
    assert polygamma(3, 1) == pi**4 / 15
    assert polygamma(3, 5) == 6 * (Rational(-22369, 20736) + pi**4 / 90)
    assert polygamma(5, 1) == 8 * pi**6 / 63
Esempio n. 4
0
def test_as_numer_denom():
    x, y = Rational(17, 26).as_numer_denom()
    assert x == Integer(17)
    assert y == Integer(26)

    x, y = Integer(-5).as_numer_denom()
    assert x == Integer(-5)
    assert y == Integer(1)
Esempio n. 5
0
def test_Pow_base_exp():
    x = Symbol("x")
    y = Symbol("y")
    e = Pow(x + y, 2)
    assert isinstance(e, Pow)
    assert e.exp == 2
    assert e.base == x + y

    assert sqrt(x - 1).as_base_exp() == (x - 1, Rational(1, 2))
Esempio n. 6
0
def test_S():
    assert S(0) == Integer(0)
    assert S(1) == Integer(1)
    assert S(-1) == Integer(-1)
    assert S(1) / 2 == Rational(1, 2)
    assert S.One is S(1)
    assert S.Zero is S(0)
    assert S.NegativeOne is S(-1)
    assert S.Half is S(1) / 2
    assert S.Pi is pi
    assert S.NaN is S(0) / 0
    assert S.Infinity is -oo * -10
    assert S.NegativeInfinity is oo * (-3)
    assert S.ComplexInfinity is zoo
    assert S.Exp1 is (E + 1 - 1)
    assert S.ImaginaryUnit is sqrt(-1)
    assert S.GoldenRatio * 2 / 2 is GoldenRatio
    assert S.Catalan * 1 is Catalan
    assert S.EulerGamma is polygamma(0, 1) * -1
    assert S.true is Eq(2, 2)
    assert S.false is Eq(2, 3)
    assert S(1) / 0 is zoo
    assert S.Pi * 1 is pi
    assert type(S.One) == One
def test_dirichlet_eta():
    assert dirichlet_eta(0) == Rational(1, 2)
    assert dirichlet_eta(-1) == Rational(1, 4)
    assert dirichlet_eta(1) == log(2)
    assert dirichlet_eta(2) == pi**2 / 12
    assert dirichlet_eta(4) == pi**4 * Rational(7, 720)
def test_zeta():
    x = Symbol("x")
    assert zeta(1) == zoo
    assert zeta(1, x) == zoo

    assert zeta(0) == Rational(-1, 2)
    assert zeta(0, x) == Rational(1, 2) - x

    assert zeta(1, 2) == zoo
    assert zeta(1, -7) == zoo

    assert zeta(2, 1) == pi**2 / 6

    assert zeta(2) == pi**2 / 6
    assert zeta(4) == pi**4 / 90
    assert zeta(6) == pi**6 / 945

    assert zeta(2, 2) == pi**2 / 6 - 1
    assert zeta(4, 3) == pi**4 / 90 - Rational(17, 16)
    assert zeta(6, 4) == pi**6 / 945 - Rational(47449, 46656)

    assert zeta(-1) == -Rational(1, 12)
    assert zeta(-2) == 0
    assert zeta(-3) == Rational(1, 120)
    assert zeta(-4) == 0
    assert zeta(-5) == -Rational(1, 252)

    assert zeta(-1, 3) == -Rational(37, 12)
    assert zeta(-1, 7) == -Rational(253, 12)
    assert zeta(-1, -4) == Rational(119, 12)
    assert zeta(-1, -9) == Rational(539, 12)

    assert zeta(-4, 3) == -17
    assert zeta(-4, -8) == 8772

    assert zeta(0, 1) == -Rational(1, 2)
    assert zeta(0, -1) == Rational(3, 2)

    assert zeta(0, 2) == -Rational(3, 2)
    assert zeta(0, -2) == Rational(5, 2)
Esempio n. 9
0
def test_special_constants():
    assert Zero() == Integer(0)
    assert One() == Integer(1)
    assert NegativeOne() == Integer(-1)
    assert Half() == Rational(1, 2)
Esempio n. 10
0
def test_is_real():
    assert Rational(1, 2).is_real
    assert Symbol('x').is_real is None
Esempio n. 11
0
def test_is_nonnegative():
    assert Rational(1, 2).is_nonnegative
    assert not Rational(-2, 3).is_nonnegative
    assert Symbol('x').is_nonnegative is None
Esempio n. 12
0
def test_special_constants():
    assert S.Zero == Integer(0)
    assert S.One == Integer(1)
    assert S.NegativeOne == Integer(-1)
    assert S.Half == Rational(1, 2)
Esempio n. 13
0
import numpy as np
from numpy.testing.utils import assert_allclose
from jitcsde import jitcsde_jump, y, UnsuccessfulIntegration
import platform
from symengine import symbols, exp, Rational
import unittest

if platform.system() == "Windows":
	compile_args = None
else:
	from jitcxde_common import DEFAULT_COMPILE_ARGS
	compile_args = DEFAULT_COMPILE_ARGS+["-g","-UNDEBUG"]

f = [-y(0)**3 + 4*y(0) + y(0)**2]
g = [5*exp(-y(0)**2+y(0)-Rational(3,2)) + 3]

λ = 1000
initial_value = np.array([1.0])

# Normal noise

result = None

class CompareResults(unittest.TestCase):
	def compare_with_result(self,new_result):
		global result
		if result is None:
			result = new_result
		else:
			assert_allclose(
					result-initial_value,
Esempio n. 14
0
from numpy.testing.utils import assert_allclose
from jitcsde import jitcsde, y, UnsuccessfulIntegration, test
import platform
from symengine import symbols, exp, Rational, Function
import unittest

if platform.system() == "Windows":
    compile_args = None
else:
    from jitcxde_common import DEFAULT_COMPILE_ARGS
    compile_args = DEFAULT_COMPILE_ARGS + ["-g", "-UNDEBUG"]

# Ensures that all kinds of formatting the input actually work and produce the same result. The correctness of this result itself is checked in validation_test.py.

f = [-y(0)**3 + 4 * y(0) + y(0)**2]
g = [5 * exp(-y(0)**2 + y(0) - Rational(3, 2)) + 3]
initial_value = np.array([1.0])

# Normal noise

result = None


class CompareResults(unittest.TestCase):
    def compare_with_result(self, new_result):
        global result
        if result is None:
            result = new_result
        else:
            assert_allclose(result - initial_value,
                            new_result - initial_value,
Esempio n. 15
0
from numpy.testing.utils import assert_allclose
from jitcsde import jitcsde, y, UnsuccessfulIntegration, test
import platform
from symengine import symbols, exp, Rational
import unittest

if platform.system() == "Windows":
    compile_args = None
else:
    from jitcxde_common import DEFAULT_COMPILE_ARGS
    compile_args = DEFAULT_COMPILE_ARGS + ["-g", "-UNDEBUG"]

# Ensures that all kinds of formatting the input actually work and produce the same result. The correctness of this result itself is checked in validation_test.py.

f = [-y(0)**3 + 4 * y(0) + y(0)**2]
g = [5 * exp(-y(0)**2 + y(0) - Rational(3, 2)) + 3]
initial_value = np.array([1.0])

# Normal noise

result = None


class CompareResults(unittest.TestCase):
    def compare_with_result(self, new_result):
        global result
        if result is None:
            result = new_result
        else:
            assert_allclose(result - initial_value,
                            new_result - initial_value,