Exemple #1
0
def test_localring():
    Qxy = QQ.old_frac_field(x, y)
    R = QQ.old_poly_ring(x, y, order="ilex")
    X = R.convert(x)
    Y = R.convert(y)

    assert x in R
    assert 1/x not in R
    assert 1/(1 + x) in R
    assert Y in R
    assert X.ring == R
    assert X*(Y**2 + 1)/(1 + X) == R.convert(x*(y**2 + 1)/(1 + x))
    assert X*y == X*Y
    raises(ExactQuotientFailed, lambda: X/Y)
    raises(ExactQuotientFailed, lambda: x/Y)
    raises(ExactQuotientFailed, lambda: X/y)
    assert X + y == X + Y == R.convert(x + y) == x + Y
    assert X - y == X - Y == R.convert(x - y) == x - Y
    assert X + 1 == R.convert(x + 1)
    assert X**2 / X == X

    assert R.from_GlobalPolynomialRing(ZZ.old_poly_ring(x, y).convert(x), ZZ.old_poly_ring(x, y)) == X
    assert R.from_FractionField(Qxy.convert(x), Qxy) == X
    raises(CoercionFailed, lambda: R.from_FractionField(Qxy.convert(x)/y, Qxy))
    raises(ExactQuotientFailed, lambda: X/Y)
    raises(NotReversible, lambda: X.invert())

    assert R._sdm_to_vector(
        R._vector_to_sdm([X/(X + 1), Y/(1 + X*Y)], R.order), 2) == \
        [X*(1 + X*Y), Y*(1 + X)]
Exemple #2
0
def test_globalring():
    Qxy = QQ.old_frac_field(x, y)
    R = QQ.old_poly_ring(x, y)
    X = R.convert(x)
    Y = R.convert(y)

    assert x in R
    assert 1/x not in R
    assert 1/(1 + x) not in R
    assert Y in R
    assert X.ring == R
    assert X * (Y**2 + 1) == R.convert(x * (y**2 + 1))
    assert X * y == X * Y == R.convert(x * y) == x * Y
    assert X + y == X + Y == R.convert(x + y) == x + Y
    assert X - y == X - Y == R.convert(x - y) == x - Y
    assert X + 1 == R.convert(x + 1)
    raises(ExactQuotientFailed, lambda: X/Y)
    raises(ExactQuotientFailed, lambda: x/Y)
    raises(ExactQuotientFailed, lambda: X/y)
    assert X**2 / X == X

    assert R.from_GlobalPolynomialRing(ZZ.old_poly_ring(x, y).convert(x), ZZ.old_poly_ring(x, y)) == X
    assert R.from_FractionField(Qxy.convert(x), Qxy) == X
    assert R.from_FractionField(Qxy.convert(x)/y, Qxy) is None

    assert R._sdm_to_vector(R._vector_to_sdm([X, Y], R.order), 2) == [X, Y]
Exemple #3
0
def test_localring():
    Qxy = QQ.old_frac_field(x, y)
    R = QQ.old_poly_ring(x, y, order="ilex")
    X = R.convert(x)
    Y = R.convert(y)

    assert x in R
    assert 1/x not in R
    assert 1/(1 + x) in R
    assert Y in R
    assert X.ring == R
    assert X*(Y**2 + 1)/(1 + X) == R.convert(x*(y**2 + 1)/(1 + x))
    assert X*y == X*Y
    raises(ExactQuotientFailed, lambda: X/Y)
    raises(ExactQuotientFailed, lambda: x/Y)
    raises(ExactQuotientFailed, lambda: X/y)
    assert X + y == X + Y == R.convert(x + y) == x + Y
    assert X - y == X - Y == R.convert(x - y) == x - Y
    assert X + 1 == R.convert(x + 1)
    assert X**2 / X == X

    assert R.from_GlobalPolynomialRing(ZZ.old_poly_ring(x, y).convert(x), ZZ.old_poly_ring(x, y)) == X
    assert R.from_FractionField(Qxy.convert(x), Qxy) == X
    raises(CoercionFailed, lambda: R.from_FractionField(Qxy.convert(x)/y, Qxy))
    raises(ExactQuotientFailed, lambda: X/Y)
    raises(NotReversible, lambda: X.invert())

    assert R._sdm_to_vector(
        R._vector_to_sdm([X/(X + 1), Y/(1 + X*Y)], R.order), 2) == \
        [X*(1 + X*Y), Y*(1 + X)]
