Ask Your Question
4

possible bug in: _cmp_ function

asked 2019-11-06 14:23:41 -0600

noa gravatar image

updated 2019-11-07 12:57:24 -0600

tmonteil gravatar image

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.

edit retag flag offensive close merge delete

Comments

(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.)

Iguananaut gravatar imageIguananaut ( 2019-11-07 09:27:09 -0600 )edit

Great, I will use this from now on. thanks.

noa gravatar imagenoa ( 2019-11-12 16:27:35 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
4

answered 2019-11-07 11:37:57 -0600

saraedum gravatar image

Ordering 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 so mpz_sgn never returns -1.

I created https://trac.sagemath.org/ticket/2870... to track this issue.

edit flag offensive delete link more

Comments

Thank you very much for the quick and thorough response.

noa gravatar imagenoa ( 2019-11-12 16:25:44 -0600 )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

Stats

Asked: 2019-11-06 14:23:41 -0600

Seen: 47 times

Last updated: Nov 07