示例#1
0
def x_minus_y() -> Polynomial:
    x = Symbol('x')
    y = Symbol('y')
    term_x = PolynomialTerm(Monomial({MonomialFactor(x, 1)}), 1.0)
    term_minus_y = PolynomialTerm(Monomial({MonomialFactor(y, 1)}), -1.0)

    return Polynomial({term_x, term_minus_y})
示例#2
0
def x_sq_minus_y_sq() -> Polynomial:
    x = Symbol('x')
    y = Symbol('y')
    term_x_sq = PolynomialTerm(Monomial({MonomialFactor(x, 2)}), 1.0)
    term_minus_y_sq = PolynomialTerm(Monomial({MonomialFactor(y, 2)}), -1.0)

    return Polynomial({term_x_sq, term_minus_y_sq})
示例#3
0
def two_x_plus_two_y() -> Polynomial:
    x = Symbol('x')
    y = Symbol('y')
    term_two_x = PolynomialTerm(Monomial({MonomialFactor(x, 1)}), 2.0)
    term_two_y = PolynomialTerm(Monomial({MonomialFactor(y, 1)}), 2.0)

    return Polynomial({term_two_x, term_two_y})
示例#4
0
def x_sq_plus_two_xy_plus_y_sq() -> Polynomial:
    x = Symbol('x')
    y = Symbol('y')
    term_2xy = PolynomialTerm(Monomial({MonomialFactor(x, 1), MonomialFactor(y, 1)}), 2.0)
    term_x_sq = PolynomialTerm(Monomial({MonomialFactor(x, 2)}), 1.0)
    term_y_sq = PolynomialTerm(Monomial({MonomialFactor(y, 2)}), 1.0)

    return Polynomial({term_x_sq, term_y_sq, term_2xy})
示例#5
0
def test_monomial_multiplication_positive_powers() -> None:
    x = Symbol('x')
    y = Symbol('y')
    z = Symbol('z')

    first_monomial = Monomial({MonomialFactor(x, 2), MonomialFactor(y, 3), MonomialFactor(z, 4)})
    second_monomial = Monomial({MonomialFactor(x, 1), MonomialFactor(y, 1), MonomialFactor(z, 1)})

    assert first_monomial * second_monomial == \
           Monomial({MonomialFactor(x, 3), MonomialFactor(y, 4), MonomialFactor(z, 5)})
示例#6
0
def test_monomial_multiplication_to_trivial() -> None:
    x = Symbol('x')
    y = Symbol('y')
    z = Symbol('z')

    first_monomial = Monomial({MonomialFactor(x, 2), MonomialFactor(y, -3), MonomialFactor(z, 4)})
    second_monomial = Monomial({MonomialFactor(x, -2), MonomialFactor(z, -4), MonomialFactor(y, 3)})

    assert first_monomial * second_monomial == Monomial({MonomialFactor(TrivialMulSymbol(), 0)})
    assert second_monomial * first_monomial == TrivialMonomial()
示例#7
0
def test_monomial_symbols() -> None:
    x = Symbol('x')
    y = Symbol('y')
    z = Symbol('z')

    Monomial({MonomialFactor(x, 2), MonomialFactor(y, 3), MonomialFactor(z, 4)})

    assert Monomial({MonomialFactor(x, 2), MonomialFactor(y, 3), MonomialFactor(z, 4)}).symbols == \
           {x, y, z}

    assert Monomial({MonomialFactor(x, 2), MonomialFactor(y, 3)}).symbols == {x, y}
示例#8
0
def first_lotke_volterra_ode() -> ODE:
    # return dx/dt = x - x*y
    x = Symbol('x')
    y = Symbol('y')
    rhs = Polynomial({
        PolynomialTerm(Monomial({MonomialFactor(x, 1)}), 1),
        PolynomialTerm(Monomial({MonomialFactor(x, 1),
                                 MonomialFactor(y, 1)}), -1)
    })

    return ODE(x, rhs)
示例#9
0
def second_lotke_volterra_ode() -> ODE:
    # return dy/dt = x*y - y
    x = Symbol('x')
    y = Symbol('y')
    rhs = Polynomial({
        PolynomialTerm(Monomial({MonomialFactor(y, 1)}), -1),
        PolynomialTerm(Monomial({MonomialFactor(x, 1),
                                 MonomialFactor(y, 1)}), 1)
    })

    return ODE(y, rhs)
示例#10
0
def one_x() -> Polynomial:
    x = Symbol('x')
    one_x = PolynomialTerm(Monomial({MonomialFactor(x, 1)}), 1.0)

    return Polynomial({one_x})
示例#11
0
def const_one() -> Polynomial:
    x = TrivialMulSymbol()
    one = PolynomialTerm(Monomial({MonomialFactor(x, 0)}), 1.0)

    return Polynomial({one})
示例#12
0
def two_x() -> Polynomial:
    x = Symbol('x')
    term_two_x = PolynomialTerm(Monomial({MonomialFactor(x, 1)}), 2.0)

    return Polynomial({term_two_x})
示例#13
0
def one_y() -> Polynomial:
    y = Symbol('y')
    one_y = PolynomialTerm(Monomial({MonomialFactor(y, 1)}), 1.0)

    return Polynomial({one_y})