Exemple #4
0
def test_globalring():
    Qxy = QQ.old_frac_field(x, y)
    R = QQ.old_poly_ring(x, y)
    X = R.convert(x)
    Y = R.convert(y)

    assert x in R
    assert 1/x not in R
    assert 1/(1 + x) not in R
    assert Y in R
    assert X.ring == R
    assert X * (Y**2 + 1) == R.convert(x * (y**2 + 1))
    assert X * y == X * Y == R.convert(x * y) == x * Y
    assert X + y == X + Y == R.convert(x + y) == x + Y
    assert X - y == X - Y == R.convert(x - y) == x - Y
    assert X + 1 == R.convert(x + 1)
    raises(ExactQuotientFailed, lambda: X/Y)
    raises(ExactQuotientFailed, lambda: x/Y)
    raises(ExactQuotientFailed, lambda: X/y)
    assert X**2 / X == X

    assert R.from_GlobalPolynomialRing(ZZ.old_poly_ring(x, y).convert(x), ZZ.old_poly_ring(x, y)) == X
    assert R.from_FractionField(Qxy.convert(x), Qxy) == X
    assert R.from_FractionField(Qxy.convert(x)/y, Qxy) is None

    assert R._sdm_to_vector(R._vector_to_sdm([X, Y], R.order), 2) == [X, Y]
Exemple #5
0
def _normalize(list_of, parent, negative=True):
    """
    Normalize a given annihilator
    """

    num = []
    denom = []
    base = parent.base
    K = base.get_field()
    R = ZZ.old_poly_ring(base.gens[0])
    lcm_denom = R.from_sympy(S(1))
    list_of_coeff = []

    # convert polynomials to the elements of associated
    # fraction field
    for i, j in enumerate(list_of):
        if isinstance(j, base.dtype):
            list_of_coeff.append(K.new(j.rep))
        elif not isinstance(j, K.dtype):
            list_of_coeff.append(K.from_sympy(sympify(j)))
        else:
            list_of_coeff.append(j)

        # corresponding numerators of the sequence of polynomials
        num.append(base(list_of_coeff[i].num))

        # corresponding denominators
        den = list_of_coeff[i].den
        if isinstance(den[0], PythonRational):
            for i, j in enumerate(den):
                den[i] = j.p

        denom.append(R(den))

    # lcm of denominators in the coefficients
    for i in denom:
        lcm_denom = i.lcm(lcm_denom)

    if negative is True:
        lcm_denom = -lcm_denom

    lcm_denom = K.new(lcm_denom.rep)

    # multiply the coefficients with lcm
    for i, j in enumerate(list_of_coeff):
        list_of_coeff[i] = j * lcm_denom

    gcd_numer = base.from_FractionField(list_of_coeff[-1], K)

    # gcd of numerators in the coefficients
    for i in num:
        gcd_numer = i.gcd(gcd_numer)

    gcd_numer = K.new(gcd_numer.rep)

    # divide all the coefficients by the gcd
    for i, j in enumerate(list_of_coeff):
        list_of_coeff[i] = base.from_FractionField(j / gcd_numer, K)

    return DifferentialOperator(list_of_coeff, parent)
Exemple #6
0
def test_GlobalPolynomialRing_convert():
    K1 = QQ.old_poly_ring(x)
    K2 = QQ[x]
    assert K1.convert(x) == K1.convert(K2.convert(x), K2)
    assert K2.convert(x) == K2.convert(K1.convert(x), K1)

    K1 = QQ.old_poly_ring(x, y)
    K2 = QQ[x]
    assert K1.convert(x) == K1.convert(K2.convert(x), K2)
    #assert K2.convert(x) == K2.convert(K1.convert(x), K1)

    K1 = ZZ.old_poly_ring(x, y)
    K2 = QQ[x]
    assert K1.convert(x) == K1.convert(K2.convert(x), K2)
