Post Reply 
(12C) Add or Subtract Fractions
09-19-2018, 06:45 PM (This post was last modified: 09-19-2018 07:25 PM by Dieter.)
Post: #4
RE: (12C) Add or Subtract Fractions
(09-19-2018 12:19 PM)Albert Chan Wrote:  
(09-19-2018 07:55 AM)Gamo Wrote:  Try this challenging example: 676/13 x 3117/22

Answer: 81042/11 or 7367+ 5/11

Even on a fast 12C+ took about 10 seconds to compute.

Why is above a challenging example ?

Because the program uses a quite ineffective way of computing the GCD, cf. line 33 ff.

(09-19-2018 12:19 PM)Albert Chan Wrote:  gcd(676*3117, 13*22) = gcd(2107092, 286) = gcd(130, 286) = gcd(130, 26) = 26 should not take long ...

Yes, this (Euklid's) method is very fast. Which is why I also chose it for my program in the 11C fractions thread.
But the above program does it this way:

2107092 – 286 = 2106806
2106086 – 286 = 2106520
2106520 – 286 = 2106234
...
(more than 7300 subtractions later)
...
702 – 286 = 416
416 – 286 = 130
286 – 130 = 156
156 – 130 = 26
130 – 26 = 104
104 – 26 = 78
78 – 26 = 52
52 – 26 = 26
26 – 26 = 0

=> GCD = 26

That's almost 7400 loops, which takes quite some time even even on a fast calculator. On the other hand the modulo-based Euclidean algorithm only requires 3 loops. For the record: even a rather slow HP67 can do it in about 3 seconds. How much faster is the 12C+? 100 times? 200? 500? If it does 7400 loops in 10 seconds it should return the result instantly when the modulo method is used.

(09-19-2018 12:19 PM)Albert Chan Wrote:  BTW, there is no need to implement fraction division
Just replace CHS with X<>Y , multiply fraction inverse = fraction division

Yes, that's exactly what I suggested in the thread with the 11C program. 1/2 : 3/4 = 1/2 · 4/3.
Maybe Gamo hasn't noticed it.

Dieter
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
(12C) Add or Subtract Fractions - Gamo - 09-17-2018, 05:49 AM
RE: (12C) Add or Subtract Fractions - Gamo - 09-19-2018, 07:55 AM
RE: (12C) Add or Subtract Fractions - Dieter - 09-19-2018 06:45 PM
RE: (12C) Add or Subtract Fractions - Gamo - 09-25-2018, 02:36 AM



User(s) browsing this thread: 1 Guest(s)