Post Reply 
Casio fx-3800P "Programming"
03-06-2020, 02:42 PM
Post: #1
Casio fx-3800P "Programming"
I use the word "programming" a bit loosely, because this model does little more than record a sequence of keystrokes, with a placeholder (ENT) to pause and get user input. It has somewhere around 150 program steps that can be split up across 4 programs, but programs can't call each other. This is literally the full extent of the flow control and decision making:

- Pause and display a result (HLT)
- Pause the program and accept an input (ENT)
- Restart the program (RTN)
- Restart the program if x>0
- Restart the program if x<=M

No labels, no goto.

Despite this, the manual has a few clever sample programs, like this one that simulates indirect addressing to accumulate frequency sums for a five-bucket histogram:

Code:
Prog I
ENT
M in
ENT
K in 6
K in + 5
5
x<=M
K out 6
K in - 5
K in + 4
4
x<=M
K out 6
K in - 4
K in + 3
3
x<=M
K out 6
K in - 3
K in + 2
2
x<=M
K out 6
K in - 2
K in + 1
1
RTN

Prog II
K out 1
HLT
K out 2
HLT
K out 3
HLT
K out 4
HLT
K out 5

Initialize the program by pressing Shift KAC, then I. Input the bucket number (1-5) and press RUN, then input the value/frequency and press RUN. Keep entering bucket number and frequency pairs, and press II to view the totals (press RUN to view the next total).

Arguably, one could simply use K in + n to accumulate the values, but the program saves one keystroke per data pair, and you don't risk destroying a total if you miss the + key.

You wouldn't think it would be possible to write a prime factor finder on a calculator with no Int or Frac functions, and no flow control besides "once more from the top", but fortunately I have more determination than sense, so here it is. The program needs all 7 storage registers and uses Fix 0 mode and the Rnd function to round division results, which is just enough to test divisibility. It can factor 9,999,999,999 in about a minute. There is definitely no mod 30 sieve here. Smile

Code:
Prog I      
K in 1      
sqrt        
M in        
1           
K in 2      Divisor increment
2           
K in 3      Divisor
Mode Fix 0  (Mode 7 0) Used for rounding
            
Prog II     
MR          M must be >= K 3 when keying in the program!
-           
K out 3     
=           
sqrt        Cause an error if the divisor is greater than the square root of the numerator
K out 1     Divide current numerator by divisor
/           
K out 3     
K in 5      Save the current divisor for later
=           
Rnd         Round the result
K in 4      Save the result for later
K out 2     Fetch the current divisor increment
K in 6      Save the current divisor increment for later
K in + 3    Increment the divisor
2           Set the divisor increment to 2
K in 2      
K out 4     Multiply the rounded division result...
*           
K out 5     ...by the previously used divisor
-           
K out 1     Subtract the original numerator
=           
x>0         Restart if difference > 0
+/-         
x>0         Restart if difference < 0
K out 5     Show the factor
HLT         
K in / 1    Divide the current numerator by the divisor
K out 1     Get the remaining numerator
sqrt        
M in        Update the square root
K out 6     Restore the previous divisor increment...
K in 2      
K in - 3    ...and roll back the divisor to test the same divisor again
RTN

To use the program, enter the number to factor and press I. Then press II to start factoring. The program will stop when it finds a factor. Press RUN to find the next factor. The program will deliberately cause an error to end early once the divisor has exceeded the square root of the remaining numerator (it does this by attempting to take the square root of the numerator's square root minus the divisor - just pretend the "E" stands for End). Press AC, K out 1 to see the final factor.

The program can accurately factor any integer up to the full 10-digit precision of the calculator, if you're patient enough. (e.g. it doesn't think 2 is a factor of 9,999,999,999.)
Visit this user's website Find all posts by this user
Quote this message in a reply
03-07-2020, 01:19 AM
Post: #2
RE: Casio fx-3800P "Programming"
That's brilliant, Dave.

And the first proper program that I've keyed into my new 3800P Smile

But I've just opened a 5800P, so I need to play with that now; somewhat of a contrast!

thanks.

