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

  • Thread starter Thread starter pyroknife
  • Start date Start date
  • Tags Tags
    Multiple
AI Thread Summary
The discussion centers around a programming code that defines the least common multiple (LCM) of two variables, x and y, as 0 if either variable is negative. This definition deviates from the standard mathematical definition, which typically calculates LCM using the absolute values of the numbers. The code snippet provided checks if either variable is less than 0 and returns 0 to indicate an error condition. Participants express confusion over this unconventional approach, suggesting that it should be clearly documented in the code's interface. For cases where negative values are valid, using the absolute value function is recommended.
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().
 
Suppose ,instead of the usual x,y coordinate system with an I basis vector along the x -axis and a corresponding j basis vector along the y-axis we instead have a different pair of basis vectors ,call them e and f along their respective axes. I have seen that this is an important subject in maths My question is what physical applications does such a model apply to? I am asking here because I have devoted quite a lot of time in the past to understanding convectors and the dual...
Insights auto threads is broken atm, so I'm manually creating these for new Insight articles. In Dirac’s Principles of Quantum Mechanics published in 1930 he introduced a “convenient notation” he referred to as a “delta function” which he treated as a continuum analog to the discrete Kronecker delta. The Kronecker delta is simply the indexed components of the identity operator in matrix algebra Source: https://www.physicsforums.com/insights/what-exactly-is-diracs-delta-function/ by...
Back
Top