Ask Your Question

IntegerModRing representation

asked 2010-10-10 10:35:27 +0200

czsan gravatar image

How can I generate the elements of IntegerModring(n) in symmetric representation? For example Integers(6) = {0, 1,-1,2, -2, 3}

edit retag flag offensive close merge delete

3 Answers

Sort by ยป oldest newest most voted

answered 2010-11-09 13:43:16 +0200

lftabera gravatar image

Well, if you want to change the representation of the objects, so when you type Integers(6)(5) it returns -1, I think that it is not implemented in sage.

However, if computing the symmetric representant of an element in Integers(n) can be done with the following code:

I use this function in some multimodular algorithms.

def lift_pm(p):  
Compute a representative of the element p mod n in [-n/2 , n/2]


- ``p`` an integer mod n


- An integer r such that  -n/2 < r <= n/2


    sage: p = Mod(2,4)
    sage: lift_pm(p)
    sage: p = Mod(3,4)
    sage: lift_pm(p)
r = p.lift()
if r*2 > p.modulus():
    r -= p.modulus()
return r
edit flag offensive delete link more


Thank you, this is close to my wish. I will use it.

czsan gravatar imageczsan ( 2010-11-14 04:16:07 +0200 )edit

The true solution would be like in Maple : `mod`:=mods

czsan gravatar imageczsan ( 2010-11-14 05:20:19 +0200 )edit

answered 2013-10-07 04:28:41 +0200

czsan gravatar image

Surprisingly in IntegerModrings Sage uses positive representations, but in polynomialrings over these it uses symmetric representation. So we can make the computations with the residues in the polynomialring.

edit flag offensive delete link more


This is true, if the polynomialring is multivariate

czsan gravatar imageczsan ( 2013-10-07 08:26:48 +0200 )edit

and only if the modulus is prime?

czsan gravatar imageczsan ( 2013-10-07 15:50:57 +0200 )edit

See the file sage/rings/polynomial/multi_polynomial_libsingular.pyx, in particular the comment at the beginning that Singular is used for multipolynomial ring over GF(p) when p is prime, and the _repr_ method at

slelievre gravatar imageslelievre ( 2019-04-18 22:48:53 +0200 )edit

answered 2010-10-10 15:36:17 +0200

niles gravatar image

You could use Python's list comprehension to make a list of the numbers you want:

sage: N = 5
sage: [(-1)^(n+1)*floor((n+1)/2) for n in range(N)]
[0, 1, -1, 2, -2]
sage: N = 6
sage: [(-1)^(n+1)*floor((n+1)/2) for n in range(N)]
[0, 1, -1, 2, -2, 3]

Is this the kind of thing you were looking for, or something else?

edit flag offensive delete link more


Thank you. It's a good idea. I believed that the IntegerModRing have a special option.

czsan gravatar imageczsan ( 2010-10-10 18:26:59 +0200 )edit

But it is not teh solition. I think, My question was'nt clear. The positive representation for mod 6 is {1,2,3,4,5,6}. The symmetric representation is {1,2,3,-2,-1}. The problem is'nt that, how can generate this remainder set, but the Integers(6) ring how can use it permanently.

czsan gravatar imageczsan ( 2010-10-10 20:04:52 +0200 )edit

oh, sorry, I don't know how to do that.

niles gravatar imageniles ( 2010-10-11 09:05:33 +0200 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2010-10-10 10:35:27 +0200

Seen: 2,596 times

Last updated: Oct 07 '13