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




Bits error versus i




Bits error versus n
| Original | 47.6 |
|---|---|
| Target | 47.7 |
| Herbie | 10.7 |
if i < -3.1828512715383011e-7Initial program 27.8
Simplified28.4
Applied pow-to-exp_binary6428.4
Simplified7.2
if -3.1828512715383011e-7 < i < 9.0970510355977131e-35Initial program 58.6
Simplified58.2
Taylor expanded in i around 0 12.9
Simplified8.3
Applied sub-neg_binary648.3
Applied distribute-rgt-in_binary648.3
Simplified8.3
Simplified8.3
Applied fma-def_binary648.3
if 9.0970510355977131e-35 < i Initial program 36.3
Simplified36.3
Taylor expanded in i around inf 34.0
Simplified24.7
Final simplification10.7
herbie shell --seed 2022125
(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))))