Casio fx-1 algorithm analysis

153 views
Skip to first unread message

Darren Lo

unread,
Feb 20, 2021, 4:45:43 AM2/20/21
to OldCalculatorForum
One of the charms of the Casio fx-1 is that it does its computations without blanking the display register, so you can watch it think. However things go a bit too fast to really catch with the naked eye. I found that I was able to use my phone's super slow motion video capability to slow things down enough that I could figure out the algorithms it uses for all its functions (besides addition/subtraction, which are instantaneous), including pulling out the exact coefficients used in its polynomial approximations. Initially I had planned to submit a complete writeup, but it ended up being too long and detailed, and perhaps not of much general interest. So I'll just say something about the square and cube root algorithms.

The square root is implemented using Toepler's algorithm (i.e. the "odd number subtraction" algorithm) which is familiar to many mechanical calculator users. Actually, it uses the "halved" variant of Toepler's algorithm where the radicand is first multiplied by 5 in lieu of being divided by 2, and then the numbers .5, 1.5, 2.5, etc. are successively subtracted. The calculator doesn't check to see if the remainder ever becomes 0; it always just goes through and computes every digit of the square root. However, iterations where the digit is 0 go quite quickly since there are no subtractions to be performed.

The cube root of a number y, cbrt(y), is implemented using the following algorithm:
x <- y
for k=1 to 19, x <- sqrt(sqrt(x * y))
return x
Ignoring truncation error, this algorithm computes approximately y^0.3333333333358, which has a relative error of about 10^-11 over the range of arguments that the calculator accepts. So the achieved accuracy is good, but the sequence converges quite slowly, especially given the cost of computing two square roots in each iteration. So it seems that not much engineering effort was spent on designing the cube root function.

This implementation sheds light on several quirks of the algorithm:
1) Why the display is so relatively legible during the process: it is repeating the square root algorithm, which builds up stably from the left in a highly visible fashion.
2) Why the cube root of negative numbers is positive: the calculator's treatment of signs is relatively cavalier anyway, but note that the first iteration is x = sqrt(sqrt(y^2)), which is the same as saying x = sqrt(abs(y)).
3) Why the maximum argument accepted is 999999.999999: the product x*y in the first iteration would overflow if y were larger than this number. Why the first iteration could  not have been special cased to only compute sqrt(abs(y)) instead of sqrt(sqrt(y*y)), is a question best posed to the original engineers.

Finally, I noticed some bugs/oddities in the trig functions of larger angles. However, given the age of the machine, it's possible that mine isn't functioning quite correctly. If you have a working Casio fx-1, could you check the values of sin(30), sin(390), and sin(1830)? Ideally these should all be 0.5. On mine, sin(390) is sqrt(3)/2, but the other two values are correct. The reason why is both baffling and actually mildly entertaining -- if it's not just a malfunction of my unit in particular.

osa...@gmail.com

unread,
Feb 20, 2021, 5:18:56 AM2/20/21
to OldCalculatorForum
Wow! I love this post :-) The Commodore PR-100 computes like this, but I don’t think it’s so informative.

Paulos, Richard G

unread,
Feb 20, 2021, 10:47:44 AM2/20/21
to oldcalcul...@googlegroups.com
I'm sure many of use would like to see the slow motion video. Perhaps you can upload that to youtube or some other video sharing site.

thanks.

rick


________________________________________
From: oldcalcul...@googlegroups.com <oldcalcul...@googlegroups.com> on behalf of Darren Lo <reckon....@gmail.com>
Sent: Saturday, February 20, 2021 3:45 AM
To: OldCalculatorForum
Subject: [External] [oldcalculatorforum] Casio fx-1 algorithm analysis

--
You received this message because you are subscribed to the Google Groups "OldCalculatorForum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to oldcalculatorfo...@googlegroups.com<mailto:oldcalculatorfo...@googlegroups.com>.
To view this discussion on the web visit https://groups.google.com/d/msgid/oldcalculatorforum/bfd0a4af-9c76-45c6-9894-9c6fd60bb37an%40googlegroups.com<https://groups.google.com/d/msgid/oldcalculatorforum/bfd0a4af-9c76-45c6-9894-9c6fd60bb37an%40googlegroups.com?utm_medium=email&utm_source=footer>.

Thomas Kirchhof

unread,
Feb 21, 2021, 5:23:36 PM2/21/21
to OldCalculatorForum
Hello Darren,
my fx-1 is giving the same results: 
sin(30) = sin(1830) = 0.5
sin(390) = 0.8660254...
So it seems to be a feature, not a bug!
Best regards, and thanks for the info (maybe you want to post the complete writeup some day?)
Th.K.
Reply all
Reply to author
Forward
0 new messages