Reverse Polish Notation
This is a very easy to program way of entering mathematical
expressions into a computer. It comes under other names, too. PostScript
is built on this concept.
A complicated function is built of a series of instructions. An
instruction can be either
- data, e.g., a number or a parameter. Then it is placed onto the
execution stack.
- an operator. The computer takes as many data off the stack as the
operator needs, performs the required operation, and places the result
onto the stack.
This is all! Now you only have to know that within Grafix the function argument is
always called x, and the
parameters p0, ..., p19.
- multiply a value by 1000: x,1000.0,*
- convert degrees
Fahrenheit to degrees Celsius: x,32,-,5,*,9,/
- calculate an exponential,
exp(-a x): x,p0,*,neg,exp
Here we use a parameter, p0, to hold the value of the coefficient a. Parameters are set with the parameters tag pair.
Note that the operators +, -, *, /, ^
(raising to a power) require 2 operands, whereas neg (change sign), inv (take reciprocal) and all
algebraic functions like exp, ln, abs,sin, ... require only 1 operand.