예제 #1
0
def test_prime_factor_multiplicities():
    assert prime_factor_multiplicities(90) == {
        Integer(2): 1,
        Integer(3): 2,
        Integer(5): 1
    }
    assert prime_factor_multiplicities(1) == {}
예제 #2
0
def test_ccode():
    x = Symbol("x")
    y = Symbol("y")
    assert ccode(x) == "x"
    assert ccode(x**3) == "pow(x, 3)"
    assert ccode(x**(y**3)) == "pow(x, pow(y, 3))"
    assert ccode(x**-1.0) == "pow(x, -1.0)"
    assert ccode(Max(x, x*x)) == "max(x, pow(x, 2))"
    assert ccode(sin(x)) == "sin(x)"
    assert ccode(Integer(67)) == "67"
    assert ccode(Integer(-1)) == "-1"
예제 #3
0
def test_set():
    i7 = Integer(7)
    y = Symbol("y")
    g = function_symbol("g", y)
    c = 2*I + 3
    A = DenseMatrix(2, 2,
        [Integer(5), Symbol("x"), function_symbol("f", Symbol("x")), 1 + I])

    A.set(0, 0, i7)
    assert A.get(0, 0) == i7
    A.set(0, 1, y)
    assert A.get(0, 1) == y
    A.set(1, 0, g)
    assert A.get(1, 0) == g
    A.set(1, 1, c)
    assert A.get(1, 1) == c
예제 #4
0
def test_add_scalar():
    A = DenseMatrix(2, 2, [1, 2, 3, 4])

    a = Symbol("a")
    assert A.add_scalar(a) == DenseMatrix(2, 2, [1 + a, 2 + a, 3 + a, 4 + a])

    i5 = Integer(5)
    assert A.add_scalar(i5) == DenseMatrix(2, 2, [6, 7, 8, 9])
    raises(TypeError, lambda: A + 5)
    raises(TypeError, lambda: 5 + A)
예제 #5
0
def test_mul_scalar():
    A = DenseMatrix(2, 2, [1, 2, 3, 4])

    a = Symbol("a")
    assert A.mul_scalar(a) == DenseMatrix(2, 2, [a, 2 * a, 3 * a, 4 * a])

    i5 = Integer(5)
    assert A.mul_scalar(i5) == DenseMatrix(2, 2, [5, 10, 15, 20])
    assert A * 5 == DenseMatrix(2, 2, [5, 10, 15, 20])
    assert 5 * A == DenseMatrix(2, 2, [5, 10, 15, 20])
예제 #6
0
def test_add_scalar():
    A = DenseMatrix(2, 2, [1, 2, 3, 4])

    a = Symbol("a")
    assert A.add_scalar(a) == DenseMatrix(2, 2, [1 + a, 2 + a, 3 + a, 4 + a])

    i5 = Integer(5)
    assert A.add_scalar(i5) == DenseMatrix(2, 2, [6, 7, 8, 9])
    assert A + 5 == DenseMatrix(2, 2, [6, 7, 8, 9])
    assert 5 + A == DenseMatrix(2, 2, [6, 7, 8, 9])
예제 #7
0
def test_series_expansion():
    x = Symbol('x')
    ex = series(sin(1 + x), x, n=10)
    assert ex.coeff(x, 7) == -cos(1) / 5040

    x = Symbol('x')
    ex = series(1 / (1 - x), x, n=10)
    assert ex.coeff(x, 9) == 1
    ex = series(sin(x) * cos(x), x, n=10)
    assert ex.coeff(x, 8) == 0
    assert ex.coeff(x, 9) == Integer(2) / Integer(2835)

    ex = series(E**x, x, n=10)
    assert ex.coeff(x, 9) == Integer(1) / Integer(362880)
    ex1 = series(1 / sqrt(4 - x), x, n=50)
    ex2 = series((4 - x)**(Integer(-1) / Integer(2)), x, n=50)
    assert ex1.coeff(x, 49) == ex2.coeff(x, 49)
예제 #8
0
def test_powermod_list():
    assert powermod_list(15, Integer(1) / 6, 21) == [3, 6, 9, 12, 15, 18]
    assert powermod_list(2, Integer(5) / 2, 11) == []
예제 #9
0
def test_powermod():
    assert powermod(3, 8, 7) == 2
    assert powermod(3, Integer(11) / 2, 13) in [3, 10]