1

What is the best way to check if a parameter increase in a mathematical expression increases or decreases the expression as a whole (in Python, preferably SymPy)?

Assumptions: all parameters are positive (i.e. > 0).

Example A*B/(A+C): A should be found as proportional to the expression and C should be found as inverse proportional.

One obvious solution would be to assign 1 to all parameters, 1 and 100 to C respectively and apply eval(), but that is very crude and might yield errors (e.g. with (A-B)/C where the best case would be to give an error instead of a wrong result).

Michael Schubert
  • 2,726
  • 4
  • 27
  • 49

1 Answers1

1

I don't believe this can be solved in the general case. A simple counter-example is sin(A), which could be both proportional and inverse proportional, depending on what value of A you are evaluating it at.

However, you could use an automatic differentiation tool, such as PyDX or Theano, to compute the derivative of functions at various parameter values.

  • Thank you for the answer. Differentiation is a nice idea, but then I'd prefer numerical methods as they are way less computationally expensive. – Michael Schubert May 26 '11 at 19:55
  • For one-shot computation, yes. If you're going to be testing a single function at multiple parameter values, AD is probably just as efficient. –  May 26 '11 at 20:23
  • True, but: in my case I only need to test each expression once ;-) Any recommendation for a tool that does this as a one-liner? – Michael Schubert May 26 '11 at 20:37