Getting 'N/D' to eval as a fraction not a decimal
03-10-2015, 04:24 AM
Post: #9
 Joe Horn Senior Member Posts: 1,998 Joined: Dec 2013
RE: Getting 'N/D' to eval as a fraction not a decimal
(03-09-2015 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 non-programmable "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 (1E-12):

exact(N/D) --> 176366/493825 (should be 1234567/3456789)

The above can be "fixed" by making epsilon smaller (e.g. 1E-13 in this case), but then larger values of N and D will fail. For example, exact(12345678/23456789) is wrong when epsilon is 1E-13. Due to a very unfortunate CAS limitation, values of epsilon smaller than 1E-15 are all treated as 1E-15 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 1E-15 or smaller.

The solution to the original problem is to use functions that force the inputs (N and D) to be CAS-type 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 CAS-type 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 as-is (because it's in a string), and didn't get upper-cased.

<0|ɸ|0>
-Joe-
 « Next Oldest | Next Newest »

 Messages In This Thread Getting 'N/D' to eval as a fraction not a decimal - BruceH - 03-05-2015, 07:57 AM RE: Getting 'N/D' to eval as a fraction not a decimal - Joe Horn - 03-06-2015, 03:50 AM RE: Getting 'N/D' to eval as a fraction not a decimal - BruceH - 03-06-2015, 08:32 PM RE: Getting 'N/D' to eval as a fraction not a decimal - Joe Horn - 03-07-2015, 01:48 AM RE: Getting 'N/D' to eval as a fraction not a decimal - BruceH - 03-07-2015, 06:31 AM RE: Getting 'N/D' to eval as a fraction not a decimal - Joe Horn - 03-09-2015, 02:21 AM RE: Getting 'N/D' to eval as a fraction not a decimal - BruceH - 03-09-2015, 10:21 PM RE: Getting 'N/D' to eval as a fraction not a decimal - Joe Horn - 03-10-2015 04:24 AM RE: Getting 'N/D' to eval as a fraction not a decimal - Han - 03-10-2015, 03:46 AM RE: Getting 'N/D' to eval as a fraction not a decimal - cyrille de brébisson - 03-10-2015, 06:26 AM RE: Getting 'N/D' to eval as a fraction not a decimal - Joe Horn - 03-11-2015, 04:23 AM RE: Getting 'N/D' to eval as a fraction not a decimal - cyrille de brébisson - 03-11-2015, 06:18 AM RE: Getting 'N/D' to eval as a fraction not a decimal - Joe Horn - 03-11-2015, 06:23 PM

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