HP 12C Permutation and Combination
|
08-17-2017, 06:35 AM
(This post was last modified: 08-17-2017 07:54 AM by Dieter.)
Post: #5
|
|||
|
|||
RE: HP 12C Permutation and Combination
(08-17-2017 05:16 AM)Gamo Wrote: I try your Permutation and Combination program and found one little problem with the Permutation answer. Most P answer correctly but with this 25P7 I check most calculator result to 2,422,728,000 but on this program result to 2,442,727999 The returned result is 2 442 727 999 and it is not exact. (08-17-2017 05:16 AM)Gamo Wrote: I'm not sure if this result is more accurate or others just round the result up. What you see is the result of limited precision and roundoff. The exact answer is 25!/18! = 15511210043330985984000000/6402373705728000 = 2422728000. But the 12C only has 10 digits, so it actually calculates 1,551121004 E+25 / 6,402373706 E+15 = 2 442 727 999,376... which is what you see here. The numerator is slightly low (rounded down) and the denominator is slightly high (rounded up) which causes a slightly low result. This will happen with any 10-digit calculator if the result is calculated by dividing factorials. You could also do it by evaluating 19 · 20 · 21 · 22 · 23 · 24 · 25 which yields the exact result. Well, at least this time. ;-) That's why most HPs, including the 12C, internally use 3 more digits for their calculations: 1,551121004333 E+25 / 6,402373705728E+15 = 2422727999,9998... which rounds to 2422728000 in the returned 10-digit result. OK, actually these calculators will evaluate permutations by 19 · 20 · ... · 25 which is faster and causes less roundoff problems. ;-) For more information on this topic and ways to calculate permutations and combinations with minimized roundoff errors cf. this thread, especially Werner's post #4. Doing this without factorials also allows larger arguments, i.e. no overflows unless the result overflows. But all this is quite cumbersome on the 12C which does not feature any loop counters. Edit: anyway, here is a short permutation routine that shows how it can be done. Code: 01 CHS 25 [ENTER] 7 [R/S] => 2422728000 99 [ENTER] 33 [R/S] => 1,714468 E+63 Dieter |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)