ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Thu, 18 Apr 2019 15:48:53 -0500IntegerModRing representationhttp://ask.sagemath.org/question/7485/integermodring-representation/How can I generate the elements of IntegerModring(n) in symmetric representation? For example Integers(6) = {0, 1,-1,2, -2, 3}Sun, 10 Oct 2010 03:35:27 -0500http://ask.sagemath.org/question/7485/integermodring-representation/Answer by czsan for <p>How can I generate the elements of IntegerModring(n) in symmetric representation? For example Integers(6) = {0, 1,-1,2, -2, 3}</p>
http://ask.sagemath.org/question/7485/integermodring-representation/?answer=15522#post-id-15522Surprisingly 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.Sun, 06 Oct 2013 21:28:41 -0500http://ask.sagemath.org/question/7485/integermodring-representation/?answer=15522#post-id-15522Comment by slelievre for <p>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.</p>
http://ask.sagemath.org/question/7485/integermodring-representation/?comment=46273#post-id-46273See 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
- [https://github.com/sagemath/sage/blob/a6041ad3e8371e8770c84a7c5f0cd1aa08381dbc/src/sage/rings/polynomial/multi_polynomial_libsingular.pyx#L2521](https://github.com/sagemath/sage/blob/a6041ad3e8371e8770c84a7c5f0cd1aa08381dbc/src/sage/rings/polynomial/multi_polynomial_libsingular.pyx#L2521)Thu, 18 Apr 2019 15:48:53 -0500http://ask.sagemath.org/question/7485/integermodring-representation/?comment=46273#post-id-46273Comment by czsan for <p>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.</p>
http://ask.sagemath.org/question/7485/integermodring-representation/?comment=16952#post-id-16952This is true, if the polynomialring is multivariateMon, 07 Oct 2013 01:26:48 -0500http://ask.sagemath.org/question/7485/integermodring-representation/?comment=16952#post-id-16952Comment by czsan for <p>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.</p>
http://ask.sagemath.org/question/7485/integermodring-representation/?comment=16951#post-id-16951and only if the modulus is prime?Mon, 07 Oct 2013 08:50:57 -0500http://ask.sagemath.org/question/7485/integermodring-representation/?comment=16951#post-id-16951Answer by lftabera for <p>How can I generate the elements of IntegerModring(n) in symmetric representation? For example Integers(6) = {0, 1,-1,2, -2, 3}</p>
http://ask.sagemath.org/question/7485/integermodring-representation/?answer=11773#post-id-11773Well, 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
Tue, 09 Nov 2010 06:43:16 -0600http://ask.sagemath.org/question/7485/integermodring-representation/?answer=11773#post-id-11773Comment by czsan for <p>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.</p>
<p>However, if computing the symmetric representant of an element in Integers(n) can be done with the following code:</p>
<p>I use this function in some multimodular algorithms.</p>
<pre><code>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
</code></pre>
http://ask.sagemath.org/question/7485/integermodring-representation/?comment=22507#post-id-22507Thank you, this is close to my wish.
I will use it.
Sat, 13 Nov 2010 21:16:07 -0600http://ask.sagemath.org/question/7485/integermodring-representation/?comment=22507#post-id-22507Comment by czsan for <p>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.</p>
<p>However, if computing the symmetric representant of an element in Integers(n) can be done with the following code:</p>
<p>I use this function in some multimodular algorithms.</p>
<pre><code>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
</code></pre>
http://ask.sagemath.org/question/7485/integermodring-representation/?comment=22506#post-id-22506The true solution would be like in Maple : `mod`:=modsSat, 13 Nov 2010 22:20:19 -0600http://ask.sagemath.org/question/7485/integermodring-representation/?comment=22506#post-id-22506Answer by niles for <p>How can I generate the elements of IntegerModring(n) in symmetric representation? For example Integers(6) = {0, 1,-1,2, -2, 3}</p>
http://ask.sagemath.org/question/7485/integermodring-representation/?answer=11722#post-id-11722You 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?
Sun, 10 Oct 2010 08:36:17 -0500http://ask.sagemath.org/question/7485/integermodring-representation/?answer=11722#post-id-11722Comment by czsan for <p>You could use Python's list comprehension to make a list of the numbers you want:</p>
<pre><code>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]
</code></pre>
<p>Is this the kind of thing you were looking for, or something else?</p>
http://ask.sagemath.org/question/7485/integermodring-representation/?comment=22586#post-id-22586Thank you. It's a good idea. I believed that the IntegerModRing have a special option.Sun, 10 Oct 2010 11:26:59 -0500http://ask.sagemath.org/question/7485/integermodring-representation/?comment=22586#post-id-22586Comment by niles for <p>You could use Python's list comprehension to make a list of the numbers you want:</p>
<pre><code>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]
</code></pre>
<p>Is this the kind of thing you were looking for, or something else?</p>
http://ask.sagemath.org/question/7485/integermodring-representation/?comment=22583#post-id-22583oh, sorry, I don't know how to do that.Mon, 11 Oct 2010 02:05:33 -0500http://ask.sagemath.org/question/7485/integermodring-representation/?comment=22583#post-id-22583Comment by czsan for <p>You could use Python's list comprehension to make a list of the numbers you want:</p>
<pre><code>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]
</code></pre>
<p>Is this the kind of thing you were looking for, or something else?</p>
http://ask.sagemath.org/question/7485/integermodring-representation/?comment=22584#post-id-22584But 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.Sun, 10 Oct 2010 13:04:52 -0500http://ask.sagemath.org/question/7485/integermodring-representation/?comment=22584#post-id-22584