Re: Fastening the run-time interpretation of mathematical expressions

"Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
13 Nov 2006 16:29:25 -0500

          From comp.compilers

Related articles
Fastening the run-time interpretation of mathematical expressions paolopantaleo@gmail.com (PAolo) (2006-11-11)
Re: Fastening the run-time interpretation of mathematical expressions haberg@math.su.se (2006-11-11)
Re: Fastening the run-time interpretation of mathematical expressions mailbox@dmitry-kazakov.de (Dmitry A. Kazakov) (2006-11-13)
Re: Fastening the run-time interpretation of mathematical expressions akk@privat.de (Andreas Kochenburger) (2006-11-13)
Re: Fastening the run-time interpretation of mathematical expressions martin@gkc.org.uk (Martin Ward) (2006-11-13)
Re: Fastening the run-time interpretation of mathematical expressions tommy.thorn@gmail.com (Tommy Thorn) (2006-11-13)
Re: Fastening the run-time interpretation of mathematical expressions 148f3wg02@sneakemail.com (Karsten Nyblad) (2006-11-15)
Re: Fastening the run-time interpretation of mathematical expressions martin@gkc.org.uk (Martin Ward) (2006-11-15)
Re: Fastening the run-time interpretation of mathematical expressions idknow@gmail.com (idknow@gmail.com) (2006-11-15)
[2 later articles]
| List of all articles for this month |
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Newsgroups: comp.compilers
Date: 13 Nov 2006 16:29:25 -0500
Organization: cbb software GmbH
References: 06-11-052
Keywords: interpreter, performance
Posted-Date: 13 Nov 2006 16:29:25 EST

On 11 Nov 2006 15:50:04 -0500, PAolo wrote:


> Given the RPN expression
> 1 2 + 3 *
> in the two stack forms is (the left of the string is the top of the
> stack):
>|1 2 3| |+ *|


Of course you can split the stack into operations and operands ones. I am
doing this all the time.


> which can also mean RPN
> 1 2 3 + *


It cannot. That were


      |2 3 1| |+ *|


> Question 2: Is always possible to rewrite the expression in the form I
> said? How could I do it automatically?


You need commutated complement operations for that. Consider:


      1 2 3 + /


You cannot rewrite it just as


      |2 3 1| |+ /|


You have to as


      |2 3 1| |+ \|


where a\b = b/a


Each time you swap operands in the stack, you have to change the operation
as well.


Alternatively you can change the operation to inverse complement and mark
an operand using commutative inverse:


      |2 3 1| |+ 1/x *|


here / --> 1/x *


I am using this technique to deal with expressions a+b-c+d, which is parsed
as +(a,b,-c,d). "+" takes four operands. See


http://www.dmitry-kazakov.de/ada/components.htm#Parsers_etc
--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.