Getting 'N/D' to eval as a fraction not a decimal

03102015, 04:24 AM
Post: #9




RE: Getting 'N/D' to eval as a fraction not a decimal
(03092015 10:21 PM)BruceH Wrote: Can you give some examples of numbers that fail? I'd like to turn this into an article. There are several failures going on here, so here's a description of them all. If N=23 and D=45, then all of the following (copied from the above discussion) return 0.51111111111 in Home instead of 23/45 *if* the nonprogrammable "Change apparent integers into exact integers" setting in CAS Settings (page 1, check box at end of line 3) is unchecked: EVAL('N/D') CAS.eval(N/D) simplify(N/D) subst(N/D,N=N,D=D) If N=1234567, and D=3456789, then the following returns the wrong fraction in Home if epsilon (CAS Settings, page 2) is the default value (1E12): exact(N/D) > 176366/493825 (should be 1234567/3456789) The above can be "fixed" by making epsilon smaller (e.g. 1E13 in this case), but then larger values of N and D will fail. For example, exact(12345678/23456789) is wrong when epsilon is 1E13. Due to a very unfortunate CAS limitation, values of epsilon smaller than 1E15 are all treated as 1E15 by the "exact" function, so exact(N/D) is usually wrong when N and D are very large. For example, exact(12345678/23456789) is wrong no matter what epsilon is, even 1E15 or smaller. The solution to the original problem is to use functions that force the inputs (N and D) to be CAStype integers, regardless of any mode settings. There are several functions that do this, such as IP. That's why CAS(IP(N)/IP(D)) works; the IP's turn the Home values of N and D into CAStype integers, then CAS divides them and returns the fraction back to Home. Annoying factoid: In CAS (not in Home), if the "Change apparent integer" flag is clear, then the IP function only turns the number into an integer if it's spelled in uppercase. Luckily, CAS(IP()) always sends IP to CAS in uppercase, no matter how the user spells it, so CAS(ip()) works in Home, and no matter what the CAS settings are. But CAS("ip(N)/ip(D)") fails, because "ip" got passed to CAS asis (because it's in a string), and didn't get uppercased. <0ɸ0> Joe 

« Next Oldest  Next Newest »

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