Ask Your Question
4

possible bug in: _cmp_ function

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

noa gravatar image

updated 2023-01-09 23:59:36 +0100

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

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

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

1 Answer

Sort by ยป oldest newest most voted
4

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

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 23:25:44 +0100 )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 21:23:41 +0100

Seen: 292 times

Last updated: Nov 07 '19