Least Common Multiple: Explaining x=-2 and y=+3's LCM

  • Context: High School 
  • Thread starter Thread starter pyroknife
  • Start date Start date
  • Tags Tags
    Multiple
Click For Summary

Discussion Overview

The discussion revolves around the least common multiple (LCM) of two variables, specifically when one variable is negative. Participants explore the implications of a programming code that defines the LCM as zero if either variable is less than zero, contrasting this with the conventional mathematical definition.

Discussion Character

  • Debate/contested

Main Points Raised

  • One participant expresses confusion over a programming definition stating that if one of the variables (x or y) is negative, the LCM is zero, questioning its intuitiveness.
  • Another participant counters that the usual mathematical definition of LCM would yield lcm(-2, 3) = 6, using the formula lcm(a, b) = |ab|/gcd(a, b).
  • A third participant reiterates the programming definition, suggesting it is simply a non-standard definition that may not be useful.
  • A participant provides a snippet of C code that implements the LCM calculation, indicating that it returns zero if either variable is negative.
  • Another participant suggests that the author of the code may have considered negative inputs as error cases, proposing that the interface should clarify this behavior and questioning the return value when an operand is zero.
  • There is a suggestion to use the absolute values of the operands if negative values are valid in the context of the LCM calculation.

Areas of Agreement / Disagreement

Participants disagree on the appropriateness of defining the LCM as zero for negative inputs. While some acknowledge the programming definition, others advocate for the conventional mathematical approach, indicating a lack of consensus.

Contextual Notes

The discussion highlights the limitations of the programming definition, which may not align with standard mathematical definitions. There are unresolved questions regarding the treatment of zero as an operand and the implications of negative values in the context of LCM.

pyroknife
Messages
611
Reaction score
4
I'm reading this programming code that basically says if 1 of 2 variables (x and y) is less than 0, then their least common multiple is 0.




If we have x=-2 and y=+3, then their least common multiple is 0.

I don't get it. I know what a least common multiple is, but this one isn't very intuitive to me.

Can someone explain?
 
Mathematics news on Phys.org
That is not the usual definition. Usually lcm(-2,3)=6 and
lcm(a,b)=|ab|/gcd(a,b)
 
pyroknife said:
I'm reading this programming code that basically says if 1 of 2 variables (x and y) is less than 0, then their least common multiple is 0.




If we have x=-2 and y=+3, then their least common multiple is 0.

I don't get it. I know what a least common multiple is, but this one isn't very intuitive to me.

Can someone explain?

Well, it's just a definition. It's not the usual definition and it's probably not a very useful one either. So there is no explanation other that the authors of the code implemented things like this.
 
Part of the code written in C is:
if ( u < 0 || v < 0 )
return 0;

The overall code asks to find the lcm of u and v. If u or v is <0, then lcm of u and v is 0.
 
Looks like the author considered it an error case and used a result of zero to signal an error condition back to the caller. This ought to be part of the declared interface. (But what does it return if an operand is 0?)
If negative values are valid in your case, just wrap the operands in abs().
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 10 ·
Replies
10
Views
3K
  • · Replies 22 ·
Replies
22
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 12 ·
Replies
12
Views
3K
  • · Replies 11 ·
Replies
11
Views
2K
  • · Replies 8 ·
Replies
8
Views
4K