# Iterate over Elements of Finite Quotient (of a Polynomial Ring) Consider the following, which works:

sage: R.<x> = Integers(4)[]
sage: Q.<a> = R.quotient(x^2)
sage: for q in Q:
....:     q
....:
0
1
2
3
a
a + 1
a + 2
a + 3
2*a
2*a + 1
2*a + 2
2*a + 3
3*a
3*a + 1
3*a + 2
3*a + 3


Now if I add a generator to the ideal and execute

sage: Q.<a> = R.quotient((x^2,2*x))
sage: for q in Q:
....:     q
....:


which should yield a quotient with 8 elements, I get an error:

NotImplementedError: object does not support iteration


How can I make it work? Sage doesn't seem to be able to deal with finite rings that aren't principal ideal rings.

edit retag close merge delete

Sort by » oldest newest most voted

Use GF(4) (finite field) rather Zmod(4) (finite ring not explicitely known to be a field) :

sage: reset()
sage: Zmod(4).is_field()
False
sage: GF(4).is_field()
True
sage: R.<x>=Zmod(4)[]
sage: Q.<a>=R.quotient((x^2,2*x))
sage: len(list(Q))
---------------------------------------------------------------------------
NotImplementedError                       Traceback (most recent call last)
Input In , in <cell line: 1>()
----> 1 len(list(Q))

File /usr/local/sage-9/src/sage/rings/ring.pyx:220, in sage.rings.ring.Ring.__iter__()
218         NotImplementedError: object does not support iteration
219     """
--> 220     raise NotImplementedError("object does not support iteration")
221
222 def __len__(self):

NotImplementedError: object does not support iteration


But :

sage: R.<x>=GF(4)[]
sage: Q.<a>=R.quotient((x^2,2*x))
sage: len(list(Q))
16
sage: list(Q)
[0,
z2,
z2 + 1,
1,
z2*a,
z2*a + z2,
z2*a + z2 + 1,
z2*a + 1,
(z2 + 1)*a,
(z2 + 1)*a + z2,
(z2 + 1)*a + z2 + 1,
(z2 + 1)*a + 1,
a,
a + z2,
a + z2 + 1,
a + 1]


HTH,

more

I would like to do calculations over Zmod(4), which is not a field. Over GF(4), the given ideal is just the ideal generated by x^2 because 2=0 and thus 2x=0. That's why in that case the quotient has 16 elements, but over Zmod(4) the quotient has 8 elements. This is significantly different. So far, Sage doesn't seem to be able to deal with finite rings that aren't principal ideal rings. Try also the following:

sage: R.<x,y> = GF(4)[]
sage: Q = R.quotient((x^2,y^2,x*y))
sage: list(Q)

1

It is a strange suggestion to use GF(4) instead of Zmod(4) as they are different algebraic objects.