Average Error: 42.5 → 18.1
Time: 28.4s
Precision: 64
\[100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\]
\[\begin{array}{l} \mathbf{if}\;n \le -0.8249084896539374:\\ \;\;\;\;100 \cdot \frac{\mathsf{expm1}\left(i\right)}{\frac{i}{n}}\\ \mathbf{elif}\;n \le -2.7004764031193593 \cdot 10^{-129}:\\ \;\;\;\;\frac{\sqrt[3]{\left(\left(\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{i}{n}\right) \cdot n\right) \cdot \mathsf{expm1}\left(\mathsf{log1p}\left(\frac{i}{n}\right) \cdot n\right)\right) \cdot \mathsf{expm1}\left(\mathsf{log1p}\left(\frac{i}{n}\right) \cdot n\right)\right) \cdot 1000000}}{\frac{i}{n}}\\ \mathbf{elif}\;n \le -1.1007636657452675 \cdot 10^{-234}:\\ \;\;\;\;\frac{100 \cdot \mathsf{expm1}\left(\mathsf{log1p}\left(\frac{i}{n}\right) \cdot n\right)}{\frac{i}{n}}\\ \mathbf{elif}\;n \le 5.476973539989824 \cdot 10^{-182}:\\ \;\;\;\;0\\ \mathbf{else}:\\ \;\;\;\;100 \cdot \frac{1}{\frac{\frac{i}{n}}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{i}{n}\right) \cdot n\right)}}\\ \end{array}\]
100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}
\begin{array}{l}
\mathbf{if}\;n \le -0.8249084896539374:\\
\;\;\;\;100 \cdot \frac{\mathsf{expm1}\left(i\right)}{\frac{i}{n}}\\

\mathbf{elif}\;n \le -2.7004764031193593 \cdot 10^{-129}:\\
\;\;\;\;\frac{\sqrt[3]{\left(\left(\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{i}{n}\right) \cdot n\right) \cdot \mathsf{expm1}\left(\mathsf{log1p}\left(\frac{i}{n}\right) \cdot n\right)\right) \cdot \mathsf{expm1}\left(\mathsf{log1p}\left(\frac{i}{n}\right) \cdot n\right)\right) \cdot 1000000}}{\frac{i}{n}}\\

\mathbf{elif}\;n \le -1.1007636657452675 \cdot 10^{-234}:\\
\;\;\;\;\frac{100 \cdot \mathsf{expm1}\left(\mathsf{log1p}\left(\frac{i}{n}\right) \cdot n\right)}{\frac{i}{n}}\\

\mathbf{elif}\;n \le 5.476973539989824 \cdot 10^{-182}:\\
\;\;\;\;0\\

\mathbf{else}:\\
\;\;\;\;100 \cdot \frac{1}{\frac{\frac{i}{n}}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{i}{n}\right) \cdot n\right)}}\\

\end{array}
double f(double i, double n) {
        double r4535355 = 100.0;
        double r4535356 = 1.0;
        double r4535357 = i;
        double r4535358 = n;
        double r4535359 = r4535357 / r4535358;
        double r4535360 = r4535356 + r4535359;
        double r4535361 = pow(r4535360, r4535358);
        double r4535362 = r4535361 - r4535356;
        double r4535363 = r4535362 / r4535359;
        double r4535364 = r4535355 * r4535363;
        return r4535364;
}

