100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\begin{array}{l}
\mathbf{if}\;i \le -0.04063035479082508:\\
\;\;\;\;\frac{100 \cdot \left({\left(\frac{i}{n}\right)}^{n} - 1\right)}{\frac{i}{n}}\\
\mathbf{elif}\;i \le 9.41291569922092328 \cdot 10^{-13}:\\
\;\;\;\;100 \cdot \frac{\left(1 \cdot i + \left(0.5 \cdot {i}^{2} + \log 1 \cdot n\right)\right) - 0.5 \cdot \left({i}^{2} \cdot \log 1\right)}{\frac{i}{n}}\\
\mathbf{else}:\\
\;\;\;\;\left(100 \cdot \frac{\sqrt[3]{{\left(1 + \frac{i}{n}\right)}^{n} - 1} \cdot \sqrt[3]{{\left(1 + \frac{i}{n}\right)}^{n} - 1}}{i}\right) \cdot \frac{\sqrt[3]{{\left(\sqrt[3]{1 + \frac{i}{n}} \cdot \sqrt[3]{1 + \frac{i}{n}}\right)}^{n} \cdot {\left(\sqrt[3]{1 + \frac{i}{n}}\right)}^{n} - 1}}{\frac{1}{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 <= -0.04063035479082508)) {
temp = ((100.0 * (pow((i / n), n) - 1.0)) / (i / n));
} else {
double temp_1;
if ((i <= 9.412915699220923e-13)) {
temp_1 = (100.0 * ((((1.0 * i) + ((0.5 * pow(i, 2.0)) + (log(1.0) * n))) - (0.5 * (pow(i, 2.0) * log(1.0)))) / (i / n)));
} else {
temp_1 = ((100.0 * ((cbrt((pow((1.0 + (i / n)), n) - 1.0)) * cbrt((pow((1.0 + (i / n)), n) - 1.0))) / i)) * (cbrt(((pow((cbrt((1.0 + (i / n))) * cbrt((1.0 + (i / n)))), n) * pow(cbrt((1.0 + (i / n))), n)) - 1.0)) / (1.0 / n)));
}
temp = temp_1;
}
return temp;
}




Bits error versus i




Bits error versus n
Results
| Original | 43.0 |
|---|---|
| Target | 42.4 |
| Herbie | 30.5 |
if i < -0.04063035479082508Initial program 28.7
rmApplied associate-*r/28.7
Taylor expanded around inf 64.0
Simplified18.4
if -0.04063035479082508 < i < 9.412915699220923e-13Initial program 50.5
Taylor expanded around 0 34.2
if 9.412915699220923e-13 < i Initial program 34.0
rmApplied div-inv34.0
Applied add-cube-cbrt34.0
Applied times-frac34.0
Applied associate-*r*34.0
rmApplied add-cube-cbrt34.0
Applied unpow-prod-down34.0
Final simplification30.5
herbie shell --seed 2020057
(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))))