sagemath / sage

Main repository of SageMath
https://www.sagemath.org
Other
1.45k stars 481 forks source link

random element madness #12236

Open a9bc4e33-7b98-4180-affc-8dfcef89e22b opened 12 years ago

a9bc4e33-7b98-4180-affc-8dfcef89e22b commented 12 years ago

The following output is generated by the code below using sage-4.7.2:

R: Univariate Quotient Polynomial Ring in xbar over Ring of integers modulo 2 with modulus x^4 + 1
S: Quotient of Univariate Quotient Polynomial Ring in xbar over Integer Ring with modulus x^4 + 1 by the ideal (2)
Now these two rings are isomorphic, but constructed in different orders, so it is not that surprising that SAGE considers them to be different:
R == S: False
And random_element on R seems sensible:
[xbar^3 + xbar + 1, xbar^3 + xbar^2 + 1, xbar^2 + xbar, xbar^2, 1, xbar^2 + xbar, xbar^3, xbar^3, xbar^3 + xbar^2, xbar^2 + xbar + 1]
But random_element on S just doesn't make sense on several levels:
[2, 1, -2, 2, 2, 0, 1, 0, 2, -2]
1) Why are there no polynomial powers?
2) Why are the integers not reduced modulo 2?

Here is the code:

def print_random_elements(R, num_elts=10):
    R_elts = [R.random_element() for i in range(num_elts)]
    print R_elts

def madness():
    U.<x> = ZZ[]
    f = x^4 + 1
    p = 2
    num_elts = 10

    S = U.quotient(f).quotient(p)

    #S.<x> = Integers(p)[]
    #S1 = S.quotient(f)
    R = (Integers(p)['x']).quotient(f)

    print 'R:', R
    print 'S:', S
    print '''Now these two rings are isomorphic, but constructed in different
orders, so it is not that surprising that SAGE considers them to
be different:'''

    print "R == S:", R == S

    print 'And random_element on R seems sensible:'
    print_random_elements(R)

    print "But random_element on S just doesn't make sense on several levels:"
    print_random_elements(S)
    print "1) Why are there no polynomial powers?"
    print "2) Why are the integers not reduced modulo %s?" % p

madness()

Component: basic arithmetic

Stopgaps: todo

Issue created by migration from https://trac.sagemath.org/ticket/12236

swenson commented 12 years ago
comment:1

I have a patch to address some of this that I will post as soon as I can, but there are two issues here, which are identified above.

Issue 1 is a "feature" of QuotientRing_generic that I am still getting to the bottom of, but notice, here

This appears to be related to the following error:

sage: ZZ['x'].quotient(2 * ZZ)
...
TypeError: polynomial must have unit leading coefficient

i.e., polynomial rings seem to expect that, if you mod out by an ideal, it should be a polynomial, which isn't the case if you are trying to mod out by an ideal in the base ring.

This seems to raise other issues with integer ideals interacting with polynomials rings, e.g.,

sage: ZZ['x'].quotient(ZZ['x'].ideal([x^4 + 1, 2])).quotient(2)
Quotient of Univariate Polynomial Ring in x over Integer Ring by the ideal (2, x^4 + 1, 2)
sage: ZZ['x'].quotient(ZZ['x'].ideal([x^4 + 1, 2])).quotient(2)(2)
2

:(

Issue 2 raised above has to do with ideal.reduce(): the default implementation is being called, which just gives a pass-through, i.e.,

sage: Integers(2).ideal().reduce(2)
2

At the very least, this should be coercing its argument into its base ring.

swenson commented 12 years ago
comment:2

Sorry -- didn't mean to steal this from AlexGhitza

mwhansen commented 12 years ago
comment:3

I think that, at least for now, we should just throw an error if you try to quotient out a polynomial ring by an ideal of the base ring since you get a "broken" object.

ea1d0bf8-c27a-4548-8cb7-de0b1d02441a commented 9 years ago

Stopgaps: todo