Bug with Integers

08202015, 09:07 PM
Post: #1




Bug with Integers
Today I thought of writing some simple programs to work with integers on my prime, so I first tried something like 7^23 MOD 143, the first part is correctly computed and gives 27368747340080916343. But then 7^23 Mod 143 on the real calculator, the PC and android deliver 23 (in Cas and Home) which simply is wrong as it must be 2, confirmed by xcas, my old and trusty (sad that it has defective keys) 49G+ and even Geogebra.
This is the first time that I encounter a mathematical error on the prime, but this renders it nearly unusable, as from now on I will clearly doublecheck every calculation that I do until I know that mistakes using numbers are fixed, unbearable. I can live with bugs, find matching workarounds as long as the problems are not essential, but a device for doing maths has to correctly do what its main purpose (crunching numbers) is, especially when a function is builtin and quite simple to program. Arno 

08202015, 09:28 PM
Post: #2




RE: Bug with Integers  
08202015, 09:59 PM
(This post was last modified: 08202015 10:00 PM by DrD.)
Post: #3




RE: Bug with Integers
Now try it in HOME
7^23 MOD 143 ==> 23 (r8151 Default settings) 

08202015, 10:04 PM
(This post was last modified: 08202015 10:04 PM by Arno K.)
Post: #4




RE: Bug with Integers
Hm, that's annoying, CAS settings : Radians, Standard number format, Integers: Decimal, Simplify: Minimum, Exact:on,use (sqrt) On Principal. on, Page 2 : 5,1,100,0.00000000000001, 1E15,40. Home: Rad, Standard. 123456.789, Textbook, Decimal, 32 a+b*i, English. I reset the calc and still got the same results.
The only setting concerning integers are Integers on both pages which I now tried to change without any success. Os is the latest, that is 8151. Thanks for your reply Arno 

08202015, 10:06 PM
(This post was last modified: 08202015 10:08 PM by Arno K.)
Post: #5




RE: Bug with Integers  
08202015, 10:31 PM
(This post was last modified: 08202015 10:34 PM by Didier Lachieze.)
Post: #6




RE: Bug with Integers
(08202015 10:06 PM)Arno K Wrote:(08202015 09:59 PM)DrD Wrote: Now try it in HOME Well, in Home this result is normal: I get 23 also on my 48GX. You are limited by the number of significant digits. You cannot fully express 7^23 with 12 significant digits. On my 41CX I get 66 and on the WP 34S I get 84. In CAS I get 2, as Helge, both on the real and the virtual calculators and I have the latest Revision: 8151. Juste one question: are you entering MOD in upper case in CAS ? 

08202015, 11:08 PM
(This post was last modified: 08202015 11:09 PM by DrD.)
Post: #7




RE: Bug with Integers
Now try it in CAS approximate mode:
7^23 MOD 143 ==> 131072 Lower case mod results in syntax error. VC toolbox MOD produces mod. Lots of interesting trivia here. Dale 

08202015, 11:54 PM
Post: #8




RE: Bug with Integers
(08202015 11:08 PM)DrD Wrote: Now try it in CAS approximate mode: Clearly Home is for numbercrunching(physics, engineering) but in casmode the entry mod(7^23, 143) is changed to 7^23 MOD 143 for display, this provides 23 in textbook as well as in algebraic entry mode, manually entered:7^23 MOD 143 provides 2. Interesting and confusing, what does a program using these commands do, well, I have not tested it, MOD/mod is a command that has to work and not to be tested, moreover, everytime I start something on the prime I encounter some unawaited difficulties, here I need to rewrite MOD, some days ago I wanted to make a program providing results for different numerical integrations where I had to use 4 casfunctions, on the 49G+ it was more difficult to get things running, but when I found out how to do, things ALWAYS worked as expected AND like I wanted. How much do I want a 50G using this hardware... Perhaps I´ll get the emu for my mobile (which is faster than the real device) and go on with the restricted display. Arno 

08212015, 12:00 AM
Post: #9




RE: Bug with Integers
FWIW, on the 50g,
7 ENTER 23 Y^X 143 MOD ==> 2 '7 Y^X 23 MOD 143' ENTER EVAL ==> 2 but '7 Y^X 23 MOD 143' ENTER >NUM ==> 23. Note the decimal point. Does the Prime not have an option to always show a decimal point on an floating point value? Otherwise how do you know if you're looking at a (precise) integral value or an approximation (potentially with rounding error or overflow)? 

08212015, 12:02 AM
Post: #10




RE: Bug with Integers
(08202015 10:31 PM)Didier Lachieze Wrote:(08202015 10:06 PM)Arno K Wrote: Perhaps Helge is using an older version, and I get this in Home and CAS,I think hardware does not matter here, this is the result I get from real calc, Pc and Android. As you can read in my answer to drd I now tried entering that directly from the keyboard, that in fact provides the correct result, but: Shouldn't a calculator like the prime provide correct results withOUT regard to one of two possible entry versions. Arno P.S. This is not my first HP, I owned a 32S 48, 49 and a 49G+ before, a TI 57, 92, 92PLUS, casio Pb100=fx702, sharp PC1401,1403, 500....they all never provided that false answers 

08212015, 12:09 AM
(This post was last modified: 08212015 12:11 AM by Arno K.)
Post: #11




