100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\begin{array}{l}
\mathbf{if}\;i \le -0.0281548125542239701 \lor \neg \left(i \le 9.41291569922092328 \cdot 10^{-13}\right):\\
\;\;\;\;\frac{100 \cdot \left({\left(1 + \frac{i}{n}\right)}^{n} - 1\right)}{\frac{i}{n}}\\
\mathbf{else}:\\
\;\;\;\;\left(100 \cdot \frac{\mathsf{fma}\left(i, 1, \mathsf{fma}\left(0.5, {i}^{2}, \log 1 \cdot n\right) - 0.5 \cdot \left({i}^{2} \cdot \log 1\right)\right)}{i}\right) \cdot n\\
\end{array}double f(double i, double n) {
double r126406 = 100.0;
double r126407 = 1.0;
double r126408 = i;
double r126409 = n;
double r126410 = r126408 / r126409;
double r126411 = r126407 + r126410;
double r126412 = pow(r126411, r126409);
double r126413 = r126412 - r126407;
double r126414 = r126413 / r126410;
double r126415 = r126406 * r126414;
return r126415;
}
double f(double i, double n) {
double r126416 = i;
double r126417 = -0.02815481255422397;
bool r126418 = r126416 <= r126417;
double r126419 = 9.412915699220923e-13;
bool r126420 = r126416 <= r126419;
double r126421 = !r126420;
bool r126422 = r126418 || r126421;
double r126423 = 100.0;
double r126424 = 1.0;
double r126425 = n;
double r126426 = r126416 / r126425;
double r126427 = r126424 + r126426;
double r126428 = pow(r126427, r126425);
double r126429 = r126428 - r126424;
double r126430 = r126423 * r126429;
double r126431 = r126430 / r126426;
double r126432 = 0.5;
double r126433 = 2.0;
double r126434 = pow(r126416, r126433);
double r126435 = log(r126424);
double r126436 = r126435 * r126425;
double r126437 = fma(r126432, r126434, r126436);
double r126438 = r126434 * r126435;
double r126439 = r126432 * r126438;
double r126440 = r126437 - r126439;
double r126441 = fma(r126416, r126424, r126440);
double r126442 = r126441 / r126416;
double r126443 = r126423 * r126442;
double r126444 = r126443 * r126425;
double r126445 = r126422 ? r126431 : r126444;
return r126445;
}




Bits error versus i




Bits error versus n
| Original | 47.8 |
|---|---|
| Target | 47.2 |
| Herbie | 17.3 |
if i < -0.02815481255422397 or 9.412915699220923e-13 < i Initial program 30.8
rmApplied associate-*r/30.7
if -0.02815481255422397 < i < 9.412915699220923e-13Initial program 58.2
Taylor expanded around 0 26.5
Simplified26.5
rmApplied associate-/r/9.2
Applied associate-*r*9.2
Final simplification17.3
herbie shell --seed 2020057 +o rules:numerics
(FPCore (i n)
:name "Compound Interest"
:precision binary64
: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))))