100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\begin{array}{l}
\mathbf{if}\;i \le -0.94939736135755615:\\
\;\;\;\;\frac{100 \cdot \left({\left(1 + \frac{i}{n}\right)}^{n} - 1\right)}{\frac{i}{n}}\\
\mathbf{elif}\;i \le -4.23204137081444262 \cdot 10^{-190}:\\
\;\;\;\;\frac{100 \cdot \left(\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) \cdot n\right)}{i}\\
\mathbf{elif}\;i \le -3.31557411309755 \cdot 10^{-239}:\\
\;\;\;\;100 \cdot \left(\left(\left(\sqrt[3]{\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)} \cdot \sqrt[3]{\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)}\right) \cdot \left(\sqrt[3]{n} \cdot \sqrt[3]{n}\right)\right) \cdot \frac{\sqrt[3]{\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}{\sqrt[3]{n}}}\right)\\
\mathbf{elif}\;i \le 6.0258825700655812 \cdot 10^{-214}:\\
\;\;\;\;100 \cdot \left(\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 n\right)\\
\mathbf{elif}\;i \le 203.39871032850647:\\
\;\;\;\;\frac{100 \cdot \left(\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) \cdot n\right)}{i}\\
\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 VAR;
if ((i <= -0.9493973613575561)) {
VAR = ((100.0 * (pow((1.0 + (i / n)), n) - 1.0)) / (i / n));
} else {
double VAR_1;
if ((i <= -4.2320413708144426e-190)) {
VAR_1 = ((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))))) * n)) / i);
} else {
double VAR_2;
if ((i <= -3.31557411309755e-239)) {
VAR_2 = (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)))))) * 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))))))) * (cbrt(n) * cbrt(n))) * (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(n)))));
} else {
double VAR_3;
if ((i <= 6.025882570065581e-214)) {
VAR_3 = (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 VAR_4;
if ((i <= 203.39871032850647)) {
VAR_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))))) * n)) / i);
} else {
VAR_4 = (100.0 * ((fma(1.0, i, fma(log(1.0), n, 1.0)) - 1.0) / (i / n)));
}
VAR_3 = VAR_4;
}
VAR_2 = VAR_3;
}
VAR_1 = VAR_2;
}
VAR = VAR_1;
}
return VAR;
}




Bits error versus i




Bits error versus n
Results
| Original | 47.4 |
|---|---|
| Target | 47.5 |
| Herbie | 17.7 |
if i < -0.9493973613575561Initial program 27.6
rmApplied associate-*r/27.6
if -0.9493973613575561 < i < -4.2320413708144426e-190 or 6.025882570065581e-214 < i < 203.39871032850647Initial program 56.1
Taylor expanded around 0 25.2
Simplified25.2
rmApplied associate-/r/13.8
rmApplied associate-*l/12.1
Applied associate-*r/12.2
if -4.2320413708144426e-190 < i < -3.31557411309755e-239Initial program 60.4
Taylor expanded around 0 27.4
Simplified27.4
rmApplied add-cube-cbrt28.0
Applied *-un-lft-identity28.0
Applied times-frac28.0
Applied add-cube-cbrt28.3
Applied times-frac9.0
Simplified9.0
if -3.31557411309755e-239 < i < 6.025882570065581e-214Initial program 61.6
Taylor expanded around 0 31.1
Simplified31.1
rmApplied associate-/r/2.7
if 203.39871032850647 < i Initial program 29.7
Taylor expanded around 0 41.7
Simplified41.7
Final simplification17.7
herbie shell --seed 2020106 +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))))