double f(double i, double n) {
        double r4535365 = n;
        double r4535366 = -0.8249084896539374;
        bool r4535367 = r4535365 <= r4535366;
        double r4535368 = 100.0;
        double r4535369 = i;
        double r4535370 = expm1(r4535369);
        double r4535371 = r4535369 / r4535365;
        double r4535372 = r4535370 / r4535371;
        double r4535373 = r4535368 * r4535372;
        double r4535374 = -2.7004764031193593e-129;
        bool r4535375 = r4535365 <= r4535374;
        double r4535376 = log1p(r4535371);
        double r4535377 = r4535376 * r4535365;
        double r4535378 = expm1(r4535377);
        double r4535379 = r4535378 * r4535378;
        double r4535380 = r4535379 * r4535378;
        double r4535381 = 1000000.0;
        double r4535382 = r4535380 * r4535381;
        double r4535383 = cbrt(r4535382);
        double r4535384 = r4535383 / r4535371;
        double r4535385 = -1.1007636657452675e-234;
        bool r4535386 = r4535365 <= r4535385;
        double r4535387 = r4535368 * r4535378;
        double r4535388 = r4535387 / r4535371;
        double r4535389 = 5.476973539989824e-182;
        bool r4535390 = r4535365 <= r4535389;
        double r4535391 = 0.0;
        double r4535392 = 1.0;
        double r4535393 = r4535371 / r4535378;
        double r4535394 = r4535392 / r4535393;
        double r4535395 = r4535368 * r4535394;
        double r4535396 = r4535390 ? r4535391 : r4535395;
        double r4535397 = r4535386 ? r4535388 : r4535396;
        double r4535398 = r4535375 ? r4535384 : r4535397;
        double r4535399 = r4535367 ? r4535373 : r4535398;
        return r4535399;
}

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.5
Target42.6
Herbie18.1
\[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 5 regimes
  2. if n < -0.8249084896539374

    1. Initial program 45.2

      \[100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\]
    2. Using strategy rm
    3. Applied add-exp-log52.9

      \[\leadsto 100 \cdot \frac{{\color{blue}{\left(e^{\log \left(1 + \frac{i}{n}\right)}\right)}}^{n} - 1}{\frac{i}{n}}\]
    4. Applied pow-exp52.9

      \[\leadsto 100 \cdot \frac{\color{blue}{e^{\log \left(1 + \frac{i}{n}\right) \cdot n}} - 1}{\frac{i}{n}}\]
    5. Applied expm1-def52.9

      \[\leadsto 100 \cdot \frac{\color{blue}{\mathsf{expm1}\left(\log \left(1 + \frac{i}{n}\right) \cdot n\right)}}{\frac{i}{n}}\]
    6. Taylor expanded around 0 24.9

      \[\leadsto 100 \cdot \frac{\mathsf{expm1}\left(\color{blue}{i}\right)}{\frac{i}{n}}\]

    if -0.8249084896539374 < n < -2.7004764031193593e-129

    1. Initial program 18.4

      \[100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\]
    2. Using strategy rm
    3. Applied add-exp-log18.4

      \[\leadsto 100 \cdot \frac{{\color{blue}{\left(e^{\log \left(1 + \frac{i}{n}\right)}\right)}}^{n} - 1}{\frac{i}{n}}\]
    4. Applied pow-exp18.4

      \[\leadsto 100 \cdot \frac{\color{blue}{e^{\log \left(1 + \frac{i}{n}\right) \cdot n}} - 1}{\frac{i}{n}}\]
    5. Applied expm1-def1.8

      \[\leadsto 100 \cdot \frac{\color{blue}{\mathsf{expm1}\left(\log \left(1 + \frac{i}{n}\right) \cdot n\right)}}{\frac{i}{n}}\]
    6. Using strategy rm
    7. Applied log1p-expm1-u1.8

      \[\leadsto 100 \cdot \frac{\mathsf{expm1}\left(\color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\log \left(1 + \frac{i}{n}\right)\right)\right)} \cdot n\right)}{\frac{i}{n}}\]
    8. Simplified31.9

      \[\leadsto 100 \cdot \frac{\mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{\frac{i}{n}}\right) \cdot n\right)}{\frac{i}{n}}\]
    9. Using strategy rm
    10. Applied associate-*r/31.8

      \[\leadsto \color{blue}{\frac{100 \cdot \mathsf{expm1}\left(\mathsf{log1p}\left(\frac{i}{n}\right) \cdot n\right)}{\frac{i}{n}}}\]
    11. Using strategy rm
    12. Applied add-cbrt-cube9.2

      \[\leadsto \frac{100 \cdot \color{blue}{\sqrt[3]{\left(\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{i}{n}\right) \cdot n\right) \cdot \mathsf{expm1}\left(\mathsf{log1p}\left(\frac{i}{n}\right) \cdot n\right)\right) \cdot \mathsf{expm1}\left(\mathsf{log1p}\left(\frac{i}{n}\right) \cdot n\right)}}}{\frac{i}{n}}\]
    13. Applied add-cbrt-cube9.2

      \[\leadsto \frac{\color{blue}{\sqrt[3]{\left(100 \cdot 100\right) \cdot 100}} \cdot \sqrt[3]{\left(\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{i}{n}\right) \cdot n\right) \cdot \mathsf{expm1}\left(\mathsf{log1p}\left(\frac{i}{n}\right) \cdot n\right)\right) \cdot \mathsf{expm1}\left(\mathsf{log1p}\left(\frac{i}{n}\right) \cdot n\right)}}{\frac{i}{n}}\]
    14. Applied cbrt-unprod9.2

      \[\leadsto \frac{\color{blue}{\sqrt[3]{\left(\left(100 \cdot 100\right) \cdot 100\right) \cdot \left(\left(\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{i}{n}\right) \cdot n\right) \cdot \mathsf{expm1}\left(\mathsf{log1p}\left(\frac{i}{n}\right) \cdot n\right)\right) \cdot \mathsf{expm1}\left(\mathsf{log1p}\left(\frac{i}{n}\right) \cdot n\right)\right)}}}{\frac{i}{n}}\]
    15. Simplified9.2

      \[\leadsto \frac{\sqrt[3]{\color{blue}{\left(\left(\mathsf{expm1}\left(n \cdot \mathsf{log1p}\left(\frac{i}{n}\right)\right) \cdot \mathsf{expm1}\left(n \cdot \mathsf{log1p}\left(\frac{i}{n}\right)\right)\right) \cdot \mathsf{expm1}\left(n \cdot \mathsf{log1p}\left(\frac{i}{n}\right)\right)\right) \cdot 1000000}}}{\frac{i}{n}}\]

    if -2.7004764031193593e-129 < n < -1.1007636657452675e-234

    1. Initial program 14.4

      \[100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\]
    2. Using strategy rm
    3. Applied add-exp-log14.4

      \[\leadsto 100 \cdot \frac{{\color{blue}{\left(e^{\log \left(1 + \frac{i}{n}\right)}\right)}}^{n} - 1}{\frac{i}{n}}\]
    4. Applied pow-exp14.4

      \[\leadsto 100 \cdot \frac{\color{blue}{e^{\log \left(1 + \frac{i}{n}\right) \cdot n}} - 1}{\frac{i}{n}}\]
    5. Applied expm1-def3.3

      \[\leadsto 100 \cdot \frac{\color{blue}{\mathsf{expm1}\left(\log \left(1 + \frac{i}{n}\right) \cdot n\right)}}{\frac{i}{n}}\]
    6. Using strategy rm
    7. Applied log1p-expm1-u3.3

      \[\leadsto 100 \cdot \frac{\mathsf{expm1}\left(\color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\log \left(1 + \frac{i}{n}\right)\right)\right)} \cdot n\right)}{\frac{i}{n}}\]
    8. Simplified16.0

      \[\leadsto 100 \cdot \frac{\mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{\frac{i}{n}}\right) \cdot n\right)}{\frac{i}{n}}\]
    9. Using strategy rm
    10. Applied associate-*r/15.9

      \[\leadsto \color{blue}{\frac{100 \cdot \mathsf{expm1}\left(\mathsf{log1p}\left(\frac{i}{n}\right) \cdot n\right)}{\frac{i}{n}}}\]

    if -1.1007636657452675e-234 < n < 5.476973539989824e-182

    1. Initial program 28.9

      \[100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\]
    2. Using strategy rm
    3. Applied add-exp-log28.9

      \[\leadsto 100 \cdot \frac{{\color{blue}{\left(e^{\log \left(1 + \frac{i}{n}\right)}\right)}}^{n} - 1}{\frac{i}{n}}\]
    4. Applied pow-exp28.9

      \[\leadsto 100 \cdot \frac{\color{blue}{e^{\log \left(1 + \frac{i}{n}\right) \cdot n}} - 1}{\frac{i}{n}}\]
    5. Applied expm1-def21.3

      \[\leadsto 100 \cdot \frac{\color{blue}{\mathsf{expm1}\left(\log \left(1 + \frac{i}{n}\right) \cdot n\right)}}{\frac{i}{n}}\]
    6. Using strategy rm
    7. Applied log1p-expm1-u21.3

      \[\leadsto 100 \cdot \frac{\mathsf{expm1}\left(\color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\log \left(1 + \frac{i}{n}\right)\right)\right)} \cdot n\right)}{\frac{i}{n}}\]
    8. Simplified16.4

      \[\leadsto 100 \cdot \frac{\mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{\frac{i}{n}}\right) \cdot n\right)}{\frac{i}{n}}\]
    9. Taylor expanded around 0 14.0

      \[\leadsto \color{blue}{0}\]

    if 5.476973539989824e-182 < n

    1. Initial program 57.6

      \[100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\]
    2. Using strategy rm
    3. Applied add-exp-log57.6

      \[\leadsto 100 \cdot \frac{{\color{blue}{\left(e^{\log \left(1 + \frac{i}{n}\right)}\right)}}^{n} - 1}{\frac{i}{n}}\]
    4. Applied pow-exp57.6

      \[\leadsto 100 \cdot \frac{\color{blue}{e^{\log \left(1 + \frac{i}{n}\right) \cdot n}} - 1}{\frac{i}{n}}\]
    5. Applied expm1-def51.3

      \[\leadsto 100 \cdot \frac{\color{blue}{\mathsf{expm1}\left(\log \left(1 + \frac{i}{n}\right) \cdot n\right)}}{\frac{i}{n}}\]
    6. Using strategy rm
    7. Applied log1p-expm1-u51.3

      \[\leadsto 100 \cdot \frac{\mathsf{expm1}\left(\color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\log \left(1 + \frac{i}{n}\right)\right)\right)} \cdot n\right)}{\frac{i}{n}}\]
    8. Simplified16.4

      \[\leadsto 100 \cdot \frac{\mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{\frac{i}{n}}\right) \cdot n\right)}{\frac{i}{n}}\]
    9. Using strategy rm
    10. Applied clear-num16.6

      \[\leadsto 100 \cdot \color{blue}{\frac{1}{\frac{\frac{i}{n}}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{i}{n}\right) \cdot n\right)}}}\]
  3. Recombined 5 regimes into one program.
  4. Final simplification18.1

    \[\leadsto \begin{array}{l} \mathbf{if}\;n \le -0.8249084896539374:\\ \;\;\;\;100 \cdot \frac{\mathsf{expm1}\left(i\right)}{\frac{i}{n}}\\ \mathbf{elif}\;n \le -2.7004764031193593 \cdot 10^{-129}:\\ \;\;\;\;\frac{\sqrt[3]{\left(\left(\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{i}{n}\right) \cdot n\right) \cdot \mathsf{expm1}\left(\mathsf{log1p}\left(\frac{i}{n}\right) \cdot n\right)\right) \cdot \mathsf{expm1}\left(\mathsf{log1p}\left(\frac{i}{n}\right) \cdot n\right)\right) \cdot 1000000}}{\frac{i}{n}}\\ \mathbf{elif}\;n \le -1.1007636657452675 \cdot 10^{-234}:\\ \;\;\;\;\frac{100 \cdot \mathsf{expm1}\left(\mathsf{log1p}\left(\frac{i}{n}\right) \cdot n\right)}{\frac{i}{n}}\\ \mathbf{elif}\;n \le 5.476973539989824 \cdot 10^{-182}:\\ \;\;\;\;0\\ \mathbf{else}:\\ \;\;\;\;100 \cdot \frac{1}{\frac{\frac{i}{n}}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{i}{n}\right) \cdot n\right)}}\\ \end{array}\]

Reproduce

herbie shell --seed 2019168 +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))))