100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}
\begin{array}{l}
\mathbf{if}\;i \leq -2.6516593092203356 \cdot 10^{-10}:\\
\;\;\;\;n \cdot \frac{\mathsf{fma}\left(100, e^{n \cdot \mathsf{log1p}\left(\frac{i}{n}\right)}, -100\right)}{i}\\
\mathbf{elif}\;i \leq 3.182613501787643 \cdot 10^{-5}:\\
\;\;\;\;\mathsf{fma}\left(16.666666666666668, n \cdot \left(i \cdot i\right), \mathsf{fma}\left(100, n, \mathsf{fma}\left(33.333333333333336, \frac{i \cdot i}{n}, 50 \cdot \left(i \cdot n\right)\right)\right)\right) + \mathsf{fma}\left(i, i, i\right) \cdot -50\\
\mathbf{else}:\\
\;\;\;\;\log \left({\left(e^{n}\right)}^{\left(100 + i \cdot \mathsf{fma}\left(i, 16.666666666666668, 50\right)\right)}\right)\\
\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 -2.6516593092203356e-10)
(* n (/ (fma 100.0 (exp (* n (log1p (/ i n)))) -100.0) i))
(if (<= i 3.182613501787643e-5)
(+
(fma
16.666666666666668
(* n (* i i))
(fma 100.0 n (fma 33.333333333333336 (/ (* i i) n) (* 50.0 (* i n)))))
(* (fma i i i) -50.0))
(log (pow (exp n) (+ 100.0 (* i (fma i 16.666666666666668 50.0))))))))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 <= -2.6516593092203356e-10) {
tmp = n * (fma(100.0, exp(n * log1p(i / n)), -100.0) / i);
} else if (i <= 3.182613501787643e-5) {
tmp = fma(16.666666666666668, (n * (i * i)), fma(100.0, n, fma(33.333333333333336, ((i * i) / n), (50.0 * (i * n))))) + (fma(i, i, i) * -50.0);
} else {
tmp = log(pow(exp(n), (100.0 + (i * fma(i, 16.666666666666668, 50.0)))));
}
return tmp;
}




Bits error versus i




Bits error versus n
| Original | 46.2 |
|---|---|
| Target | 42.2 |
| Herbie | 11.2 |
if i < -2.65165930922033559e-10Initial program 28.5
Simplified28.9
Applied pow-to-exp_binary6430.6
Simplified9.0
if -2.65165930922033559e-10 < i < 3.1826135017876433e-5Initial program 58.1
Simplified57.8
Taylor expanded in i around 0 9.4
Simplified9.4
Applied sub-neg_binary649.4
Simplified9.4
if 3.1826135017876433e-5 < i Initial program 34.2
Simplified34.0
Taylor expanded in i around 0 51.4
Simplified51.4
Taylor expanded in n around inf 40.3
Applied add-log-exp_binary6429.0
Simplified17.1
Final simplification11.2
herbie shell --seed 2022068
(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))))