100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\begin{array}{l}
\mathbf{if}\;i \le -0.0749921289443250955:\\
\;\;\;\;\left(100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{i}\right) \cdot n\\
\mathbf{elif}\;i \le 9.29801943706574769 \cdot 10^{-129}:\\
\;\;\;\;100 \cdot \left(\frac{\log 1 \cdot \left(n - 0.5 \cdot {i}^{2}\right) + i \cdot \left(i \cdot 0.5 + 1\right)}{-i} \cdot \left(-n\right)\right)\\
\mathbf{elif}\;i \le 3.8426241943682245 \cdot 10^{22}:\\
\;\;\;\;\frac{100 \cdot \left(\left(\left(\log 1 \cdot \left(n - 0.5 \cdot {i}^{2}\right)\right) \cdot \left(\log 1 \cdot \left(n - 0.5 \cdot {i}^{2}\right)\right) - \left(i \cdot \left(i \cdot 0.5 + 1\right)\right) \cdot \left(i \cdot \left(i \cdot 0.5 + 1\right)\right)\right) \cdot \left(-n\right)\right)}{\left(-i\right) \cdot \left(\log 1 \cdot \left(n - 0.5 \cdot {i}^{2}\right) - i \cdot \left(i \cdot 0.5 + 1\right)\right)}\\
\mathbf{else}:\\
\;\;\;\;\left(100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{i}\right) \cdot 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 VAR;
if ((i <= -0.0749921289443251)) {
VAR = ((100.0 * ((pow((1.0 + (i / n)), n) - 1.0) / i)) * n);
} else {
double VAR_1;
if ((i <= 9.298019437065748e-129)) {
VAR_1 = (100.0 * ((((log(1.0) * (n - (0.5 * pow(i, 2.0)))) + (i * ((i * 0.5) + 1.0))) / -i) * -n));
} else {
double VAR_2;
if ((i <= 3.8426241943682245e+22)) {
VAR_2 = ((100.0 * ((((log(1.0) * (n - (0.5 * pow(i, 2.0)))) * (log(1.0) * (n - (0.5 * pow(i, 2.0))))) - ((i * ((i * 0.5) + 1.0)) * (i * ((i * 0.5) + 1.0)))) * -n)) / (-i * ((log(1.0) * (n - (0.5 * pow(i, 2.0)))) - (i * ((i * 0.5) + 1.0)))));
} else {
VAR_2 = ((100.0 * ((pow((1.0 + (i / n)), n) - 1.0) / i)) * n);
}
VAR_1 = VAR_2;
}
VAR = VAR_1;
}
return VAR;
}




Bits error versus i




Bits error versus n
Results
| Original | 48.2 |
|---|---|
| Target | 47.6 |
| Herbie | 16.5 |
if i < -0.0749921289443251 or 3.8426241943682245e+22 < i Initial program 30.0
rmApplied associate-/r/30.3
Applied associate-*r*30.3
if -0.0749921289443251 < i < 9.298019437065748e-129Initial program 59.0
Taylor expanded around 0 27.2
Simplified27.2
rmApplied frac-2neg27.2
Applied associate-/r/7.8
if 9.298019437065748e-129 < i < 3.8426241943682245e+22Initial program 53.0
Taylor expanded around 0 26.3
Simplified26.3
rmApplied frac-2neg26.3
Applied associate-/r/19.2
rmApplied flip-+19.3
Applied associate-/l/19.2
Applied associate-*l/14.9
Applied associate-*r/15.0
Final simplification16.5
herbie shell --seed 2020078
(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))))