100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\begin{array}{l}
\mathbf{if}\;i \leq -0.000889700083721587:\\
\;\;\;\;100 \cdot \frac{-1 + {\left(\frac{i}{n}\right)}^{n}}{\frac{i}{n}}\\
\mathbf{elif}\;i \leq 289668601567762.06:\\
\;\;\;\;n \cdot \left(\left(100 + \left(i \cdot i\right) \cdot 16.666666666666668\right) + i \cdot 50\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.000889700083721587)
(* 100.0 (/ (+ -1.0 (pow (/ i n) n)) (/ i n)))
(if (<= i 289668601567762.06)
(* n (+ (+ 100.0 (* (* i i) 16.666666666666668)) (* i 50.0)))
0.0)))double code(double i, double n) {
return ((double) (100.0 * (((double) (((double) pow(((double) (1.0 + (i / n))), n)) - 1.0)) / (i / n))));
}
double code(double i, double n) {
double tmp;
if ((i <= -0.000889700083721587)) {
tmp = ((double) (100.0 * (((double) (-1.0 + ((double) pow((i / n), n)))) / (i / n))));
} else {
double tmp_1;
if ((i <= 289668601567762.06)) {
tmp_1 = ((double) (n * ((double) (((double) (100.0 + ((double) (((double) (i * i)) * 16.666666666666668)))) + ((double) (i * 50.0))))));
} else {
tmp_1 = 0.0;
}
tmp = tmp_1;
}
return tmp;
}




Bits error versus i




Bits error versus n
Results
| Original | 47.0 |
|---|---|
| Target | 47.1 |
| Herbie | 15.0 |
if i < -8.8970008372158695e-4Initial program 27.7
Taylor expanded around inf 64.0
Simplified19.0
if -8.8970008372158695e-4 < i < 289668601567762.062Initial program 57.4
Taylor expanded around 0 27.5
Simplified27.5
Taylor expanded around 0 10.2
Simplified10.2
Taylor expanded around 0 10.2
Simplified10.2
if 289668601567762.062 < i Initial program 31.6
Taylor expanded around 0 30.9
Final simplification15.0
herbie shell --seed 2020219
(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))))