100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\begin{array}{l}
\mathbf{if}\;i \le -0.24222034813966126:\\
\;\;\;\;100 \cdot \frac{\frac{{\left(1 + \frac{i}{n}\right)}^{\left(2 \cdot n\right)} + \left(-1 \cdot 1\right)}{{\left(1 + \frac{i}{n}\right)}^{n} + 1}}{\frac{i}{n}}\\
\mathbf{elif}\;i \le 0.011056763714875576:\\
\;\;\;\;100 \cdot \left(\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} \cdot n\right)\\
\mathbf{else}:\\
\;\;\;\;100 \cdot \frac{\mathsf{fma}\left(1, i, \mathsf{fma}\left(\log 1, n, 1\right)\right) - 1}{\frac{i}{n}}\\
\end{array}double code(double i, double n) {
return (100.0 * ((pow((1.0 + (i / n)), n) - 1.0) / (i / n)));
}
double code(double i, double n) {
double VAR;
if ((i <= -0.24222034813966126)) {
VAR = (100.0 * (((pow((1.0 + (i / n)), (2.0 * n)) + -(1.0 * 1.0)) / (pow((1.0 + (i / n)), n) + 1.0)) / (i / n)));
} else {
double VAR_1;
if ((i <= 0.011056763714875576)) {
VAR_1 = (100.0 * ((fma(i, 1.0, (fma(0.5, pow(i, 2.0), (log(1.0) * n)) - (0.5 * (pow(i, 2.0) * log(1.0))))) / i) * n));
} else {
VAR_1 = (100.0 * ((fma(1.0, i, fma(log(1.0), n, 1.0)) - 1.0) / (i / n)));
}
VAR = VAR_1;
}
return VAR;
}




Bits error versus i




Bits error versus n
Results
| Original | 47.4 |
|---|---|
| Target | 47.7 |
| Herbie | 17.8 |
if i < -0.24222034813966126Initial program 27.1
rmApplied flip--27.1
Simplified27.1
if -0.24222034813966126 < i < 0.011056763714875576Initial program 58.3
Taylor expanded around 0 26.1
Simplified26.1
rmApplied associate-/r/9.2
if 0.011056763714875576 < i Initial program 31.3
Taylor expanded around 0 41.2
Simplified41.2
Final simplification17.8
herbie shell --seed 2020092 +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))))