100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\begin{array}{l}
\mathbf{if}\;i \leq -3.827469972222611 \cdot 10^{-31}:\\
\;\;\;\;100 \cdot \frac{-1 + {\left(\frac{i}{n}\right)}^{n}}{\frac{i}{n}}\\
\mathbf{elif}\;i \leq 2003.3137174584608:\\
\;\;\;\;\left(i \cdot n\right) \cdot 50 + n \cdot \left(100 + \left(i \cdot i\right) \cdot 16.666666666666668\right)\\
\mathbf{else}:\\
\;\;\;\;0\\
\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.827469972222611e-31)
(* 100.0 (/ (+ -1.0 (pow (/ i n) n)) (/ i n)))
(if (<= i 2003.3137174584608)
(+ (* (* i n) 50.0) (* n (+ 100.0 (* (* i i) 16.666666666666668))))
0.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 <= -3.827469972222611e-31) {
tmp = 100.0 * ((-1.0 + pow((i / n), n)) / (i / n));
} else if (i <= 2003.3137174584608) {
tmp = ((i * n) * 50.0) + (n * (100.0 + ((i * i) * 16.666666666666668)));
} else {
tmp = 0.0;
}
return tmp;
}




Bits error versus i




Bits error versus n
Results
| Original | 47.6 |
|---|---|
| Target | 47.5 |
| Herbie | 14.6 |
if i < -3.8274699722226108e-31Initial program 29.6
Taylor expanded around inf 64.0
Simplified20.9
if -3.8274699722226108e-31 < i < 2003.3137174584608Initial program 58.5
Taylor expanded around 0 26.3
Simplified26.3
Taylor expanded around 0 8.8
Simplified8.8
if 2003.3137174584608 < i Initial program 30.7
Taylor expanded around 0 30.2
Final simplification14.6
herbie shell --seed 2020231
(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))))