Exact integer arithmetic in Home?
10-27-2014, 12:43 PM
Post: #1
 lenborje Member Posts: 53 Joined: Jul 2014
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
10-27-2014, 12:51 PM (This post was last modified: 10-27-2014 12:53 PM by DrD.)
Post: #2
 DrD Senior Member Posts: 1,132 Joined: Feb 2014
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-
10-27-2014, 01:22 PM
Post: #3
 lenborje Member Posts: 53 Joined: Jul 2014
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... ;-)
10-27-2014, 01:27 PM
Post: #4
 Han Senior Member Posts: 1,843 Joined: Dec 2013
RE: Exact integer arithmetic in Home?
Are you aware that you can create CAS programs?

Graph 3D | QPI | SolveSys
10-27-2014, 01:36 PM (This post was last modified: 10-27-2014 01:44 PM by lenborje.)
Post: #5
 lenborje Member Posts: 53 Joined: Jul 2014
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.
10-27-2014, 01:46 PM
Post: #6
 DrD Senior Member Posts: 1,132 Joined: Feb 2014
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-
10-27-2014, 01:58 PM
Post: #7
 lenborje Member Posts: 53 Joined: Jul 2014
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! ;-)
10-28-2014, 03:58 AM (This post was last modified: 10-28-2014 03:10 PM by Joe Horn.)
Post: #8
 Joe Horn Senior Member Posts: 1,687 Joined: Dec 2013
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-
10-28-2014, 07:37 AM
Post: #9
 lenborje Member Posts: 53 Joined: Jul 2014
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
10-28-2014, 01:07 PM
Post: #10
 Jake Schwartz Member Posts: 269 Joined: Dec 2013
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
10-28-2014, 02:20 PM
Post: #11
 DrD Senior Member Posts: 1,132 Joined: Feb 2014
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-
10-28-2014, 03:16 PM
Post: #12
 Joe Horn Senior Member Posts: 1,687 Joined: Dec 2013
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-
 « Next Oldest | Next Newest »

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