Average Error: 42.2 → 18.5
Time: 24.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.2657089139394981:\\ \;\;\;\;100 \cdot \frac{\mathsf{expm1}\left(n \cdot \mathsf{log1p}\left(\frac{i}{n}\right)\right)}{\frac{i}{n}}\\ \mathbf{elif}\;n \le -5.215706912201119 \cdot 10^{-75}:\\ \;\;\;\;100 \cdot \frac{\frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{i}}{\frac{1}{n}}\\ \mathbf{elif}\;n \le -1.2129113627355937 \cdot 10^{-111}:\\ \;\;\;\;\left(n \cdot \mathsf{expm1}\left(n \cdot \mathsf{log1p}\left(\frac{i}{n}\right)\right)\right) \cdot \frac{100}{i}\\ \mathbf{elif}\;n \le 7.188766975051312 \cdot 10^{-261}:\\ \;\;\;\;0\\ \mathbf{else}:\\ \;\;\;\;100 \cdot \frac{\mathsf{expm1}\left(n \cdot \mathsf{log1p}\left(\frac{i}{n}\right)\right)}{\frac{i}{n}}\\ \end{array}\]
100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}
\begin{array}{l}
\mathbf{if}\;n \le -1.2657089139394981:\\
\;\;\;\;100 \cdot \frac{\mathsf{expm1}\left(n \cdot \mathsf{log1p}\left(\frac{i}{n}\right)\right)}{\frac{i}{n}}\\

\mathbf{elif}\;n \le -5.215706912201119 \cdot 10^{-75}:\\
\;\;\;\;100 \cdot \frac{\frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{i}}{\frac{1}{n}}\\

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

\mathbf{elif}\;n \le 7.188766975051312 \cdot 10^{-261}:\\
\;\;\;\;0\\

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

\end{array}
double f(double i, double n) {
        double r2191463 = 100.0;
        double r2191464 = 1.0;
        double r2191465 = i;
        double r2191466 = n;
        double r2191467 = r2191465 / r2191466;
        double r2191468 = r2191464 + r2191467;
        double r2191469 = pow(r2191468, r2191466);
        double r2191470 = r2191469 - r2191464;
        double r2191471 = r2191470 / r2191467;
        double r2191472 = r2191463 * r2191471;
        return r2191472;
}

double f(double i, double n) {
        double r2191473 = n;
        double r2191474 = -1.2657089139394981;
        bool r2191475 = r2191473 <= r2191474;
        double r2191476 = 100.0;
        double r2191477 = i;
        double r2191478 = r2191477 / r2191473;
        double r2191479 = log1p(r2191478);
        double r2191480 = r2191473 * r2191479;
        double r2191481 = expm1(r2191480);
        double r2191482 = r2191481 / r2191478;
        double r2191483 = r2191476 * r2191482;
        double r2191484 = -5.215706912201119e-75;
        bool r2191485 = r2191473 <= r2191484;
        double r2191486 = 1.0;
        double r2191487 = r2191486 + r2191478;
        double r2191488 = pow(r2191487, r2191473);
        double r2191489 = r2191488 - r2191486;
        double r2191490 = r2191489 / r2191477;
        double r2191491 = r2191486 / r2191473;
        double r2191492 = r2191490 / r2191491;
        double r2191493 = r2191476 * r2191492;
        double r2191494 = -1.2129113627355937e-111;
        bool r2191495 = r2191473 <= r2191494;
        double r2191496 = r2191473 * r2191481;
        double r2191497 = r2191476 / r2191477;
        double r2191498 = r2191496 * r2191497;
        double r2191499 = 7.188766975051312e-261;
        bool r2191500 = r2191473 <= r2191499;
        double r2191501 = 0.0;
        double r2191502 = r2191500 ? r2191501 : r2191483;
        double r2191503 = r2191495 ? r2191498 : r2191502;
        double r2191504 = r2191485 ? r2191493 : r2191503;
        double r2191505 = r2191475 ? r2191483 : r2191504;
        return r2191505;
}

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.2
Target42.2
Herbie18.5
\[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 4 regimes
  2. if n < -1.2657089139394981 or 7.188766975051312e-261 < n

    1. Initial program 51.3

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

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

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

      \[\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-u50.5

      \[\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. Simplified19.8

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

    if -1.2657089139394981 < n < -5.215706912201119e-75

    1. Initial program 18.2

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

      \[\leadsto 100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\color{blue}{i \cdot \frac{1}{n}}}\]
    4. Applied associate-/r*18.4

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

    if -5.215706912201119e-75 < n < -1.2129113627355937e-111

    1. Initial program 20.2

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

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

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

      \[\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-u2.2

      \[\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. Simplified29.6

      \[\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/29.5

      \[\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 div-inv29.6

      \[\leadsto \frac{100 \cdot \mathsf{expm1}\left(\mathsf{log1p}\left(\frac{i}{n}\right) \cdot n\right)}{\color{blue}{i \cdot \frac{1}{n}}}\]
    13. Applied times-frac20.6

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

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

    if -1.2129113627355937e-111 < n < 7.188766975051312e-261

    1. Initial program 16.4

      \[100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\]
    2. Using strategy rm
    3. Applied add-exp-log16.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-exp16.4

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

      \[\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 12.4

      \[\leadsto \color{blue}{0}\]
  3. Recombined 4 regimes into one program.
  4. Final simplification18.5

    \[\leadsto \begin{array}{l} \mathbf{if}\;n \le -1.2657089139394981:\\ \;\;\;\;100 \cdot \frac{\mathsf{expm1}\left(n \cdot \mathsf{log1p}\left(\frac{i}{n}\right)\right)}{\frac{i}{n}}\\ \mathbf{elif}\;n \le -5.215706912201119 \cdot 10^{-75}:\\ \;\;\;\;100 \cdot \frac{\frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{i}}{\frac{1}{n}}\\ \mathbf{elif}\;n \le -1.2129113627355937 \cdot 10^{-111}:\\ \;\;\;\;\left(n \cdot \mathsf{expm1}\left(n \cdot \mathsf{log1p}\left(\frac{i}{n}\right)\right)\right) \cdot \frac{100}{i}\\ \mathbf{elif}\;n \le 7.188766975051312 \cdot 10^{-261}:\\ \;\;\;\;0\\ \mathbf{else}:\\ \;\;\;\;100 \cdot \frac{\mathsf{expm1}\left(n \cdot \mathsf{log1p}\left(\frac{i}{n}\right)\right)}{\frac{i}{n}}\\ \end{array}\]

Reproduce

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