Lcm: I've written a program to calculate the HCF & LCM for 2 or more numbers....

TheOAP

New member
Joined
Nov 5, 2017
Messages
16
Hi.
I've written a program to calculate the HCF & LCM for 2 or more numbers. This was originally for integer values only but now I've adapted it.
Basically I turn all the numbers to fractions - using 2 arrays. So 2.0 => 20 and denominator => 10 etc.
HCF is easy to calc. as there is an elegant solution.
In 1 of the web forums it's claimed that the LCM can be deduced by : Product of numbers / HCF.
Do you know if this is true ?
As a well known comedian said "I'm getting the right numbers, but in the wrong order!" ;)
Be obliged for your answer.
Pete
 
Last edited by a moderator:
I've written a program to calculate the HCF & LCM for 2 or more numbers. This was originally for integer values only but now I've adapted it.
Basically I turn all the numbers to fractions - using 2 arrays. So 2.0 => 20 and denominator => 10 etc.
HCF is easy to calc. as there is an elegant solution.
In 1 of the web forums it's claimed that the LCM can be deduced by : Product of numbers / HCF.
Do you know if this is true ?

Yes, it's true: LCM(a,b) * HCF(a,b) = ab, for any positive integers a and b. See, for example, here, or equations 13 and 14 here.

I presume you are referring to using the Euclidean Algorithm to find the HCF. That, together with this product theorem is certainly the best way to write a program for this purpose.

But you appear to be trying to extend the concepts to rational numbers. How are you defining HCF and LCM in this case? The product theorem applies specifically to integers; if you want to use it other than for integers, you'd have to prove that it applies to your extension.
 
Calculating HCF & LCM of decimal fractions

For fractions the conversion is :
0.5 => 5 /10, 7 => 70/10 etc
[A] Determine the products of the Numerator (N) and Denominator (D).
Get the HCF's of the N & D
[C] Get the LCM's of the N & D
[D] Then HCF = HCF (N) / LCM (D)
LCM = LCM (N) / HCF (D)

That's what I intended but I haven't worked out how to get the LCM's
in stage [D] !

Hope this makes sense.
Please note I use Euclid's technique for the HCF
 
For fractions the conversion is :
0.5 => 5 /10, 7 => 70/10 etc
[A] Determine the products of the Numerator (N) and Denominator (D).
Get the HCF's of the N & D
[C] Get the LCM's of the N & D
[D] Then HCF = HCF (N) / LCM (D)
LCM = LCM (N) / HCF (D)

That's what I intended but I haven't worked out how to get the LCM's
in stage [D] !

Hope this makes sense.
Please note I use Euclid's technique for the HCF


What I asked was not how you are calculating the HCF, but how you are defining the HCF of two non-integers: What does it mean that c is the HCF of a and b when they are not necessarily integers? How do you know your result deserves the name? The concept is rarely used, but there is a definition you can find; if you are inventing the concept yourself, it is possible that you are not doing the right thing.

Let's take an example and see if your method at least makes sense. You used 0.5 and 7; the method you outlined takes them as 5/10 and 70/10, and you claim the HCF is HCF(5,70)/LCM(10,10) = 5/10 = 0.5, and the LCM is LCM(5,70)/HCF(10,10) = 70/10 = 7. That makes sense (though it's not a very deep example). Now, suppose we had used reduced forms, 1/2 and 7/1. Then you get HCF = HCF(1,7)/LCM(2,1) = 1/2, and LCM = LCM(1,7)/HCF(2,1) = 7/1 = 7 again. That's good -- if the answer depended on the form you started with, it couldn't be right.

Are you sure it will always work? Do you have a way to tell whether it did work? And can you show me what it is that you aren't able to do with the LCMs?
 
Hcf & lcm

What I asked was not how you are calculating the HCF, but how you are defining the HCF of two non-integers: What does it mean that c is the HCF of a and b when they are not necessarily integers? How do you know your result deserves the name? The concept is rarely used, but there is a definition you can find; if you are inventing the concept yourself, it is possible that you are not doing the right thing.

Let's take an example and see if your method at least makes sense. You used 0.5 and 7; the method you outlined takes them as 5/10 and 70/10, and you claim the HCF is HCF(5,70)/LCM(10,10) = 5/10 = 0.5, and the LCM is LCM(5,70)/HCF(10,10) = 70/10 = 7. That makes sense (though it's not a very deep example). Now, suppose we had used reduced forms, 1/2 and 7/1. Then you get HCF = HCF(1,7)/LCM(2,1) = 1/2, and LCM = LCM(1,7)/HCF(2,1) = 7/1 = 7 again. That's good -- if the answer depended on the form you started with, it couldn't be right.
Are you sure it will always work? Do you have a way to tell whether it did work? And can you show me what it is that you aren't able to do with the LCMs?

Dr Peterson, I have some 20 test examples, chosen at random and have checked the (program) results manually - they match.
It's not a proof I know. By the way I solved the LCM problem. Needless to say I'm NOT a mathematician, just a former electronics
engineer and programmer who is interested in Maths.
 
Top