Re: Mathematica challenge Message #28 Posted by James M. Prange (Michigan) on 9 Oct 2006, 3:20 a.m., in response to message #24 by Don Shepherd
Sometimes brute-force problem solving really does seem to be the
"best" way, although various "nifty tricks" are indeed impressive
and are much better if you happen to know of them or figure them
out. Often it seems to be a trade-off between how fast one can
come up with a "good" program and how fast the calculator can
execute the program. Would you rather spend your time writing a
more "optimal" program, or waiting for the calculator to run a
"good enough" program?
Yes, it appears to me that the 49 series errors out immediately
with "^ Error: Integer too large" if I ask it to raise any exact
integer (even 0 or 1) to the power of any exact integer greater
than 9999. So, at first look, it seems that 2 raised to some power
greater than 16000 would be well beyond its capability. But I can
raise 2 to the power of 400, and then raise the result to the
power of 40, which would end up the same value as 2 to the power
of 16000. So in some cases, those in which the exponent can be
factored into integers all less than 10000, integers can be raised
to powers greater than 9999 (always assuming enough available
memory); it's just a round-about way of cajoling the calculator
into working out the result, and waiting for it.
Whether it would eventually return a result for an integer raised
to a large power is another matter. For example, with
\<<
10000
9999 ^
\>>
or
\<<
10000
101 ^
11 ^
3 ^
3 ^
\>>
it does (eventually) return the correct 39997-digit number (1
followed by 39996 0s), which takes up 20004 bytes. But I don't
care to experiment with finding the largest values that it can
handle.
An obvious limitation for very large exact integers is the
available memory. Except for the integers "built-in" to ROM, which
each take 2.5 bytes (for the address), as far as I've been able to
surmise, each one takes 5 nibbles for the prologue address, 5
nibbles for the self-inclusive length field, 1 nibble for each
digit, and 1 nibble for the sign field. So the rule for
non-built-in exact integers is 11 nibbles plus 1 nibble per digit,
or 5.5 bytes plus 0.5 byte per digit.
Since the length field is 5 nibbles, it's largest notional value
would be FFFFFh, or 1048575; subtracting 5 nibbles for the length
field itself and 1 nibble for the sign field, that would leave us
1048569 nibbles for the digits, and it would take 1048580 nibbles
(remember that the prologue takes 5 nibbles), or 524290 bytes, to
hold the object.
But since memory is addressed by the nibble with 5-nibble
addresses, the directly addressable memory space is 1048576
nibbles (512KiB). I think that half of that is reserved for ROM,
and some of the RAM is reserved for system use, leaving somewhat
less than 524288 nibbles (256KiB) of "user memory" actually
available for the user.
Anyway, the limitation on the length of exact integers is imposed
by available memory, not the structure of the exact integer object
itself. One could construct a 1048569-digit exact integer object
on a PC and store it on a flash memory card, but the 49 series
would never be able to actually read it.
Experimentally, on my 49g+, after clearing memory, restoring RPN
and "soft menu" modes, disabling last stack, arguments, and
command line saves, purging 'CASDIR' and letting the system
restore part of it, the MEM command returns 246554 (in bytes),
which would be 493108 nibbles, and figuring that the prologue,
length field, and sign field of an integer use up 11 nibbles, that
leaves 493097 nibbles for the digits. To put an object on the
stack takes 5 nibbles for the stack pointer, which cuts it down to
493092 digits. With various other uses of memory probably cutting
it down a bit more, I surmise that the longest exact integer that
one could possiby get onto the stack of a 49 series would be
slightly less than that. Since it's generally desirable to have
the "last" saves enabled, memory is needed for other purposes, and
doing anything with very large integers takes a long time, the
longest integer that it would be comfortable to work with would be
much smaller.
What other limitations the 49 series may have with large exact
integers, I don't know.
Regards, James
Edited: 9 Oct 2006, 3:28 a.m.
|