100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\begin{array}{l}
\mathbf{if}\;i \le -5.737712731949101 \cdot 10^{-05}:\\
\;\;\;\;\frac{1}{\frac{i}{\mathsf{fma}\left(e^{\mathsf{log1p}\left(\frac{i}{n}\right) \cdot n}, 100, -100\right) \cdot n}}\\
\mathbf{elif}\;i \le 0.0004866774544189746:\\
\;\;\;\;\frac{1}{\mathsf{fma}\left(\frac{-1}{200}, \frac{i}{n}, \mathsf{fma}\left(\frac{\sqrt[3]{i}}{n} \cdot \left(\sqrt[3]{i} \cdot \frac{\sqrt[3]{i}}{n}\right), \frac{1}{200}, \frac{\frac{1}{100}}{n}\right)\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{-100 + {\left(1 + \frac{i}{n}\right)}^{n} \cdot 100}{\frac{i}{n}}\\
\end{array}double f(double i, double n) {
double r4742476 = 100.0;
double r4742477 = 1.0;
double r4742478 = i;
double r4742479 = n;
double r4742480 = r4742478 / r4742479;
double r4742481 = r4742477 + r4742480;
double r4742482 = pow(r4742481, r4742479);
double r4742483 = r4742482 - r4742477;
double r4742484 = r4742483 / r4742480;
double r4742485 = r4742476 * r4742484;
return r4742485;
}
double f(double i, double n) {
double r4742486 = i;
double r4742487 = -5.737712731949101e-05;
bool r4742488 = r4742486 <= r4742487;
double r4742489 = 1.0;
double r4742490 = n;
double r4742491 = r4742486 / r4742490;
double r4742492 = log1p(r4742491);
double r4742493 = r4742492 * r4742490;
double r4742494 = exp(r4742493);
double r4742495 = 100.0;
double r4742496 = -100.0;
double r4742497 = fma(r4742494, r4742495, r4742496);
double r4742498 = r4742497 * r4742490;
double r4742499 = r4742486 / r4742498;
double r4742500 = r4742489 / r4742499;
double r4742501 = 0.0004866774544189746;
bool r4742502 = r4742486 <= r4742501;
double r4742503 = -0.005;
double r4742504 = cbrt(r4742486);
double r4742505 = r4742504 / r4742490;
double r4742506 = r4742504 * r4742505;
double r4742507 = r4742505 * r4742506;
double r4742508 = 0.005;
double r4742509 = 0.01;
double r4742510 = r4742509 / r4742490;
double r4742511 = fma(r4742507, r4742508, r4742510);
double r4742512 = fma(r4742503, r4742491, r4742511);
double r4742513 = r4742489 / r4742512;
double r4742514 = r4742489 + r4742491;
double r4742515 = pow(r4742514, r4742490);
double r4742516 = r4742515 * r4742495;
double r4742517 = r4742496 + r4742516;
double r4742518 = r4742517 / r4742491;
double r4742519 = r4742502 ? r4742513 : r4742518;
double r4742520 = r4742488 ? r4742500 : r4742519;
return r4742520;
}




Bits error versus i




Bits error versus n
| Original | 42.7 |
|---|---|
| Target | 42.2 |
| Herbie | 13.3 |
if i < -5.737712731949101e-05Initial program 29.1
Simplified29.1
rmApplied add-exp-log29.1
Applied pow-exp29.1
Simplified5.7
rmApplied clear-num5.8
rmApplied div-inv5.8
Applied associate-/l*6.2
Simplified6.2
if -5.737712731949101e-05 < i < 0.0004866774544189746Initial program 50.1
Simplified50.1
rmApplied add-exp-log50.1
Applied pow-exp50.1
Simplified49.3
rmApplied clear-num49.3
Taylor expanded around 0 13.3
Simplified13.2
rmApplied add-cube-cbrt13.2
Applied times-frac11.9
Simplified11.9
if 0.0004866774544189746 < i Initial program 31.4
Simplified31.4
rmApplied fma-udef31.4
Final simplification13.3
herbie shell --seed 2019163 +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))))