ejolson
Posts: 3031
Joined: Tue Mar 18, 2014 11:47 am

Re: A Second Age of Personal Computing

Sun May 12, 2019 5:43 pm

k-pi wrote:
Sun May 12, 2019 2:21 pm
Hmm...personal computing...now there's a thing..... I did once own a personal computer - it had 2 floppy drives, a 9" monochrome monitor, & a keyboard - it wasn't connected in any way to anything else.
Now that's personal! :lol:
I also had one! The characters on the monitor glowed magically with green phosphor. It even said "Personal Computer" right on the front just below the letters IBM.
Heater wrote:
Sun May 12, 2019 1:27 pm
I quite like the idea of a Second Age of Personal Computing. As long as we don't have to go back to those big, heavy, ugly, noisy, horribly engineered, unreliable so called PC's inspired and derived from the horror that was the IBM PC.
If you open that sleek, fashionable, quiet and beautifully engineered i7-based computer you're currently typing on, does it have a 34-pin header to connect a floppy drive? The AMD system sitting on my desk at home includes one, though not connected.

As demonstrated by the Raspberry Pi, running from removable media may be one of the characteristic traits of personal computers that help keep them personal.
Last edited by ejolson on Sun May 12, 2019 7:30 pm, edited 3 times in total.

User avatar
rpdom
Posts: 14417
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: A Second Age of Personal Computing

Sun May 12, 2019 5:50 pm

ejolson wrote:
Sun May 12, 2019 5:43 pm
If you open that sleek, fashionable, quiet, beautifully engineered i7-based computer you're currently typing on, does it have a 34-pin header to connect a floppy drive?
Mine is only an i5 laptop, but I do have a USB floppy drive. However, booting from removable media usually means USB sticks with the capacity of over ten thousand floppy disks.

User avatar
bensimmo
Posts: 4062
Joined: Sun Dec 28, 2014 3:02 pm
Location: East Yorkshire

Re: A Second Age of Personal Computing

Sun May 12, 2019 5:53 pm

Mine has no floppy connector, about 4 years old now.
It has a gazillion usb connectors or headers that could be used, for your usb floppy drive

User avatar
Burngate
Posts: 5884
Joined: Thu Sep 29, 2011 4:34 pm
Location: Berkshire UK Tralfamadore
Contact: Website

Re: A Second Age of Personal Computing

Sun May 12, 2019 5:57 pm

Whether Turing's completeness has anything to do with personal computing, I'm not sure, but one thing I learnt some years ago is that specifying an "infinite tape with storage cells" is also lacking in meaning.
There are many infinities, the lowest being (probably) that of integers and similar, and that's the one he (probably) meant.
But there are many more. The only other one I've found is the one for real numbers, but there could be others between the two, and any of them could become useful.

But ... personal computing?
As a person, I could just want to do what everyone else does - social media, financial spreadsheets, storing my Rock collection ...
That's not what we mean here.

Surely, there's at least two things that could be involved.

One is "How did they do that?"
Which requires the realization that that could be quite difficult, and could need a teacher.

The other is "why can't I do this?"
Which involves working out what this is in minute detail, and probably involves working out why noone else has bothered.

ejolson
Posts: 3031
Joined: Tue Mar 18, 2014 11:47 am

Re: A Second Age of Personal Computing

Sun May 12, 2019 6:07 pm

bensimmo wrote:
Sun May 12, 2019 5:53 pm
Mine has no floppy connector, about 4 years old now.
It would appear my desktop is getting a bit dated. It doesn't even have UEFI secure-boot.

Speaking of bugs, it may be possible to identify the woman in the prologue of this thread with Grace Hopper

Image

who historically coined the word.
Last edited by ejolson on Sun May 12, 2019 10:54 pm, edited 1 time in total.

Heater
Posts: 12628
Joined: Tue Jul 17, 2012 3:02 pm

Re: A Second Age of Personal Computing

Sun May 12, 2019 6:19 pm

ejolson,
If you open that sleek, fashionable, quiet, beautifully engineered, i7-based computer you're currently typing on, does it have a 34-pin header to connect a floppy drive? The AMD system sitting on my desk at home includes one, though not connected.
Strangely enough I had to open it up this morning to fix a fan that had started to make noises like a concrete mixer overnight. Amusingly a label on the fan announces "Nexus - The quietest fans in the world"

This box does look quite sexy, all black with stylish vent grills and blue power LED. But one soon finds that is an illusion created by some cheap plastic clipped on the front and top. Under that it is much the same bent up sheet metal box as PC's have ever been. With a rats nest of cables inside.

There is no floppy here and I did not check but I guess it has the header. As for removable media I can boot from DVD, USB sticks or SD cards.

After using an MS Surface Pro for two years I was almost at the point of having a home free of the big ugly PC boxes for the first time since decades. But then the battery in the Surface exploded and I rescued this PC from the homeless old PC pound to use whilst MS replaced the Surface.

