![]() |
![]() |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
This article has been rewritten. Also, the full Delphi project with source code and an excerciser program are made available. Click here Introduction This article describes the translation of a mathematical formula into a sequence of basic operations. The method was developed for Graphics-Explorer, a versatile program to investigate various types of functions and equations. (Click here to see specifications or to download Graphics-Explorer) Graphics-Explorer may handle up to 9 different equations of 4 different types simultaniously:
The same translation proces is used for all types of equations. The final result of the translation is the 'director-table', a list of basic calculations in the order of their priority. In the following description, the formula y = 3.2 + 1.6(x-0.5) + 0.22x^2 will be translated. Multiply operator insertion Before the translation starts, the multiply operator '*' is inserted where needed. This changes the formula to y = 3.2 + 1.6*(x-0.5) + 0.22*x^2 Also, any blank characters are removed. Priority Because of different priorities of the operators + * ^, the value of y cannot be calculated simply in the 'left to right' sequence. The priority of an operation is the sum of two values: 1. the biaspriority:
biaspriority by 10, where occurrence of ')' decreases this priority by 10.
Constants and variables In the formula above, constants 3.2 , 1.6 , 0.5 and 0.22 are noticed as well as variables x and y. These values are stored in an array called Freg[1..250] (floating point registers) as follows:
After scanning above formula (as number 1), Freg will look like:
The constants are stored in the sequence of their occurrence. The Director table This table is the final result of the translation. Each row describes a basic arithmetic operation or function and has the form:
For clarity, x and y are printed instead of 200 and 201. Also, operators +,-,*,^ are printed instead of the numeric code, indicating that operator. The meaning of row 1 is:
of the director table from top to bottom. After executing row 7, the final result is hold by Freg[201] (y). The Priority Table This table is an intermediate during formula-string to Director Table translation. A row of the priority table has the form:
The first 2 colums, red row by row, resemble the formula string with constants and variables replaced by their reference to the Freg[] array. The third column indicates the priority of the operation and is the addition of operator- and bias priority. Notice, that row 4 has the priority 13, not 3, because a '(' parenthesis has been passed. The translation The Director Table is built while eliminating the Priority Table row by row, always taking the operation with the highest priority first.
The operation of row 4 is removed from the priority table and added to the director table. Since registers x and 22 may not be modified, the first register for intermediate results, 1, receives the difference. Now, row 6 has the highest priority.
The result is stored in register 2, the next available register for intermediate results.
Register 1 is overwritten, not to waste registers 1..19 continuing the process:
Continuing:
And after the next step:
And after the last step:
This completes the translation. Additional notes Functions like sin, cos, abs are treated the same way as operators +,- etc. however the source1 operand is ignored. The separator character ';' for parametric functions (type 3) is regarded as a dummy operator with lowest priority. This prevents interaction between values of x and y. The calculated values for x and y are available in Freg[200] and Freg[201] after processing the director table. Intrinsic functions (type 4) treat the '=' operator as a '-' operator. An intrinsic function f(x) = g(x) is transformed to v = f(x) - g(x). A dot (x,y) is plotted if v = 0. If v changes sign, the dot (x,y) with the lowest absolute value is plotted. Graphics-Explorer contains debug code for examining the tables. This code is activated/deactivated by typing The unairy '-' operator is shown as (-). David E. Dirkse, May 2004, the Netherlands david@davdata.nl
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
![]() |
![]() |