Cambridge, UK
41CL/DM41X 12/15C/16C DM15/16 17B/II/II+ 28S 42S/DM42 32SII 48GX 50g 35s WP34S PrimeG2 WP43S/pilot/C47
Casio, Rockwell 18R
Find all posts by this user
Quote this message in a reply
03-07-2020, 02:34 AM
Post: #3
RE: Casio fx-3800P "Programming"
(03-07-2020 01:19 AM)cdmackay Wrote:  That's brilliant, Dave.

And the first proper program that I've keyed into my new 3800P Smile

But I've just opened a 5800P, so I need to play with that now; somewhat of a contrast!

thanks.

Ha ha, yeah, rather stark difference between those two.

Not sure what the upper limit is on program complexity for the 3800, but it looks like it's possible to compute incomplete gamma by integration:

http://www.rskey.org/fx3600p

And it can probably handle the usual stuff like cumulative binomial and negative binomial probability.
Visit this user's website Find all posts by this user
Quote this message in a reply
03-07-2020, 12:18 PM
Post: #4
RE: Casio fx-3800P "Programming"
I recently acquired a Tandy EC-4019, which appears to be one of those Casio OEM machines. In this instance it's a rebranded Casio fx-3800P. I'll have to try this on it.

[Image: ec-4019.jpg]

There are only 10 types of people in this world. Those who understand binary and those who don't.
Find all posts by this user
Quote this message in a reply
03-07-2020, 12:22 PM
Post: #5
RE: Casio fx-3800P "Programming"
(03-07-2020 12:18 PM)grsbanks Wrote:  I recently acquired a Tandy EC-4019, which appears to be one of those Casio OEM machines. In this instance it's a rebranded Casio fx-3800P. I'll have to try this on it.

Yup! Mine is actually a "Radio Shack EC-4019". I didn't realize they also sold rebranded calculators with the Tandy name on them. I guess that gives me more search ammo for ebay. Wink
Visit this user's website Find all posts by this user
Quote this message in a reply
03-07-2020, 12:32 PM
Post: #6
RE: Casio fx-3800P "Programming"
(03-07-2020 12:22 PM)Dave Britten Wrote:  Yup! Mine is actually a "Radio Shack EC-4019". I didn't realize they also sold rebranded calculators with the Tandy name on them. I guess that gives me more search ammo for ebay. Wink

Tandy Corporation stuff was always marketed under the "Radio Shack" brand in the US for some reason. Over here in the UK, they kept the name Tandy for this kind of product. HiFi equipment was sold under the "Realistic" brand, I think.

There are only 10 types of people in this world. Those who understand binary and those who don't.
Find all posts by this user
Quote this message in a reply
03-08-2020, 03:47 AM
Post: #7
RE: Casio fx-3800P "Programming"
Amazing! I've had Casios since I were a lad… yet I've never seen one of those Tandy OEMs. Were they common? Where were they sold, do you know?

Cambridge, UK
41CL/DM41X 12/15C/16C DM15/16 17B/II/II+ 28S 42S/DM42 32SII 48GX 50g 35s WP34S PrimeG2 WP43S/pilot/C47
Casio, Rockwell 18R
Find all posts by this user
Quote this message in a reply
03-08-2020, 11:12 AM
Post: #8
RE: Casio fx-3800P "Programming"
(03-08-2020 03:47 AM)cdmackay Wrote:  Amazing! I've had Casios since I were a lad… yet I've never seen one of those Tandy OEMs. Were they common? Where were they sold, do you know?

It's hard to tell, for me anyway. I was living abroad at the time of Tandy/RS's heyday in this country (I was in France from 1983 to 2007) and this calculator was a chance find on TAS.

There are only 10 types of people in this world. Those who understand binary and those who don't.
Find all posts by this user
Quote this message in a reply
03-08-2020, 02:34 PM
Post: #9
RE: Casio fx-3800P "Programming"
(03-07-2020 12:22 PM)Dave Britten Wrote:  
(03-07-2020 12:18 PM)grsbanks Wrote:  I recently acquired a Tandy EC-4019, which appears to be one of those Casio OEM machines. In this instance it's a rebranded Casio fx-3800P. I'll have to try this on it.

Yup! Mine is actually a "Radio Shack EC-4019". I didn't realize they also sold rebranded calculators with the Tandy name on them. I guess that gives me more search ammo for ebay. Wink

