title: Generate algebraic expression at compile time in D
body: <p>Let's consider a function defined as follows:</p>
  
  <pre><code>f(n, x) = F(n, x, f(n-1, x))
  f(0, x) = g(x)
  </code></pre>
  
  <p>In my program the value of <code>n</code> is always known at compile time. I want to optimize my program and avoid loops or recursive calls in this function. Whole expression for <code>f(n, x)</code> should be generated at compile time in order to allow compiler optimize it.</p>
  
  <p>The direct solution is "manually" generate a string containing this expression and use <code>mixin</code> statement. I don't like this way.</p>
  
  <p>Is compiler able/supposed to unfold a recursion with known depth?</p>
  
  <p>I.e. will the following function be optimized in the way I want:</p>
  
  <pre><code>double f(uint n)(double x)
  {
      static if(n == 0)
          return g(x);
      else
          return F(n, x, f!(n-1)(x));
  }
  </code></pre>