100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\begin{array}{l}
\mathbf{if}\;i \le -1.72344950658396212:\\
\;\;\;\;100 \cdot \frac{\frac{{\left(1 + \frac{i}{n}\right)}^{\left(2 \cdot n\right)} + \left(-1 \cdot 1\right)}{{\left(1 + \frac{i}{n}\right)}^{n} + 1}}{\frac{i}{n}}\\
\mathbf{elif}\;i \le 4.77111076326675766 \cdot 10^{-63}:\\
\;\;\;\;\mathsf{fma}\left(i, 50, \mathsf{fma}\left(100, \frac{\log 1 \cdot n}{i}, 100\right) - 50 \cdot \left(i \cdot \log 1\right)\right) \cdot n\\
\mathbf{elif}\;i \le 1.64857016151695042 \cdot 10^{218}:\\
\;\;\;\;100 \cdot \frac{\frac{{\left(1 + \frac{i}{n}\right)}^{\left(2 \cdot n\right)} + \left(-1 \cdot 1\right)}{{\left(1 + \frac{i}{n}\right)}^{n} + 1}}{\frac{i}{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 <= -1.7234495065839621)) {
temp = (100.0 * (((pow((1.0 + (i / n)), (2.0 * n)) + -(1.0 * 1.0)) / (pow((1.0 + (i / n)), n) + 1.0)) / (i / n)));
} else {
double temp_1;
if ((i <= 4.7711107632667577e-63)) {
temp_1 = (fma(i, 50.0, (fma(100.0, ((log(1.0) * n) / i), 100.0) - (50.0 * (i * log(1.0))))) * n);
} else {
double temp_2;
if ((i <= 1.6485701615169504e+218)) {
temp_2 = (100.0 * (((pow((1.0 + (i / n)), (2.0 * n)) + -(1.0 * 1.0)) / (pow((1.0 + (i / n)), n) + 1.0)) / (i / n)));
} else {
temp_2 = (100.0 * ((fma(1.0, i, fma(log(1.0), n, 1.0)) - 1.0) / (i / n)));
}
temp_1 = temp_2;
}
temp = temp_1;
}
return temp;
}




Bits error versus i




Bits error versus n
Results
| Original | 43.3 |
|---|---|
| Target | 42.6 |
| Herbie | 23.1 |
if i < -1.7234495065839621 or 4.7711107632667577e-63 < i < 1.6485701615169504e+218Initial program 32.7
rmApplied flip--32.7
Simplified32.7
if -1.7234495065839621 < i < 4.7711107632667577e-63Initial program 50.7
rmApplied div-inv50.7
Applied *-un-lft-identity50.7
Applied times-frac50.3
Applied associate-*r*50.4
Simplified50.4
Taylor expanded around 0 16.0
Simplified16.0
rmApplied associate-/r/15.9
Applied associate-*r*16.9
Simplified16.6
Taylor expanded around 0 16.6
Simplified16.6
if 1.6485701615169504e+218 < i Initial program 35.1
Taylor expanded around 0 30.2
Simplified30.2
Final simplification23.1
herbie shell --seed 2020053 +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))))