Category Archives: apple ii

Post Pi Day Post

Well, Pi Day has come and gone, so what’s left for a Pi nerd to look forward to? Tau Day? Heresy! That other Pi Day, July 22nd (22/7)? Pa-lease. Accept the fact that it’s OK to talk about Pi when it’s not Pi Day? Sure, why not?

A random thought caught my attention after I posted my article Pi Day Rematch: Apple II vs. HP-41C that suggested that I could have been more fair to the HP-41C by highlighting some of it’s obvious strengths, e.g. portability and energy efficiency. And, I got a lot of personal emails expressing that thought as well. (In my defense, it wasn’t I that compared the two in the first place–some people are just too serious :-).

Lets be honest, was there any doubt in anybody’s mind that a late ’70s pocket calculator could best an Apple II in a 1000 digit drag race? Or ENIAC for that matter? However, what if, you had to compute Pi within a fixed energy budget of 1 Wh or on a flight to Paris? Which would you choose?


Energy Efficiency

I remember a time when the energy utilization of home computing equipment was never given a second thought other than, “turn it off before you go to bed.” Fast-forward to today: Our consumer electronics have a plethora of energy saving options, e.g. my computer suspends when not in use, my external drives spin down when unused, my fridge has a vacation mode, all my LCD TVs have a green mode (my Sharp rates your energy efficiency with green leaves (0-5)), my electric utility company wants to control my air conditioner, etc… Today, energy utilization matters. So, lets pretend it mattered in 1980. You’ve got a 1 Wh budget to compute Pi to 1000 digits. What do you use, the Apple II or the HP-41C?

The community members of comp.sys.apple2 and MoHPC were kind enough to measure the power consumption of the Apple II and HP-41C and reported 24 Watts and 72 mW respectively.

The best Apple II and HP-41C times reported by my tests were 194 seconds and 08:21:57 (30,117 seconds) respectively making the energy used 24W*(194/3600) = 1.29 Wh and 0.072W*(30117/3600) = 0.60 Wh.

It should be obvious why. The Apple II, as a general-purpose computer, has a lot of unused powered components where as the HP-41C, while still a computer, is a limited-purpose device for specific computational tasks. To further handicap the Apple II, the Apple II has to convert from AC to DC. The drop in efficiency for retro tech could be as high as 50%. However, none of that takes away from the fact that for computational intensive tasks, at least those involving Pi, the HP-41C is more efficient.

The table below contains all the benchmarks that I ran with their estimated energy usage. The original Apple Pi uses more than 1000 times the energy of the HP-41C; a whopping 1KWh!


Platform
Code
Base Time(s) Watts Wh
HP-41C
RPN
105 30117 0.072 0.60
Apple II
Assembly
10 194 24 1.29
Apple II
MAF
216 1496 24 9.97
Apple II
cc65 2.13
216 1514 24 10.09
Apple II
Aztec C
216 2180 24 14.53
Apple II
Integer BASIC
10 150410 24 1002.73


Portability

The HP-41C is a remarkable late-’70s gadget. It has a display, an alphanumeric keyboard, a file system, removable storage, expandable memory, and sports general purpose programmable I/O (via HP-IL); all the earmarks of a ’70s computer, and it fits in your pocket.

Lets say that you are traveling non-stop to Paris from my hometown, and in the 10-11 Hr journey you need to compute at least 704 digits of Pi so that you can personally confirm that the digits of Pi in the Palais de la Découverte “π Room”, that were originally incorrect until corrected in 1945, are actually correct[1, pp. 50].

No contest here. There isn’t a pocket-able Apple II product unless you count emulation on the iPhone/iPad. What you need is a very capable, energy efficient, pocket computer–the HP-41C. 704 digits in < 10-11 Hr? No problem, it'd take a little over 4 hours. You can use the rest of your time to compute e. Too bad there isn’t an “e room”, or is there?


The “π Room”

No, I didn’t compute Pi on my way to Paris, but just knowing that I could have with my 41CX in my pocket reassured me. :-)

All Pi nerds (make that all nerds) that find themselves in Paris should make the pilgrimage to Palais de la Découverte to visit the only “π Room” in existence (or so I have been able to find). This science museum is a short walk from the Eiffel Tower, so if you are willing to spend the time to see a marvel of French engineering, then you might as well go see the most fabulous piece of calculation ever performed[2, pp.406] by an Englishman.


William Shanks of England

William Shanks (1812 – 1882) was an amateur mathematician and IMHO is still the king of all Pi nerds. William Shanks computed Pi to 707 places over a 15+ year period with nothing but pen, paper, and his wits[2, pp. 305]. A stunning achievement and the last computation of its kind, however, there is an error, can you see it?


Proceedings of the Royal Society of London, 21 (1873), 319.

An example of a mechanical desk calculator available in 1945

No? Don’t worry, nobody else did either until 72 years later when another Englishman, D. F. Ferguson, in 1945 using a mechanical desk calculator checked Shanks’ results and discovered that Shanks was only correct up to digit 527[2, pp. 592]. Fortunately (for Shanks), Shanks never knew of his error. He passed away with the belief that he had achieved the unachievable.

Ferguson’s Pi were last non-digital calculations[2, pp. 627]; the era of supermen manually computing Pi ended in 1949 when ENIAC cranked out 2047 digits over a three-day holiday weekend[2, pp. 277].

Shanks’ Pi with corrections:


Value of π = 3 ·

· 
1
4
1
5
9
  
2
6
5
3
5
  