Mine is also a Radio Shack EC-4019. I was disappointed to learn that this model doesn't have the AND and OR Boolean functions.
Visit this user's website Find all posts by this user
Quote this message in a reply
03-08-2020, 02:52 PM
Post: #10
RE: Casio fx-3800P "Programming"
(03-08-2020 02:34 PM)Eddie W. Shore Wrote:  Mine is also a Radio Shack EC-4019. I was disappointed to learn that this model doesn't have the AND and OR Boolean functions.

I think there are a lot of other lacking features I would address before worrying too much about those. Wink

Anyway, there are plenty of alternatives for those on Casio's symbolic programming models (fx-4000P/EC-4020, fx-7000G, etc.) which also don't allow them in conditional tests.

And: Just string two conditions together.

X>0=>X<Y=>Goto 4

Or: Either write the conditions+predicate multiple times, or if that's too wasteful (lots of conditions, multiple statements in the predicate, etc.), logically invert the conditions you're testing and jump over the conditionally executed code with a Goto.

If you're talking about bitwise And/Or for Base-N mode, then those might be doable with what passes for programming on the 3800P. Not sure.
Visit this user's website Find all posts by this user
Quote this message in a reply
03-09-2020, 08:10 AM
Post: #11
RE: Casio fx-3800P "Programming"
(03-08-2020 03:47 AM)cdmackay Wrote:  Amazing! I've had Casios since I were a lad… yet I've never seen one of those Tandy OEMs. Were they common? Where were they sold, do you know?

In the UK, they were sold only in Tandy stores.

— Ian Abbott
Find all posts by this user
Quote this message in a reply
03-09-2020, 10:50 AM
Post: #12
RE: Casio fx-3800P "Programming"
(03-07-2020 02:34 AM)Dave Britten Wrote:  Not sure what the upper limit is on program complexity for the 3800...

Check Xerxes' posts here: https://www.hpmuseum.org/forum/thread-7772.html
New dimensions in blind programming. Highly recommended the GCD routine and do not forget two times press the minus key before running! Is there someone who can explain Wink how this program works with this constant feature?! Big Grin

Cs.
Find all posts by this user
Quote this message in a reply
03-09-2020, 11:58 AM
Post: #13
RE: Casio fx-3800P "Programming"
(03-09-2020 10:50 AM)Csaba Tizedes Wrote:  
(03-07-2020 02:34 AM)Dave Britten Wrote:  Not sure what the upper limit is on program complexity for the 3800...

Check Xerxes' posts here: https://www.hpmuseum.org/forum/thread-7772.html
New dimensions in blind programming. Highly recommended the GCD routine and do not forget two times press the minus key before running! Is there someone who can explain Wink how this program works with this constant feature?! Big Grin

Cs.

That's pretty clever switching in and out of Base-n mode to extract the integer part. I'm used to Casios requiring you to define your program mode up front (Comp, Base-N, SD, LR, etc.), and it never occurred to me that you could switch on the fly with these keystroke-programmable models.
Visit this user's website Find all posts by this user
Quote this message in a reply
03-10-2020, 01:33 PM
Post: #14
RE: Casio fx-3800P "Programming"
(03-07-2020 12:18 PM)grsbanks Wrote:  I recently acquired a Tandy EC-4019, which appears to be one of those Casio OEM machines. In this instance it's a rebranded Casio fx-3800P. I'll have to try this on it.

Xerxes adviced for me to use the fx-180P Plus. This is a fastest "blind programmable" and fortunately not blind programmable, because there is a possibility to edit and modify the code.

The smallest counter (1 M+ RTN) program speed is exactly 100 counts/sec(!) which is really notable.

[Image: FX-180P-Plus-persp2.jpg]

Today evening (CET) I will go back with a little program for my 50F, which can be run on any similar unit.

Csaba
Find all posts by this user
Quote this message in a reply
03-10-2020, 11:02 PM
Post: #15
RE: Casio fx-3800P "Programming"
(03-10-2020 01:33 PM)Csaba Tizedes Wrote:  Today evening (CET) I will go back with a little program for my 50F, which can be run on any similar unit.

