Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Approximate" greatest common divisor

Suppose you have a list of floating point numbers that are approximately multiples of a common quantity, for example

2.468, 3.700, 6.1699

which are approximately all multiples of 1.234. How would you characterize this "approximate gcd", and how would you proceed to compute or estimate it?

Strictly related to my answer to this question.

like image 640
Federico A. Ramponi Avatar asked Jan 14 '09 23:01

Federico A. Ramponi


People also ask

What is the fastest way to find the greatest common divisor?

GCD of two numbers is the largest number that divides both of them. A simple way to find GCD is to factorize both numbers and multiply common prime factors.

Why do we calculate GCD?

The GCD is used for a variety of applications in number theory, particularly in modular arithmetic and thus encryption algorithms such as RSA. It is also used for simpler applications, such as simplifying fractions.

What is GCD Theorem?

The theorem states that if we divide two integers by their greatest common divisor, then the outcome is a couple of integers that are relatively prime.


1 Answers

You can run Euclid's gcd algorithm with anything smaller then 0.01 (or a small number of your choice) being a pseudo 0. With your numbers:

3.700 = 1 * 2.468 + 1.232, 2.468 = 2 * 1.232 + 0.004.  

So the pseudo gcd of the first two numbers is 1.232. Now you take the gcd of this with your last number:

6.1699 = 5 * 1.232 + 0.0099. 

So 1.232 is the pseudo gcd, and the mutiples are 2,3,5. To improve this result, you may take the linear regression on the data points:

(2,2.468), (3,3.7), (5,6.1699). 

The slope is the improved pseudo gcd.

Caveat: the first part of this is algorithm is numerically unstable - if you start with very dirty data, you are in trouble.

like image 56
David Lehavi Avatar answered Sep 20 '22 03:09

David Lehavi