8
9
7
9
3
  
2
3
8
4
6
  
2
6
4
3
3
  
8
3
2
7
9
  
5
0
2
8
8
  
4
1
9
7
1
  
6
9
3
9
9
  
3
7
5
1
0
  
5
8
2
0
9
  
7
4
9
4
4
5
9
2
3
0
  
7
8
1
6
4
  
0
6
2
8
6
  
2
0
8
9
9
  
8
6
2
8
0
  
3
4
8
2
5
  
3
4
2
1
1
  
7
0
6
7
9
  
8
2
1
4
8
  
0
8
6
5
1
  
3
2
8
2
3
  
0
6
6
4
7
0
9
3
8
4
  
4
6
0
9
5
  
5
0
5
8
2
  
2
3
1
7
2
  
5
3
5
9
4
  
0
8
1
2
8
  
4
8
1
1
1
  
7
4
5
0
2
  
8
4
1
0
2
  
7
0
1
9
3
  
8
5
2
1
1
  
0
5
5
5
9
6
4
4
6
2
  
2
9
4
8
9
  
5
4
9
3
0
  
3
8
1
9
6
  
4
4
2
8
8
  
1
0
9
7
5
  
6
6
5
9
3
  
3
4
4
6
1
  
2
8
4
7
5
  
6
4
8
2
3
  
3
7
8
6
7
  
8
3
1
6
5
2
7
1
2
0
  
1
9
0
9
1
  
4
5
6
4
8
  
5
6
6
9
2
  
3
4
6
0
3
  
4
8
6
1
0
  
4
5
4
3
2
  
6
6
4
8
2
  
1
3
3
9
3
  
6
0
7
2
6
  
0
2
4
9
1
  
4
1
2
7
3
7
2
4
5
8
  
7
0
0
6
6
  
0
6
3
1
5
  
5
8
8
1
7
  
4
8
8
1
5
  
2
0
9
2
0
  
9
6
2
8
2
  
9
2
5
4
0
  
9
1
7
1
5
  
3
6
4
3
6
  
7
8
9
2
5
  
9
0
3
6
0
0
1
1
3
3
  
0
5
3
0
5
  
4
8
8
2
0
  
4
6
6
5
2
  
1
3
8
4
1
  
4
6
9
5
1
  
9
4
1
5
1
  
1
6
0
9
4
  
3
3
0
5
7
  
2
7
0
3
6
  
5
7
5
9
5
  
9
1
9
5
3
0
9
2
1
8
  
6
1
1
7
3
  
8
1
9
3
2
  
6
1
1
7
9
  
3
1
0
5
1
  
1
8
5
4
8
  
0
7
4
4
6
  
2
3
7
9
9
  
6
2
7
4
9
  
5
6
7
3
5
  
1
8
8
5
7
  
5
2
7
2
4
8
9
1
2
2
  
7
9
3
8
1
  
8
3
0
1
1
  
9
4
9
1
2
  
9
8
3
3
6
  
7
3
3
6
2
  
4
4
0
6
5
  
6
6
4
3
0
  
8
6
0
2
1
  
3
9
4
9
4
  
6
3
9
5
2
  
2
4
7
3
7
1
9
0
7
0
  
2
1
7
9
8
  
6
0
9
4
3
  
7
0
2
7
7
  
0
5
3
9
2
  
1
7
1
7
6
  
2
9
3
1
7
  
6
7
5
2
3
  
8
4
6
7
4
  
8
1
8
4
6
  
7
6
6
9
4
  
0
5
1
3
2
0
0
0
5
6
  
8
1
2
7
1
  
4
5
2
6
3
  
5
6
0
8
2
  
7
7
8
5
7
  
7
1
3
4
2
  
7
5
7
7
8
  
9
6
0
9
1
  
7
3
6
3
7
  
1
7
8
7
2
  
1
4
6
8
4
  
4
0
9
0
1
2
2
4
9
5
  
3
4
3
0
1
  
4
6
5
4
9
  
5
8
5
3
7
  
1
0
5
0
7
  
9
2
2
7
9
  
6
8
9
2
5
  
8
9
2
3
5
  
4
2
0
1
9
  
9
6
  &c.
  April 14, 2011.


The “π Room” Corrected

Unfortunately, I have been unable to find any pictures of the original 1937 “π Room”. I would have really liked to have seen a before and after. Sadly, I can only give you my picture of the after:

8 6 0 2 1 3 9 4 … Yep, they fixed it.


One More Thing

There is a bonus for the retro nerd at the Palais de la Découverte: 8-bit restrooms:

Au Revoir.


Print References

  1. Arndt, Jörg, and Christoph Haenel. [Pi] – unleased . 2. ed. Berlin: Springer, 2001. Print.
  2. Berggren, Lennart, Jonathan M. Borwein, and Peter B. Borwein. Pi, a source book . 3rd ed. New York: Springer, 2004. Print.
  3. Beckmann, Petr. A history of [pi] (pi) . 4th ed. New York: Barnes & Noble, 19931971. Print.

Credits

  1. Pi Day Deathmatch Poster. Dhemerae Ford (dhemerae@gmail.com).
  2. First Pi Room Picture: http://www.palais-decouverte.fr/index.php?id=824
  3. William Shanks Picture: http://shankfamily.us/images/WilliamShank1821e.jpg
  4. Mechanical Desk Calculator Picture: http://upload.wikimedia.org/wikipedia/commons/e/ee/Comptometer_Model_WM.jpg