RE: Bug with Integers
(08212015 12:00 AM)nlj Wrote: FWIW, on the 50g, I haven't tried that with approx mode on on the 49G+, in exact mode this calc provided the awaited 2, interesting that approx mode delivers the 23 like the prime does. On the prime the problem seems to lie deeper in the system, both exact and approx with the CASorder (mod(...)) deliver 23, only the (nonCAS)command a MOD is correct, this must be manually entered and display with both possibilities is the same: 7^23 MOD 143, manually entered provides 2, mod chosen from catalog: 23. So I really am annoyed. THX for your ideas Arno 

08212015, 12:47 AM
Post: #12




RE: Bug with Integers
(08212015 12:09 AM)Arno K Wrote: I haven't tried that with approx mode on on the 49G+, in exact mode this calc provided the awaited 2, interesting that approx mode delivers the 23 like the prime does. Well, in approximate mode 23 is the correct answer (for some value of correct, and extending the meaning of modulus to rational numbers): 7^23 ==> 2.73687473401E19 2.73687473401E19 MOD 143 ==> 23. (08212015 12:09 AM)Arno K Wrote: On the prime the problem seems to lie deeper in the system, both exact and approx with the CASorder (mod(...)) deliver 23, only the (nonCAS)command a MOD is correct, this must be manually entered and display with both possibilities is the same The Home/CAS dichotomy on the Prime is worse than a multiple personality disorder; more like a severed corpus callosum. I'm not sure if the complexity of this model causes more headaches and confusion for users or for the poor developers who have to make this untidiness work inside, but I'm utterly amazed that it's resulted in so _few_ bugs! 

08212015, 01:55 AM
Post: #13




RE: Bug with Integers
As pointed out above, you can't expect a long integer modulo 143 to return the correct result in Home, or in a Home program, because long integers aren't supported in Home.
Besides the manual entry in CAS, a CAS program works just fine, e.g., #cas TEST(k,l):= k^l MOD 143; END; #end At first, coming from the 48/49/50 environment, I didn't like the CAS/Home dichotomy either, but I have now learned to appreciate it. For sheer number crunching, Home is ideal since CAS doesn't get in the way, and for everything else, I use the builtin command power of CAS, which makes most daytoday math tasks a cinch! 

08212015, 08:54 AM
Post: #14




RE: Bug with Integers
(08212015 01:55 AM)Helge Gabert Wrote: As pointed out above, you can't expect a long integer modulo 143 to return the correct result in Home, or in a Home program, because long integers aren't supported in Home. Thank you, a little program like that is what I wanted to do today, you are right, I also use Home for physics... and cas for math, but this has happened in cas, as I know that home doesn't handle long integers correctly, I then tried home to find out. Arno 

08212015, 09:16 AM
Post: #15




RE: Bug with Integers
(08212015 08:54 AM)Arno K Wrote: I also use Home for physics... and cas for math, but this has happened in cas, as I know that home doesn't handle long integers correctly, I then tried home to find out. One of the sources of confusion is that CAS silently resorts to home functions when there is no CAS function especially if spelled "the wrong way", i. e. upper case instead of lower case. This mode switch converts the arguments to home reals as necessary. Marcus von Cube Wehrheim, Germany http://www.mvcsys.de http://wp34s.sf.net http://mvcsys.de/doc/basiccompare.html 

08212015, 09:35 AM
Post: #16




RE: Bug with Integers
It is very confusing to know what is the "good way" to spell the appropriate function. As you can see on the screenshot below, there is no way to see what is the good answer :
the wrong answer is obtained by typing "mod(7^23,143)" in lower case in CAS mode the good answer is obtained by typing "(7^23) MOD 143" in upper case in CAS mode too All this is very confusing. 

08212015, 11:09 AM
Post: #17




RE: Bug with Integers
MOD was implemented inside the CAS for the first version of the 39GII, it was not meant to be used with exact data, the CAS function for integer remainder is irem, and here the right function is powmod(7,23,143) because computing 7^23 before doing remaindering is much much less efficient.
I will add integer checking for arguments inside MOD. 

08212015, 11:53 AM
Post: #18




RE: Bug with Integers
Thanks Parisse, and so we learn.
To be fair, Excel and Scilab didn't return the correct result for this example, either. Maxima, and Wolfram Alpha did return the result as expected. There is enough confusion to go around. There still remains a problem with CAS and the Prime [Toolbox] which returns a lowercase mod, and always results in an error. The help documentation for MOD could be improved, as well. Dale 

08212015, 03:14 PM
Post: #19




RE: Bug with Integers
(08212015 11:09 AM)parisse Wrote: MOD was implemented inside the CAS for the first version of the 39GII, it was not meant to be used with exact data, the CAS function for integer remainder is irem, and here the right function is powmod(7,23,143) because computing 7^23 before doing remaindering is much much less efficient. Ups, I totally forgot to check available commands for integers before I started, but if I had, this bug would not have been found. Your remark concerning implementation for the HP39 clarifies matters. I don't know if the manual provides information about ranges, but perhaps you can give them here. Thanks Arno 

08212015, 10:16 PM
Post: #20




RE: Bug with Integers
(08202015 10:31 PM)Didier Lachieze Wrote: [ 7^23 mod 143 ] For the record: the 34s correctly returns 2. Since 7^23 has more than 16 significant digits (which is obvious as it appears as an intermediate result of ~10^19) of course you have to switch to double precision. Dieter 

« Next Oldest  Next Newest »

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