From: | Karsten Nyblad <148f3wg02@sneakemail.com> |
Newsgroups: | comp.compilers |
Date: | 15 Nov 2006 00:10:33 -0500 |
Organization: | Compilers Central |
References: | 06-11-052 |
Keywords: | interpreter |
Posted-Date: | 15 Nov 2006 00:10:33 EST |
PAolo wrote:
> I am writing a piece of software that accept in input the definition
> of a mathematical function and a list of points in which evaluate the
> function and puts the result in output. The main feature of the progam
> is that once the function definition is read, the program evaluates
> the function very fast [Well this isn't done already...]. I was
> thinking to build a pair of stacks, one containig the operands
> (floats) and the other containig the operators (function pointers).
You have stated the problem in such a way that it can be implemented
by vector operations, e.g., f(x) = cos(x) + sin(x) on 1.2 2.6 3.8 4.1
5.0 can be calculated by first calculating the vector cos(1.2)
cos(2.6) cos(3.8) cos(4.1) cos(5.0), then the vector sin(1.2) sin(2.6)
sin(3.8) sin(4.1) sin(5.0), and at last adding the two vectors.
Assume the function takes more than one argument. The you are simply
working with more than one vector, e.g., let f(x,y,z) = tan(z) +
cos(y) * exp(x) on (1,2,3), (4,5,6), (7,8,9) and (10,11,12). Then you
define three vectors X = 1, 4, 7, 10 and Y = 2, 5, 8, 11 and Z = 3, 6,
9, 12. Then you calculate the vectors tan(Z), cos(Y) and exp(X)
followed by the vector cos(Y)*exp(X) and at last the vector tan(Z) +
cos(y)*exp(X).
Now it does not make sense to compile the function at all. The price of
doing if my way is that you should have main storage enough for keeping
the intermediate result vectors.
Karsten Nyblad
Return to the
comp.compilers page.
Search the
comp.compilers archives again.