Programming the Sinclair Cambridge Programmable

Can you do anything useful in an 18-byte program?

It used to have a name but it wore off; the key legends are fading too.

Key functions

key

base function

upshift function

downshift function

prog base function

prog downshift function

prog num function

prog symbol

comment

./EE/-

./EE/-

downshift

./EE/-

A

decimal point / enter exponent / negate
exponent

up/down

up and down shift

once for up, twice for down

C/CE

clear/clear entry

step

once for CE, twice for C; step in learn mode

7

7

sin

arcsin

sin

arcsin

7

7

8

8

cos

arccos

cos

arccos

8

8

9

9

tan

arctan

tan

arctan

9

9

RUN

RUN

learn

run the stored prog; enter learn mode

4

4

lnx

ex

lnx

ex

4

4

5

5

rcl

MEx

rcl

MEx

5

5

recall from mem; exchange with mem

6

6

()

R>D

()

R>D

6

6

parens; radians to deg

/

/

G

1/x memo to auto constant function

1

1

sqrt

go if neg

sqrt

go if neg

1

1

2-dig step # after go if neg

2

2

sto

goto

sto

goto

2

2

store; 2-dig step # after goto

3

3

ChN

D>R

#

D>R

3

3

show all 8 digits of mantissa; escape to number; deg to radians

x

x

&nbsp

.

x2 memo to auto constant function

0

0

+/-

stop

+/-

0

0

=

=

-

+

+

&nbsp

E

2x memo to auto constant function

-

-

&nbsp

F

-x memo to auto constant function

The trick used to minimise keystrokes is to treat program and direct entry
differently. In direct entry number keys enter numbers and other functions
are accessed by single (up) or double (down) presses of the shift key. On
the assumption that programs are more functions than data, in program mode
the number keys do the upper function with no shift, the lower on one
shift, and numbers only after a specific numeric shift. This is rather
confusing to use, but is a typical Sinclair trick to get something out of
almost nothing. Or possibly almost something out of next to nothing.

Only the 16 keys with an entry in the "prog symbol" column can be in a
program. The symbol is the 7-segment symbol used to indicate the contents of
a program step. The symbol is the numeric value, or the symbol shown in
blue below to the right of the key.

There are 36 steps available, 00 to 35 (18 bytes total).

Functions shown in "prog base function" can be used as a single step.
Functions shown in "prog downshift function" use 2 steps, a downshift
(shows as A) followed by the key from the table.

Numbers can be placed in the program after a # step (shows as 3). Numbers
are terminated by anything that cannot be part of a number, basically the
four arithmetic operators and =. It's a lot more efficient to put in a
number by a recall from memory.

The ./EE/- key succesively enters a decimal point, then starts an
exponent, then makes the exponent negative.

The legends below the arithmetic keys hint at useful functions -x, 2x,
1/x and x2. These are not true operators, just an indication
of what, with no pending operations, the autoconstant function will do if
that key is pressed, then the = key.

Here is a silly program that just counts the memory up by one each time
the RUN key is pressed:

Model of the Sinclair Cambridge Programmable

A quick Javascript model:

Press the keys to operate. Power key does a complete reset. The display
does not do exactly what the real one does, and it's far too accurate. To
catch infinite loops, maximum program execution is set to 5000 steps. (To
play, load the example factorial program using the link below, enter an
integer 1..69 and press RUN.)

Control

Example programs

I've done almost no testing. There are sure to be numerous bugs! The code
is here.

Sinclair maths

This calculator, like previous Sinclair Scientifics, has appalling trig
functions. For example, [4] [5] [D>R] [sin] gives 0.7069515 instead
of the correct 0.7071068, that's a 0.02% error on an 8-digit calculator.
But there is worse. Observe this sequence of calculations:

#

radians

sine calculated

true value (hp49g+)

1

0.1

0.099823

0.0998334

2

0.10009

0.099823

0.0999230

3

0.1001

0.0999224

0.0999329

4

0.10019

0.0999224

0.1000225

5

0.1002

0.1000218

0.1000324

6

0.10029

0.1000218

0.1001220

7

0.1003

0.1001212

0.1001319

8

0.06320

0.0631504

0.0631579

9

0.06329

0.0631504

0.0632478

10

0.06330

0.0632502

0.0632577

It appears to use only the first four places of decimals and to ignore
any input after that. So, about the same as ordinary log tables.

It also does not even cover the full -pi/2 to pi/2 range that it claims.
Here is the behaviour around the positive limit:

#

radians

sine calculated

true value (hp49g+)

11

1.57

0.9998869

0.9999997

12

1.5700001

E 0.9998854

0.9999997

13

1.570001

E 0.9998854

0.9999997

14

1.57001

E 0.9998854

0.9999997

15

1.57002

E 0.9998854

0.9999997

16

1.57009

E 0.9998854

0.9999998

17

1.5701

E 0.9998853

0.9999998

18

1.5705

E 0.9998831

1.0000000

19

1.5707

E 0.999882

1.0000000

20

1.5707963

E 0.9998814

1.0000000

21

1.5708

E 0.9998814

1.0000000

22

1.571

E 0.9998803

1.0000000

23

1.58

E 0.999829

0.9999576

Firstly the error indicator comes on too early, pi/2 is 1.5707963, yet it
indicates error for angles greater than 1.57. Secondly 1.5700xxx is the angle
for the peak value of the function, at 89.95° instead of 90°.
Thirdly the peak value is a little short of 1. Note also in this sequence
that although the results are generally insensitive to decimal places
beyond four in the argument, the transitions are not where the 4th decimal
digit changes.

I wonder what it does to calculate sines? Even the simple power series for
sine truncated after the fourth term:

sin(x) ~= x - x3/6 + x5/120 - x7/5040

gives better results than this over -pi/2 to pi/2. And that simplifies to
just five multiplies and three adds.

Some other functions:

#

function and argument

result calculated

true value (hp49g+)

24

sqrt(2)

1.414213

1.4142136

25

ln(2)

0.693172

0.6931472

26

tan(D>R(45))

0.9995621

1.0000000

27

1/9

0.1111111

0.1111111

28

e10

22024.952

22026.466

29

eln(2.02)

2.0198033

2.0200000

30

arctan(1)

0.7854105

0.7853982

Today we can buy a scientific calculator that does much more than this one,
with 15-digit accuracy and solar powered, for the price of two pints of
beer. Back in 1977, any scientific that didn't cost a week's wages was
remarkable. I suppose it was about 30 GBP when I bought it. The cost
of two pints then would have been about 1 GBP. In 1975 I paid 125 GBP for
an HP-25, which was then 5% of my gross salary or 88% of one month's net
pay.