Average Error: 42.6 → 19.0
Time: 33.3s
Precision: 64
\[100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\]
\[\begin{array}{l} \mathbf{if}\;i \le -1.5720465037026253 \cdot 10^{-287}:\\ \;\;\;\;\frac{\mathsf{expm1}\left(n \cdot \mathsf{log1p}\left(\frac{i}{n}\right)\right) \cdot 100}{\frac{i}{n}}\\ \mathbf{elif}\;i \le 3.5578967950695884 \cdot 10^{-291}:\\ \;\;\;\;\left(n \cdot \frac{{\left(\frac{i}{n} + 1\right)}^{n} - 1}{i}\right) \cdot 100\\ \mathbf{elif}\;i \le 2.4265255985886543 \cdot 10^{+183}:\\ \;\;\;\;\frac{\mathsf{expm1}\left(n \cdot \mathsf{log1p}\left(\frac{i}{n}\right)\right) \cdot 100}{\frac{i}{n}}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array}\]
100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}
\begin{array}{l}
\mathbf{if}\;i \le -1.5720465037026253 \cdot 10^{-287}:\\
\;\;\;\;\frac{\mathsf{expm1}\left(n \cdot \mathsf{log1p}\left(\frac{i}{n}\right)\right) \cdot 100}{\frac{i}{n}}\\

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

\mathbf{elif}\;i \le 2.4265255985886543 \cdot 10^{+183}:\\
\;\;\;\;\frac{\mathsf{expm1}\left(n \cdot \mathsf{log1p}\left(\frac{i}{n}\right)\right) \cdot 100}{\frac{i}{n}}\\

\mathbf{else}:\\
\;\;\;\;0\\

\end{array}
double f(double i, double n) {
        double r5579548 = 100.0;
        double r5579549 = 1.0;
        double r5579550 = i;
        double r5579551 = n;
        double r5579552 = r5579550 / r5579551;
        double r5579553 = r5579549 + r5579552;
        double r5579554 = pow(r5579553, r5579551);
        double r5579555 = r5579554 - r5579549;
        double r5579556 = r5579555 / r5579552;
        double r5579557 = r5579548 * r5579556;
        return r5579557;
}

double f(double i, double n) {
        double r5579558 = i;
        double r5579559 = -1.5720465037026253e-287;
        bool r5579560 = r5579558 <= r5579559;
        double r5579561 = n;
        double r5579562 = r5579558 / r5579561;
        double r5579563 = log1p(r5579562);
        double r5579564 = r5579561 * r5579563;
        double r5579565 = expm1(r5579564);
        double r5579566 = 100.0;
        double r5579567 = r5579565 * r5579566;
        double r5579568 = r5579567 / r5579562;
        double r5579569 = 3.5578967950695884e-291;
        bool r5579570 = r5579558 <= r5579569;
        double r5579571 = 1.0;
        double r5579572 = r5579562 + r5579571;
        double r5579573 = pow(r5579572, r5579561);
        double r5579574 = r5579573 - r5579571;
        double r5579575 = r5579574 / r5579558;
        double r5579576 = r5579561 * r5579575;
        double r5579577 = r5579576 * r5579566;
        double r5579578 = 2.4265255985886543e+183;
        bool r5579579 = r5579558 <= r5579578;
        double r5579580 = 0.0;
        double r5579581 = r5579579 ? r5579568 : r5579580;
        double r5579582 = r5579570 ? r5579577 : r5579581;
        double r5579583 = r5579560 ? r5579568 : r5579582;
        return r5579583;
}

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.6
Target42.2
Herbie19.0
\[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 < -1.5720465037026253e-287 or 3.5578967950695884e-291 < i < 2.4265255985886543e+183

    1. Initial program 43.2

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

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

      \[\leadsto 100 \cdot \frac{\color{blue}{\mathsf{expm1}\left(\log \left(1 + \frac{i}{n}\right) \cdot n\right)}}{\frac{i}{n}}\]
    5. Using strategy rm
    6. Applied associate-*r/37.6

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

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

    if -1.5720465037026253e-287 < i < 3.5578967950695884e-291

    1. Initial program 47.2

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

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

    if 2.4265255985886543e+183 < i

    1. Initial program 30.3

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;i \le -1.5720465037026253 \cdot 10^{-287}:\\ \;\;\;\;\frac{\mathsf{expm1}\left(n \cdot \mathsf{log1p}\left(\frac{i}{n}\right)\right) \cdot 100}{\frac{i}{n}}\\ \mathbf{elif}\;i \le 3.5578967950695884 \cdot 10^{-291}:\\ \;\;\;\;\left(n \cdot \frac{{\left(\frac{i}{n} + 1\right)}^{n} - 1}{i}\right) \cdot 100\\ \mathbf{elif}\;i \le 2.4265255985886543 \cdot 10^{+183}:\\ \;\;\;\;\frac{\mathsf{expm1}\left(n \cdot \mathsf{log1p}\left(\frac{i}{n}\right)\right) \cdot 100}{\frac{i}{n}}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array}\]

Reproduce

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