BBS: Get your retro on!

Note: certain names have been changed to protect the guilty.


1984

Beep, beep.

I looked out the window. It was Cookie Monster in his cherry red Isuzu Impulse (girl car :-). I grabbed my jacket off the kitchen table, flipped off the lights, and locked up behind me–it was going to be a long night.

We headed west, under the overpass, across the tracks, and through a maze of dimly lit streets to Scott’s house.

Scott, had a modem. Almost all my friends had some type of computer, but a modem and a phone line was elite (even if it was your dad’s modem).

We knocked. Scott answered, and led us to his dad’s den. Door closed, he produced a dot matrix printout with six integers; one per line. While his parents were at work and we were in high school preparing for college and an honest living, the apathetic Apple IIe quietly searched, for numbers. To the untrained eye they were just numbers, but for young pirates to be, they were free long distance.

Cookie knew things, and had a knack for finding things. From his jacket pocket Cookie produced a scrap of paper with a hand written number and a floppy disk. He took the con, inserted the floppy, and powered up the dormant IIe.

The green CRT glow, the stutter of the disk ][, all that was missing was the smell of ozone. Cookie’s slender fingers danced with the agility of an medieval organist; a console jockey with no equal, and in no time…

BUSY. Redial. BUSY. Redial. BUSY. Redial. BUSY. Redial. … Ring! The screech of a modem!

Aloha!

We were in! An ASCII Express warez hole. To call it a BBS would be a stretch since there were no bulletins. This Hawaiian-based AE had one purpose: the distribution of warez. And we found what we were looking for: Pitfall II.

Download started. ETA: 45 minutes.

Convenient stores weren’t conveniently located in the ’80s suburbs. But we had time to kill. It took us nearly 45 minutes to navigate east to 7-11 where we loaded up on sugar and caffeine. Big Gulps in hand, we entered the den, and powered on the CRT.

Download complete.

We had it. But I never booted it up, I didn’t care. This was more fun than any Apple II game could ever be. I was hooked. I had to get a modem. I had to get online. Did people even say that in ’84?


Late ’80s

I’m 21, in school, have an apartment, a girlfriend, and a full time job writing ERP/MRP code for a local manufacturing shop. I also have my own BBS, a WWIVnet node, and I agreed to foot the long distance bill (yes, I paid for it myself) to Michigan to bring a feed into my city for the other WWIVnet boards. It was fun while it lasted (about a year). However I actually spent more time not dialing into other BBSes, but into my local university and BBSes that specialized in gateways to The Internet.

Usenet had no equal. I remember when I got my employer its own UUCP feed. I rushed with excitement to the city county building to get my longitude and latitude so that I could complete the registration of my site. The BBS scene had become passé.

But there was something missing, and still missing today: a local, personal face-to-face community. BBS parties and BBQs were awesome, but the best was BBS vs. BBS volleyball. And my board kicked ass every time.


I’m not dead yet… I feel happy! Really, I’d like to go for a walk

Recently I completed watching the circa 2005, three-disc DVD set, BBS The Documentary, and I was surprised that some still carry the torch–flame on! :-) The BBS is not dead–yet.

This documentary will appeal to my generation, my culture, my nerddom, more than any other. The interviews provide firsthand anecdotal experiences and knowledge and they all convey dial-up nerddom very well from its start to its decline.

Google for BBS phone numbers and eventually you’ll find one, perhaps one that’s close to home. And BBS F2F communities still exist; some have grown into ISP communities.


Ok, I’m ready, lets do this BBS thing

You are going to need a few things:

  1. A (locally preferred) BBS phone number
  2. A modem (and perhaps a serial port)
  3. An analog phone line
  4. Terminal software

Most of us 40ish retro geeks, including myself, have moved on. I don’t have a modem or a local BBS number. However I do have an analog phone line because VOIP sucks–a rant for another time. And like billions others I also have a mobile phone that drops calls–I am keeping my analog phone line.

The good news is that you do not need any of the aforementioned to get your retro geek on. Many BBSes have converted from dial-up to telnet. And Age of Reason is one such board.

Age of Reason is a telnet accessible BBS that’s running on an Enhanced Apple IIe, using GBBS Pro as the host software. AoR also features the adventure game Land of Spur, as it was when last run on the Tacoma, WA BBS Dura Europos in the late 80’s. — Gene Buckle


Accessing a 25-year-old BBS with today’s technology

What would a 2400 BPS BBS look like on an Apple II and Apple IIe?

With a few fonts and setup you can come close to the ’80s experience without the actual ’80s tech. I am going illustrate this on my Mac, but something similar should work for Windoze and Linux.

First, you are going to need some fonts. Download PrintChar21.ttf and PRNumber3.ttf, open them up and install them–just double click and install from Font Book.

Tip: If you want to simulate other 8-bit and 16-bit systems then checkout 8-bit system fonts and 16-bit system fonts.

Next, launch Terminal, then navigate to Terminal/Preferences…, Settings, then + to add a setting. I’ve taking a few screen shots of my Apple II (40 characters/line) settings and posted below. You may want to create an Apple IIe (80 characters/line) setting as well.

Print Char 21 is an Apple II-esque 40 character/line font. However a keen observer will notice that it produces lowercase letters. A real Apple II was SHOUTING AT YOU ALL THE TIME or worse SHOUTING AT YOU.

The animation at the beginning of this post uses this font.

I opted for no scroll back, but it is not required.

