Zulip Chat Archive
Stream: Is there code for X?
Topic: Signed Modulo Operator
Aymeric Fromherz (Nov 09 2023 at 15:34):
Hi! Is there a library/operator for a signed integer modulo operation that would return an integer between [-floor(N/2); floor((N-1)/2)] (assuming we are operating modulo N)?
The operation a % n
seems to always return a number in [0; n-1], even when a
is negative, while Int.mod seems to return a value between [-n + 1; n - 1].
Thanks!
Eric Wieser (Nov 09 2023 at 15:52):
Aymeric Fromherz (Nov 09 2023 at 15:53):
Thanks!
Eric Wieser (Nov 09 2023 at 15:56):
Unfortunately it's not computable, but probably it ought to be
Jireh Loreaux (Nov 09 2023 at 17:14):
I think there's something in std that does this version. Hold on.
Yaël Dillies (Nov 09 2023 at 17:20):
There's docs#Int.mod, docs#Int.fmod, docs#Int.emod, but not the one Aymeric is looking for.
Jireh Loreaux (Nov 09 2023 at 17:20):
No, I think it's docs#Int.fmod
Jireh Loreaux (Nov 09 2023 at 17:22):
(deleted)
Scott Morrison (Nov 10 2023 at 00:38):
I have some results about bmod
(for balanced mod) with this definition. I can put them in Std sooner rather than later if that is useful.
Scott Morrison (Nov 10 2023 at 00:38):
What are you using it for?
Aymeric Fromherz (Nov 10 2023 at 11:02):
That'd be very helpful! I'm trying to prove the correctness of a Signed Montgomery Reduction, used in cryptographic code. Section 2.4 of https://eprint.iacr.org/2021/986.pdf gives a good overview of how this is supposed to work (and of the mod^{+,-}
operator needed)
Scott Morrison (Nov 11 2023 at 03:38):
@Aymeric Fromherz https://github.com/leanprover/std4/pull/361
Last updated: Dec 20 2023 at 11:08 UTC