Skip to content

lcm and gcd for negative numbers, should obey lattice laws - #4

Open
telephon wants to merge 5 commits into
mainfrom
gcd-negative
Open

telephon wants to merge 5 commits into
mainfrom
gcd-negative

Conversation

@telephon

Copy link
Copy Markdown
Collaborator

Here is my improved implementation of lcm and gcd. It should obey the respective lattice laws. The tests should pass posting only true. I was not yet able to run them, because I can only use the REPL, and it doesn't allow me to override basic functions, as it seems.

@lfnoise

lfnoise commented Mar 16, 2026

Copy link
Copy Markdown
Owner

gcd and lcm should not be in dsp_math because they are built-in functions. And they always return positive numbers because the representation of fractions in this language always has positive denominators.

@telephon

Copy link
Copy Markdown
Collaborator Author

As far as I know, the meaning of gcd/lcm is not necessarily connected to denominators, there is no concept of denominators for integers, strictly speaking. Just my 2c.

@lfnoise

lfnoise commented Mar 17, 2026

Copy link
Copy Markdown
Owner

When you divide two integers in this language, a Fraction is returned. gcd and lcm are used to simplify the fraction. The representation of Fraction keeps the denominator always positive.

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