Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

quotient and modulus for non-integers are wrong #3340

Open
mahrud opened this issue Jun 30, 2024 · 3 comments · May be fixed by #3400
Open

quotient and modulus for non-integers are wrong #3340

mahrud opened this issue Jun 30, 2024 · 3 comments · May be fixed by #3400
Assignees

Comments

@mahrud
Copy link
Member

mahrud commented Jun 30, 2024

Unless I'm way off about what we want // and % to mean, I think these are all wrong:

M2/M2/Macaulay2/m2/reals.m2

Lines 213 to 226 in ec9e9ac

scan((QQ,RR,CC), F -> (
F // F := (x,y) -> if y == 0 then 0_F else x/y;
F % F := (x,y) -> if y == 0 then x else 0_F;
F // ZZ := (x,y) -> x // y_F;
F % ZZ := (x,y) -> x % y_F;
))
scan((RR,CC), F -> (
F // QQ := (x,y) -> x // y_F;
F % QQ := (x,y) -> x % y_F;
))
CC // RR := (x,y) -> x // y_CC;
CC % RR := (x,y) -> x % y_CC;

Some examples: (afterprints are silenced)

i1 : 13.3 // 4.0

o1 = 3.325

i2 : 13.3 % 4.0

o2 = 0

i3 : 13.3 // 4

o3 = 3.325

i4 : 13.3 % 4

o4 = 0

i5 : 13.3 // (4/1)

o5 = 3.325

i6 : 13.3 % (4/1)

o6 = 0

i7 : (pi*ii) // 3.0

o7 = 1.0471975511966*ii

i8 : (pi*ii) % 3.0

o8 = 0

What's the point of having // be a synonym for /, and why even define % for non-integers if the answer is always zero anyway?!

@d-torrance
Copy link
Member

I think they're correct. My understanding is that // and % give the quotient and remainder from division in a Euclidean domain, and fields are trivially Euclidean domains since $x = y(xy^{-1}) + 0$ for nonzero $y$.

@mahrud
Copy link
Member Author

mahrud commented Jun 30, 2024

But that's just / division in fields, whereas // and % also work on domains.

I should have also included an example from python for contrast:

>>> 13.3 // 4.0
3.0
>>> 13.3 % 4.0
1.3000000000000007
>>> 13.3 // 4
3.0
>>> 13.3 % 4
1.3000000000000007
>>> 13.3 // (4/1)
3.0
>>> 13.3 % (4/1)
1.3000000000000007

I think this makes more sense, both mathematically and in terms of what is actually useful. Currently computing the non-zero value of 13.3 % 4 in Macaulay2 takes several steps:

i13 : 13.3 - 4 * floor(13.3 // 4)

o13 = 1.3

@d-torrance
Copy link
Member

Ok, I think I'm convinced that it's wrong, too. :)

Here's an article with a few different possibilities for how // and % might be defined over the reals: Boute, The Euclidean Definition of the Functions div and mod.

@mahrud mahrud added this to the version 1.24.11 milestone Jul 21, 2024
@mahrud mahrud linked a pull request Aug 10, 2024 that will close this issue
@mahrud mahrud self-assigned this Aug 10, 2024
@mahrud mahrud linked a pull request Aug 10, 2024 that will close this issue
@mahrud mahrud removed this from the version 1.24.11 milestone Oct 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants