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




Bits error versus i




Bits error versus n
Results
| Original | 47.7 |
|---|---|
| Target | 47.3 |
| Herbie | 14.9 |
if i < -0.080777469534452029Initial program 28.7
Taylor expanded around inf 64.0
Simplified18.6
if -0.080777469534452029 < i < 0.12982209090675584Initial program 58.1
Taylor expanded around 0 26.8
Simplified26.8
rmApplied div-inv_binary64_179626.8
Applied add-cube-cbrt_binary64_183427.5
Applied times-frac_binary64_180510.3
Applied associate-*r*_binary64_173910.3
Simplified10.3
Taylor expanded around 0 38.5
Simplified9.8
if 0.12982209090675584 < i Initial program 33.1
Taylor expanded around 0 31.1
Final simplification14.9
herbie shell --seed 2020289
(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))))