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

Computing Pi on the Apple II and //e.

98 views
Skip to first unread message

datajerk

unread,
Aug 9, 2009, 4:23:40 PM8/9/09
to
In the Aug/Sept 1978 issue of Micro Magazine Robert Bishop published
an Integer Basic program to compute the first 1000 digits of Pi. It
took ~40 hours.

Did anybody ever improve on this benchmark?

Thanks.

brad

unread,
Aug 11, 2009, 1:06:24 AM8/11/09
to
"datajerk" <data...@gmail.com> wrote in message > In the Aug/Sept 1978


i had a buddy named Qazz (don guse) he used to run pi on an old apple ][
when not using it just for the heck of it...not sure how his pi program
worked..but even with an apple ][ setup... he i think.... did so from the
late 70's till his passing in 2005....

brad
former sysop lost gonzo bbs

Charles Richmond

unread,
Aug 11, 2009, 1:59:28 AM8/11/09
to

Bob Bishop's "Apple Pi" article originally published in Micro
magazine at:

http://bob-bishop.awardspace.com/ApplePi/index.html


The Apple BASIC source code is included in the article.


On my Linux box a few years ago, I recoded this algorithm in C and
computed at least 100,000 digits of PI. To check my result, I
downloaded the value of PI to 1 megadigit from a Gutenberg site
and wrote another program to compare the digits downloaded with
the digits computed.

--
+----------------------------------------+
| Charles and Francis Richmond |
| |
| plano dot net at aquaporin4 dot com |
+----------------------------------------+

datajerk

unread,
Aug 11, 2009, 12:24:26 PM8/11/09
to
On Aug 10, 11:59 pm, Charles Richmond <friz...@tx.rr.com> wrote:
> datajerk wrote:
> > In the Aug/Sept 1978 issue of Micro Magazine Robert Bishop published
> > an Integer Basic program to compute the first 1000 digits of Pi.  It
> > took ~40 hours.
>
> > Did anybody ever improve on this benchmark?
>
> Bob Bishop's "Apple Pi" article originally published in Micro
> magazine at:
>
> http://bob-bishop.awardspace.com/ApplePi/index.html
>
> The Apple BASIC source code is included in the article.

Thanks for the link. I also found it from a different source:

http://www.6502.org/documents/publications/micro/micro_6_aug_1978.pdf

> On my Linux box a few years ago, I recoded this algorithm in C and
> computed at least 100,000 digits of PI. To check my result, I
> downloaded the value of PI to 1 megadigit from a Gutenberg site
> and wrote another program to compare the digits downloaded with
> the digits computed.

The algorithm used is based on the very popular Machin Arctan
formula. I found a C version and compiled it with Aztec C for the //e
(http://sense.net/~egan/apple2e_aztec_c/pi.c). It runs in ~37
minutes.

I also gave FORTH a try. My own implementation of the same formula in
Mad Apple Forth ran in just under 25 minutes.

I was hoping before publishing my results in another online forum that
I could reference other attempts, but so far I have found none.

Thanks.

mmphosis

unread,
Aug 11, 2009, 7:08:09 PM8/11/09
to

D Finnigan

unread,
Aug 12, 2009, 2:36:14 PM8/12/09
to

Here's a program which claims to be able to do it in 40 minutes:




Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10.2 9/18/84; site ski.UUCP
Path: utzoo!linus!philabs!cmcl2!seismo!lll-crg!dual!ptsfa!ski!eeg
From: e...@ski.UUCP (eeg systems )
Newsgroups: net.sources
Subject: Solving Pi
Message-ID: <1...@ski.UUCP>
Date: Mon, 22-Jul-85 23:29:18 EDT
Article-I.D.: ski.187
Posted: Mon Jul 22 23:29:18 1985
Date-Received: Thu, 25-Jul-85 21:36:52 EDT
Reply-To: e...@ski.UUCP (eeg systems (bcx)
Organization: Smith-Kettlewell Institute, S.F., CA.
Lines: 286


I am posting this as an interesting approach to solving
pi to many decimal places. Originally compiled and run on an Apple
II, it took 40 minutes to solve pi to 1000 places. On a Vax, it took
1.5 seconds! I limited its precision to 1000 places because the only
listing for pi I had available only listed that many places.

To use, cut below and compile.

Enjoy. Bryan Costales ( ...!dual!ptsfa!ski!eeg!bcx )

--------------------------< cut here >-------------------------------
/*
** NAME
** pi -- a program to calculate the value of pi
**
** SYNOPSIS
** pi {-}digits {t}
**
** DESCRIPTION
** Pi calculates the value of pi to the number of digits
** specified. Output is to the standard output, if the
** digits specifed is negative, output is formatted
** for attractive display on an 80col printer.
**
** The optional last argument "t" enables timing of the
** computational loop. The pitime() function must be supplied
** by the individual site implimentation.
**
** This is an adaptation in C of the BASIC program "Apple Pi"
** by Robert J. Bishop, published in Micro Apple (c) 1981
** Micro Ink, Inc. That program, when run on an Apple II,
** took 40 hours to solve pi to 1000 places. Arrays of digits
** are used to impliment extended precision arithmatic. The
** program solves pi using the series expansion:
**
** infinity infinity
** ____ 16*(-1e(k+1)) ____ 4*(-1e(k+1))
** \ \
** pi = > ------------- - > ------------
** / /
** ---- (2k-1)*5e(2k-1) ---- (2k-1)*239e(2k-1)
** k = 1 k = 1
**
** AUTHOR
** Bryan Costales ( ...!dual!ptsfa!ski!eeg!bcx )
** pi.c (c) 1985 Bryan Costales
**
** BUGS
**
*/


#include <stdio.h>

/*
* The maximum number of digits (plus 5 for rounding).
*/
#define MAX 10005

/*
* Global variables
*/
int Sign,
Zero,
Size,
Pass, /* two passes */
Exp, /* exponent for divide */
Divide;

/*
* These character arrays represent the digits for extended
* precision arithmatic. (These may need to be int on some machines).
*/
#define DIGIT char
DIGIT Power[MAX], Term[MAX], Result[MAX];

main(argc, argv)
int argc;
char *argv[];
{
static int constant[3]={0,25,239};
register int i;
int charcount, printer = 0;
void exit(); /* for lint */

if(argc == 1)
{
(void)fprintf(stderr,"usage: pi {-}digits {t}\n");
exit(1);
}

Size = atoi(argv[1]);
if(Size < 0)
{
Size = -Size;
printer++;
}

if(Size >= MAX-4 || Size <= 0)
{
(void)fprintf(stderr,"'digits' must be 1 thru %d.\n",MAX-5);
exit(1);
}

if( (argc==3) && (*argv[2]=='t') )
{
(void)fprintf(stderr,"start computation: ");
pitime();
}

for(Pass=1; Pass < 3; Pass++)
{
init();

do
{
copy();
Divide = Exp;
div(Term);
if ( Sign > 0 )
add();
if ( Sign < 0 )
sub();
Exp = Exp + 2;
Sign *= -1;
Divide = constant[Pass];
div(Power);
if (Pass == 2)
div(Power);
} while( Zero != 0 );
}

if( (argc == 3) && (*argv[2] == 't') )
{
(void)fprintf(stderr,"end computation: ");
pitime();
}

if( printer )
{
(void)printf("\t\tThe value of pi" );
(void)printf(" to %d decimal places\n\n\t\t",Size);
}

(void)printf("%d.",Result[0]);
charcount = 0;

for(i = 1; i <= Size; i++)
{
(void)printf( "%d", Result[i]);
charcount++;
if ( (charcount == 50) && printer )
{
(void)printf( "\n\t\t " );
charcount = 0;
}
}
(void)printf( "\n" );
return( 0 ); /* for lint */
}

add()
{
register DIGIT *r, *t;
register int sum, carry = 0;

r = Result + Size;
t = Term + Size;

while( r >= Result )
{
sum = *r + *t + carry;
carry = 0;
if( sum >= 10 )
{
sum -= 10;
carry++;
}
*r-- = sum;
--t;
}
}

sub()
{
register DIGIT *r, *t;
register int diff, loan = 0;

r = Result + Size;
t = Term + Size;

while( r >= Result )
{
diff = *r - *t - loan;
loan =0;
if( diff < 0 )
{
diff += 10;
loan++;
}
*r-- = diff;
--t;
}
}

div(array)
register DIGIT *array;
{
register DIGIT *end;
register int quotient, residue, digit = 0;

Zero = 0;

for( end = array + Size; array <= end; )
{
digit += *array;
quotient = digit / Divide;
residue = digit % Divide;

if((Zero !=0) || ((quotient+residue) != 0))
Zero = 1;
else
Zero = 0;

*array++ = quotient;
digit = 10 * residue;
}
}

init()
{
register DIGIT *p, *t, *r, *end;

p = Power;
t = Term;
r = Result;
end = Power+Size;

while( p <= end )
{
*p++ = 0;
*t++ = 0;

if (Pass == 1)
*r++ = 0;
}

*Power = 16 / (Pass * Pass);

if( Pass == 1 )
{
Divide = 5;
}
else
{
Divide = 239;
}

div(Power);
Exp = 1;
Sign = 3 - (2 * Pass);
}

copy()
{
register DIGIT *t, *p, *end;

t = Term;
p = Power;
end = Term + Size;

while (t <= end)
{
*t++ = *p++;
}
}

pitime()
{
/* Print the current time \n */

/* Here we just beep */
(void)fprintf( stderr, "%c\n", 0x07 );
}

datajerk

unread,
Aug 12, 2009, 3:18:46 PM8/12/09
to
On Aug 12, 12:36 pm, D Finnigan <dog_...@macgui.com> wrote:
> datajerk wrote:
> > In the Aug/Sept 1978 issue of Micro Magazine Robert Bishop published
> > an Integer Basic program to compute the first 1000 digits of Pi.  It
> > took ~40 hours.
>
> > Did anybody ever improve on this benchmark?
>
> > Thanks.
>
> Here's a program which claims to be able to do it in 40 minutes:

...

Thank you for this. And thanks for including the headers with dates.
I am trying to create a time line and this really helps.

bill.m...@gmail.com

unread,
Aug 19, 2009, 10:47:01 AM8/19/09
to

For anyone interested, here is the Text of the Bob Bishop Pi Program

----------------APPLEPI.TXT---------------------
0 REM *** APPLE-PI *** WRITTEN BY BOB BISHOP
5 CALL 936: VTAB 10: TAB 5: PRINT "HOW MANY DIGITS DO YOU WANT";
10 INPUT SIZE
15 CALL -936
20 TEN=10: IF SIZE>200 THEN 50
30 TEN=100: SIZE=(SIZE+1)/2
50 POWER=4096:TERM=8192:RESULT=12288
60 DIV=1000:ADD=2000:SUB=3000:INIT=4000:COPY=5000
70 DIM CONTANT(2):CONSTANT(1)=25:CONSTANT(2)=239
100 REM MAIN LOOP
125 FOR PASS=1 TO 2
150 GOSUB INIT
200 GOSUB COPY
210 POINT=TERM:DIVIDE=EXP:GOSUB DIV
220 IF SIGN>0 THEN GOSUB ADD
230 IF SIGN<0 THEN GOSUB SUB
240 EXP=EXP+2:SIGN=-SIGN
250 POINT=POWER:DIVIDE=CONSTANT(PASS):GOSUB DIV
260 IF PASS=2 THEN GOSUB DIV
270 IF ZERO<>0 THEN 200
300 NEXT PASS
400 REM PRINT THE RESULT
500 PRINT : PRINT
510 PRINT "THE VALUE OF PI TO ";(TEN/100+1)*SIZE;" DECIMAL
PLACE:":PRINT
520 PRINT PEEK (RESULT);".";
530 FOR PLACE=RESULT+1 TO RESULT+SIZE
540 IF TEN=10 THEN 570
560 IF PEEK(PLACE)<10 THEN PRINT"0";
570 PRINT PEEK(PLACE);
580 NEXT PLACE
590 PRINT
600 END
1000 REM DIVISION SUBROUTINE
1010 DIGIT=0:ZERO=0
1020 FOR PLACE=POINT TO POINT+SIZE
1030 DIGIT=DIGIT+PEEK(PLACE)
1040 QUOTIENT=DIGIT/DIVIDE
1050 RESIDUE=DIGIT MOD DIVIDE
1055 ZERO=ZERO OR (QUOTIENT+RESIDUE)
1060 POKE PLACE, QUOTIENT
1070 DIGIT=TEN*RESIDUE
1080 NEXT PLACE
1090 RETURN
2000 REM ADDITION SUBROUTINE
2010 CARRY=0
2020 FOR PLACE=SIZE TO 0 STEP -1
2030 SUM=PEEK(RESULT+PLACE)+PEEK(TERM+PLACE)+CARRY
2040 CARRY=0
2050 IF SUM<TEN THEN 2080
2060 SUM=SUM-TEN
2070 CARRY=1
2080 POKE RESULT+PLACE,SUM
2090 NEXT PLACE
2100 RETURN
3000 REM SUBTRACTION SUBROUTINE
3010 LOAD=0
3020 FOR PLACE=SIZE TO 0 STEP -1
3030 DIFFERENCE=PEEK(RESULT+PLACE)-PEEK(TERM+PLACE)-LOAD
3040 LOAN=0
3050 IF DIFFERENCE>=0 THEN 3080
3060 DIFFERENCE=DIFFERENCE+TEN
3070 LOAN=1
3080 POKE RESULT+PLACE,DIFFERENCE
3090 NEXT PLACE
3100 RETURN
4000 REM INITIALIZE REGISTERS
4010 FOR PLACE=0 TO SIZE
4020 POKE POWER+PLACE,0
4030 POE TERM+PLACE,0
4040 IF PASS-1 THEN POKE RESULT+PLACE,0
4050 NEXT PLACE
4060 POKE POWER,16/PASS^2
4070 IF PASS=1 THEN DIVIDE=5
4080 IF PASS=2 THEN DIVIDE=239
4090 POINT=POWER:GOSUB DIV
4100 EXP=1:SIGN=3-2*PASS
4110 RETURN
5000 REM COPY "POWER" INTO "TERM"
5010 FOR PLACE=0 TO SIZE
5020 POKE TERM+PLACE, PEEK(POWER+PLACE)
5030 NEXT PLACE
5040 RETURN
--------------------End of APPLEPI.TXT------------------

schmidtd

unread,
Aug 19, 2009, 11:43:30 AM8/19/09
to
On Aug 19, 10:47 am, "bill.mart...@gmail.com" <bill.mart...@gmail.com>
wrote:

> For anyone interested, here is the Text of the Bob Bishop Pi Program
>
> ----------------APPLEPI.TXT---------------------
> --------------------End of APPLEPI.TXT------------------
With the power of cut-n-paste, I'm interested! I fixed a few typos.
After comparing to the original text a couple of times, I must still
be missing something... I'm getting output in the 99.99x range.

< 5 CALL 936: VTAB 10: TAB 5: PRINT "HOW MANY DIGITS DO YOU WANT";

> 5 CALL -936: VTAB 10: TAB 5: PRINT "HOW MANY DIGITS DO YOU WANT";

< 70 DIM CONTANT(2):CONSTANT(1)=25:CONSTANT(2)=239

> 70 DIM CONSTANT(2):CONSTANT(1)=25:CONSTANT(2)=239

< 3010 LOAD=0
> 3010 LOAN=0

< 3030 DIFFERENCE=PEEK(RESULT+PLACE)-PEEK(TERM+PLACE)-LOAD
> 3030 DIFFERENCE=PEEK(RESULT+PLACE)-PEEK(TERM+PLACE)-LOAN

< 4030 POE TERM+PLACE,0
> 4030 POKE TERM+PLACE,0

schmidtd

unread,
Aug 19, 2009, 12:00:43 PM8/19/09
to
On Aug 19, 11:43 am, schmidtd <schmi...@my-deja.com> wrote:
> On Aug 19, 10:47 am, "bill.mart...@gmail.com" <bill.mart...@gmail.com>
> wrote:> For anyone interested, here is the Text of the Bob Bishop Pi Program
>
> > ----------------APPLEPI.TXT---------------------
> > --------------------End of APPLEPI.TXT------------------
>
> With the power of cut-n-paste, I'm interested!  I fixed a few typos.
> After comparing to the original text a couple of times, I must still
> be missing something... I'm getting output in the 99.99x range.

Sorry all for the crosspost (and code), but I have one final typo that
fixed it for me:


<4040 IF PASS-1 THEN POKE RESULT+PLACE,0

>4040 IF PASS=1 THEN POKE RESULT+PLACE,0

Pesky OCR! :-)

bill.m...@gmail.com

unread,
Aug 19, 2009, 12:35:55 PM8/19/09
to

Actually it was hand typed by me which is why there were typo's.
Sorry about that one and thanks for the fixes.

Charles Richmond

unread,
Aug 19, 2009, 9:30:23 PM8/19/09
to

Of course!!! If you OCR it, then it would have OCR-o's and *not*
typos. ;-)

bill.m...@gmail.com

unread,
Aug 19, 2009, 11:30:29 PM8/19/09
to
On Aug 20, 10:30 am, Charles Richmond <friz...@tx.rr.com> wrote:

OK...HERE IS THE CORRECTED file.

---------APPLEPI.TXT----------------


0 REM *** APPLE-PI *** WRITTEN BY BOB BISHOP

5 CALL -936: VTAB 10: TAB 5: PRINT "HOW MANY DIGITS DO YOU WANT";

10 INPUT SIZE
15 CALL -936
20 TEN=10: IF SIZE>200 THEN 50
30 TEN=100: SIZE=(SIZE+1)/2
50 POWER=4096:TERM=8192:RESULT=12288
60 DIV=1000:ADD=2000:SUB=3000:INIT=4000:COPY=5000

70 DIM CONSTANT(2):CONSTANT(1)=25:CONSTANT(2)=239

3010 LOAN=0


3020 FOR PLACE=SIZE TO 0 STEP -1

3030 DIFFERENCE=PEEK(RESULT+PLACE)-PEEK(TERM+PLACE)-LOAN


3040 LOAN=0
3050 IF DIFFERENCE>=0 THEN 3080
3060 DIFFERENCE=DIFFERENCE+TEN
3070 LOAN=1
3080 POKE RESULT+PLACE,DIFFERENCE
3090 NEXT PLACE
3100 RETURN
4000 REM INITIALIZE REGISTERS
4010 FOR PLACE=0 TO SIZE
4020 POKE POWER+PLACE,0

4030 POKE TERM+PLACE,0


4040 IF PASS=1 THEN POKE RESULT+PLACE,0

4050 NEXT PLACE
4060 POKE POWER,16/PASS^2
4070 IF PASS=1 THEN DIVIDE=5
4080 IF PASS=2 THEN DIVIDE=239
4090 POINT=POWER:GOSUB DIV
4100 EXP=1:SIGN=3-2*PASS
4110 RETURN
5000 REM COPY "POWER" INTO "TERM"
5010 FOR PLACE=0 TO SIZE
5020 POKE TERM+PLACE, PEEK(POWER+PLACE)
5030 NEXT PLACE
5040 RETURN

-----------------------------End of APPLEPI.TXT------------------------

Bill Buckels

unread,
Aug 20, 2009, 3:53:21 AM8/20/09
to

"Charles Richmond" <fri...@tx.rr.com> wrote:
>Of course!!! If you OCR it, then it would have OCR-o's and *not* typos.
>;-)

And if you compile the equivalent in Aztec C you will have Cheerios:) Or at
least something that will run significantly faster.

Cheerio,

Bill


0 new messages