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{\frac{{\left(\frac{i}{n} + 1\right)}^{\left(n \cdot 2\right)} + -1}{1 + {\left(\frac{i}{n} + 1\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
(/
(/
(+ (pow (+ (/ i n) 1.0) (* n 2.0)) -1.0)
(+ 1.0 (pow (+ (/ i n) 1.0) 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 * (((pow(((i / n) + 1.0), (n * 2.0)) + -1.0) / (1.0 + pow(((i / n) + 1.0), 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 | 16.8 |
if i < -3.82748e-31Initial program 29.6
rmApplied flip--_binary64_252629.6
Simplified29.6
Simplified29.6
if -3.82748e-31 < i < 2003.31Initial program 58.5
Taylor expanded around 0 26.3
Simplified26.3
Taylor expanded around 0 8.8
Simplified8.8
if 2003.31 < i Initial program 30.7
Taylor expanded around 0 30.2
Final simplification16.8
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))))