Beispiel #1
0
def test_as_numer_denom():
    assert oo.as_numer_denom() == (1, 0)
    assert (-oo).as_numer_denom() == (-1, 0)
    assert zoo.as_numer_denom() == (zoo, 1)
    assert (-zoo).as_numer_denom() == (zoo, 1)

    assert x.as_numer_denom() == (x, 1)
    assert (1 / x).as_numer_denom() == (1, x)
    assert (x / y).as_numer_denom() == (x, y)
    assert (x / 2).as_numer_denom() == (x, 2)
    assert (x * y / z).as_numer_denom() == (x * y, z)
    assert (x / (y * z)).as_numer_denom() == (x, y * z)
    assert Rational(1, 2).as_numer_denom() == (1, 2)
    assert (1 / y**2).as_numer_denom() == (1, y**2)
    assert (x / y**2).as_numer_denom() == (x, y**2)
    assert ((x**2 + 1) / y).as_numer_denom() == (x**2 + 1, y)
    assert (x * (y + 1) / y**7).as_numer_denom() == (x * (y + 1), y**7)
    assert (x**-2).as_numer_denom() == (1, x**2)
    n = symbols('n', negative=True)
    assert (x**n).as_numer_denom() == (x**n, 1)
    assert sqrt(1 / n).as_numer_denom() == (I, sqrt(-n))
    n = Symbol('0 or neg', nonpositive=True)
    assert (1 / sqrt(x / n)).as_numer_denom() == (1, sqrt(x / n))

    A, B, C = symbols('A,B,C', commutative=False)

    assert (A * B * C**-1).as_numer_denom() == (A * B * C**-1, 1)
    assert (A * B * C**-1 / x).as_numer_denom() == (A * B * C**-1, x)
    assert (C**-1 * A * B).as_numer_denom() == (C**-1 * A * B, 1)
    assert (C**-1 * A * B / x).as_numer_denom() == (C**-1 * A * B, x)
    assert ((A * B * C)**-1).as_numer_denom() == ((A * B * C)**-1, 1)
    assert ((A * B * C)**-1 / x).as_numer_denom() == ((A * B * C)**-1, x)
Beispiel #2
0
def test_as_numer_denom():
    assert oo.as_numer_denom() == (1, 0)
    assert (-oo).as_numer_denom() == (-1, 0)
    assert zoo.as_numer_denom() == (zoo, 1)
    assert (-zoo).as_numer_denom() == (zoo, 1)

    assert x.as_numer_denom() == (x, 1)
    assert (1/x).as_numer_denom() == (1, x)
    assert (x/y).as_numer_denom() == (x, y)
    assert (x/2).as_numer_denom() == (x, 2)
    assert (x*y/z).as_numer_denom() == (x*y, z)
    assert (x/(y*z)).as_numer_denom() == (x, y*z)
    assert Rational(1, 2).as_numer_denom() == (1, 2)
    assert (1/y**2).as_numer_denom() == (1, y**2)
    assert (x/y**2).as_numer_denom() == (x, y**2)
    assert ((x**2+1)/y).as_numer_denom() == (x**2+1, y)
    assert (x*(y+1)/y**7).as_numer_denom() == (x*(y+1), y**7)
    assert (x**-2).as_numer_denom() == (1, x**2)
    n = symbols('n', negative=True)
    assert (x**n).as_numer_denom() == (x**n, 1)
    assert sqrt(1/n).as_numer_denom() == (I, sqrt(-n))
    n = Symbol('0 or neg', nonpositive=True)
    assert ((x/n)**-S.Half).as_numer_denom() == (1, (x/n)**S.Half)

    A, B, C = symbols('A,B,C', commutative=False)

    assert (A*B*C**-1).as_numer_denom() == (A*B*C**-1, 1)
    assert (A*B*C**-1/x).as_numer_denom() == (A*B*C**-1, x)
    assert (C**-1*A*B).as_numer_denom() == (C**-1*A*B, 1)
    assert (C**-1*A*B/x).as_numer_denom() == (C**-1*A*B, x)
    assert ((A*B*C)**-1).as_numer_denom() == ((A*B*C)**-1, 1)
    assert ((A*B*C)**-1/x).as_numer_denom() == ((A*B*C)**-1, x)
Beispiel #3
0
def test_as_numer_denom():
    assert oo.as_numer_denom() == (1, 0)
    assert (-oo).as_numer_denom() == (-1, 0)
    assert zoo.as_numer_denom() == (zoo, 1)
    assert (-zoo).as_numer_denom() == (zoo, 1)
    assert (1/x).as_numer_denom() == (1, x)
    assert x.as_numer_denom() == (x, 1)
    assert (x/y).as_numer_denom() == (x, y)
