TICALCS.net

Full Version: Optimization
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Discuss tips and tricks for optimizing TI-BASIC programs for the z80 calculators...

Let me start off with one of the most basic of optimizations, wherein closing parentheses (")") and end-quotes ('"') can be omitted from the end of a full line of code. In addition, note that parentheses and quotes can be omitted from the left of a "store" operation ("->"), because the code to the left of such an operation is treated as a full line.

Example:

Code:
(1-A)/(B/(4+C)+1)->D


Is more optimal as the following (saving one byte):

Code:
(1-A)/(B/(4+C)+1->D


And even better (saving two bytes):

Code:
(1-A)/(1+B/(4+C->D


Note that the aforementioned optimizations do not have a very high yield, but when they are used out of habit when writing code, they do add up, so to speak.

Booleans!

When programming, if you have something like

Code:
If X=5
X+1→X

Then you can use

Code:
(X=5)+X→X

This works because X=5 is evaluated to either 1 (true) or 0 (false) first, and then the result is added to X.
Also, adding Vladik's optimization:

Code:
X+(X=5→X



Get rid of =0 or ≠0.
This is some commonly seen code in a beginner's program:

Code:
If X=0
// Do stuff

or

Code:
If X≠0
// Do stuff

However, you can optimize these:

Code:
If not(X

and

Code:
If X

These work because any non-zero value is evaluated to true. Therefore, if X is any non-zero value, then the second example will be true. not( reverses true or false, so if X is zero the first example will evaluate to true.

Reference URL's