100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}
\begin{array}{l}
\mathbf{if}\;i \leq -0.0001322261859959142:\\
\;\;\;\;n \cdot \frac{\mathsf{fma}\left(100, e^{i}, -100\right)}{i}\\
\mathbf{elif}\;i \leq 8.722702919778021 \cdot 10^{-6}:\\
\;\;\;\;\mathsf{fma}\left(16.666666666666668, n \cdot \left(i \cdot i\right), \mathsf{fma}\left(n, 100, \mathsf{fma}\left(\frac{i \cdot i}{n}, 33.333333333333336, 50 \cdot \left(i \cdot n\right)\right)\right)\right) - 50 \cdot \left(i + i \cdot i\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{{n}^{2} \cdot \left(100 \cdot \log i - 100 \cdot \log n\right)}{i}\\
\end{array}
(FPCore (i n) :precision binary64 (* 100.0 (/ (- (pow (+ 1.0 (/ i n)) n) 1.0) (/ i n))))
(FPCore (i n)
:precision binary64
(if (<= i -0.0001322261859959142)
(* n (/ (fma 100.0 (exp i) -100.0) i))
(if (<= i 8.722702919778021e-6)
(-
(fma
16.666666666666668
(* n (* i i))
(fma n 100.0 (fma (/ (* i i) n) 33.333333333333336 (* 50.0 (* i n)))))
(* 50.0 (+ i (* i i))))
(/ (* (pow n 2.0) (- (* 100.0 (log i)) (* 100.0 (log n)))) i))))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 tmp;
if (i <= -0.0001322261859959142) {
tmp = n * (fma(100.0, exp(i), -100.0) / i);
} else if (i <= 8.722702919778021e-6) {
tmp = fma(16.666666666666668, (n * (i * i)), fma(n, 100.0, fma(((i * i) / n), 33.333333333333336, (50.0 * (i * n))))) - (50.0 * (i + (i * i)));
} else {
tmp = (pow(n, 2.0) * ((100.0 * log(i)) - (100.0 * log(n)))) / i;
}
return tmp;
}




Bits error versus i




Bits error versus n
| Original | 47.3 |
|---|---|
| Target | 47.7 |
| Herbie | 11.9 |
if i < -1.3222618599591419e-4Initial program 28.3
Simplified28.9
Taylor expanded in n around inf 13.0
if -1.3222618599591419e-4 < i < 8.7227029197780214e-6Initial program 57.9
Simplified57.5
Taylor expanded in i around 0 9.0
Simplified9.0
if 8.7227029197780214e-6 < i Initial program 32.7
Simplified32.7
Taylor expanded in n around 0 22.6
Final simplification11.9
herbie shell --seed 2021313
(FPCore (i n)
:name "Compound Interest"
:precision binary64
:herbie-target
(* 100.0 (/ (- (exp (* n (if (== (+ 1.0 (/ i n)) 1.0) (/ i n) (/ (* (/ i n) (log (+ 1.0 (/ i n)))) (- (+ (/ i n) 1.0) 1.0))))) 1.0) (/ i n)))
(* 100.0 (/ (- (pow (+ 1.0 (/ i n)) n) 1.0) (/ i n))))