100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\begin{array}{l}
\mathbf{if}\;i \le -6.8977356701701615 \cdot 10^{-9}:\\
\;\;\;\;100 \cdot \left(\frac{{\left(1 + \frac{i}{n}\right)}^{n}}{\frac{i}{n}} - \frac{1}{\frac{i}{n}}\right)\\
\mathbf{elif}\;i \le 5.88981601408302989 \cdot 10^{-8}:\\
\;\;\;\;100 \cdot \left(\frac{\left({\left(1 + \frac{i}{n}\right)}^{\left(\frac{n}{2}\right)} + \sqrt{1}\right) \cdot \mathsf{fma}\left(i, 0.5, \mathsf{fma}\left(\frac{1}{2}, \log 1 \cdot n, 1\right) - \sqrt{1}\right)}{i} \cdot n\right)\\
\mathbf{else}:\\
\;\;\;\;\left(\left({\left(1 + \frac{i}{n}\right)}^{\left(\frac{n}{2}\right)} + \sqrt{1}\right) \cdot 100\right) \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{\left(\frac{n}{2}\right)} - \sqrt{1}}{\frac{i}{n}}\\
\end{array}double f(double i, double n) {
double r178403 = 100.0;
double r178404 = 1.0;
double r178405 = i;
double r178406 = n;
double r178407 = r178405 / r178406;
double r178408 = r178404 + r178407;
double r178409 = pow(r178408, r178406);
double r178410 = r178409 - r178404;
double r178411 = r178410 / r178407;
double r178412 = r178403 * r178411;
return r178412;
}
double f(double i, double n) {
double r178413 = i;
double r178414 = -6.8977356701701615e-09;
bool r178415 = r178413 <= r178414;
double r178416 = 100.0;
double r178417 = 1.0;
double r178418 = n;
double r178419 = r178413 / r178418;
double r178420 = r178417 + r178419;
double r178421 = pow(r178420, r178418);
double r178422 = r178421 / r178419;
double r178423 = r178417 / r178419;
double r178424 = r178422 - r178423;
double r178425 = r178416 * r178424;
double r178426 = 5.88981601408303e-08;
bool r178427 = r178413 <= r178426;
double r178428 = 2.0;
double r178429 = r178418 / r178428;
double r178430 = pow(r178420, r178429);
double r178431 = sqrt(r178417);
double r178432 = r178430 + r178431;
double r178433 = 0.5;
double r178434 = 0.5;
double r178435 = log(r178417);
double r178436 = r178435 * r178418;
double r178437 = 1.0;
double r178438 = fma(r178434, r178436, r178437);
double r178439 = r178438 - r178431;
double r178440 = fma(r178413, r178433, r178439);
double r178441 = r178432 * r178440;
double r178442 = r178441 / r178413;
double r178443 = r178442 * r178418;
double r178444 = r178416 * r178443;
double r178445 = r178432 * r178416;
double r178446 = r178430 - r178431;
double r178447 = r178446 / r178419;
double r178448 = r178445 * r178447;
double r178449 = r178427 ? r178444 : r178448;
double r178450 = r178415 ? r178425 : r178449;
return r178450;
}




Bits error versus i




Bits error versus n
| Original | 43.2 |
|---|---|
| Target | 42.9 |
| Herbie | 21.6 |
if i < -6.8977356701701615e-09Initial program 29.3
rmApplied div-sub29.3
if -6.8977356701701615e-09 < i < 5.88981601408303e-08Initial program 51.2
rmApplied div-inv51.2
Applied add-sqr-sqrt51.2
Applied sqr-pow51.2
Applied difference-of-squares51.2
Applied times-frac50.9
Simplified50.9
Taylor expanded around 0 50.7
Simplified15.5
rmApplied associate-*r*16.3
rmApplied associate-*l/16.2
if 5.88981601408303e-08 < i Initial program 32.1
rmApplied *-un-lft-identity32.1
Applied *-un-lft-identity32.1
Applied times-frac32.1
Applied add-sqr-sqrt32.1
Applied sqr-pow32.2
Applied difference-of-squares32.2
Applied times-frac32.2
Applied associate-*r*32.2
Simplified32.2
Final simplification21.6
herbie shell --seed 2020060 +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))))