Post Reply 
INV DSZ in its natural habitat
10-15-2021, 01:56 PM
Post: #1
INV DSZ in its natural habitat
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:

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 Wink 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.
Visit this user's website Find all posts by this user
Quote this message in a reply
10-15-2021, 04:18 PM
Post: #2
RE: INV DSZ in its natural habitat
I assume these two statements are used to implement the following types of loop (expressed in C syntax), in which case both have their place.

Code:
/* DSZ */
do {
...
} while (--x != 0)

whereas

Code:
/* INV DSZ (or DSNZ) */
while (--x != 0) {
...
}
Find all posts by this user
Quote this message in a reply
10-15-2021, 04:24 PM
Post: #3
RE: INV DSZ in its natural habitat
Kind of. It's more akin to this, at least in my example:

Code:
 c = 10;
while (true) {
  //do stuff
  if (--c == 0) break;
  //do more stuff
}
Visit this user's website Find all posts by this user
Quote this message in a reply
10-16-2021, 12:12 AM
Post: #4
RE: INV DSZ in its natural habitat
Dave,
Someone at TI found INV DSZ useful since it was used in steps 28-29 of their Battleship program in the SR-56 Application Library book, p. 188.
Ross
Find all posts by this user
Quote this message in a reply
10-18-2021, 06:38 PM
Post: #5
RE: INV DSZ in its natural habitat
INV DSZ/ISZ can be usefull in some cases. Here a size optimized code for the TI-62 to calculate the factoral:

Code:
00 *
01 INV DSZ
02 R/S
03 RCL 0

Usage example: 69 STO 0 RST R/S

Calculator Benchmark
Find all posts by this user
Quote this message in a reply
10-19-2021, 06:54 PM
Post: #6
RE: INV DSZ in its natural habitat
(10-18-2021 06:38 PM)xerxes Wrote:  INV DSZ/ISZ can be usefull in some cases. Here a size optimized code for the TI-62 to calculate the factoral:

Code:
00 *
01 INV DSZ
02 R/S
03 RCL 0

Usage example: 69 STO 0 RST R/S

Nice, didn't realize the lower-end machines had it too. I wonder if it works on the TI-65.
Visit this user's website Find all posts by this user
Quote this message in a reply
10-19-2021, 09:03 PM
Post: #7
RE: INV DSZ in its natural habitat
(10-19-2021 06:54 PM)Dave Britten Wrote:  Nice, didn't realize the lower-end machines had it too. I wonder if it works on the TI-65.

INV DSZ is also present on the TI-65, but I'm not sure, if the code works on the TI-65 too, because it based on the circular program execution ability of the TI-62.

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




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