After your Apple II and Apple IIe setups ares complete you will need to restart Terminal before your new settings will appear in the Shell/New Windows menu.

If you are an X11 user like myself, then it’s easier, just type:

xterm -title "Apple II Terminal" -xrm "XTerm*faceName: Print Char 21" 
-xrm "XTerm*faceSize: 9" -fg green -bg black -geometry 40x24 &

or

xterm -title "Apple IIe Terminal" -xrm "XTerm*faceName: PR Number 3" 
-xrm "XTerm*faceSize: 12" -fg green -bg black -geometry 80x24 &

for 40 or 80 columns respectively. You could get fancy and add -e telnet destination and then add that to your X11 menu so that you can get your BBS on with minimal effort.


BBS: Get your retro on!

Open up a 40 or 80 column retro terminal and type: telnet aor.retroarchive.org, and you should see something like this:

And like all single line BBSes, you will get BUSY signals. Just keep trying. To exit telnet type ctrl-[, then ‘q’, then ‘return’.


BBS 2011

The BBS glory days may be over, but their legacy lives on in the form of forums, blogs (where you can still be your own sysop!), and chat rooms. The Internet didn’t create these things, they already existed.

datajerk, #19, Age of Reason (75.145.20.98)

Pi Day Rematch: Apple II vs. HP-41C

Yes, the thought of two vintage computing devices battling as digital gladiators in a cage match to the death under the watchful eye of our supercomputer overlord, the HAL 9000, is amusing at best. But this is Pi Day, and what better way to celebrate than with silicon blood. Who knows, perhaps this did happen a long time ago in The Grid.

Let the games begin!


Mano-a-mano

In a battle before time itself (I’m referring to the lack of a clock in the Apple II and 41C), this David and Goliath-esque story started to unfold as I was cleaning my office not too long ago. (Cleaning my office is really an excuse to get my retro on.)

I’ve always been a fan (and user) of the Apple II, RPN calculators, and of course, Pi. It’s no wonder that I have stacks of machines, journals, books, magazines, printouts, etc… related to all three topics.

As I was filtering through stacks of papers to determine the value of each scrap of paper, I stumbled across a 1980 article by Ron Knapp, PI TO 1,110 PLACES[1]. I had forgotten about this article. I remember printing it out along with a 1981 followup article by the same author, FASTEST PI TO 1,000 PLACES[2]. At the time I was interested in the relative 1000-digit Pi performance of all ’80s calculators, and gravitated towards the newer, faster code, and had forgotten to read the first article.

So, I read it. Hmmm…

The run-time for this program is relatively short: 30 places in 2 min., 90 places in 9 min., 200 places in 34 min., 1000 places in 11 ½ hr., and 1160 places in 15 ¼ hr. When you consider that an article in “The Best of Micro” some time ago stated that an Apple II had been programmed to calculate “pi” to 1000 places in 40 hours–the run-time for the 41-C, a shirt-pocked calculator, seems very fast indeed[2].

Wow! Really? Can this be true? I was determined to get to the bottom of this. I’ll be “cleaning” my office for a bit longer.


Confirming the Results

It didn’t take too long to track down the source of Ron Knapp’s statement; Robert J. Bishop’s article, APPLE PI[3]:

Since the program is written entirely in BASIC it is understandably slow[3].

Ah ha! BASIC! That explains everything. Right?

I knew from my Apple II days in high school that machine language was faster than BASIC, as was Pascal. But is a circa 1977 computer running BASIC really 4-5 times slower than a circa 1979 pocket calculator? I wanted to see the results myself, and find out why?.

I do not have a clock card in my Apple //c, nor did I have the time to fashion one out of a serial cable and a GPS unit (I’ve done this before), and I am not going to sit around with a stopwatch; I opted to use Virtual ][ on my Mac. IMHO, Virtual ][ is the most authentic Apple II series emulator available. And thankfully Virtual ][ emulates a clock card.

For the HP-41C I’ll be using my HP-41CX. The 41C and 41CX run at the same speed (the X in CX stands for eXpanded memory). Fortunately the CX (unlike the C) has a clock built-in.

I modified both programs to output to a printer and to leverage the clocks so that I could get an accurate reading of the performance. The output with source for the Apple II and HP-41C can be obtained here and here.

The results:


APPLE II
START: MON MAR 7 10:40:40 PM THE VALUE OF PI TO 1001 DECIMAL PLACES: 3.14159265358979323846264338327950288419  7169399375105820974944592307816406286208 9986280348253421170679821480865132823066 4709384460955058223172535940812848111745 0284102701938521105559644622948954930381 9644288109756659334461284756482337867831 6527120190914564856692346034861045432664 8213393607260249141273724587006606315588 1748815209209628292540917153643678925903 6001133053054882046652138414695194151160 9433057270365759591953092186117381932611 7931051185480744623799627495673518857527 2489122793818301194912983367336244065664 3086021394946395224737190702179860943702 7705392171762931767523846748184676694051 3200056812714526356082778577134275778960 9173637178721468440901224953430146549585 3710507922796892589235420199561121290219 6086403441815981362977477130996051870721 1349999998372978049951059731732816096318 5950244594553469083026425223082533446850 3526193118817101000313783875288658753320 8381420617177669147303598253490428755468 7311595628638823537875937519577818577805 3217122680661300192787661119590921642019 898 END: WED MAR 9 4:27:30 PM


41 hours, 46 minutes, and 50 seconds. Confirmed, BASIC is indeed slow.

NOTE: I had to compute 1001 digits of Pi to get 1000 accurate digits.


HP-41C
3. 14159 26535 89793 23846 98336 73362 44065 66430 26433 83279 50288 41971 86021 39494 63952 24737 69399 37510 58209 74944 19070 21798 60943 70277 59230 78164 06286 20899 05392 17176 29317 67523 86280 34825 34211 70679 84674 81846 76694 05132 82148 08651 32823 06647 00056 81271 45263 56082 09384 46095 50582 23172 77857 71342 75778 96091 53594 08128 48111 74502 73637 17872 14684 40901 84102 70193 85211 05559 22495 34301 46549 58537 64462 29489 54930 38196 10507 92279 68925 89235 44288 10975 66593 34461 42019 95611 21290 21960 28475 64823 37867 83165 86403 44181 59813 62977 27120 19091 45648 56692 47713 09960 51870 72113 34603 48610 45432 66482 49999 99837 29780 49951 13393 60726 02491 41273 05973 17328 16096 31859 72458 70066 06315 58817 50244 59455 34690 83026 48815 20920 96282 92540 42522 30825 33446 85035 91715 36436 78925 90360 26193 11881 71010 00313 01133 05305 48820 46652 78387 52886 58753 32083 13841 46951 94151 16094 81420 61717 76691 47303 33057 27036 57595 91953 59825 34904 28755 46873 09218 61173 81932 61179 11595 62863 88235 37875 31051 18548 07446 23799 93751 95778 18577 80532 62749 56735 18857 52724 17122 68066 13001 92787 89122 79381 83011 94912 66111 95909 21642 01989 TIME: 30116.94 SEC

8 hours, 21 minutes, and 56.94 seconds.

NOTE: I did not use Ron’s original 1980 program (where the first stone was thrown), but opted to use the optimized 1981 version instead. The Apple II would have taking a a beating in either case.


And the Winner Is…

Ron was right to boast. I have been unable to find any public Apple II results dated before 1982 to take back the title, Microcomputer/Calculator Class: Fastest Pi to 1000 digits.

To add insult to injury, in 1949, the hulking 30-ton giant ENIAC enslaved a team of four humans and computed Pi to 2037 digits in 70 wall clock hours over a three day holiday weekend. ENIAC throughout the computation also reversed the calculations to check for errors. The humans were leveraged as bio-mechanical RAM since ENIAC could only hold 200 decimal numbers in memory. Team ENIAC worked in shifts collecting, organizing, and feeding IBM punch cards. All compute, check, and human interaction took 70 hours[4, pp. 277-281, 731].

I’ll demonstrate later that 2037 digits in 70 hours is computationally the same as 1000 digits in ~17 hours. The Apple II in 1978 cannot best a 30-something-year-old cyborg?

Why? Did all three use the same algorithm? In the same way? Are there technological factors or limitations? Can the Apple II best the HP-41C and ENIAC?

To answer all those questions we need to better understand how to compute Pi to 1000 digits.


Computing Pi with arctan

There are many different methods to compute the digits of Pi by hand or with a computer. The arctan formulas since the second half of the 17th century have been the most popular for computing a relatively small (less than a million) number of Pi digits[5, pp. 65, 205]. So it is no surprise that Ron, Robert, and Team ENIAC used arctan as well. Specifically, Machin’s formula.


Machin’s arctan Formula

John Machin discovered and used this formula in 1706 to compute the first 100 digits of Pi[5, p. 72]. It has been the most widely used formula by Pi digit hunters until the early ’80’s when the state-of-the-art shifted to Gauss AGM and other exotic formulas[5, pp. 206]. However, Machin is still very popular because it’s easy to implement, fast, and has a low memory footprint. All three are important factors when using retro tech.

Many mathematical functions can be numerically computed with a series which is relatively easy to calculate. The arctan function possesses just such a series which was discovered by James Gregory in 1671[5, p. 67].

Combine the two and voilà! We have something that we can compute efficiently that will converge quickly.

The first series converges with log10(52) = 1.3979 decimal places per series term and the second converges with log10(2392) = 4.7568 decimal places per series term[5, p. 72].

The total number of terms required for each series for 1000 decimal Pi digits can be calculated with ⎡1000 / log10(52)⎤ = 716 and ⎡1000 / log10(2392)⎤ = 211 respectively. 927 terms total.

NOTE: The ⎡ ⎤ brackets is defined as round up to the next integer.
NOTE: The number of terms does not change if the numeric base for computation changes. IOW, it is constant. More on this later.
TIP: http://www.codecogs.com/latex/eqneditor.php was used to create all equations used in this article.


Arbitrary-Precision Arithmetic

Go ahead, load up that last equation into Apple’s Integer BASIC and see what you get for Pi. 3? Don’t worry, you are are in good company; the biblical value of Pi = 3[6, p. 174] :-). Apple’s Floating Point BASIC doesn’t fair well either; at best, it would have computed 10 or 11 digits.

