Algorithmically Finding the LCD (or decimal to fractions)

In summary, the conversation discusses a program that converts decimals into fractions by dividing by two and five until they cannot be divided anymore. This method simplifies the process and uses the fundamental theorem of arithmetic. The Euclidean algorithm can also be used for more efficient calculations.
  • #1
k_squared
64
0
I wrote a program to convert decimals into fractions. It basically puts the decimal over the proper power of ten, and simplifies (at least, for nonreapeating fractions.) However, it uses a brute force method to find the LCD, and as a matter of aesthetics, I never like brute force. Does anyone know of some more efficient ways do do that?
 
Mathematics news on Phys.org
  • #2
Just divide by two until it won't go in any longer, then divide by 5 until it won't go in any longer.

0.88 -> 88/100 = 44/50 = 22/25. Two won't go into the denominator anymore, and 5 won't go into the numerator, so you're done.

This let's you simplify 0.00000000000001048576 in twenty steps instead of a million.
 
  • #3
Awesome.
Neat how it works like that - I wish I had a knack for seeing that kinda thing off the top of my head.
 
  • #4
k_squared said:
Awesome.
Neat how it works like that - I wish I had a knack for seeing that kinda thing off the top of my head.

It's just the fundamental theorem of arithmetic (aka "uniqueness of prime factorization") at work. The only prime factors of any positive power of ten (eg 10 100 1000 etc) are 2 and 5.
 
  • #5
CRGreathouse said:
This let's you simplify 0.00000000000001048576 in twenty steps instead of a million.

The Euclidean algorithm will find this is ONE step, since 1048576 divides 10^20. The reduced fraction is 1/95367431640625.
 

1. What is the purpose of finding the LCD (Least Common Denominator) in fractions?

The purpose of finding the LCD is to make it easier to add, subtract, or compare fractions with different denominators. By finding the LCD, we can convert all fractions to equivalent fractions with the same denominator, making it simpler to perform operations on them.

2. How do you find the LCD of two or more fractions?

To find the LCD of two fractions, you need to list out the multiples of each denominator and find the smallest number that is common to both lists. This number is the LCD. If there are more than two fractions, you need to find the LCD of each pair and then find the LCD of the resulting fractions until you have one final LCD for all the fractions.

3. Why is it important to convert decimals to fractions algorithmically?

Converting decimals to fractions algorithmically allows us to express the decimal value as an exact fraction, rather than an approximation. This can be useful in various applications, such as in scientific calculations or in comparing values. It also helps us better understand the relationship between decimals and fractions.

4. Can you use an algorithm to find the LCD of fractions with variables?

Yes, an algorithm can also be used to find the LCD of fractions with variables. The process is similar to finding the LCD of fractions with numbers. You need to find the factors of each polynomial and identify the common factors. The LCD will then be the product of the common factors raised to the highest power.

5. How does finding the LCD relate to simplifying fractions?

When finding the LCD, we are essentially finding the smallest number that can be divided evenly by the denominators of all the fractions. This also means that the LCD is the smallest number that can be used to simplify all the fractions. By converting fractions to equivalent fractions with the LCD as the denominator, we can easily simplify them by dividing the numerator and denominator by the same number.

Similar threads

Replies
1
Views
3K
Replies
2
Views
627
Replies
7
Views
3K
Replies
18
Views
3K
Replies
2
Views
8K
  • General Math
Replies
2
Views
9K
Replies
1
Views
2K
  • Quantum Physics
Replies
3
Views
946
Replies
6
Views
1K
  • Programming and Computer Science
Replies
30
Views
4K
Back
Top