Ask Your Question

possible bug in: _cmp_ function

asked 2019-11-06 21:23:41 +0200

noa gravatar image

updated 2019-11-07 19:57:24 +0200

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:


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


(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 16:27:09 +0200 )edit

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

noa gravatar imagenoa ( 2019-11-12 23:27:35 +0200 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2019-11-07 18:37:57 +0200

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 to track this issue.

edit flag offensive delete link more


Thank you very much for the quick and thorough response.

noa gravatar imagenoa ( 2019-11-12 23:25:44 +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: 2019-11-06 21:23:41 +0200

Seen: 86 times

Last updated: Nov 07 '19