100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\begin{array}{l}
\mathbf{if}\;i \le -0.27000945627389827:\\
\;\;\;\;100 \cdot \frac{\mathsf{fma}\left({\left(\sqrt[3]{1 + \frac{i}{n}} \cdot \sqrt[3]{1 + \frac{i}{n}}\right)}^{n}, {\left(\sqrt[3]{1 + \frac{i}{n}}\right)}^{n}, -1\right)}{\frac{i}{n}}\\
\mathbf{elif}\;i \le 0.34323219986681708:\\
\;\;\;\;\left(100 \cdot \left(\left(\sqrt[3]{\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)}{i}} \cdot \sqrt[3]{\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)}{i}}\right) \cdot \sqrt[3]{\left(\sqrt[3]{\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)}{i}} \cdot \sqrt[3]{\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)}{i}}\right) \cdot \sqrt[3]{\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)}{i}}}\right)\right) \cdot n\\
\mathbf{elif}\;i \le 3.6088222865594129 \cdot 10^{217}:\\
\;\;\;\;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 1.30620374507854063 \cdot 10^{237}:\\
\;\;\;\;100 \cdot \frac{\mathsf{fma}\left(1, i, \mathsf{fma}\left(\log 1, n, 1\right)\right) - 1}{\frac{i}{n}}\\
\mathbf{else}:\\
\;\;\;\;100 \cdot \left(\left({\left(1 + \frac{i}{n}\right)}^{n} - 1\right) \cdot \frac{n}{i}\right)\\
\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.2700094562738983)) {
VAR = (100.0 * (fma(pow((cbrt((1.0 + (i / n))) * cbrt((1.0 + (i / n)))), n), pow(cbrt((1.0 + (i / n))), n), -1.0) / (i / n)));
} else {
double VAR_1;
if ((i <= 0.3432321998668171)) {
VAR_1 = ((100.0 * ((cbrt((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)) * cbrt((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))) * cbrt(((cbrt((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)) * cbrt((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))) * cbrt((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 VAR_2;
if ((i <= 3.608822286559413e+217)) {
VAR_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 {
double VAR_3;
if ((i <= 1.3062037450785406e+237)) {
VAR_3 = (100.0 * ((fma(1.0, i, fma(log(1.0), n, 1.0)) - 1.0) / (i / n)));
} else {
VAR_3 = (100.0 * ((pow((1.0 + (i / n)), n) - 1.0) * (n / i)));
}
VAR_2 = VAR_3;
}
VAR_1 = VAR_2;
}
VAR = VAR_1;
}
return VAR;
}




Bits error versus i




Bits error versus n
Results
| Original | 47.7 |
|---|---|
| Target | 46.9 |
| Herbie | 16.9 |
if i < -0.2700094562738983Initial program 28.8
rmApplied add-cube-cbrt28.9
Applied unpow-prod-down28.9
Applied fma-neg28.9
if -0.2700094562738983 < i < 0.3432321998668171Initial program 57.8
Taylor expanded around 0 27.1
Simplified27.1
rmApplied associate-/r/9.4
Applied associate-*r*9.4
rmApplied add-cube-cbrt9.4
rmApplied add-cube-cbrt9.4
if 0.3432321998668171 < i < 3.608822286559413e+217Initial program 31.4
rmApplied flip--31.5
Simplified31.4
if 3.608822286559413e+217 < i < 1.3062037450785406e+237Initial program 32.0
Taylor expanded around 0 36.2
Simplified36.2
if 1.3062037450785406e+237 < i Initial program 33.1
rmApplied div-inv33.1
Simplified33.0
Final simplification16.9
herbie shell --seed 2020103 +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))))