100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\begin{array}{l}
\mathbf{if}\;i \le -2.56140166535216897 \cdot 10^{135}:\\
\;\;\;\;\frac{100 \cdot \frac{\log \left(e^{\mathsf{fma}\left(-1, 1, {\left(1 + \frac{i}{n}\right)}^{\left(2 \cdot n\right)}\right)}\right)}{{\left(1 + \frac{i}{n}\right)}^{n} + 1}}{\frac{i}{n}}\\
\mathbf{elif}\;i \le -1.3992561866449662 \cdot 10^{-10}:\\
\;\;\;\;\frac{100 \cdot \left({\left(\frac{i}{n}\right)}^{n} - 1\right)}{\frac{i}{n}}\\
\mathbf{elif}\;i \le 2.51591290926460688 \cdot 10^{-160}:\\
\;\;\;\;100 \cdot \frac{\mathsf{fma}\left(i, 1, \mathsf{fma}\left(0.5, {i}^{2}, \log 1 \cdot n\right) - 0.5 \cdot \left({i}^{2} \cdot \log 1\right)\right)}{\frac{i}{n}}\\
\mathbf{elif}\;i \le 6.02622510223326963 \cdot 10^{-125}:\\
\;\;\;\;\frac{\frac{100 \cdot \mathsf{fma}\left(-1, 1, {\left(1 + \frac{i}{n}\right)}^{\left(2 \cdot n\right)}\right)}{i \cdot \left({\left(1 + \frac{i}{n}\right)}^{n} + 1\right)}}{\frac{1}{n}}\\
\mathbf{elif}\;i \le 8532543483832934860000:\\
\;\;\;\;100 \cdot \frac{\mathsf{fma}\left(i, 1, \mathsf{fma}\left(0.5, {i}^{2}, \log 1 \cdot n\right) - 0.5 \cdot \left({i}^{2} \cdot \log 1\right)\right)}{\frac{i}{n}}\\
\mathbf{elif}\;i \le 7.39555913873958208 \cdot 10^{219}:\\
\;\;\;\;\frac{\frac{100 \cdot \mathsf{fma}\left(-1, 1, {\left(1 + \frac{i}{n}\right)}^{\left(2 \cdot n\right)}\right)}{i \cdot \left({\left(1 + \frac{i}{n}\right)}^{n} + 1\right)}}{\frac{1}{n}}\\
\mathbf{else}:\\
\;\;\;\;100 \cdot \frac{\mathsf{fma}\left(1, i, \mathsf{fma}\left(\log 1, n, 1\right)\right) - 1}{\frac{i}{n}}\\
\end{array}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 temp;
if ((i <= -2.561401665352169e+135)) {
temp = ((100.0 * (log(exp(fma(-1.0, 1.0, pow((1.0 + (i / n)), (2.0 * n))))) / (pow((1.0 + (i / n)), n) + 1.0))) / (i / n));
} else {
double temp_1;
if ((i <= -1.3992561866449662e-10)) {
temp_1 = ((100.0 * (pow((i / n), n) - 1.0)) / (i / n));
} else {
double temp_2;
if ((i <= 2.515912909264607e-160)) {
temp_2 = (100.0 * (fma(i, 1.0, (fma(0.5, pow(i, 2.0), (log(1.0) * n)) - (0.5 * (pow(i, 2.0) * log(1.0))))) / (i / n)));
} else {
double temp_3;
if ((i <= 6.02622510223327e-125)) {
temp_3 = (((100.0 * fma(-1.0, 1.0, pow((1.0 + (i / n)), (2.0 * n)))) / (i * (pow((1.0 + (i / n)), n) + 1.0))) / (1.0 / n));
} else {
double temp_4;
if ((i <= 8.532543483832935e+21)) {
temp_4 = (100.0 * (fma(i, 1.0, (fma(0.5, pow(i, 2.0), (log(1.0) * n)) - (0.5 * (pow(i, 2.0) * log(1.0))))) / (i / n)));
} else {
double temp_5;
if ((i <= 7.395559138739582e+219)) {
temp_5 = (((100.0 * fma(-1.0, 1.0, pow((1.0 + (i / n)), (2.0 * n)))) / (i * (pow((1.0 + (i / n)), n) + 1.0))) / (1.0 / n));
} else {
temp_5 = (100.0 * ((fma(1.0, i, fma(log(1.0), n, 1.0)) - 1.0) / (i / n)));
}
temp_4 = temp_5;
}
temp_3 = temp_4;
}
temp_2 = temp_3;
}
temp_1 = temp_2;
}
temp = temp_1;
}
return temp;
}




Bits error versus i




Bits error versus n
Results
| Original | 42.7 |
|---|---|
| Target | 42.6 |
| Herbie | 31.4 |
if i < -2.561401665352169e+135Initial program 15.4
rmApplied associate-*r/15.4
rmApplied flip--15.4
Simplified15.4
rmApplied add-log-exp15.4
if -2.561401665352169e+135 < i < -1.3992561866449662e-10Initial program 41.3
rmApplied associate-*r/41.3
Taylor expanded around inf 64.0
Simplified27.6
if -1.3992561866449662e-10 < i < 2.515912909264607e-160 or 6.02622510223327e-125 < i < 8.532543483832935e+21Initial program 49.9
Taylor expanded around 0 33.7
Simplified33.7
if 2.515912909264607e-160 < i < 6.02622510223327e-125 or 8.532543483832935e+21 < i < 7.395559138739582e+219Initial program 38.2
rmApplied associate-*r/38.1
rmApplied flip--38.1
Simplified38.1
rmApplied add-log-exp38.3
rmApplied div-inv38.3
Applied associate-/r*38.3
Simplified38.0
if 7.395559138739582e+219 < i Initial program 30.6
Taylor expanded around 0 34.7
Simplified34.7
Final simplification31.4
herbie shell --seed 2020056 +o rules:numerics
(FPCore (i n)
:name "Compound Interest"
:precision binary64
:herbie-target
(* 100 (/ (- (exp (* n (if (== (+ 1 (/ i n)) 1) (/ i n) (/ (* (/ i n) (log (+ 1 (/ i n)))) (- (+ (/ i n) 1) 1))))) 1) (/ i n)))
(* 100 (/ (- (pow (+ 1 (/ i n)) n) 1) (/ i n))))