Beispiel #4
0
def test_as_numer_denom():
    assert oo.as_numer_denom() == (1, 0)
    assert (-oo).as_numer_denom() == (-1, 0)
    assert zoo.as_numer_denom() == (zoo, 1)
    assert (-zoo).as_numer_denom() == (zoo, 1)
    assert (1 / x).as_numer_denom() == (1, x)
    assert x.as_numer_denom() == (x, 1)
    assert (x / y).as_numer_denom() == (x, y)
Beispiel #5
0
def test_as_numer_denom():
    a, b, c = symbols('a, b, c')

    assert nan.as_numer_denom() == (nan, 1)
    assert oo.as_numer_denom() == (oo, 1)
    assert (-oo).as_numer_denom() == (-oo, 1)
    assert zoo.as_numer_denom() == (zoo, 1)
    assert (-zoo).as_numer_denom() == (zoo, 1)

    assert x.as_numer_denom() == (x, 1)
    assert (1 / x).as_numer_denom() == (1, x)
    assert (x / y).as_numer_denom() == (x, y)
    assert (x / 2).as_numer_denom() == (x, 2)
    assert (x * y / z).as_numer_denom() == (x * y, z)
    assert (x / (y * z)).as_numer_denom() == (x, y * z)
    assert Rational(1, 2).as_numer_denom() == (1, 2)
    assert (1 / y**2).as_numer_denom() == (1, y**2)
    assert (x / y**2).as_numer_denom() == (x, y**2)
    assert ((x**2 + 1) / y).as_numer_denom() == (x**2 + 1, y)
    assert (x * (y + 1) / y**7).as_numer_denom() == (x * (y + 1), y**7)
    assert (x**-2).as_numer_denom() == (1, x**2)
    n = symbols('n', negative=True)
    assert (x**n).as_numer_denom() == (x**n, 1)
    assert sqrt(1 / n).as_numer_denom() == (I, sqrt(-n))
    n = Symbol('0 or neg', nonpositive=True)
    assert (1 / sqrt(x / n)).as_numer_denom() == (1, sqrt(x / n))
    assert (a/x + b/2/x + c/3/x).as_numer_denom() == \
            (6*a + 3*b + 2*c, 6*x)
    assert (a/x + b/2/x + c/3/y).as_numer_denom() == \
            (2*c*x + y*(6*a + 3*b), 6*x*y)
    assert (a/x + b/2/x + c/.5/x).as_numer_denom() == \
            (2*a + b + 4.0*c, 2*x)
    # this should take no more than a few seconds
    assert int(
        log(
            Add(*[Dummy() / i / x
                  for i in xrange(1, 705)]).as_numer_denom()[1] /
            x).n(4)) == 705
    for i in [S.Infinity, S.NegativeInfinity, S.ComplexInfinity]:
        assert (i + x/3).as_numer_denom() == \
            (x + i, 3)
    assert (S.Infinity + x/3 + y/4).as_numer_denom() == \
        (4*x + 3*y + S.Infinity, 12)
    assert (oo*x + zoo*y).as_numer_denom() == \
        (zoo*y + oo*x, 1)

    A, B, C = symbols('A,B,C', commutative=False)

    assert (A * B * C**-1).as_numer_denom() == (A * B * C**-1, 1)
    assert (A * B * C**-1 / x).as_numer_denom() == (A * B * C**-1, x)
    assert (C**-1 * A * B).as_numer_denom() == (C**-1 * A * B, 1)
    assert (C**-1 * A * B / x).as_numer_denom() == (C**-1 * A * B, x)
    assert ((A * B * C)**-1).as_numer_denom() == ((A * B * C)**-1, 1)
    assert ((A * B * C)**-1 / x).as_numer_denom() == ((A * B * C)**-1, x)