Clearly we are going to have to create some arbitrary-precision (AP) arithmetic code. The good news is that all we need is add, subtract, multiply, and divide. The simplest method for all four is to go old skool. That’s right, the same way you learned how to do this in elementary school is still applicable today. Simply represent each digit in an array and perform the operations the same way you would with pen and paper. Get out a pen and paper and try it!

It’s easier than it sounds. Although the adds and subtracts will be AP +/- AP, the multiply and divides will be AP ∗/÷ SP (single-precision). Now that’s even easier. AP:AP mult/div is harder and the subject of many papers and AP libraries.

For each operation, as your code loops from the least significant digit to the most significant digit (except divide, go the other way), the four arithmetic routines will perform two basic operations per iteration; add, sub, mult, div, and then a carry. I understand that this is an oversimplification, and if you want a clearer understanding, then I suggest you look at some code. However, the point I am trying to make is that if the number of digits doubles (e.g. computing Pi to 2000 digits), then the number of operations for AP:AP add/sub and SP:AP div/mult also doubles. It also works the other way. If I can half the number of digits, then I half my number of operations, and therefore half the time for basic arithmetic operations.


Covering Your Bases

The amount of effort it takes an 8-bit computer to add two base 10 numbers is the same effort as adding two base 256 (28) numbers. Therefore, if you can pack your 1000 digit base 10 arrays into fewer base 256 digits, then you can also reduce the number of operations and get a proportional speed up in time. Your new array size will = ⎡number of decimal digits / log10base⎤.