ejolson
Posts: 3031
Joined: Tue Mar 18, 2014 11:47 am

Re: A Second Age of Personal Computing

Sun May 12, 2019 6:46 pm

Burngate wrote:
Sun May 12, 2019 5:57 pm
But ... personal computing?
As a person, I could just want to do what everyone else does - social media, financial spreadsheets, storing my Rock collection ...
That's not what we mean here.
For me personal computing is having the freedom to compute anything I am personally interested in up to the limits of the hardware. The age of personal computing is when everyone has that freedom.

All I wanted to do was run QB64 on my Raspberry Pi and calculate Fibonacci numbers. Following these instructions it compiled quite easily. Unfortunately, the resulting binary wants to open an SDL graphics window and I am logged in through ssh. Since the expressiveness of QB64 is currently zero when running on my Zero, maybe it's not Turing complete either.
Last edited by ejolson on Sun May 12, 2019 6:55 pm, edited 3 times in total.

User avatar
ScriptBasic
Posts: 1231
Joined: Wed Apr 03, 2019 5:53 pm
Location: Anacortes, WA USA
Contact: Website Twitter

Re: A Second Age of Personal Computing

Sun May 12, 2019 6:48 pm

I owned an Osborne 'portable' (suitecase) computer when they came out. My second computer after the Heathkit PDP-11 using paper tape as storage.

hippy
Posts: 5335
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: A Second Age of Personal Computing

Sun May 12, 2019 7:47 pm

Well here's an aside just for fun, here as the old thread got closed, is a PICAXE-28X2 microcontroller calculating fibo(24) in 465ms 233ms.

Now I know that's quite slow, but it is comparable to better than Python 3.5 running the non-optimised recursive Fibo(24) on a Pi 3B which took 399ms.

But the really interesting part is that it is an 8-bit micro running at 64MHz, running a Basic-style tokenised language interpreter in firmware which only supports 16-bit variables, using ''bigint' implemented using 1KB of byte-only RAM array. There will be no surprise it uses brute force addition because recursion doesn't stand a chance with such limited amounts of RAM.

It appears to be calculating upto Fibo(200) correctly. I will have to check how high it can go before it hits its 1025 digit maximum, and see how long that takes. I might try optimising first as it was thrown together in an hour or so. Enjoy.

Code: Select all

#Picaxe 28X2
#Terminal 76800

