Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How do I calculate 2^850000 and see all the digits?

6 views
Skip to first unread message

Blake Patterson

unread,
Dec 10, 1995, 3:00:00 AM12/10/95
to

I understand this _is_ possible under gcl with 'bignums.' I
lack significant documentation of the language -- can anyone show me
some example code where bignums are used? I need to (in case you missed
the topic) print out all the decimals in the computation of 2^850000.

Thanks.

Email is supernice.

bp
--
[[[ URL: http://www.pcs.cnu.edu/~bpatters ]]]
+--------------------------------- ---- -- - - - - -
|Blake W. Patterson "I'm not quite clear about what you just spoke-
|bpat...@pcs.cnu.edu Was that a parable, or a very subtle joke?"
|bl...@vigsun1.larc.nasa.gov
+--ToriAmos-LoreenaMcKennitt-Enya-DavidWilcox-SarahMcLachlan-ElvisCostello--+
+----DavidBowie-CrashTestDummies-TheyMightBeGiants-RustedRoot-Pixies-XTC----+


Jack Harper

unread,
Dec 11, 1995, 3:00:00 AM12/11/95
to
In article <4afc4g$n...@news.infi.net>, bpat...@pcs.cnu.edu (Blake
Patterson) wrote:

"Things should be as simple as possible...but no simpler" -- A. Einstein.

I would suggest:

(expt 2 850000)

It might run for awhile -- but should work -- assuming you have enough memory.

Regards...

Jack Harper

---------------------------------------------------------------------
Jack Harper Bank Systems 2000, Inc.
e-mail: jha...@bs2000.com 350 Indiana Street, Suite 350
voice: 303-277-1892 fax: 303-277-1785 Golden, Colorado 80401 USA

"21st Century Banking Applications"
Private Label Optical Bank Card Systems
Visit our Web Page: http://www.bs2000.com/talos
---------------------------------------------------------------------

Jack Harper

unread,
Dec 11, 1995, 3:00:00 AM12/11/95
to
<snip>

Oops...

You said GCL -- My error. See - Albert was right.

Jean-David Marrow

unread,
Dec 11, 1995, 3:00:00 AM12/11/95
to

> I understand this _is_ possible under gcl with 'bignums.' I
>lack significant documentation of the language -- can anyone show me
>some example code where bignums are used? I need to (in case you
missed
>the topic) print out all the decimals in the computation of 2^850000.

Too bad that you want decimals. In binary, of course, the answer is 1
followed by 850000 0's. :)

Sorry for the non-answer...

jdm
pach...@ix.netcom.com


Peter Adams

unread,
Dec 12, 1995, 3:00:00 AM12/12/95
to
bpat...@pcs.cnu.edu (Blake Patterson) wrote:


> I understand this _is_ possible under gcl with 'bignums.' I
>lack significant documentation of the language -- can anyone show me
>some example code where bignums are used? I need to (in case you missed
>the topic) print out all the decimals in the computation of 2^850000.

> Thanks.

> Email is supernice.

>bp
>--
> [[[ URL: http://www.pcs.cnu.edu/~bpatters ]]]
>+--------------------------------- ---- -- - - - - -
>|Blake W. Patterson "I'm not quite clear about what you just spoke-
>|bpat...@pcs.cnu.edu Was that a parable, or a very subtle joke?"
>|bl...@vigsun1.larc.nasa.gov
>+--ToriAmos-LoreenaMcKennitt-Enya-DavidWilcox-SarahMcLachlan-ElvisCostello--+
>+----DavidBowie-CrashTestDummies-TheyMightBeGiants-RustedRoot-Pixies-XTC----+

If you want to see the result as a binary number it is simply 1
followed by 850000 zeros. You don't even need a Lisp program to tell
you that 8-)

The answer in decimal form would be 255,876 digits long (very nearly
60 pages at 60 lines to the page, and 72 digits to the line).

Here are two ways to calculate the answer in bignums. They work in ACL
so I preume the answer would be the same with GCL:

(defun pwr1 (lim)
(do ((n 1) (count 0)) ((>= count lim) n)
(setq n (* 2 n))
(setq count (1+ count))))
;;
;;
(defun pwr2 (n)
(cond
((= n 2) 4)
((oddp n) (* (pwr2 (- n 1)) 2))
(t (square (pwr2 (/ n 2))))))
;;
;;
;;
I hope that your computer doesn't choke if you try to run the above
code using an argument value of 850,000 8-(.

Regards,


Peter Adams


Erik Naggum

unread,
Dec 12, 1995, 3:00:00 AM12/12/95
to
[Peter Adams]

| If you want to see the result as a binary number it is simply 1
| followed by 850000 zeros. You don't even need a Lisp program to tell
| you that 8-)

this implies to me that (ash 1 850000) would do the job perfectly.

| Here are two ways to calculate the answer in bignums. They work in ACL
| so I preume the answer would be the same with GCL:

GCL gets severely depressed when faced with very large bignums. even after
(si::multiply-bignum-stack n), which is complains is necessary, it dumps
core with an "unrecoverable error". (n = 20, n = 10 is too small, other
values not tested.)

#<Erik 3027765906>
--
suppose we actually were immortal...
what is the opposite of living your life as if every day were your last?

Pierpaolo Bernardi

unread,
Dec 12, 1995, 3:00:00 AM12/12/95
to
Peter Adams (pad...@actrix.gen.nz) wrote:
: bpat...@pcs.cnu.edu (Blake Patterson) wrote:


: > I understand this _is_ possible under gcl with 'bignums.' I
: >lack significant documentation of the language -- can anyone show me
: >some example code where bignums are used? I need to (in case you missed
: >the topic) print out all the decimals in the computation of 2^850000.

: > Thanks.

: > Email is supernice.

: >bp
: >--

Using Clisp on a 486/66

(expt 2 850000)

takes about 3 min.

Cheers.

John R. Bob Bane

unread,
Dec 14, 1995, 3:00:00 AM12/14/95
to
In article <4akem6$e...@serra.unipi.it> bern...@cli.di.unipi.it (Pierpaolo Bernardi) writes:
>
>Using Clisp on a 486/66
>
>(expt 2 850000)
>
>takes about 3 min.
>
Try timing the following two forms:

(expt 2 850000)

(progn (setq foo (expt 2 850000)) nil)

I'll bet that the second one will be *much* faster than the first, which
has to spend a bunch of time converting the internal bignum representation
to decimal for printing.
--
Internet: ba...@tove.cs.umd.edu
Voice: 301-552-4860

Pierpaolo Bernardi

unread,
Dec 15, 1995, 3:00:00 AM12/15/95
to
John R. "Bob" Bane (ba...@cs.umd.edu) wrote:

: (expt 2 850000)

Of course. The three minutes are for converting the thing in decimal.
Your second expression will probably run in no time flat.

Cheers.

P.

0 new messages