100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\begin{array}{l}
\mathbf{if}\;i \leq -3905150655849648:\\
\;\;\;\;100 \cdot \frac{-1 + {\left(\frac{i}{n}\right)}^{n}}{\frac{i}{n}}\\
\mathbf{elif}\;i \leq 9.837932042159025:\\
\;\;\;\;100 \cdot \left(n + n \cdot \left(i \cdot \left(0.5 + i \cdot 0.16666666666666666\right)\right)\right)\\
\mathbf{else}:\\
\;\;\;\;0\\
\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 (<= i -3905150655849648.0)
(* 100.0 (/ (+ -1.0 (pow (/ i n) n)) (/ i n)))
(if (<= i 9.837932042159025)
(* 100.0 (+ n (* n (* i (+ 0.5 (* i 0.16666666666666666))))))
0.0)))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 <= -3905150655849648.0) {
tmp = 100.0 * ((-1.0 + pow((i / n), n)) / (i / n));
} else if (i <= 9.837932042159025) {
tmp = 100.0 * (n + (n * (i * (0.5 + (i * 0.16666666666666666)))));
} else {
tmp = 0.0;
}
return tmp;
}




Bits error versus i




Bits error versus n
Results
| Original | 48.1 |
|---|---|
| Target | 47.7 |
| Herbie | 14.7 |
if i < -3905150655849648Initial program 27.3
Taylor expanded around inf 64.0
Simplified17.8
if -3905150655849648 < i < 9.837932042159025Initial program 58.0
Taylor expanded around 0 26.8
Simplified26.8
Taylor expanded around 0 10.5
Simplified10.5
if 9.837932042159025 < i Initial program 32.2
Taylor expanded around 0 30.4
Final simplification14.7
herbie shell --seed 2020232
(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))))