Use of 'mod' versus '%' in Sage.

asked 2024-06-24 18:25:24 +0200

Peter Luschny gravatar image

I would like to better understand the use of 'mod' in Sage.

The function 'mod', as defined in sage/rings/finite_rings/integer_mod, returns mod(a, 0) = a, which is fine.

On the other hand, in sage/arith/misc, the function 'quadratic_residues' is defined as

 sorted(set(ZZ((a*a) % n) for a in range(n // 2 + 1)))

Thus, if n = 0, a ZeroDivisionError is thrown. If, on the other hand, the function had been implemented with 'mod', there would be no error and 0 would be returned. This variant looks more advantageous for me.

Test:

for n in range(0, 11):
    print(sorted(set(ZZ(mod((a*a), n)) for a in range(n // 2 + 1))))
edit retag flag offensive close merge delete

Comments

This is a suggestion to amend Sage's behaviour. May I suggest to discuss it on sage-support ?

Emmanuel Charpentier gravatar imageEmmanuel Charpentier ( 2024-06-24 21:04:19 +0200 )edit

Thanks Emmanuel, I might do that. Is there a general recommendation in which cases to use AskSage and in which cases sage-support?

Peter Luschny gravatar imagePeter Luschny ( 2024-06-25 18:58:06 +0200 )edit