A few examples based on 1000 decimal digits of Pi:


Base Calculation
Array Size
10 ⎡1000 / log1010⎤
1000
28 (256) ⎡1000 / log10(28)⎤
416
216 (65536) ⎡1000 / log10(216)⎤
208
100,000 ⎡1000 / log10100,000⎤
200
10,000,000,000 ⎡1000 / log1010,000,000,000⎤
100


The speed-up should be proportional to the array size assuming that a larger base will not have a disproportional overhead. E.g. The 6502, an 8-bit processor, will take more that twice the instructions to add two 16-bit numbers compared to two 8-bit numbers. However using 16-bit numbers on an 8-bit system is still more efficient that using base 10.

There is a caveat when not using base 10, 100, 1000, etc…; the end result must be converted back to base 10 if you are truly computing 1000 decimal digits of Pi. This adds a bit of overhead to the end of the computation, however it is only a fraction (e.g. 1/6th for base 216 to base 10) of the total computation.

I am assuming that ENIAC can leverage it’s double precision support and use base 1010 (10,000,000,000) and therefore only require an array of 100 base 1010 digits for 1000 decimal digits of Pi. Ron’s HP-41C program uses base 105 (100,000) requiring only 200 base 105 digit arrays. Robert’s Apple Pi uses base 10 requiring 1000 digit arrays.

This begins to shed some light on why Apple Pi performs so poorly. If Apple Pi could use base 100,000 or base 10,000,000,000 then its time would be reduced by a factor of 5 and 10 respectively. However, Integer BASIC and the 6502 are not designed to support this. ENIAC and the HP-41C are both designed and optimized for base 1010. As they should be; they are calculators.


Computation Complexity

Earlier I said, I’ll demonstrate later that 2037 digits in 70 hours is computationally the same as 1000 digits in ~17 hours.

That statement makes two assumptions. The first is that Team ENIAC used the Gregory expansion of Machin’s arctan formula, and the second is that their AP arithmetic scaled linearly. If that is the case, as is the case with Ron’s and Robert’s programs, and since the number of terms and the number of digits is a fixed ratio based on the desired number of digits; then if the number of desired digits double, then so does the number of terms to be computed and the size of the array to hold the digits, and therefore the amount of computation is double * double. IOW, the computational complexity is O(n2).

Simply put, if I double the digits the time increases by four. Therefore, the estimated time for ENIAC to compute 1000 digits is: 70 hr * (1000/2037)2 = 16.87 hr.


Back to Apple Pi

The number of terms to be computed will be constant regardless of the program’s numeric base. That leaves optimizing the arithmetic routines. Assuming that Robert’s BASIC program could be rewritten in base 256 (and it cannot without a lot of effort; effort that would not yield sufficient benefit), then the best speed up would be 41.78 hr * (416/1000) = 17.38 hr. Still deficient.

When writing fundamental AP routines it helps to have unsigned double precision integer support; if not, make your base the square-root of (the largest positive integer + 1), e.g. the largest HP-41C positive integer is 9,999,999,999, making the optimal base 100,000 since the HP-41C does not have double precision integer support. Because of the wacky integer support in Integer BASIC, the largest base would be 181 and not offer up enough performance.

Bottom line, Integer BASIC is most likely our culprit. In 1978 Robert had very few options. BASIC and assembly language were the dominate languages, and if I were in Robert’s shoes I would have picked BASIC too (Robert wrote the program in less than 40 hours)[3]. However, there was another option; Apple FORTH from Programma Consultants[7, p. 26]. And by 1980, when Ron first mentioned the Apple II’s poor performance, there were many more Apple languages to choose from, such as FORTRAN and Pascal.


Pi Day Rematch: Apple II vs. HP-41C

FORTH seems promising for a few reasons; one, it was available in 1978; two, it’s most like RPN, making a comparison to the 41C a bit more apples to apples; and three, with FORTH it will be easy to use a larger base (I used base 216) thus reducing the size of the arrays. Lastly, FORTH is fast.