Beispiel #6
0
def test_as_numer_denom():
    a, b, c = symbols('a, b, c')

    assert nan.as_numer_denom() == (nan, 1)
    assert oo.as_numer_denom() == (oo, 1)
    assert (-oo).as_numer_denom() == (-oo, 1)
    assert zoo.as_numer_denom() == (zoo, 1)
    assert (-zoo).as_numer_denom() == (zoo, 1)

    assert x.as_numer_denom() == (x, 1)
    assert (1/x).as_numer_denom() == (1, x)
    assert (x/y).as_numer_denom() == (x, y)
    assert (x/2).as_numer_denom() == (x, 2)
    assert (x*y/z).as_numer_denom() == (x*y, z)
    assert (x/(y*z)).as_numer_denom() == (x, y*z)
    assert Rational(1, 2).as_numer_denom() == (1, 2)
    assert (1/y**2).as_numer_denom() == (1, y**2)
    assert (x/y**2).as_numer_denom() == (x, y**2)
    assert ((x**2+1)/y).as_numer_denom() == (x**2+1, y)
    assert (x*(y+1)/y**7).as_numer_denom() == (x*(y+1), y**7)
    assert (x**-2).as_numer_denom() == (1, x**2)
    n = symbols('n', negative=True)
    assert (x**n).as_numer_denom() == (x**n, 1)
    assert sqrt(1/n).as_numer_denom() == (I, sqrt(-n))
    n = Symbol('0 or neg', nonpositive=True)
    assert (1/sqrt(x/n)).as_numer_denom() == (1, sqrt(x/n))
    assert (a/x + b/2/x + c/3/x).as_numer_denom() == \
            (6*a + 3*b + 2*c, 6*x)
    assert (a/x + b/2/x + c/3/y).as_numer_denom() == \
            (2*c*x + y*(6*a + 3*b), 6*x*y)
    assert (a/x + b/2/x + c/.5/x).as_numer_denom() == \
            (2*a + b + 4.0*c, 2*x)
    # this should take no more than a few seconds
    assert int(log(Add(*[Dummy()/i/x for i in xrange(1, 705)]
                       ).as_numer_denom()[1]/x).n(4)) == 705
    for i in [S.Infinity, S.NegativeInfinity, S.ComplexInfinity]:
        assert (i + x/3).as_numer_denom() == \
            (x + i, 3)
    assert (S.Infinity + x/3 + y/4).as_numer_denom() == \
        (4*x + 3*y + S.Infinity, 12)
    assert (oo*x + zoo*y).as_numer_denom() == \
        (zoo*y + oo*x, 1)

    A, B, C = symbols('A,B,C', commutative=False)

    assert (A*B*C**-1).as_numer_denom() == (A*B*C**-1, 1)
    assert (A*B*C**-1/x).as_numer_denom() == (A*B*C**-1, x)
    assert (C**-1*A*B).as_numer_denom() == (C**-1*A*B, 1)
    assert (C**-1*A*B/x).as_numer_denom() == (C**-1*A*B, x)
    assert ((A*B*C)**-1).as_numer_denom() == ((A*B*C)**-1, 1)
    assert ((A*B*C)**-1/x).as_numer_denom() == ((A*B*C)**-1, x)
Beispiel #7
0
def test_as_numer_denom():
    assert oo.as_numer_denom() == (1, 0)
    assert (-oo).as_numer_denom() == (-1, 0)
    assert zoo.as_numer_denom() == (zoo, 1)
    assert (-zoo).as_numer_denom() == (zoo, 1)

    assert x.as_numer_denom() == (x, 1)
    assert (1 / x).as_numer_denom() == (1, x)
    assert (x / y).as_numer_denom() == (x, y)
    assert (x / 2).as_numer_denom() == (x, 2)
    assert (x * y / z).as_numer_denom() == (x * y, z)
    assert (x / (y * z)).as_numer_denom() == (x, y * z)
    assert Rational(1, 2).as_numer_denom() == (1, 2)
    assert (1 / y**2).as_numer_denom() == (1, y**2)
    assert (x / y**2).as_numer_denom() == (x, y**2)
    assert ((x**2 + 1) / y).as_numer_denom() == (x**2 + 1, y)
    assert (x * (y + 1) / y**7).as_numer_denom() == (x * (y + 1), y**7)
    assert (x**-2).as_numer_denom() == (1, x**2)
    n = symbols('n', negative=True)
    assert (x**n).as_numer_denom() == (x**n, 1)
    assert sqrt(1 / n).as_numer_denom() == (I, sqrt(-n))
    n = Symbol('0 or neg', nonpositive=True)
    assert ((x / n)**-S.Half).as_numer_denom() == (1, (x / n)**S.Half)
Beispiel #8
0
def test_as_numer_denom():
    assert oo.as_numer_denom() == (1, 0)
    assert (-oo).as_numer_denom() == (-1, 0)
    assert zoo.as_numer_denom() == (zoo, 1)
    assert (-zoo).as_numer_denom() == (zoo, 1)

    assert x.as_numer_denom() == (x, 1)
    assert (1 / x).as_numer_denom() == (1, x)
    assert (x / y).as_numer_denom() == (x, y)
    assert (x / 2).as_numer_denom() == (x, 2)
    assert (x * y / z).as_numer_denom() == (x * y, z)
    assert (x / (y * z)).as_numer_denom() == (x, y * z)
    assert Rational(1, 2).as_numer_denom() == (1, 2)
    assert (1 / y ** 2).as_numer_denom() == (1, y ** 2)
    assert (x / y ** 2).as_numer_denom() == (x, y ** 2)
    assert ((x ** 2 + 1) / y).as_numer_denom() == (x ** 2 + 1, y)
    assert (x * (y + 1) / y ** 7).as_numer_denom() == (x * (y + 1), y ** 7)
    assert (x ** -2).as_numer_denom() == (1, x ** 2)
    n = symbols("n", negative=True)
    assert (x ** n).as_numer_denom() == (x ** n, 1)
    assert sqrt(1 / n).as_numer_denom() == (I, sqrt(-n))
    n = Symbol("0 or neg", nonpositive=True)
    assert ((x / n) ** -S.Half).as_numer_denom() == (1, (x / n) ** S.Half)