Exemple #7
0
def test_units():
    R = QQ.old_poly_ring(x)
    assert R.is_unit(R.convert(1))
    assert R.is_unit(R.convert(2))
    assert not R.is_unit(R.convert(x))
    assert not R.is_unit(R.convert(1 + x))

    R = QQ.old_poly_ring(x, order='ilex')
    assert R.is_unit(R.convert(1))
    assert R.is_unit(R.convert(2))
    assert not R.is_unit(R.convert(x))
    assert R.is_unit(R.convert(1 + x))

    R = ZZ.old_poly_ring(x)
    assert R.is_unit(R.convert(1))
    assert not R.is_unit(R.convert(2))
    assert not R.is_unit(R.convert(x))
    assert not R.is_unit(R.convert(1 + x))
Exemple #8
0
def test_units():
    R = QQ.old_poly_ring(x)
    assert R.is_unit(R.convert(1))
    assert R.is_unit(R.convert(2))
    assert not R.is_unit(R.convert(x))
    assert not R.is_unit(R.convert(1 + x))

    R = QQ.old_poly_ring(x, order='ilex')
    assert R.is_unit(R.convert(1))
    assert R.is_unit(R.convert(2))
    assert not R.is_unit(R.convert(x))
    assert R.is_unit(R.convert(1 + x))

    R = ZZ.old_poly_ring(x)
    assert R.is_unit(R.convert(1))
    assert not R.is_unit(R.convert(2))
    assert not R.is_unit(R.convert(x))
    assert not R.is_unit(R.convert(1 + x))
Exemple #9
0
def _normalize(list_of, parent, negative=True):
    """
    Normalize a given annihilator
    """

    num = []
    denom = []
    base = parent.base
    K = base.get_field()
    R = ZZ.old_poly_ring(base.gens[0])
    lcm_denom = R.from_sympy(S(1))
    list_of_coeff = []

    for i, j in enumerate(list_of):
        if not isinstance(j, K.dtype):
            list_of_coeff.append(K.from_sympy(sympify(j)))
        else:
            list_of_coeff.append(j)
        num.append(base(list_of_coeff[i].num))
        den = list_of_coeff[i].den
        if isinstance(den[0], PythonRational):
            for i, j in enumerate(den):
                den[i] = j.p
        denom.append(R(den))

    for i in denom:
        lcm_denom = i.lcm(lcm_denom)

    if negative is True:
        lcm_denom = -lcm_denom

    lcm_denom = K.new(lcm_denom.rep)

    for i, j in enumerate(list_of_coeff):
        list_of_coeff[i] = j * lcm_denom

    gcd_numer = base.from_FractionField(list_of_coeff[-1], K)
    for i in num:
        gcd_numer = i.gcd(gcd_numer)
    gcd_numer = K.new(gcd_numer.rep)
    for i, j in enumerate(list_of_coeff):
        list_of_coeff[i] = base.from_FractionField(j / gcd_numer, K)

    return DifferentialOperator(list_of_coeff, parent)
Exemple #10
0
def _normalize(list_of, parent, negative=True):
    """
    Normalize a given annihilator
    """

    num = []
    denom = []
    base = parent.base
    K = base.get_field()
    R = ZZ.old_poly_ring(base.gens[0])
    lcm_denom = R.from_sympy(S(1))
    list_of_coeff = []

    for i, j in enumerate(list_of):
        if not isinstance(j, K.dtype):
            list_of_coeff.append(K.from_sympy(sympify(j)))
        else:
            list_of_coeff.append(j)
        num.append(base(list_of_coeff[i].num))
        den = list_of_coeff[i].den
        if isinstance(den[0], PythonRational):
            for i, j in enumerate(den):
                den[i] = j.p
        denom.append(R(den))

    for i in denom:
        lcm_denom = i.lcm(lcm_denom)

    if negative is True:
        lcm_denom = -lcm_denom

    lcm_denom = K.new(lcm_denom.rep)

    for i, j in enumerate(list_of_coeff):
        list_of_coeff[i] = j * lcm_denom

    gcd_numer = base.from_FractionField(list_of_coeff[-1], K)
    for i in num:
        gcd_numer = i.gcd(gcd_numer)
    gcd_numer = K.new(gcd_numer.rep)
    for i, j in enumerate(list_of_coeff):
        list_of_coeff[i] = base.from_FractionField(j / gcd_numer, K)

    return DifferentialOperator(list_of_coeff, parent)