100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\begin{array}{l}
\mathbf{if}\;i \leq -4.486060090746444 \cdot 10^{+21}:\\
\;\;\;\;100 \cdot \frac{-1 + {\left(\frac{i}{n}\right)}^{n}}{\frac{i}{n}}\\
\mathbf{elif}\;i \leq -3.558185175373979 \cdot 10^{-154}:\\
\;\;\;\;100 \cdot \left(\frac{1}{i} \cdot \left(n \cdot \left({i}^{3} \cdot 0.16666666666666666 + \left(i + \left(i \cdot i\right) \cdot 0.5\right)\right)\right)\right)\\
\mathbf{elif}\;i \leq 250.08617759702352:\\
\;\;\;\;\left(i \cdot n\right) \cdot 50 + 100 \cdot n\\
\mathbf{else}:\\
\;\;\;\;100 \cdot \left(\frac{{\left(\frac{i}{n} + 1\right)}^{n}}{\frac{i}{n}} - \frac{n}{i}\right)\\
\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 -4.486060090746444e+21)
(* 100.0 (/ (+ -1.0 (pow (/ i n) n)) (/ i n)))
(if (<= i -3.558185175373979e-154)
(*
100.0
(*
(/ 1.0 i)
(* n (+ (* (pow i 3.0) 0.16666666666666666) (+ i (* (* i i) 0.5))))))
(if (<= i 250.08617759702352)
(+ (* (* i n) 50.0) (* 100.0 n))
(* 100.0 (- (/ (pow (+ (/ i n) 1.0) n) (/ i n)) (/ n i)))))))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 <= -4.486060090746444e+21)) {
tmp = ((double) (100.0 * (((double) (-1.0 + ((double) pow((i / n), n)))) / (i / n))));
} else {
double tmp_1;
if ((i <= -3.558185175373979e-154)) {
tmp_1 = ((double) (100.0 * ((double) ((1.0 / i) * ((double) (n * ((double) (((double) (((double) pow(i, 3.0)) * 0.16666666666666666)) + ((double) (i + ((double) (((double) (i * i)) * 0.5))))))))))));
} else {
double tmp_2;
if ((i <= 250.08617759702352)) {
tmp_2 = ((double) (((double) (((double) (i * n)) * 50.0)) + ((double) (100.0 * n))));
} else {
tmp_2 = ((double) (100.0 * ((double) ((((double) pow(((double) ((i / n) + 1.0)), n)) / (i / n)) - (n / i)))));
}
tmp_1 = tmp_2;
}
tmp = tmp_1;
}
return tmp;
}




Bits error versus i




Bits error versus n
Results
| Original | 47.6 |
|---|---|
| Target | 47.4 |
| Herbie | 14.5 |
if i < -4.4860600907464442e21Initial program 26.3
Taylor expanded around inf 64.0
Simplified16.1
if -4.4860600907464442e21 < i < -3.55818517537397883e-154Initial program 53.5
Taylor expanded around 0 27.4
Simplified27.4
rmApplied div-inv_binary6427.5
Applied *-un-lft-identity_binary6427.5
Applied times-frac_binary6416.8
Simplified16.7
if -3.55818517537397883e-154 < i < 250.086177597023521Initial program 59.0
Taylor expanded around 0 28.2
Simplified28.2
Taylor expanded around 0 8.2
Simplified8.2
Taylor expanded around 0 8.3
Simplified8.3
if 250.086177597023521 < i Initial program 31.1
rmApplied div-sub_binary6431.1
Simplified33.6
Final simplification14.5
herbie shell --seed 2020210
(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))))