Estimating real numbers with fractions
======================================

Let K is a (real) number and estimate it with the fraction A/B, where A and B are relative primes and ABS(A/B-K)<=E, where E is a small number. The algorithm is a simple brute-force-counting algorithm: Let A=0 and B=1. If ABS(A/B-K)<=E, the program stops. If A/B-K<0 then A=A+1, else B=B+1.


The above in BASIC:
-------------------
10 D=A/B-K
20 IF E>=ABS(D) THEN PRINT A,B:END
30 IF D<0 THEN A=A+1:GOTO 10
40 B=B+1:GOTO10


On blind programmable CASIOs:
-----------------------------

Code:
P1:
-----------
01:  Kout4
     Min
     Kout5
     M-      // M=K-E
-----------
05:  1
     Kin+1   // A++
-----------
07:  Kout1
     ÷
     Kout2
     =
     Kin3    // let H=A/B
     x<=M    // H<K-E ?
-----------
13:  1
     Kin-1   // A--
     Kin+2   // B++
-----------
16:  Kout5
     M+
     M+      // let M=K+E
     Kout3
     -
     MR
     =
     x>0     // H>K+E ?
-----------
24:  1
     Kin+1
26:  Kin-2   // end of the program
-----------
     alphaA  // only for display the numerator and
     alphaB  // denominator
-----------

Variables:
----------
K1: A (numerator)
K2: B (denominator)
K3: H (=A/B)
K4: K (the number)
K5: E (eps = absolute error of estimation; can be calculated as percent of K for relative error)
M: for decisions


For type in: (let K=PI)
------------
1 Kin1 Kin2
PI Kin4 ×0.001 = Kin5


For running:
------------
0 Kin1 1 Kin2 P1


The results:
------------
Tested on CASIO fx-50F
Code:

+--------------+-----+-----+----------------------+---------------------------+-------------+
|   E(rel) (%) |   A |   B |   Running time (sec) |   Number of steps (A+B-1) |   Steps/sec |
+--------------+-----+-----+----------------------+---------------------------+-------------+
|      1       |  19 |   6 |                 12.9 |                        24 |        1.86 |
|      0.1     |  22 |   7 |                 14.9 |                        28 |        1.88 |
|      0.01    | 289 |  92 |                189.6 |                       380 |        2.00 |
|      0.001   | 355 | 113 |                232.2 |                       467 |        2.01 |
+--------------+-----+-----+----------------------+---------------------------+-------------+

Short explanation:
------------------
In 05~12 steps the A is increased until H>K-E.
If we are in K+/-E "good" range (tested in step 23) the program ends...
...or A is too high and H>K+E, in this case we must to increase the B.
We can increase B in the following way: first decrease A in step 14 because in steps 05~12 the A will be increased during the next cycle and the original A will be present and increase B in step 15.
Important: the H is not changed when A and B changed, because H is required in step 23, but when the program finished, must to correct A and B in step 24~26.


nJoy! Big Grin

Csaba
Find all posts by this user
Quote this message in a reply
03-11-2020, 12:06 AM
Post: #16
RE: Casio fx-3800P "Programming"
(03-06-2020 02:42 PM)Dave Britten Wrote:  You wouldn't think it would be possible to write a prime factor finder on a calculator with no Int or Frac functions, and no flow control besides "once more from the top",

Well done! I love it to check the limits of this type of keystroke programming.

I use normally these steps for INT and FRAC:

Code:
Rounding:

01  FIX0
02  RND
03  NORM

Integer part:

01  -
02  .
03  5
04  =
05  FIX0
06  RND
07  NORM

Fractional part:

01  Kin1
02  -
03  .
04  5
05  =
06  FIX0
07  RND
08  NORM
09  Kin-1
10  Kout1

Round(x)-x to loop, if the fractional part is not zero:

01  Kin1
02  FIX0
03  RND
04  NORM
05  Kin-1
06  Kout1
07  x^2
08  x>0

Round(x)-x to stop, if the fractional part is zero:

01  Kin1
02  FIX0
03  RND
04  NORM
05  Kin-1
06  Kout1
07  1/x

Calculator Benchmark
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 4 Guest(s)