100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\begin{array}{l}
\mathbf{if}\;i \leq -5.3039574522220784 \cdot 10^{-05} \lor \neg \left(i \leq 0.005516776241547936\right):\\
\;\;\;\;100 \cdot \left(\frac{n}{i} \cdot \left(-1 + {\left(\frac{i}{n}\right)}^{n}\right)\right)\\
\mathbf{else}:\\
\;\;\;\;100 \cdot \left(n + n \cdot \left(i \cdot \left(0.5 + i \cdot 0.16666666666666666\right)\right)\right)\\
\end{array}(FPCore (i n) :precision binary64 (* 100.0 (/ (- (pow (+ 1.0 (/ i n)) n) 1.0) (/ i n))))
(FPCore (i n) :precision binary64 (if (or (<= i -5.3039574522220784e-05) (not (<= i 0.005516776241547936))) (* 100.0 (* (/ n i) (+ -1.0 (pow (/ i n) n)))) (* 100.0 (+ n (* n (* i (+ 0.5 (* i 0.16666666666666666))))))))
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 tmp;
if ((i <= -5.3039574522220784e-05) || !(i <= 0.005516776241547936)) {
tmp = 100.0 * ((n / i) * (-1.0 + pow((i / n), n)));
} else {
tmp = 100.0 * (n + (n * (i * (0.5 + (i * 0.16666666666666666)))));
}
return tmp;
}




Bits error versus i




Bits error versus n
Results
| Original | 47.4 |
|---|---|
| Target | 47.7 |
| Herbie | 14.6 |
if i < -5.30395745222207843e-5 or 0.00551677624154793631 < i Initial program 29.0
Taylor expanded around inf 51.7
Simplified24.1
if -5.30395745222207843e-5 < i < 0.00551677624154793631Initial program 58.2
Taylor expanded around 0 26.8
Simplified26.8
Taylor expanded around 0 9.1
Simplified9.1
Final simplification14.6
herbie shell --seed 2020260
(FPCore (i n)
:name "Compound Interest"
:precision binary64
:herbie-target
(* 100.0 (/ (- (exp (* n (if (== (+ 1.0 (/ i n)) 1.0) (/ i n) (/ (* (/ i n) (log (+ 1.0 (/ i n)))) (- (+ (/ i n) 1.0) 1.0))))) 1.0) (/ i n)))
(* 100.0 (/ (- (pow (+ 1.0 (/ i n)) n) 1.0) (/ i n))))