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




Bits error versus i




Bits error versus n
Results
| Original | 47.6 |
|---|---|
| Target | 48.0 |
| Herbie | 14.6 |
if i < -0.056267999484461595Initial program 27.6
Taylor expanded around inf 64.0
Simplified19.3
if -0.056267999484461595 < i < 9.6667659487219382Initial program 58.2
Taylor expanded around 0 26.3
Simplified26.3
Taylor expanded around 0 9.3
Simplified9.3
rmApplied add-cube-cbrt_binary64_28669.3
Applied associate-*l*_binary64_27729.3
Simplified9.3
rmApplied associate-*r*_binary64_27719.3
if 9.6667659487219382 < i < 5.8779358902733686e141Initial program 31.0
rmApplied associate-*r/_binary64_277330.9
Simplified30.9
if 5.8779358902733686e141 < i Initial program 30.0
Taylor expanded around 0 33.1
Final simplification14.6
herbie shell --seed 2020292
(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))))