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

changed lcm and gcd implementations for when just one arg is infinite #57067

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Priynsh
Copy link
Contributor

@Priynsh Priynsh commented Jan 16, 2025

Fixes #56991 by adding conditions for both gcd and lcm cases. Also fixes tests for the same i.e. lot of tests regarding gcdx and lcm are removed. Two relevant tests have been added as well.

@inkydragon inkydragon added rationals The Rational type and values thereof maths Mathematical functions labels Jan 16, 2025
@LilithHafner
Copy link
Member

LilithHafner commented Jan 16, 2025

Thanks! Looking at this I'm realizing there is another way to define lcm and gcd that allows lcm(1//1, 1//0), and possibly even lcm(0//1, 1//0) to be well-defined.

Currently, we define

a is a multiple of b if there exists an integer m such that a=mb.

If we change that to

a is a multiple of b if there exists an integer or 1//0 or false m such that a=mb.

Then the following are correct:

julia> lcm(1//0, 1//1)
1//0 # currently 1//1

julia> lcm(1//0, 0//1)
0//1 # current behavior, only correct with #57068, otherwise error is appropriate

julia> gcd(1//0, 1//1)
1//1 # currently 1//0

julia> gcd(1//0, 0//1)
1//0 # current behavior, only correct with #57068, otherwise error is appropriate

@LilithHafner LilithHafner added the triage This should be discussed on a triage call label Jan 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
maths Mathematical functions rationals The Rational type and values thereof triage This should be discussed on a triage call
Projects
None yet
Development

Successfully merging this pull request may close these issues.

lcm should throw when one arg is infinite and the other is finite
3 participants