# IntegerModRing representation

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

IntegerModRing representation

add a comment

2

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]
INPUT:
- ``p`` an integer mod n
OUTPUT:
- An integer r such that -n/2 < r <= n/2
EXAMPLES::
sage: p = Mod(2,4)
sage: lift_pm(p)
2
sage: p = Mod(3,4)
sage: lift_pm(p)
-1
"""
r = p.lift()
if r*2 > p.modulus():
r -= p.modulus()
return r
```

1

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.

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

0

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?

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.

Asked: **
2010-10-10 03:35:27 -0500
**

Seen: **1,715 times**

Last updated: **Oct 06 '13**

what is the equivalent function of mathematica's FullForm in Sage?

Can I get the invariant subspaces of a matrix group action?

Print to latex according to line width

specific representation for groups inheriting from Sage's Group class

Computing square root in IntegerModRing(2^n)

Specifying cardinality for action of permutation group

Several variables, consider polynomail as polynomial only of $X$, group coefficients

Copyright Sage, 2010. Some rights reserved under creative commons license. Content on this site is licensed under a Creative Commons Attribution Share Alike 3.0 license.