Average Error: 42.3 → 19.6
Time: 26.9s
Precision: 64
\[100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\]
\[\begin{array}{l} \mathbf{if}\;n \le -1.1462618234168955:\\ \;\;\;\;\left(\frac{\left(\left(i \cdot i\right) \cdot \frac{1}{2} + i\right) + \left(i \cdot i\right) \cdot \left(i \cdot \frac{1}{6}\right)}{i} \cdot n\right) \cdot 100\\ \mathbf{elif}\;n \le 5.351279663469521 \cdot 10^{-167}:\\ \;\;\;\;0\\ \mathbf{else}:\\ \;\;\;\;\left(\frac{\left(\left(i \cdot i\right) \cdot \frac{1}{2} + i\right) + \left(i \cdot i\right) \cdot \left(i \cdot \frac{1}{6}\right)}{i} \cdot n\right) \cdot 100\\ \end{array}\]
100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}
\begin{array}{l}
\mathbf{if}\;n \le -1.1462618234168955:\\
\;\;\;\;\left(\frac{\left(\left(i \cdot i\right) \cdot \frac{1}{2} + i\right) + \left(i \cdot i\right) \cdot \left(i \cdot \frac{1}{6}\right)}{i} \cdot n\right) \cdot 100\\

\mathbf{elif}\;n \le 5.351279663469521 \cdot 10^{-167}:\\
\;\;\;\;0\\

\mathbf{else}:\\
\;\;\;\;\left(\frac{\left(\left(i \cdot i\right) \cdot \frac{1}{2} + i\right) + \left(i \cdot i\right) \cdot \left(i \cdot \frac{1}{6}\right)}{i} \cdot n\right) \cdot 100\\

\end{array}
double f(double i, double n) {
        double r5361767 = 100.0;
        double r5361768 = 1.0;
        double r5361769 = i;
        double r5361770 = n;
        double r5361771 = r5361769 / r5361770;
        double r5361772 = r5361768 + r5361771;
        double r5361773 = pow(r5361772, r5361770);
        double r5361774 = r5361773 - r5361768;
        double r5361775 = r5361774 / r5361771;
        double r5361776 = r5361767 * r5361775;
        return r5361776;
}

double f(double i, double n) {
        double r5361777 = n;
        double r5361778 = -1.1462618234168955;
        bool r5361779 = r5361777 <= r5361778;
        double r5361780 = i;
        double r5361781 = r5361780 * r5361780;
        double r5361782 = 0.5;
        double r5361783 = r5361781 * r5361782;
        double r5361784 = r5361783 + r5361780;
        double r5361785 = 0.16666666666666666;
        double r5361786 = r5361780 * r5361785;
        double r5361787 = r5361781 * r5361786;
        double r5361788 = r5361784 + r5361787;
        double r5361789 = r5361788 / r5361780;
        double r5361790 = r5361789 * r5361777;
        double r5361791 = 100.0;
        double r5361792 = r5361790 * r5361791;
        double r5361793 = 5.351279663469521e-167;
        bool r5361794 = r5361777 <= r5361793;
        double r5361795 = 0.0;
        double r5361796 = r5361794 ? r5361795 : r5361792;
        double r5361797 = r5361779 ? r5361792 : r5361796;
        return r5361797;
}

Error

Bits error versus i

Bits error versus n

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original42.3
Target42.4
Herbie19.6
\[100 \cdot \frac{e^{n \cdot \begin{array}{l} \mathbf{if}\;1 + \frac{i}{n} = 1:\\ \;\;\;\;\frac{i}{n}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{i}{n} \cdot \log \left(1 + \frac{i}{n}\right)}{\left(\frac{i}{n} + 1\right) - 1}\\ \end{array}} - 1}{\frac{i}{n}}\]

Derivation

  1. Split input into 2 regimes
  2. if n < -1.1462618234168955 or 5.351279663469521e-167 < n

    1. Initial program 52.3

      \[100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\]
    2. Taylor expanded around 0 36.6

      \[\leadsto 100 \cdot \frac{\color{blue}{i + \left(\frac{1}{2} \cdot {i}^{2} + \frac{1}{6} \cdot {i}^{3}\right)}}{\frac{i}{n}}\]
    3. Simplified36.6

      \[\leadsto 100 \cdot \frac{\color{blue}{\left(\frac{1}{2} \cdot i\right) \cdot i + \left(\frac{1}{6} \cdot \left(i \cdot \left(i \cdot i\right)\right) + i\right)}}{\frac{i}{n}}\]
    4. Using strategy rm
    5. Applied associate-/r/21.1

      \[\leadsto 100 \cdot \color{blue}{\left(\frac{\left(\frac{1}{2} \cdot i\right) \cdot i + \left(\frac{1}{6} \cdot \left(i \cdot \left(i \cdot i\right)\right) + i\right)}{i} \cdot n\right)}\]
    6. Simplified21.1

      \[\leadsto 100 \cdot \left(\color{blue}{\frac{\left(i + \left(i \cdot i\right) \cdot \frac{1}{2}\right) + \left(i \cdot \frac{1}{6}\right) \cdot \left(i \cdot i\right)}{i}} \cdot n\right)\]

    if -1.1462618234168955 < n < 5.351279663469521e-167

    1. Initial program 21.6

      \[100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\]
    2. Taylor expanded around 0 16.5

      \[\leadsto \color{blue}{0}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification19.6

    \[\leadsto \begin{array}{l} \mathbf{if}\;n \le -1.1462618234168955:\\ \;\;\;\;\left(\frac{\left(\left(i \cdot i\right) \cdot \frac{1}{2} + i\right) + \left(i \cdot i\right) \cdot \left(i \cdot \frac{1}{6}\right)}{i} \cdot n\right) \cdot 100\\ \mathbf{elif}\;n \le 5.351279663469521 \cdot 10^{-167}:\\ \;\;\;\;0\\ \mathbf{else}:\\ \;\;\;\;\left(\frac{\left(\left(i \cdot i\right) \cdot \frac{1}{2} + i\right) + \left(i \cdot i\right) \cdot \left(i \cdot \frac{1}{6}\right)}{i} \cdot n\right) \cdot 100\\ \end{array}\]

Reproduce

herbie shell --seed 2019158 
(FPCore (i n)
  :name "Compound Interest"

  :herbie-target
  (* 100 (/ (- (exp (* n (if (== (+ 1 (/ i n)) 1) (/ i n) (/ (* (/ i n) (log (+ 1 (/ i n)))) (- (+ (/ i n) 1) 1))))) 1) (/ i n)))

  (* 100 (/ (- (pow (+ 1 (/ i n)) n) 1) (/ i n))))