#Macro Fibo(arg)
  n = arg
  SerTxd( "Fibo(", #n, ") = " )
  Gosub CalculateFibo
  Gosub PrintFibo
  SerTxd( CR, LF )
#EndMacro

Symbol reserveW0 = w0 ; b1:b0
Symbol w0.lsb    = b0 
Symbol w0.msb    = b1

Symbol reserveW1 = w1 ; b3:b2
Symbol w1.lsb    = b2
Symbol w1.msb    = b3

Symbol fiboN     = w2 ; b5:b4
Symbol n         = w3 ; b7:b6
Symbol carry     = w8
Symbol hadDigits = b9

Symbol RAM_BYTES    = 1024
Symbol BIGINT_BYTES = RAM_BYTES / 2
Symbol BIGINT_WORDS = BIGINT_BYTES / 2
Symbol RAM_TOP      = RAM_BYTES - 1
Symbol FIBO_TOP     = BIGINT_BYTES - 2
 
Main:
  SetFreq EM64
  Do
    Pause 16000
    High C.0
    Fibo(24)
    Low C.0
  Loop

CalculateFibo:
  Gosub ClearRam
  If n > 0 Then
    ptr = 0
    @ptr = 1
    ptr = ptr + BIGINT_BYTES
    @ptr = 1
    ptr = ptr - BIGINT_BYTES
    Do While n > 2
      Gosub AddLastToFibo
      n = n - 1
    Loop
  End If
  Return

ClearRam:
  For ptr = 0 To RAM_TOP
    @ptr = 0
  Next
  Return 

AddLastToFibo:
  carry = 0
  For ptr = 0 To FIBO_TOP Step 2
    w0.lsb = @ptrInc : w0.msb = @ptrDec : ptr = ptr + BIGINT_BYTES
    w1.lsb = @ptrInc : w1.msb = @ptrDec
    @ptrInc = w0.lsb : @ptrDec = w0.msb : ptr = ptr - BIGINT_BYTES
    w0 = w0 + w1 + carry
    If w0 = 0 Then
      Return
    End If
    carry = w0 /  10000
    w0 = w0 // 10000
    @ptrInc = w0.lsb : @ptrDec = w0.msb
  Next  
  Return

PrintFibo:
  ptr = FIBO_TOP + 1
  hadDigits = 0
  Do
    w0.msb = @ptrDec : w0.lsb = @ptrDec
    If w0 <> 0 Or hadDigits <> 0 Then
      If hadDigits = 0 Then
        SerTxd( #w0 )
      Else
        Select Case w0
          Case <   10 : SerTxd( "000", #w0 )
          Case <  100 : SerTxd( "00",  #w0 )
          Case < 1000 : SerTxd( "0",   #w0 )
          Else        : SerTxd(        #w0 )
        End Select
      End If
      hadDigits = 1
    End If
  Loop Until ptr >= FIBO_TOP
  If hadDigits = 0 Then
    SerTxd( "0" )
  End If
  Return

Heater
Posts: 12628
Joined: Tue Jul 17, 2012 3:02 pm

Re: A Second Age of Personal Computing

Sun May 12, 2019 8:15 pm

Outstanding!

What did I do? When will this madness stop?

hippy
Posts: 5335
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: A Second Age of Personal Computing

Sun May 12, 2019 8:22 pm

Heater wrote:
Sun May 12, 2019 8:15 pm
What did I do? When will this madness stop?
Hopefully never. Because, when it does, that's probably the time we will have lost Personal Computing.

Heater
Posts: 12628
Joined: Tue Jul 17, 2012 3:02 pm

Re: A Second Age of Personal Computing

Sun May 12, 2019 8:49 pm

Well, you can't get much more personal than a PICAXE.

Speaking of madness. Guess what I've been doing today?

Writing a Scala/SpinalHDL wrapper for an SDRAM controller, written in Verilog, with the hope of allowing my RISC V core in FPGA to make use of the 32MB SDRAM chip on a DE0-Nano FPGA board.

Quite a lot motivated by the thought of getting my RISC V core to run the C and/or C++ versions of fibo(4784969) challenge code.

I figure that if we are to have a Second Age of Personal Computing I'm going to start by designing my own personal computer :)

SpinalHDL: https://spinalhdl.github.io/SpinalDoc-RTD/index.html
The SDRAM controller: https://github.com/stffrdhrn/sdram-controller

User avatar
Gavinmc42
Posts: 3142
Joined: Wed Aug 28, 2013 3:31 am

Re: A Second Age of Personal Computing

Mon May 13, 2019 12:40 am

I figure that if we are to have a Second Age of Personal Computing I'm going to start by designing my own personal computer :)
Running an OS we write ourselves :D

SCAMP :o that old memory is still intact :lol:
Is it too late to preserve programs and data on those 5 1/4 and 3 1.2 disks?
Is any worth preserving except as history?

A few more decades and those that remember the first PC age will be gone.
Those that where there, compare a $35 Pi to those old boat anchors.

But with the retirement of Moore's Law what will be the third age?
That is going to be really interesting.
I'm dancing on Rainbows.
Raspberries are not Apples or Oranges

User avatar
scruss
Posts: 2255
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON
Contact: Website

Re: A Second Age of Personal Computing

Mon May 13, 2019 2:19 am

ejolson wrote:
Sun May 12, 2019 4:30 pm
I looked up the definition of personal computer and found SCAMP: the Special Computer APL Machine Portable.
Interesting machine, but it never got past prototype stage. Meanwhile, in Canada, MCM started selling the MCM/70: also a portable APL machine. A friend has been repairing some of the MCM hardware from York University. It's really interesting insde: lots of odd design decisions and hardware (like VFD displays) that no-one really wants to see any more.
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.

ejolson
Posts: 3031
Joined: Tue Mar 18, 2014 11:47 am

Re: A Second Age of Personal Computing

Fri May 24, 2019 8:19 pm

In the beginning was personal computing, and personal computing was with Basic, and personal computing was Basic. The same was in the beginning with Basic. All programs were made with Basic; and without Basic was not any thing made that was made. In Basic was programming; and that programming was the code of programmers. And the code shineth in the forum; and the forum comprehended it not.

As the phase of the moon has changed, so has the title of this thread. As the title of this thread has changed to the Final Fibonacci Challenge, here are some Pi Zero results showing the relative scaling of five famous Fibonacci codes:
  • classic--the line numbered Basic program classic.bas which is compatible with the original version of MITS/Altair Basic compiled with Free Basic. This program uses floating-point arrays to store the big Fibonacci numbers.
  • integervol--a variation of the classic line numbered Basic program integer.bas which instead uses 32-bit integer arrays again compiled with Free Basic. Note that the volatility keyword was added in the needed places to work around bugs in how gosub was implemented by the C code-generator backend.
  • serial--based on the OpenMP code parallel.c but compiled for serial operation without the -fopenmp using gcc 6.3.0.
  • gmp--a simple call to the mpz_fib_ui subroutine from the GMP multi-precision library.
  • visual--the program visual.bas written in structured Basic with arrays of 32-bit integers compiled with vbnc 0.0.0.5943 and executed using mono 4.6.2.
To obtain timing metrics independent of run-time system startup each program was modified to repeatedly present a "? " prompt to input the number n after which the resulting value of the n-th Fibonacci number F(n) was output. Rather than take the timings by hand with a stop watch, it was then decided to create a separate benchmarking program that ran each of the corresponding Fibonacci codes under a pty device to automatically calculate the computational time needed to calculate Fibonacci numbers for randomly chosen values of n between 1 and 4784969. Graphs and output will be included in a separate post soon.

While the C code ran in a fairly straightforward way under the pty device, the Basic implementations had various difficulties. For example, when executing the statement

input n

Free Basic wrote the "? " prompt to standard input rather than standard output. Since the same pty device is used for both input and output, this wouldn't have been a problem except for another bug. When run under the pty device (or even ssh) the Free Basic input routines occasionally fail to process characters as they are typed. The result being that the calculation of F(n) doesn't begin reliably upon receiving the value of n.

It turns out that Free Basic reads input more reliably from a pipe. Therefore the following was used as a workaround

cat | ./classic

However, at this point the "? " prompt generated by the input statement disappears because it is being written to standard input. Therefore, the Basic code was changed to read

print "? ";:input "",n

so the prompt is output to standard output.

It should also be noted without the pipeline that Free Basic outputs escape codes to the pty device unless the TERM environment variable is unset. While there is some sense in this, I find no reason to add escape codes to the output of a console-mode text-only program.

Even when TERM was unset, Visual Basic refused to stop writing escape codes to the pty device. However, sending the output through a pipe did prevent the escape codes from appearing. Therefore, the work-around needed for running the Visual basic code under the benchmarking program was

mono ./visual.exe | cat

which then prevented the automatic generation of unwanted escape codes.

If this thread were titled Why avoid Basic, the need for workarounds to interactively drive standard input and output of a text-only program through a pty device could be seen as a reason for avoidance.

For reference the benchmarking program is

Code: Select all

/*  fibench -- Benchmark a Fibonacci Program.
    Written May 22, 2019 by Eric Olson

    This program provides a benchmarking harness for interactive
    programs that compute million-digit Fibonacci numbers using 
    the following protocol:

    1.  The program being timed presents a prompt "? " without
        the quotes and waits for the number n.

    2.  Upon receiving the number n followed by a line-feed
        the program then output the n-th Fibonacci number on
        one line followed by a line feed.

    3.  The process repeats until n=0 is received upon which
        the program exits.
*/    
#include <stdio.h>
#include <math.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <pty.h>
#include <sys/time.h>
#include <time.h>
#include <signal.h>
#include <termios.h>
#include <gmp.h>

#define MAXFN 4784969
#define MAXDG 1048576
#define FSEED 2019

static int fibskip=MAXFN, fibiter=1000, fibrep=1, fibfail=1;
static char *fibprog="internal";
static int fibmaster,fibpid;
static char fibbuf[MAXDG],gmpbuf[MAXDG];
static char rdrbuf[4096];
static int rdrcur,rdrend;
static mpz_t fibres;

void onint(){
    if(fibpid) kill(fibpid,SIGINT);
    exit(1);
}
void onquit(){
    if(fibpid) kill(fibpid,SIGQUIT);
    exit(1);
}
void onkill(){
    if(fibpid) kill(fibpid,SIGKILL);
    exit(1);
}

#ifdef CLOCK_MONOTONIC_RAW
static struct timespec tic_start;
static void tic() {
    clock_gettime(CLOCK_MONOTONIC_RAW,&tic_start);
}
static double toc() {
    struct timespec tic_stop;
    clock_gettime(CLOCK_MONOTONIC_RAW,&tic_stop);
    double sec=tic_stop.tv_sec-tic_start.tv_sec;
    return sec+(tic_stop.tv_nsec-tic_start.tv_nsec)*1.0e-9;
}
#else
static struct timeval tic_start;
static void tic() {
    gettimeofday(&tic_start,0);
}
static double toc() {
    struct timeval tic_stop;
    gettimeofday(&tic_stop,0);
    double sec=tic_stop.tv_sec-tic_start.tv_sec;
    return sec+(tic_stop.tv_usec-tic_start.tv_usec)*1.0e-6;
}
#endif

static int fibgetc(){
    while(rdrcur==rdrend){
        rdrend=read(fibmaster,rdrbuf,sizeof(rdrbuf));
        if(rdrend<0) onkill();
        rdrcur=0;
    }
    int c=rdrbuf[rdrcur++];
//    printf("c=%d %c\n",c,isprint(c)?c:'?');
    return c;
}
static void fibqmsp(){
    int fibhang=0;
    for(;;){
        int c=fibgetc();
        if(!fibhang&&c=='?'){
            c=fibgetc();
            if(c==' ') return;
        }
        if (c=='\n'||c=='\r') fibhang=0;
        else fibhang=1;
    }
}
static void fibnum(){
    int i=0;
    for(;;){
        int c=fibgetc();
        if(isdigit(c)) fibbuf[i++]=c;
        if(i&&(c=='\n'||c=='\r')) {
            fibbuf[i]=0;
            return;
        }
    }
}

int fiborun(){
    if(strcmp(fibprog,"internal")){
        unsetenv("TERM");
        unsetenv("DISPLAY");
        unsetenv("SSH_CLIENT");
        unsetenv("SSH_CONNECTION");
        unsetenv("SSH_TTY");
        execlp(fibprog,fibprog,(char *)0);
    }
    for(;;){
        printf("? ");
        char buf[128];
        fgets(buf,sizeof(buf),stdin);
        int n=atoi(buf);
        if(!n) return 0;
        mpz_fib_ui(fibres,n);
        gmp_printf("%Zd\n",fibres);
    }
}

static int fibench(){
    mpz_init(fibres);
    struct termios termiost;
    cfmakeraw(&termiost);
    if(!(fibpid=forkpty(&fibmaster,0,&termiost,0))){
        return fiborun();
    }
    signal(SIGINT, onint);
    signal(SIGQUIT, onquit);
    signal(SIGKILL, onkill);
    FILE *fibinp=fdopen(fibmaster,"w");
    for(int k=0;k<fibrep;k++){
        int n=7499;
        srandom(FSEED);
        printf("#%8s %12s -- %s\n","n","Tn",fibprog);
        fflush(stdout);
        for(int i=-1;i<fibiter;i++){
            if(n<=fibskip&&n>=1){
                fibqmsp();
                char fibn[128];
                tic();
                fprintf(fibinp,"%d\n",n); fflush(fibinp);
                fibnum();
                double t=toc();
                mpz_fib_ui(fibres,n);
                gmp_sprintf(gmpbuf,"%Zd",fibres);
                int r=strcmp(fibbuf,gmpbuf);
                if(fibfail&&r){
                    printf("#F(%d) failed!\n",n);
                    printf("#<%s>\n#<%s>\n",fibbuf,gmpbuf);
                    exit(1);
                }
                if(i>=0) printf("%c%8d %12.4e\n",r?'#':' ',n,t);
                fflush(stdout);
            }
            n=MAXFN;
            if(i>=0) n=n*exp(-log(MAXFN)*random()/RAND_MAX)+0.5;
        }
        if(k+1<fibrep) printf("\n\n");
    }
    fprintf(fibinp,"0\n"); fflush(fibinp);
    return 0;
}
static void fibhelp(){
    printf(
"fibench -- Benchmark a Fibonacci Program.\n"
"Usage: fibench [options] program\n"
"Options:\n"
"\t-i  \tIgnore failures when GMP doesn't match.\n"
"\t-l n\tPerform n number of different timings.\n"
"\t-r n\tRepeat the entire benchmark run n times.\n"
"\t-s n\tSkip computing Fibonacci numbers greater than n.\n"
"\t-h  \tPrint this help.\n"
);
    exit(1);
}

int main(int argc, char *argv[]){
    int opt;
    while((opt=getopt(argc,argv,"il:r:s:"))!=-1){
        switch(opt){
case 'i':
            fibfail=0;
            break;
case 'l':
            fibiter=atoi(optarg);
            break;
case 'r':
            fibrep=atoi(optarg);
            break;
case 's':
            fibskip=atoi(optarg);
            break;
default:
            fibhelp();
        }
    }
    if(optind<argc) fibprog=argv[optind];
    return fibench();
}
Changes to the classic.bas and integer.bas programs were

Code: Select all

280 dim m(d9*m9)
290 m0=1:print "? ";:input "",n:if n=0 then stop
300 a=m0:m0=m0+1+d9:b=m0:m0=m0+1+d9
310 t1=m0:m0=m0+1+d9:t2=m0:m0=m0+1+d9
400 r0=n:gosub 1000
420 r7=b:gosub 7000
430 goto 290
Changes to the parallel.c program were

Code: Select all

    for(;;){
        printf("? ");
        char buf[128];
        fgets(buf,sizeof(buf),stdin);
        n=atoi(buf);
        if(n==0) return 0;
        work(n);
    }
Changes to the visual.bas program were

Code: Select all

    while 1
        dim s as string
        console.write("? ")
        s=console.readline()
        n=val(s)
        if n=0 then return 0
        fibo(n)
        bigprint(b)
    end while
Update: The program fibench.c was updated with minor changes to allow more convenient timings for Fibonacci codes that don't always give the correct answer.
Last edited by ejolson on Wed May 29, 2019 7:20 pm, edited 3 times in total.

ejolson
Posts: 3031
Joined: Tue Mar 18, 2014 11:47 am

Re: A Final Fibonacci Challenge

Fri May 24, 2019 10:56 pm

Here is the graph that goes with the previous post:

Image

All runs were performed with a Pi Zero using this super-cheap personal computing cluster.

I find the staircase effect in the blue dots a bit amusing. Does anyone have an idea what is causing them? Also, given the apparent slopes, it looks like the blue line might eventually cross the green one.

User avatar
ScriptBasic
Posts: 1231
Joined: Wed Apr 03, 2019 5:53 pm
Location: Anacortes, WA USA
Contact: Website Twitter

Re: A Final Fibonacci Challenge

Sat May 25, 2019 3:11 am

It's also a nice chart showing BIGINT emulation performance. Once languages exceed hardware precision, the magic takes over.

I was surprised GMP runs so slow on your Zero. My tests return almost instantly with GMP.

ejolson
Posts: 3031
Joined: Tue Mar 18, 2014 11:47 am

Re: A Final Fibonacci Challenge

Sat May 25, 2019 7:41 am

ScriptBasic wrote:
Sat May 25, 2019 3:11 am
I was surprised GMP runs so slow on your Zero.
While the Zero is slower than a PC, I find it surprisingly powerful given the $5 cost. To paraphrase Leo Tolstoy, see also Quote 1 in this post, Happy programmers are all alike; every unhappy programmer is avoiding Basic in his or her own way.

I stand on the edge of the second age of personal computing and wonder whether the Raspberry Pi will bear my weight. The Pi does not appear as sturdy as the IBM 5150 of the golden age or even the faster and better Sage II by Sage Technology. Moreover, I've gained a little weight since Basic and the UCSD p-system were replaced by Python, the Java virtual machine and a real computer cheap enough that a child can afford to own one.

Upon surveying the current landscape I notice the minions of Mrs Verda Spell have been busy improving Bywater BASIC. It can now emulate 24 different classic dialects from CBASIC to XBASIC including DEC 8K BASIC for the PDP-8, TRS-80 Model I LBASIC and Mainframe BASIC for the IBM System/360--the ultimate personal computer.

As the version of bwBASIC that ships with Raspbian is hopelessly out of date, I fearlessly download the source for bwBASIC 3.2.0 and begin patching:
  • In bwbasic.c between lines 67 and 84 comment out the huge and unsightly login banner.
  • In bwb_fnc.c on line 45 add "int putenv(char *string);"
  • In bwb_int.c on line 3978 change "double Result;" to
    "double Result=0;" for uninitialized use warning.
  • In bwb_var.c line 113 remove the semicolon, who knows why.
After it compiles with the command

Code: Select all

$ gcc -O3 -o bwbasic -lm -ansi -pedantic -Wall -Werror bw*.c
I copy the executable bwbasic to /usr/local/bin to prepare for the final Fibonacci challenge. To my astonishment the classic line-numbered Fibonacci program loads and runs to produce the output

Code: Select all

$ bwbasic 
Bywater BASIC Interpreter, version 3.20                                       
Copyright (c) 1993, Ted A. Campbell                                           
Copyright (c) 1995-1997, Jon B. Volkoff                                       
Copyright (c) 2014-2017, Howard Wulf, AF5NE                                   
                                                                              
bwBASIC: load "classic.bas"
bwBASIC: run
? 100
3.54225E+64.81793E+61.91508E+6
Since no version of Basic was actually compatible with another during the golden ago of personal computing, I've learned more than cut and paste. Therefore, after some thought, I make the following changes to the output routine of the classic line-numbered Basic program:

Code: Select all

7000 rem Big-number print
7010 rem   inputs: r7 the value to print
7020 if m(r7)=0 then print "0":return
7030 for i=m(r7) to 1 step -1
7035 j9=int(m(r7+i)/10000):j8=m(r7+i)-j9*10000
7040 s$=str$(j8):if mid$(s$,1,1)=" " then s$=mid$(s$,2,len(s$)-1)
7042 if j9>0 then s$=str$(j9)+mid$("000000",1,4-len(s$))+s$
7045 if mid$(s$,1,1)=" " then s$=mid$(s$,2,len(s$)-1)
7050 if i=m(r7) or b9<=len(s$) then 7070
7060 s$=mid$("0000000000000",1,b9-len(s$))+s$
7070 print s$;:next i:print:return
as well as

Code: Select all

246 width 0
And so it is, bwBASIC is ready for the final Fibonacci challenge.

Update: Fixed the link for the Sage II, which was conceived as the world's fastest personal computer.
Last edited by ejolson on Sat May 25, 2019 5:00 pm, edited 8 times in total.

Heater
Posts: 12628
Joined: Tue Jul 17, 2012 3:02 pm

Re: A Final Fibonacci Challenge

Sat May 25, 2019 9:50 am

ejolson,

In the beginning was the WORD and the word was 36 bits and 36 bits was the WORD. [1]

The WORD was without form, and void until LISP [2]. LISP begat Scheme. Scheme begat Javascript. Javascript begat TypeScript. Typescript begat Microsoft Visual Studio Code. VS Code begat this forum post.

Speaking of which I was tweaking with the Scheme Fibonacci Challenge entry yesterday. I wanted to try it under Chibi Scheme. Chibi is a nice candidate for Scheme embedded in C/C++ applications or even on embedded systems. It's pretty small and supports the latest Scheme 7 standards.

Well of course Chibi Scheme did not like the hash functions used by the Racket dialect fibo we have so the memoization feature had to go.

Chibi did not like the non-standard use of square brackets by Racket so they had to go.

Chibi complained about undefined variables until I replaced a "let" of the Racket version with "let*"

My mind reeled at the confusion of bracket worms that Schemers love so much, I pulled them out straight so I can see what is going on. The end result is this fibo.chibi:

Code: Select all

(import (scheme base))
(import (scheme write))

(define (fibo n)
    (cond
        ((= n 0) 0)
        ((= n 1) 1)
        (else
            (let*
                (
                    (k (quotient n 2))
                    (a (fibo k))
                    (b (fibo (- k 1)))
                )
                (if (even? n)
                    (* a (+ (* 2 b) a))
                    (let
                        (
                            (c (* (+ (* 2 a) b) (- (* 2 a) b)))
                        )

                        (if (= (modulo n 4) 1)
                            (+ c 2)
                            (- c 2)
                        )
                    )
                )
            )
        )
    )
)

(display (fibo 4784969)
(newline)
Yay! It works. Sadly it's very slow. Sixteen minutes slow!

Code: Select all

$ time chibi-scheme fibo.chibi | head -c 32 ;  time chibi-scheme fibo.chibi | tail -c 32
10727395641800477229364813596225
real    16m13.998s
user    16m13.641s
sys     0m0.094s

4856539211500699706378405156269
real    16m24.671s
user    16m22.297s
sys     0m0.078s
Thinking that removing the memoization may have slowed things down a lot I ran it with Racket for comparison:

Code: Select all

$ time racket fibo.chibi | head -c 32 ; time racket fibo.chibi | tail -c 32
10727395641800477229364813596225

real    0m1.563s
user    0m1.016s
sys     0m0.547s
4856539211500699706378405156269

real    0m1.585s
user    0m1.047s
sys     0m0.516s
Nope. That's not it. Chibi is just slow with big integers. Interestingly this shows that the memoization of the original Racket fibo only saves about 10% execution time. Not worth the bother.



By the way, ScriptBasic, I added your fibo challange entry in Go from this post: viewtopic.php?f=62&t=227343&start=1850#p1458678 to the challenge repository.



Notes:

1. IBM 704 - 1954

2. LISP - 1958

ejolson
Posts: 3031
Joined: Tue Mar 18, 2014 11:47 am

Re: A Final Fibonacci Challenge

Sat May 25, 2019 6:12 pm

Heater wrote:
Sat May 25, 2019 9:50 am
My mind reeled at the confusion of bracket worms that Schemers love so much, I pulled them out straight so I can see what is going on.
Is it possible that Racket Scheme does memoisation behind the scenes?

Here on the liberal frontier, just like wild horses, the Basic interpreters are being rounded up. While the horses will be tamed and sold at auction, the interpreters are untamable and have a less certain fate: the final Fibonacci challenge.

Along these lines I was reading the install instructions
GitHub wrote:$ git clone https://github.com/rtrussell/BBCSDL.git
$ cd BBCSDL/
$ vim licence.txt
$ cd bin/
$ cd linux/
$ sudo apt-get install libsdl2-dev
$ sudo apt-get install nasm
$ sudo apt-get install libsdl2-ttf-dev
$ sudo apt-get install libsdl2-net-dev
$ make
$ ./bbcsdl
$ cd heater/fibo_4784969/BASIC/
$ /home/heater/BBCSDL/bin/linux/bbcsdl fibo_bbc.bas
and wondering whether it is possible to build Richard's interpreter without the SDL libraries. Even if not, can the resulting programs still be tamed to run from an ssh login without a monitor attached?

After the difficulties I had with qb64, I'm a bit hesitant to install another programming language that has a simple direct-media layer built in.

Heater
Posts: 12628
Joined: Tue Jul 17, 2012 3:02 pm

Re: A Final Fibonacci Challenge

Sat May 25, 2019 8:01 pm

ejolson,
...and wondering whether it is possible to build Richard's interpreter without the SDL libraries. Even if not, can the resulting programs still be tamed to run from an ssh login without a monitor attached?
From what I gathered from my lengthy discussion with Richard Russell re: getting a fibo(4784969) result out of BBCBasic it is not possible to run it as a normal command line program. I ended up going through all of the hassel of hooking up a momitor just to run the damn thing.

Discussion here:

viewtopic.php?t=238001&start=375#p1466181
...the Basic interpreters are being rounded up.
Odd that, I have been rounding up Scheme engines. Got Racket and Chibi, today it was Chez Scheme and Guile. Easy peesy:

Code: Select all

$ sudo apt-get install uuid-dev
$ git clone https://github.com/cisco/ChezScheme.git
$ cd ChezScheme/
$ ./configure
$ make
$ sudo make install
$ 
$ time scheme --script fibo.chez.scm | head -c 32
10727395641800477229364813596225

real    0m13.386s
user    0m13.141s
sys     0m0.141s
$ time scheme --script fibo.chez.scm | tail  -c 32
4856539211500699706378405156269

real    0m16.942s
user    0m16.734s
sys     0m0.203s

$ sudo apt-get install guile-2.0
$ time guile fibo.scm | head -c 32
10727395641800477229364813596225
real    0m1.785s
user    0m1.969s
sys     0m0.094s
[email protected]:/mnt/c/Users/michael/Documents/fibo_4784969/scheme$ time guile fibo.scm | tail  -c 32
4856539211500699706378405156269

real    0m1.757s
user    0m2.125s
sys     0m0.172s
Why can't Smalltalk and BBCBasic be so user friendly?

Chez is about 10 times slower than Racket Scheme, 60 times faster than Chibi Scheme.
Guile is about neck and neck with Racket.

Chez and Guile are the only ones that run the plain fibo scheme code without some tweaky lines added to the top of the source file to import functionality.

I have to check these all work on a Pi.

Heater
Posts: 12628
Joined: Tue Jul 17, 2012 3:02 pm

Re: A Final Fibonacci Challenge

Sat May 25, 2019 8:24 pm

TinyScheme does not appear to support big integers at all:

Code: Select all

$ time tinyscheme fibo.scm
4701041550771754413

real    0m30.925s
user    0m30.906s
sys     0m0.000s
Do I now have to implement Karatsuba in Scheme?!

User avatar
scruss
Posts: 2255
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON
Contact: Website

Re: A Final Fibonacci Challenge

Sat May 25, 2019 9:00 pm

Heater wrote:
Sat May 25, 2019 9:50 am
In the beginning was the WORD and the word was 36 bits and 36 bits was the WORD. [1]

1. IBM 704 - 1954

Code: Select all

s/36/40/g; 
s/IBM.*/Manchester Mark 1/; # FTFY ...
Early word length was messy. The Baby was 32 bit, EDSAC 17¹ bit, the IAC machine 40 bit and poor old EDVAC was 44 bits. Of course, all of these pre-date programming languages of any sort.

It's possible to run fibo(40) in the 32 words of store of the Manchester Baby. JsSSEM has the code. Loks like it would have run in a few seconds, too. JsSSEM is all about authenticity, so the only inputs are Base-32 paper tape. Here's the program, converted to slightly more modern opcodes:

Code: Select all

; fibo(40) for Manchester SSEM
; returns 102334155 in accumulator
; original code: http://www.edmundgriffiths.com/jsssem.html
; possibly badly translated to 'modern' opcodes by scruss
; 
00  LDN 21
01  STO 22
02  SUB 20
03  STO 21
04  LDN 21
05  STO 21
06  LDN 22
07  STO 20
08  LDN 23
09  SUB 24
10  CMP
11  JMP 25	; skipped if CMP was negative
12  STO 23
13  LDN 23
14  STO 23
15  JMP 24
16  LDN 21
17  STO 21
18  LDN 21
19  STP
20  NUM 1
21  NUM 1
22  NUM 0
23  NUM 39	; set to n-2
24  NUM -1	; might be wrong - was all binary 1s in source
25  NUM 15
Baby's instruction set is somewhat odd in that it couldn't add but only subtract.
--
¹: EDSAC had an 18-bit word, but timing issues prevented the top bit being readable
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.

User avatar
scruss
Posts: 2255
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON
Contact: Website

Re: A Final Fibonacci Challenge

Sat May 25, 2019 9:04 pm

ejolson wrote:
Sat May 25, 2019 6:12 pm
… wondering whether it is possible to build Richard's interpreter without the SDL libraries. Even if not, can the resulting programs still be tamed to run from an ssh login without a monitor attached?
BBCSDL can't, but Matrix Brandy can. You can build console-only versions with its makefile.text
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.

Heater
Posts: 12628
Joined: Tue Jul 17, 2012 3:02 pm

Re: A Final Fibonacci Challenge

Sat May 25, 2019 9:39 pm

scruss,
Early word length was messy.
Yeah, yeah, I know. The first machine I ever got to use had a 24 bit word length. http://www.findlayw.plus.com/ICL1900/index.html

I chose 36 bits for a reason. The word size of the IBM 704 was 36 bits, it was the machine that Lisp was developed on. The first high level language.

Code: Select all

24  NUM -1	; might be wrong - was all binary 1s in source
The Manchester Baby used two's complement representation. So that "-1" would indeed have been all ones. I don't think there is anything wrong there.

Return to “General programming discussion”