10-15-2021, 01:56 PM
Yesterday there was some question as to whether or not the INV DSZ (decrement and skip if not zero) instruction present on some TIs was at all useful. I maintain that it's useful in any situation where you decrement a counter and break out of the middle of a loop, rather than at the end of the loop body.
I put together a little example by way of a cumulative binomial distribution program. First, a BASIC version for the 71B that makes the algorithm a little easier to read:
To use it, run the program, enter the number of trials N, the probability of success in a single trial P, and the number of successful trials X. The program will show the cumulative lower tail binomial probability, i.e. probability of the number of successes being between 0 and X.
Note line 90, where the program decrements a counter, and breaks out of the middle of the loop (lines 80 to 110) when the counter reaches zero.
Now, here are printouts of both an HP 97 version, and a TI-59 version. On the HP version, you have to do something like using an extra LBL and GTO to invert the DSZ test behavior. On the TI-59, you can simply use INV DSZ directly.
To run either of these, store N in R01, P in R02, X in R03, and press A.
https://i.imgur.com/rxENjWN.jpg
Ignoring the fact that the TI program is about twice the size of the HP one
it's clear that this is a case where INV DSZ can be used to save a couple of steps, and make the program flow easier to read.
I put together a little example by way of a cumulative binomial distribution program. First, a BASIC version for the 71B that makes the algorithm a little easier to read:
Code:
0001 DESTROY ALL
0010 INPUT "N?";N
0020 INPUT "P?";P
0030 INPUT "X?";X
0040 T=0 @ R=0
0050 F=P/(1-P)
0060 K=X+1
0070 B=(1-P)^N
0080 T=T+B
0090 K=K-1 @ IF K=0 THEN GOTO 120 @ REM INV DSZ!
0100 B=B*(N-R)/(R+1)*F @ R=R+1
0110 GOTO 80
0120 PRINT T
To use it, run the program, enter the number of trials N, the probability of success in a single trial P, and the number of successful trials X. The program will show the cumulative lower tail binomial probability, i.e. probability of the number of successes being between 0 and X.
Note line 90, where the program decrements a counter, and breaks out of the middle of the loop (lines 80 to 110) when the counter reaches zero.
Now, here are printouts of both an HP 97 version, and a TI-59 version. On the HP version, you have to do something like using an extra LBL and GTO to invert the DSZ test behavior. On the TI-59, you can simply use INV DSZ directly.
To run either of these, store N in R01, P in R02, X in R03, and press A.
https://i.imgur.com/rxENjWN.jpg
Ignoring the fact that the TI program is about twice the size of the HP one
