title: Parsing an equation with custom functions in Python
body: <p>I have a string that is a mathematical equation, but with some custom functions. I need to find all such functions and replace them with some code.</p>
  
  <p>For example, I have a string:</p>
  
  <pre><code>a+b+f1(f2(x,y),x)
  </code></pre>
  
  <p>I want code that will replace (say) <code>f2(x,y)</code> with <code>x+y^2</code> and <code>f1(x,y)</code> with <code>sin(x+y)</code>.</p>
  
  <p>It would be ideal if nested functions were supported, like in the example. However, it would still be useful if nesting was not supported.</p>
  
  <p>As I understand from similar topics this can be done using a compiler module like <code>compiler.parse(eq)</code>. How I can work with AST object created by <code>compiler.parse(eq)</code> to reconstruct my string back, replacing all found functions?</p>
  
  <p>I need only to perform substitution and then string will be used in other program. Evaluation is not needed.</p>