ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 12 Nov 2019 23:27:35 +0100possible bug in: _cmp_ functionhttps://ask.sagemath.org/question/48658/possible-bug-in-_cmp_-function/Hello,
on a 2019-release of sage, the following behaviour was observed:
After defining:
R = Zp(5)
a = R(5, 6)
b = R(10)
an inconsistent output was given for `a<b` and `b>a`:
a<b
False
b>a
True
Is this a bug, or should the output not be consistent here for some reason?
P.S: The comparison function is implemented in the file: `padic_generic_element.pyx`
Thank you.Wed, 06 Nov 2019 21:23:41 +0100https://ask.sagemath.org/question/48658/possible-bug-in-_cmp_-function/Comment by Iguananaut for <p>Hello,
on a 2019-release of sage, the following behaviour was observed:
After defining:</p>
<pre><code>R = Zp(5)
a = R(5, 6)
b = R(10)
</code></pre>
<p>an inconsistent output was given for <code>a<b</code> and <code>b>a</code>:</p>
<pre><code>a<b
False
b>a
True
</code></pre>
<p>Is this a bug, or should the output not be consistent here for some reason?
P.S: The comparison function is implemented in the file: <code>padic_generic_element.pyx</code>
Thank you.</p>
https://ask.sagemath.org/question/48658/possible-bug-in-_cmp_-function/?comment=48666#post-id-48666(Aside: When posting to this site you can format blocks of code either by indenting them, or by surrounding them with backticks. I have fixed the formatting of your post.)Thu, 07 Nov 2019 16:27:09 +0100https://ask.sagemath.org/question/48658/possible-bug-in-_cmp_-function/?comment=48666#post-id-48666Comment by noa for <p>Hello,
on a 2019-release of sage, the following behaviour was observed:
After defining:</p>
<pre><code>R = Zp(5)
a = R(5, 6)
b = R(10)
</code></pre>
<p>an inconsistent output was given for <code>a<b</code> and <code>b>a</code>:</p>
<pre><code>a<b
False
b>a
True
</code></pre>
<p>Is this a bug, or should the output not be consistent here for some reason?
P.S: The comparison function is implemented in the file: <code>padic_generic_element.pyx</code>
Thank you.</p>
https://ask.sagemath.org/question/48658/possible-bug-in-_cmp_-function/?comment=48713#post-id-48713Great, I will use this from now on. thanks.Tue, 12 Nov 2019 23:27:35 +0100https://ask.sagemath.org/question/48658/possible-bug-in-_cmp_-function/?comment=48713#post-id-48713Answer by saraedum for <p>Hello,
on a 2019-release of sage, the following behaviour was observed:
After defining:</p>
<pre><code>R = Zp(5)
a = R(5, 6)
b = R(10)
</code></pre>
<p>an inconsistent output was given for <code>a<b</code> and <code>b>a</code>:</p>
<pre><code>a<b
False
b>a
True
</code></pre>
<p>Is this a bug, or should the output not be consistent here for some reason?
P.S: The comparison function is implemented in the file: <code>padic_generic_element.pyx</code>
Thank you.</p>
https://ask.sagemath.org/question/48658/possible-bug-in-_cmp_-function/?answer=48667#post-id-48667Ordering of p-adics is not terribly meaningful of course but it should at least be consistent. So I think this is a bug.
If I understood things correctly, the code that eventually runs is:
mpz_sub(holder.value, a, b)
mpz_mod(holder.value, holder.value, prime_pow.pow_mpz_t_tmp(prec))
return mpz_sgn(holder.value)
The problem here is that `mpz_mod` [is always non-negative](https://gmplib.org/manual/Integer-Division.html) so `mpz_sgn` never returns -1.
I created https://trac.sagemath.org/ticket/28704#ticket to track this issue.Thu, 07 Nov 2019 18:37:57 +0100https://ask.sagemath.org/question/48658/possible-bug-in-_cmp_-function/?answer=48667#post-id-48667Comment by noa for <p>Ordering of p-adics is not terribly meaningful of course but it should at least be consistent. So I think this is a bug.</p>
<p>If I understood things correctly, the code that eventually runs is:</p>
<pre><code> mpz_sub(holder.value, a, b)
mpz_mod(holder.value, holder.value, prime_pow.pow_mpz_t_tmp(prec))
return mpz_sgn(holder.value)
</code></pre>
<p>The problem here is that <code>mpz_mod</code> <a href="https://gmplib.org/manual/Integer-Division.html">is always non-negative</a> so <code>mpz_sgn</code> never returns -1.</p>
<p>I created <a href="https://trac.sagemath.org/ticket/28704#ticket">https://trac.sagemath.org/ticket/2870...</a> to track this issue.</p>
https://ask.sagemath.org/question/48658/possible-bug-in-_cmp_-function/?comment=48712#post-id-48712Thank you very much for the quick and thorough response.Tue, 12 Nov 2019 23:25:44 +0100https://ask.sagemath.org/question/48658/possible-bug-in-_cmp_-function/?comment=48712#post-id-48712