<ehsan.akhgari@gmail.com> wrote:>Is there any upper bounds on the number of temporary variables that are>needed to translate any given mathematical expression? By intuition, I>guess the answer is 2,

To start at the end, I think commutativity is not relevant with three
address code, since if c and d are the wrong way around in "/ c, d,
t2", then you just write "/ d, c, t2".

To answer the original question, it firstly depends on what you include
in the definition of a mathematical expression. If you include
arbitrary mathematical expressions, there is no limit:
f(a0+b, f(a1+b, f(a2+b, f(a3+b, ... f(aN+b)... ))))
requires N+1 temporaries. Of course you might want to disregard
function arguments on the grounds that you're going to push them on a
stack, so they don't take up registers. In that case it depends on the
number of precedences in the language and operator properties. For
example, with (+, *, ^) you may need three: