Average Error: 42.3 → 11.7
Time: 33.1s
Precision: 64
\[100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\]
\[\begin{array}{l} \mathbf{if}\;i \le -3.074115167804112:\\ \;\;\;\;\frac{1}{\frac{\frac{i}{n}}{\sqrt[3]{\mathsf{fma}\left(e^{\mathsf{log1p}\left(\frac{i}{n}\right) \cdot n}, 100, -100\right) \cdot \left(\mathsf{fma}\left(e^{\mathsf{log1p}\left(\frac{i}{n}\right) \cdot n}, 100, -100\right) \cdot \mathsf{fma}\left(e^{\mathsf{log1p}\left(\frac{i}{n}\right) \cdot n}, 100, -100\right)\right)}}}\\ \mathbf{elif}\;i \le 1.5588973207876802:\\ \;\;\;\;\frac{1}{\mathsf{fma}\left(\frac{-1}{200}, \frac{i}{n}, \mathsf{fma}\left(\frac{\frac{i}{n}}{n}, \frac{1}{200}, \frac{1}{\frac{n}{\frac{1}{100}}}\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\frac{\frac{i}{n}}{\mathsf{fma}\left(50, \left(\log n \cdot n\right) \cdot \left(\log n \cdot n\right), \mathsf{fma}\left(\log i \cdot n, 100, \mathsf{fma}\left(\frac{50}{3}, \left(\log i \cdot n\right) \cdot \left(\left(\log i \cdot n\right) \cdot \left(\log i \cdot n\right)\right), \mathsf{fma}\left(\left(\log i \cdot n\right) \cdot \left(\log i \cdot n\right), 50, 50 \cdot \left(\left(\left(\log n \cdot n\right) \cdot \left(\log n \cdot n\right)\right) \cdot \left(\log i \cdot n\right)\right)\right)\right)\right)\right) - \mathsf{fma}\left(\frac{100}{3} \cdot \left(n \cdot \left(n \cdot n\right)\right), \left(\log n \cdot \log i\right) \cdot \log i, \mathsf{fma}\left(\log n \cdot \log i, \left(n \cdot n\right) \cdot 100, \mathsf{fma}\left(\frac{50}{3}, \mathsf{fma}\left(\log n \cdot \log n, \log n, \left(\log n \cdot \log i\right) \cdot \log i\right) \cdot \left(n \cdot \left(n \cdot n\right)\right), \left(\log n \cdot n\right) \cdot 100\right)\right)\right)}}\\ \end{array}\]
100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}
\begin{array}{l}
\mathbf{if}\;i \le -3.074115167804112:\\
\;\;\;\;\frac{1}{\frac{\frac{i}{n}}{\sqrt[3]{\mathsf{fma}\left(e^{\mathsf{log1p}\left(\frac{i}{n}\right) \cdot n}, 100, -100\right) \cdot \left(\mathsf{fma}\left(e^{\mathsf{log1p}\left(\frac{i}{n}\right) \cdot n}, 100, -100\right) \cdot \mathsf{fma}\left(e^{\mathsf{log1p}\left(\frac{i}{n}\right) \cdot n}, 100, -100\right)\right)}}}\\

\mathbf{elif}\;i \le 1.5588973207876802:\\
\;\;\;\;\frac{1}{\mathsf{fma}\left(\frac{-1}{200}, \frac{i}{n}, \mathsf{fma}\left(\frac{\frac{i}{n}}{n}, \frac{1}{200}, \frac{1}{\frac{n}{\frac{1}{100}}}\right)\right)}\\

\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{\frac{i}{n}}{\mathsf{fma}\left(50, \left(\log n \cdot n\right) \cdot \left(\log n \cdot n\right), \mathsf{fma}\left(\log i \cdot n, 100, \mathsf{fma}\left(\frac{50}{3}, \left(\log i \cdot n\right) \cdot \left(\left(\log i \cdot n\right) \cdot \left(\log i \cdot n\right)\right), \mathsf{fma}\left(\left(\log i \cdot n\right) \cdot \left(\log i \cdot n\right), 50, 50 \cdot \left(\left(\left(\log n \cdot n\right) \cdot \left(\log n \cdot n\right)\right) \cdot \left(\log i \cdot n\right)\right)\right)\right)\right)\right) - \mathsf{fma}\left(\frac{100}{3} \cdot \left(n \cdot \left(n \cdot n\right)\right), \left(\log n \cdot \log i\right) \cdot \log i, \mathsf{fma}\left(\log n \cdot \log i, \left(n \cdot n\right) \cdot 100, \mathsf{fma}\left(\frac{50}{3}, \mathsf{fma}\left(\log n \cdot \log n, \log n, \left(\log n \cdot \log i\right) \cdot \log i\right) \cdot \left(n \cdot \left(n \cdot n\right)\right), \left(\log n \cdot n\right) \cdot 100\right)\right)\right)}}\\

\end{array}
double f(double i, double n) {
        double r4216394 = 100.0;
        double r4216395 = 1.0;
        double r4216396 = i;
        double r4216397 = n;
        double r4216398 = r4216396 / r4216397;
        double r4216399 = r4216395 + r4216398;
        double r4216400 = pow(r4216399, r4216397);
        double r4216401 = r4216400 - r4216395;
        double r4216402 = r4216401 / r4216398;
        double r4216403 = r4216394 * r4216402;
        return r4216403;
}

double f(double i, double n) {
        double r4216404 = i;
        double r4216405 = -3.074115167804112;
        bool r4216406 = r4216404 <= r4216405;
        double r4216407 = 1.0;
        double r4216408 = n;
        double r4216409 = r4216404 / r4216408;
        double r4216410 = log1p(r4216409);
        double r4216411 = r4216410 * r4216408;
        double r4216412 = exp(r4216411);
        double r4216413 = 100.0;
        double r4216414 = -100.0;
        double r4216415 = fma(r4216412, r4216413, r4216414);
        double r4216416 = r4216415 * r4216415;
        double r4216417 = r4216415 * r4216416;
        double r4216418 = cbrt(r4216417);
        double r4216419 = r4216409 / r4216418;
        double r4216420 = r4216407 / r4216419;
        double r4216421 = 1.5588973207876802;
        bool r4216422 = r4216404 <= r4216421;
        double r4216423 = -0.005;
        double r4216424 = r4216409 / r4216408;
        double r4216425 = 0.005;
        double r4216426 = 0.01;
        double r4216427 = r4216408 / r4216426;
        double r4216428 = r4216407 / r4216427;
        double r4216429 = fma(r4216424, r4216425, r4216428);
        double r4216430 = fma(r4216423, r4216409, r4216429);
        double r4216431 = r4216407 / r4216430;
        double r4216432 = 50.0;
        double r4216433 = log(r4216408);
        double r4216434 = r4216433 * r4216408;
        double r4216435 = r4216434 * r4216434;
        double r4216436 = log(r4216404);
        double r4216437 = r4216436 * r4216408;
        double r4216438 = 16.666666666666668;
        double r4216439 = r4216437 * r4216437;
        double r4216440 = r4216437 * r4216439;
        double r4216441 = r4216435 * r4216437;
        double r4216442 = r4216432 * r4216441;
        double r4216443 = fma(r4216439, r4216432, r4216442);
        double r4216444 = fma(r4216438, r4216440, r4216443);
        double r4216445 = fma(r4216437, r4216413, r4216444);
        double r4216446 = fma(r4216432, r4216435, r4216445);
        double r4216447 = 33.333333333333336;
        double r4216448 = r4216408 * r4216408;
        double r4216449 = r4216408 * r4216448;
        double r4216450 = r4216447 * r4216449;
        double r4216451 = r4216433 * r4216436;
        double r4216452 = r4216451 * r4216436;
        double r4216453 = r4216448 * r4216413;
        double r4216454 = r4216433 * r4216433;
        double r4216455 = fma(r4216454, r4216433, r4216452);
        double r4216456 = r4216455 * r4216449;
        double r4216457 = r4216434 * r4216413;
        double r4216458 = fma(r4216438, r4216456, r4216457);
        double r4216459 = fma(r4216451, r4216453, r4216458);
        double r4216460 = fma(r4216450, r4216452, r4216459);
        double r4216461 = r4216446 - r4216460;
        double r4216462 = r4216409 / r4216461;
        double r4216463 = r4216407 / r4216462;
        double r4216464 = r4216422 ? r4216431 : r4216463;
        double r4216465 = r4216406 ? r4216420 : r4216464;
        return r4216465;
}

Error

Bits error versus i

Bits error versus n

Target

Original42.3
Target42.0
Herbie11.7
\[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 3 regimes
  2. if i < -3.074115167804112

    1. Initial program 27.8

      \[100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\]
    2. Simplified27.8

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left({\left(1 + \frac{i}{n}\right)}^{n}, 100, -100\right)}{\frac{i}{n}}}\]
    3. Using strategy rm
    4. Applied add-exp-log27.8

      \[\leadsto \frac{\mathsf{fma}\left(\color{blue}{e^{\log \left({\left(1 + \frac{i}{n}\right)}^{n}\right)}}, 100, -100\right)}{\frac{i}{n}}\]
    5. Simplified5.4

      \[\leadsto \frac{\mathsf{fma}\left(e^{\color{blue}{n \cdot \mathsf{log1p}\left(\frac{i}{n}\right)}}, 100, -100\right)}{\frac{i}{n}}\]
    6. Using strategy rm
    7. Applied *-un-lft-identity5.4

      \[\leadsto \frac{\color{blue}{1 \cdot \mathsf{fma}\left(e^{n \cdot \mathsf{log1p}\left(\frac{i}{n}\right)}, 100, -100\right)}}{\frac{i}{n}}\]
    8. Applied associate-/l*5.4

      \[\leadsto \color{blue}{\frac{1}{\frac{\frac{i}{n}}{\mathsf{fma}\left(e^{n \cdot \mathsf{log1p}\left(\frac{i}{n}\right)}, 100, -100\right)}}}\]
    9. Using strategy rm
    10. Applied add-cbrt-cube5.4

      \[\leadsto \frac{1}{\frac{\frac{i}{n}}{\color{blue}{\sqrt[3]{\left(\mathsf{fma}\left(e^{n \cdot \mathsf{log1p}\left(\frac{i}{n}\right)}, 100, -100\right) \cdot \mathsf{fma}\left(e^{n \cdot \mathsf{log1p}\left(\frac{i}{n}\right)}, 100, -100\right)\right) \cdot \mathsf{fma}\left(e^{n \cdot \mathsf{log1p}\left(\frac{i}{n}\right)}, 100, -100\right)}}}}\]

    if -3.074115167804112 < i < 1.5588973207876802

    1. Initial program 49.6

      \[100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\]
    2. Simplified49.6

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left({\left(1 + \frac{i}{n}\right)}^{n}, 100, -100\right)}{\frac{i}{n}}}\]
    3. Using strategy rm
    4. Applied add-exp-log49.6

      \[\leadsto \frac{\mathsf{fma}\left(\color{blue}{e^{\log \left({\left(1 + \frac{i}{n}\right)}^{n}\right)}}, 100, -100\right)}{\frac{i}{n}}\]
    5. Simplified48.6

      \[\leadsto \frac{\mathsf{fma}\left(e^{\color{blue}{n \cdot \mathsf{log1p}\left(\frac{i}{n}\right)}}, 100, -100\right)}{\frac{i}{n}}\]
    6. Using strategy rm
    7. Applied *-un-lft-identity48.6

      \[\leadsto \frac{\color{blue}{1 \cdot \mathsf{fma}\left(e^{n \cdot \mathsf{log1p}\left(\frac{i}{n}\right)}, 100, -100\right)}}{\frac{i}{n}}\]
    8. Applied associate-/l*48.6

      \[\leadsto \color{blue}{\frac{1}{\frac{\frac{i}{n}}{\mathsf{fma}\left(e^{n \cdot \mathsf{log1p}\left(\frac{i}{n}\right)}, 100, -100\right)}}}\]
    9. Taylor expanded around 0 13.4

      \[\leadsto \frac{1}{\color{blue}{\left(\frac{1}{200} \cdot \frac{i}{{n}^{2}} + \frac{1}{100} \cdot \frac{1}{n}\right) - \frac{1}{200} \cdot \frac{i}{n}}}\]
    10. Simplified12.0

      \[\leadsto \frac{1}{\color{blue}{\mathsf{fma}\left(\frac{-1}{200}, \frac{i}{n}, \mathsf{fma}\left(\frac{\frac{i}{n}}{n}, \frac{1}{200}, \frac{\frac{1}{100}}{n}\right)\right)}}\]
    11. Using strategy rm
    12. Applied *-un-lft-identity12.0

      \[\leadsto \frac{1}{\mathsf{fma}\left(\frac{-1}{200}, \frac{i}{n}, \mathsf{fma}\left(\frac{\frac{i}{n}}{n}, \frac{1}{200}, \frac{\color{blue}{1 \cdot \frac{1}{100}}}{n}\right)\right)}\]
    13. Applied associate-/l*12.0

      \[\leadsto \frac{1}{\mathsf{fma}\left(\frac{-1}{200}, \frac{i}{n}, \mathsf{fma}\left(\frac{\frac{i}{n}}{n}, \frac{1}{200}, \color{blue}{\frac{1}{\frac{n}{\frac{1}{100}}}}\right)\right)}\]

    if 1.5588973207876802 < i

    1. Initial program 30.9

      \[100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\]
    2. Simplified30.9

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left({\left(1 + \frac{i}{n}\right)}^{n}, 100, -100\right)}{\frac{i}{n}}}\]
    3. Using strategy rm
    4. Applied add-exp-log30.9

      \[\leadsto \frac{\mathsf{fma}\left(\color{blue}{e^{\log \left({\left(1 + \frac{i}{n}\right)}^{n}\right)}}, 100, -100\right)}{\frac{i}{n}}\]
    5. Simplified50.5

      \[\leadsto \frac{\mathsf{fma}\left(e^{\color{blue}{n \cdot \mathsf{log1p}\left(\frac{i}{n}\right)}}, 100, -100\right)}{\frac{i}{n}}\]
    6. Using strategy rm
    7. Applied *-un-lft-identity50.5

      \[\leadsto \frac{\color{blue}{1 \cdot \mathsf{fma}\left(e^{n \cdot \mathsf{log1p}\left(\frac{i}{n}\right)}, 100, -100\right)}}{\frac{i}{n}}\]
    8. Applied associate-/l*50.5

      \[\leadsto \color{blue}{\frac{1}{\frac{\frac{i}{n}}{\mathsf{fma}\left(e^{n \cdot \mathsf{log1p}\left(\frac{i}{n}\right)}, 100, -100\right)}}}\]
    9. Taylor expanded around 0 21.5

      \[\leadsto \frac{1}{\frac{\frac{i}{n}}{\color{blue}{\left(50 \cdot \left({n}^{2} \cdot {\left(\log n\right)}^{2}\right) + \left(\frac{50}{3} \cdot \left({n}^{3} \cdot {\left(\log i\right)}^{3}\right) + \left(100 \cdot \left(n \cdot \log i\right) + \left(\frac{100}{3} \cdot \left({n}^{3} \cdot \left({\left(\log n\right)}^{2} \cdot \log i\right)\right) + \left(\frac{50}{3} \cdot \left({n}^{3} \cdot \left(\log i \cdot {\left(\log n\right)}^{2}\right)\right) + 50 \cdot \left({n}^{2} \cdot {\left(\log i\right)}^{2}\right)\right)\right)\right)\right)\right) - \left(\frac{100}{3} \cdot \left({n}^{3} \cdot \left({\left(\log i\right)}^{2} \cdot \log n\right)\right) + \left(50 \cdot \left({n}^{2} \cdot \left(\log n \cdot \log i\right)\right) + \left(50 \cdot \left({n}^{2} \cdot \left(\log i \cdot \log n\right)\right) + \left(\frac{50}{3} \cdot \left({n}^{3} \cdot {\left(\log n\right)}^{3}\right) + \left(\frac{50}{3} \cdot \left({n}^{3} \cdot \left(\log n \cdot {\left(\log i\right)}^{2}\right)\right) + 100 \cdot \left(n \cdot \log n\right)\right)\right)\right)\right)\right)}}}\]
    10. Simplified21.5

      \[\leadsto \frac{1}{\frac{\frac{i}{n}}{\color{blue}{\mathsf{fma}\left(50, \left(n \cdot \log n\right) \cdot \left(n \cdot \log n\right), \mathsf{fma}\left(\log i \cdot n, 100, \mathsf{fma}\left(\frac{50}{3}, \left(\log i \cdot n\right) \cdot \left(\left(\log i \cdot n\right) \cdot \left(\log i \cdot n\right)\right), \mathsf{fma}\left(\left(\log i \cdot n\right) \cdot \left(\log i \cdot n\right), 50, \left(\left(\log i \cdot n\right) \cdot \left(\left(n \cdot \log n\right) \cdot \left(n \cdot \log n\right)\right)\right) \cdot 50\right)\right)\right)\right) - \mathsf{fma}\left(\left(n \cdot \left(n \cdot n\right)\right) \cdot \frac{100}{3}, \log i \cdot \left(\log i \cdot \log n\right), \mathsf{fma}\left(\log i \cdot \log n, \left(n \cdot n\right) \cdot 100, \mathsf{fma}\left(\frac{50}{3}, \left(n \cdot \left(n \cdot n\right)\right) \cdot \mathsf{fma}\left(\log n \cdot \log n, \log n, \log i \cdot \left(\log i \cdot \log n\right)\right), \left(\log n \cdot n\right) \cdot 100\right)\right)\right)}}}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification11.7

    \[\leadsto \begin{array}{l} \mathbf{if}\;i \le -3.074115167804112:\\ \;\;\;\;\frac{1}{\frac{\frac{i}{n}}{\sqrt[3]{\mathsf{fma}\left(e^{\mathsf{log1p}\left(\frac{i}{n}\right) \cdot n}, 100, -100\right) \cdot \left(\mathsf{fma}\left(e^{\mathsf{log1p}\left(\frac{i}{n}\right) \cdot n}, 100, -100\right) \cdot \mathsf{fma}\left(e^{\mathsf{log1p}\left(\frac{i}{n}\right) \cdot n}, 100, -100\right)\right)}}}\\ \mathbf{elif}\;i \le 1.5588973207876802:\\ \;\;\;\;\frac{1}{\mathsf{fma}\left(\frac{-1}{200}, \frac{i}{n}, \mathsf{fma}\left(\frac{\frac{i}{n}}{n}, \frac{1}{200}, \frac{1}{\frac{n}{\frac{1}{100}}}\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\frac{\frac{i}{n}}{\mathsf{fma}\left(50, \left(\log n \cdot n\right) \cdot \left(\log n \cdot n\right), \mathsf{fma}\left(\log i \cdot n, 100, \mathsf{fma}\left(\frac{50}{3}, \left(\log i \cdot n\right) \cdot \left(\left(\log i \cdot n\right) \cdot \left(\log i \cdot n\right)\right), \mathsf{fma}\left(\left(\log i \cdot n\right) \cdot \left(\log i \cdot n\right), 50, 50 \cdot \left(\left(\left(\log n \cdot n\right) \cdot \left(\log n \cdot n\right)\right) \cdot \left(\log i \cdot n\right)\right)\right)\right)\right)\right) - \mathsf{fma}\left(\frac{100}{3} \cdot \left(n \cdot \left(n \cdot n\right)\right), \left(\log n \cdot \log i\right) \cdot \log i, \mathsf{fma}\left(\log n \cdot \log i, \left(n \cdot n\right) \cdot 100, \mathsf{fma}\left(\frac{50}{3}, \mathsf{fma}\left(\log n \cdot \log n, \log n, \left(\log n \cdot \log i\right) \cdot \log i\right) \cdot \left(n \cdot \left(n \cdot n\right)\right), \left(\log n \cdot n\right) \cdot 100\right)\right)\right)}}\\ \end{array}\]

Reproduce

herbie shell --seed 2019138 +o rules:numerics
(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))))