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




Bits error versus i




Bits error versus n
| Original | 47.4 |
|---|---|
| Target | 47.3 |
| Herbie | 11.6 |
if i < -1.52637993881606391e-4Initial program 28.2
Simplified28.6
Taylor expanded in n around inf 12.8
Simplified11.8
if -1.52637993881606391e-4 < i < 8.92730443070515327e-7Initial program 58.1
Simplified57.8
Taylor expanded in i around 0 9.0
Simplified9.0
Taylor expanded in i around 0 9.0
Simplified8.9
Taylor expanded in n around inf 9.1
Simplified9.1
if 8.92730443070515327e-7 < i Initial program 33.6
Simplified33.5
Taylor expanded in n around 0 22.2
Simplified22.1
Final simplification11.6
herbie shell --seed 2022130
(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))))