(12C) Add or Subtract Fractions
|
09-17-2018, 05:49 AM
(This post was last modified: 09-17-2018 01:18 PM by Gamo.)
Post: #1
|
|||
|
|||
(12C) Add or Subtract Fractions
Program to Add or Subtract Fractions
Result is simplify to lowest term and convert to Mixed Fraction. In the form of a/b [+ or -] c/d = e/f If f < e Then get the result for Mixed Fraction of g+ h/f Procedure: a [ENTER] b [ENTER] c [ENTER] d [R/S] Answer e [X<>Y] f If Answer f < e press [R/S] --> answer display of g.000h [X<>Y] f of g+ h/f If Answer f > e is the "Final Answer" press [R/S] and ignore any decimal display. ----------------------------------------------------------------------------------------- Example: 8/71 + 7/8 8 [ENTER] 71 [ENTER] 7 [ENTER] 8 [R/S] Display 561 [X<>Y] 568 Answer is 561/568 // Denominator is larger than numerator is a "Final Answer" Press [R/S] and ignore any decimal display. ------------------------------------------------------------------ Example: 130/19 + 7/3 130 [ENTER] 19 [ENTER] 7 [ENTER] 3 [R/S] Display 523 [X<>Y] 57 Answer is 523/57 // Denominator is less than numerator then get Mixed Fraction. Press [R/S] Display 9.0010 [X<>Y] 57 Final Answer is 9+ 10/57 ---------------------------------------------------------- Program: Add or Subtract Fractions Code:
Remark: Program will run fast on modern HP-12C like 12C+ and HP-12C Emulators Gamo |
|||
09-19-2018, 07:55 AM
(This post was last modified: 09-19-2018 09:10 AM by Gamo.)
Post: #2
|
|||
|
|||
RE: (12C) Add or Subtract Fractions
Continue form post #1
Here is the "Multiply and Divide Fractions" program. Most of the procedure is the same except Only when calculate "Fractions Division" the last input must follow with [CHS] Example: 153/15 ÷ 13/17 153 [ENTER] 15 [ENTER] 13 [ENTER] 17 [CHS] [R/S] Display 867 [Y<>Y] 65 Answer is 867/65 // Denominator < Numerator find Mixed Fraction [R/S] 13.0022 [X<>Y] 65 Answer is 13+ 22/65 ------------------------------------------------------ Program: Multiply or Divide Fractions Code:
Remark: This Multiply or Divide program will not work with negative fractions. 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. Gamo |
|||
09-19-2018, 12:19 PM
(This post was last modified: 09-19-2018 01:39 PM by Albert Chan.)
Post: #3
|
|||
|
|||
RE: (12C) Add or Subtract Fractions
(09-19-2018 07:55 AM)Gamo Wrote: Remark: This Multiply or Divide program will not work with negative fractions. Why is above a challenging example ? gcd(676*3117, 13*22) = gcd(2107092, 286) = gcd(130, 286) = gcd(130, 26) = 26 should not take long ... -> fraction = (2107092/26) / (286/26) = 81042 / 11 BTW, there is no need to implement fraction division Just replace CHS with X<>Y , multiply fraction inverse = fraction division |
|||
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 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 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 |
|||
09-24-2018, 05:24 PM
(This post was last modified: 09-24-2018 06:40 PM by Dieter.)
Post: #5
|
|||
|
|||
RE: (12C) Add or Subtract Fractions
(09-19-2018 07:55 AM)Gamo Wrote: Continue form post #1 You can have both programs at the same time, even on a 12C. (09-19-2018 07:55 AM)Gamo Wrote: Remark: This Multiply or Divide program will not work with negative fractions. This one will: Code: 01 STO 4 Enter program, switch back to run mode, f [PRGM] to reset. Usage: 1. Enter both fractions: a [ENTER] b [ENTER] c [ENTER] d [R/S] => 0 2. Enter command code: 1 = add 2 = subtract 3 = multiply 4 = divide [R/S] 3. Result is displayed as "numerator", denominator. 4. Now you can do one of the following: 4a. Convert result to mixed fraction: Enter 0 [R/S] => "whole part", "numerator", denominator Continue with step 4. 4b. Enter another fraction e/f to be added/subtracted/multiplied/divided: e [ENTER] f [R/S] Continue with step 2. 4c. Start a completely new calculation: Continue with step 1. (09-19-2018 07:55 AM)Gamo Wrote: Try this challenging example: 676/13 x 3117/22 676 [ENTER] 13 [ENTER] 3117 [ENTER] 22 [R/S] => 0 3 [R/S] => "81042" 11 Convert this into a mixed fraction: 0 [R/S] => "7367" "5" "11" Now add 1/22 1 [ENTER] 22 [R/S] 1 [R/S] => "14735" 2 Finally subtract 1/4 1 [ENTER] 4 [R/S] 2 [R/S] => "29469" 4 View this as a mixed fraction: 0 [R/S] => "7367" "1" 4 New calculation: 1/3 – 2/5 1 [ENTER] 3 [ENTER] 2 [ENTER] 5 [R/S] 2 [R/S] "1" –15 Add 1/25 1 [ENTER] 25 [R/S] 1 [R/S] "–2" 75 Re. memory uisage: g MEM yields P–92 r–08 No registers beyond R4 are used. Dieter Edit: replaced program with a slightly modified version, now down to 90 steps. |
|||
09-25-2018, 02:36 AM
Post: #6
|
|||
|
|||
RE: (12C) Add or Subtract Fractions
Dieter
That's a very good Arithmetic with Fractions for HP-12C while I'm still shuffling on how to do this and you already done it. Your program is very good with easy to use program procedures. Thank You Gamo |
|||
09-27-2018, 04:52 PM
(This post was last modified: 09-28-2018 05:44 AM by Dieter.)
Post: #7
|
|||
|
|||
RE: (12C) Add or Subtract Fractions
(09-24-2018 05:24 PM)Dieter Wrote: New calculation: 1/3 – 2/5 Update: there are still a few steps left, so here is a slightly modified version that adds a nicer display of negative results: now the numerator has the sign of the result and the denominator is always positive. So the above example will now be displayed as "–1" 15. The same holds for mixed fractions, so –3 1/4 is returned as "–3" "–1" 4. Here is the code: Code: 01 STO 4 I think it won't get much better now. There's still room for one more step. You may use this to add a FIX 0 (f 0) somewhere. ;-) Dieter |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 3 Guest(s)