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

Define gcd & lcm of single element #3595

Open
wants to merge 1 commit into
base: development
Choose a base branch
from

Conversation

d-torrance
Copy link
Member

Previously, gcd and lcm raised an error if we passed a single element. This seems a bit odd, especially when we use parentheses, since it works with any other number of arguments:

i1 : gcd()

o1 = 0

i2 : gcd(3)
stdio:2:3:(3): error: no method found for applying gcd to:
     argument   :  3 (of class ZZ)

i3 : gcd(3, 6)

o3 = 3

i4 : gcd(3, 6, 9)

o4 = 3

After defining gcd(ZZ):

i1 : gcd(3)

o1 = 3

@d-torrance d-torrance requested a review from pzinn November 27, 2024 03:06
@@ -68,6 +69,7 @@ lcm(QQ,QQ) := (f,g) -> (
d := gcd(f, g);
if d == 0 then 0_QQ
else abs f * (abs g / d))
lcm ZZ := lcm QQ := identity
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Number, perhaps?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about that. I stuck with ZZ and QQ since those are the ones we have binary methods for. It seems like it might be a bit strange if, say, gcd(3.0) worked but gcd(3.0, 6.0) didn't.

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 this pull request may close these issues.

2 participants