Unfortunately I was unable to locate a copy of Apple FORTH from Programma Consultants, so I opted to use Mad Apple Forth (MAF) as a substitute. My program with timings can be located here. I didn’t have time to figure out how to access the clock card from MAF, so I used the Virtual ][ record function and then noted the time stamps on the output.

Start:       22:44:47
Print:       23:05:24
End:         23:09:43
Total Time:  00:24:56

The HP-41C and ENIAC were both schooled by the Apple II with FORTH.


HP-41C cries foul!

If you could only use what came in the box with your Apple II or HP-41C, then what would be the results? Fortunately the Apple II mini-assembler is in the box.

In 1982 Glen Bredon wrote an APPLE PI program in assembly that blows the battery door off the 41C with a time of 194 seconds. Game over! The Apple II wins again!

My 1496 sec. FORTH version doesn’t hold an LED to assembly.

If you are looking for Glen’s program, it is packaged with the Merlin Assembler.


HP-41C Machine Language

To be thorough I asked a friend of mine to compute Pi on the 41C with a 100% machine language (ML) program. He came back with 5 hours, 9 minutes. No question, the Apple II is king.


Victory Lap

In my quest to best the 41C, I tried C as well. The C language hit the seen in the mid ’80s making it easier to write and port over existing Pi programs.

Why not rub it in a bit?


C Version C Year Base
Time (s)
Aztec K&R C 3.2b 1986 216
2180
Aztec K&R C 3.2b 1986 10
6746
cc65 ANSI C 2.12 2010 216
1764
cc65 ANSI C 2.13 2010 216
1514
cc65 ANSI C 2.13 2010 10
4241


Summary

BASIC sucks. The HP-41C is truly awesome, and for a time bested the Apple II in the Fastest to Compute 1000 digits of Pi benchmark. But, in the end, the true potential of the Apple II smoked the 41C.

BTW, you’ll never need more than 50 digits of Pi[5, p. 153].


On the other hand…

To continue reading this fascinating tale click here.


Some Great Pi Books

If you like Pi, especially computing Pi, then I recommend the following three books[4, 5, 6]:

Print References

  1. Knapp, Ron. PI TO 1,110 PLACES. PPC Calculator Journal Jun. 1980: 9-10.
  2. Knapp, Ron. FASTEST PI TO 1,000 PLACES. PPC Calculator Journal Aug.-Dec. 1981: 68-69
  3. Bishop, Robert J. APPLE PI. MICRO THE 6502 JOURNAL Aug.-Sep. 1978: 15-16.
  4. Berggren, Lennart, Jonathan M. Borwein, and Peter B. Borwein. Pi, a source book . 3rd ed. New York: Springer, 2004. Print.
  5. Arndt, Jörg, and Christoph Haenel. [Pi] – unleased . 2. ed. Berlin: Springer, 2001. Print.
  6. Beckmann, Petr. A history of [pi] (pi) . 4th ed. New York: Barnes & Noble, 19931971. Print.
  7. Apple Computer Inc. the best of the user group newsletters for 1978. Contact ’78 Dec. 1978: 26.

Credits

  1. Pi Day Deathmatch Poster. Dhemerae Ford (dhemerae@gmail.com).
  2. ENIAC photo (linked). Wikipedia.

Finally, Apple II and IIgs warez on your iPad

Updated: November 26 2012 (does not work with iOS6!)

See updates at the end.


Running 1985 Code on a 2010 Device

I had an awesome childhood; a big part of that was computers, specifically my Apple II+.  Ah, the memories…

Sadly I do not have my original Apple II+ (clone). Nor do I recall the name of the manufacture. C’est la vie.

Well now I can relive all my “memories” on my iPhone and iPad.  But it’s going to take a bit of work, and I am going to need some stuff:

  1. My “memories”, i.e. my original Apple II+ floppies from high school.
  2. An Apple II computer with floppy drive and a serial port.
  3. A null-modem serial cable to connect my Apple II to my Mac.
  4. ADTpro Apple II to Mac transfer software.
  5. ActiveGS – Best Of FTA iOS app from the App Store.  This is an Apple IIgs emulator capable of running most Apple II, II+, IIe, and IIgs warez.
  6. A text editor to edit the list of images in ActiveGS.
  7. Something to create ActiveGS icons. (optional)
  8. iExplorer, to get my stuff into ActiveGS.

Memories

After a bit of digging I found my very first floppy disk.  I should probably have it framed, like others do with their first dollar.  Hopefully it still works.


Hardware

This is the hard (pun intended) part.  You are going to need a real Apple II or know someone that has one.  Your best bet is an Apple //c.  They are self-contained (floppy drive and serial port) and are easy to find.  As I write this there are many on eBay and at least one listed in the local classifieds.  To connect your Apple //c to your computer (MacBook Air in my case) you are going to need a serial cable and a USB to serial adapter.  I opted to purchased my cable (call me lazy) from http://retrofloppy.com/products.html#DIN5DE9.  I had an existing USB to serial adapter from Keyspan that works just fine.


Liberating Your Warez

ADTpro (http://adtpro.sourceforge.net/) is a very well maintained Apple II floppy disk to floppy image (and v.v.) utility and is very easy to use.  Just follow the instructions from their site and in a few minutes you will have liberated your first floppy disk.  (It is very cool to see ADTpro boot your Apple //c from the serial port.)


ActiveGS

ActiveGS is an Apple IIgs emulator and is available for most platforms as a standalone app and as a browser plug-in.  Recently (Feb 24th) an iOS ActiveGS app was published and is available via the App Store.  However, I do not think it will last very long…

iDOS (based on DOSBox) is very similar to ActiveGS, but for DOS programs.  After a rocky start iDOS finally made it to the App Store just to be removed because users could add their own binary content to iDOS.  That was the point of iDOS to begin with.  To get back online iDOS had to come with preloaded apps and remove the ability to add content via iTunes File Sharing.  But it didn’t take long for users to figure out that by using iExplorer content could be added.  This same “trick” needs to utilized to add content to ActiveGS.  In time, this will be the undoing of ActiveGS.


Inserting content to ActiveGS

Download, install, and launch iExplorer (NOTE: If you have problems with iExplorer, then use DiskAid).   Connect up your iOS device and then find the Best of FTA/Documents directory. This is where you will place all your disk images as well as any thumbnails and/or screen shots. Note: Do not place your images, thumbnails, or screen shots in the Best of FTA/Best of FTA.app directory, unless you want them read-only and lost on iPad/iPhone restore.


To add a disk image, just drag-and-drop an Apple II or IIgs disk image into that directory along with any thumbnails and screen shots (NOTE: iExplorer will only drop a single file, IOW, do not multi-select; drag one at a time). Next, you will need to define your image to ActiveGS. This needs to be done in the Best of FTA/Best of FTA.app directory.


Copy the list.activesxml file to your computer, then open it up with your favorite text editor and add a section for your image, e.g.:


<config version="2" id="my0a">
        <name>High School Classics</name>
        <year>1984</year>
        <publisher>Me</publisher>
        <desc><![CDATA[
        Midlife Crisis Classics!
        ]]></desc>
        <pic type="thumbnail" width="64" height="40">../Documents/dos33-0.png</pic>
        <format>APPLE2</format>
        <image slot="6" disk="1">../Documents/my0a.dsk</image>
        <pic type="screenshot" width="320" height="240">../Documents/dos33-1.png</pic>
        <bootslot>6</bootslot>
</config>

It should be obvious where to place your new config section.  Review the file for other examples.  After you have made your changes drag lists.activesxml back to your iOS device.  You should also create a 64×40 pixel image for the icon and drag that there too. You’re done!

You will need to kill (double click the home button, find ActiveGS, and press the minus (-) sign) and restart ActiveGS on your iOS device for the changes to take effect. Hopefully your new start-up screen will look something like this:


ActiveGS iPad Usability Tips

  • Swipe down to reveal the ActiveGS menu bar. The menu bar has a button to return back to the main menu on the left side, and a button on the right for various emulator options.
  • Swipe up to reveal the keyboard. Swipe up a 2nd time to get a 2 button gamepad.
  • Pinch to zoom the screen, however you cannot place the screen.
  • You can use a Bluetooth keyboard. However none of the modifier keys (including control) are mapped. This is a limitation of the Apple iOS SDK. To use the BT keyboard ActiveGS must be in keyboard mode (swipe up until you have just a row of modifier keys on the bottom).

    iPad 2 + BT Keyboard + ActiveGS = Apple IIcgs

  • The virtual joystick is difficult to use, practice, practice, practice…

Enjoy!


Credits

  1. Apple II+ Picture. oldcomputers.net

Update: March 2 2011, Multi-disk sets

I actually had two high school diskettes that I labeled I and II (I is in the photo above). Yielding a small pair of scissors, I cut a notch in both diskettes so that I could use the flip side (this was common practice in the ’80s to double your capacity). 27 years later, I’ve now imaged all 4 sides. Do I really need 4 different menu items? No. Just add multiple duplicate entries for each disk in your config, e.g.:

        <image slot="6" disk="1">../Documents/my0a.dsk</image>
        <image slot="6" disk="1">../Documents/my0b.dsk</image>
        <image slot="6" disk="1">../Documents/my1a.dsk</image>
        <image slot="6" disk="1">../Documents/my1b.dsk</image>

Then boot up. The first disk will boot. To change disks on the fly, swipe down to get the menu. In the upper right corner you’ll notice a floppy icon rotating on its Y-axis. Tap it and the next disk will be inserted. Keep taping to cycle through all your disks. Each tap action will summon a pop-up message with the name of the disk. Easy.


Update: March 15 2011, iOS 4.3 and iPad 2

No worries, iOS 4.3 on iPad I and 2 tested.


Update: April 6 2011, ActiveGS 1.22

ActiveGS 1.22 tested.


Update: April 11 2011, More config file tips and 1.22 corrections

For 144K Apple II disk images use slot 6 with an Apple2 format, e.g.:

    <format>APPLE2</format>
    <image slot="6" disk="1">../Documents/appleii.dsk</image>
    <bootslot>6</bootslot>

For 800K Apple IIgs disk images use slot 5 with a 2GS format, e.g.:

    <format>2GS</format>
    <image slot="5" disk="1">../Documents/SYSTEM6.2MG</image>
    <bootslot>5</bootslot>

For Apple IIgs HD images use slot 7 with a 2GS format, e.g.:

    <format>2GS</format>
    <image slot="7" disk="1">../Documents/c.2mg</image>
    <bootslot>7</bootslot>

Custom color config example:

    <bramparam>background:black;border:dark-gray;font:green</bramparam>

Thanks to Rich and John (see comments) for the tips.


Update: August 22 2011, More RAM

If you need more RAM (in MB), then add this to your config (e.g. 8 for 8 MB):

    <emulatorParam>_memorySize:8</emulatorParam>

 

Update: September 21 2011, DiskAid

Many Windows users are having problems with iExplorer and have reported that DiskAid is a good alternative.


Update: October 15 2011, iOS5

Mike has confirmed that iOS 5 is safe for ActiveGS and iExplorer. Apple II Forever!


Update: October 16 2011, iExplorer

Changed iPhone Explorer to iExplorer in document.


Update: November 26 2012, iOS6

This hack does not work with iOS6. The app directory is locked down. Jailbreaking is your only hope.