Post Reply 
Exact integer arithmetic in Home?
10-27-2014, 12:43 PM
Post: #1
Exact integer arithmetic in Home?
Is it possible to use exact integer arithmetic in Home view? And in programs?

I searching for a way to access the "infinite integer precision" of CAS in Home, or just anything similar to HP50g "exact" integers. Using CAS interactively isn't sufficient, I want to be able to code using exact integers.

/Lennart

/Lennart Börjeson
Stockholm, Sweden
Find all posts by this user
Quote this message in a reply
10-27-2014, 12:51 PM (This post was last modified: 10-27-2014 12:53 PM by DrD.)
Post: #2
RE: Exact integer arithmetic in Home?
Is the function exact(), or it's corrollary approx(), sufficient for your needs? <See help exact(Expr)>

exact(.5) => 1/2
approx(1/2) => 0.5

-Dale-
Find all posts by this user
Quote this message in a reply
10-27-2014, 01:22 PM
Post: #3
RE: Exact integer arithmetic in Home?
(10-27-2014 12:51 PM)DrD Wrote:  Is the function exact(), or it's corrollary approx(), sufficient for your needs? <See help exact(Expr)>

exact(.5) => 1/2
approx(1/2) => 0.5

-Dale-

No, not really. I need large products to be evaluated exactly, e.g. 9999999999*9999999999 => 99999999980000000001

That's possible to calculate in CAS interactively, but AFAIK neither in Home nor in code, which I'm hoping someone will correct me on... ;-)
Find all posts by this user
Quote this message in a reply
10-27-2014, 01:27 PM
Post: #4
RE: Exact integer arithmetic in Home?
Are you aware that you can create CAS programs?

Graph 3D | QPI | SolveSys
Find all posts by this user
Quote this message in a reply
10-27-2014, 01:36 PM (This post was last modified: 10-27-2014 01:44 PM by lenborje.)
Post: #5
RE: Exact integer arithmetic in Home?
(10-27-2014 01:27 PM)Han Wrote:  Are you aware that you can create CAS programs?

Yes, I am, and I've tried but I did not succeed getting the results I expected other than for the simplest programs. (E.g RETURN(999999999*9999999999))

(It's a little hard to debug CAS program when you can not single-step them.)

I've also not been able to invoke my own CAS programs from Home view.
Find all posts by this user
Quote this message in a reply
10-27-2014, 01:46 PM
Post: #6
RE: Exact integer arithmetic in Home?
This probably is quite 'it' either then, right(?):

<home | settings | Entry |Algebraic>

<Home>
9999999999*9999999999 => 9.999999998ᴇ19

-Dale-
Find all posts by this user
Quote this message in a reply
10-27-2014, 01:58 PM
Post: #7
RE: Exact integer arithmetic in Home?
(10-27-2014 01:46 PM)DrD Wrote:  This probably is quite 'it' either then, right(?):

<home | settings | Entry |Algebraic>

<Home>
9999999999*9999999999 => 9.999999998ᴇ19

-Dale-

Yes, and that's perfectly OK according to what I gathered Home and CAS view is intended for, i.e Home for approximate calculations on "real" numbers, and CAS for "exact" analysis.

(I use RPN in Home view, but it doesn't affect the integer precision.)

But calculations on large precision integers aren't the kinds of mathematics CAS is suitable for, either. I'd use CAS for algebra or calculus.

Maybe this is just one of the things done more easily on the hp50g, then? If I just had the speed of the Prime on it! ;-)
Find all posts by this user
Quote this message in a reply
10-28-2014, 03:58 AM (This post was last modified: 10-28-2014 03:10 PM by Joe Horn.)
Post: #8
RE: Exact integer arithmetic in Home?
(10-27-2014 12:43 PM)lenborje Wrote:  Is it possible to use exact integer arithmetic in Home view? And in programs?

Here's a tiny Home program which multiplies 123456789012345 (Edit: the second "4" was missing and has now been put back in... thanks, Jake!) times 234567890123456 and returns the complete correct product of 28958998520042431946358064320:

Code:
EXPORT bigmult
BEGIN
CAS("s1:=123456789012345");
CAS("s2:=234567890123456");
RETURN CAS.string(s1*s2);
END;

Some tidbits above might be unnecessary, but at least it DOES work. There are probably many ways to skin this particular cat.

If you want to input large integers, you can input them as strings, and then use CAS("var:=expr(whatever)") to turn them into actual integers. For some reason, CAS(string(var)) works differently from CAS.string(var). And be sure to use CAS.string, in lowercase, not CAS.STRING, in uppercase. Please explore such things and let us know what you find. Thanks!

<0|ɸ|0>
-Joe-
Visit this user's website Find all posts by this user
Quote this message in a reply
10-28-2014, 07:37 AM
Post: #9
RE: Exact integer arithmetic in Home?
(10-28-2014 03:58 AM)Joe Horn Wrote:  ...

Please explore such things and let us know what you find. Thanks!

Thank you! FYI, I've been exploring https://projecteuler.net problems and tried solving some of them with my HP calculators. The exact integer arithmetic of the HP50g has been very helpful, but for most of the problems I long for the speed of the Prime. I'll experiment further using your hints.

/Lennart
Find all posts by this user
Quote this message in a reply
10-28-2014, 01:07 PM
Post: #10
RE: Exact integer arithmetic in Home?
(10-28-2014 03:58 AM)Joe Horn Wrote:  Here's a tiny Home program which multiplies 12345678901235 times 234567890123456 and returns the complete correct product of 28958998520042431946358064320:

This is a bit off topic, but...
Just for grins, I entered the two numbers into the WP 34S and after multiplying, got a different result. I then tried Wolfram Alpha and got the same result as the WP 34S, which was puzzling. Then noticed that the first number in the sentence was missing the digit "4" at the end in "12345" as was shown in the actual code example (which had the "4"). After putting in the 4, the 34S, Wolfram and the 29-digit product above all were in agreement and my faith was restored in double-precision mode of the 34S :-)

Jake
Find all posts by this user
Quote this message in a reply
10-28-2014, 02:20 PM
Post: #11
RE: Exact integer arithmetic in Home?
No doubt your eyes immediately spotted the fact that the length of the s1 value is greater than the length of it's corresponding value in the sentence. I mean, who wouldn't?

-Dale-
Find all posts by this user
Quote this message in a reply
10-28-2014, 03:16 PM
Post: #12
RE: Exact integer arithmetic in Home?
(10-28-2014 01:07 PM)Jake Schwartz Wrote:  
(10-28-2014 03:58 AM)Joe Horn Wrote:  Here's a tiny Home program which multiplies 12345678901235 times 234567890123456 and returns the complete correct product of 28958998520042431946358064320:
Just for grins, I entered the two numbers into the WP 34S and after multiplying, got a different result. I then tried Wolfram Alpha and got the same result as the WP 34S, which was puzzling. Then noticed that the first number in the sentence was missing the digit "4" at the end in "12345" as was shown in the actual code example (which had the "4"). After putting in the 4, the 34S, Wolfram and the 29-digit product above all were in agreement and my faith was restored in double-precision mode of the 34S :-)

Thanks for catching that typo, Jake! It has been corrected in my original posting.

<0|ɸ|0>
-Joe-
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 




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