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




Bits error versus i




Bits error versus n
Results
| Original | 47.7 |
|---|---|
| Target | 47.7 |
| Herbie | 14.3 |
if i < -0.027868397286282341Initial program 28.5
Taylor expanded around inf 64.0
Simplified19.6
if -0.027868397286282341 < i < 1.3295774325707314e-4Initial program 58.2
Taylor expanded around 0 26.6
Simplified26.6
Taylor expanded around 0 9.1
Simplified9.1
rmApplied add-cube-cbrt_binary64_32109.1
Applied associate-*r*_binary64_31159.1
rmApplied associate-*r*_binary64_31159.1
if 1.3295774325707314e-4 < i Initial program 32.4
Taylor expanded around 0 29.2
Final simplification14.3
herbie shell --seed 2020288
(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))))