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 \cdot e^{\log \left(\frac{i + \left(i \cdot i\right) \cdot \left(0.5 + i \cdot 0.16666666666666666\right)}{i}\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
(exp (log (/ (+ i (* (* i i) (+ 0.5 (* i 0.16666666666666666)))) i)))))
(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 * exp(log((i + ((i * i) * (0.5 + (i * 0.16666666666666666)))) / i)));
} 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
rmApplied associate-/r/_binary64_27219.3
Simplified9.3
rmApplied add-exp-log_binary64_280839.3
Applied add-exp-log_binary64_280836.9
Applied div-exp_binary64_282136.9
Simplified9.3
if 9.6667659487219382 < i < 5.8779358902733686e141Initial program 31.0
rmApplied associate-*r/_binary64_271730.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))))