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




Bits error versus i




Bits error versus n
Results
| Original | 47.7 |
|---|---|
| Target | 46.9 |
| Herbie | 14.6 |
if i < -192.07922351078327Initial program 28.8
Taylor expanded around inf 64.0
Simplified18.6
if -192.07922351078327 < i < 0.11891451146914414Initial program 57.8
Taylor expanded around 0 26.7
Simplified26.7
Taylor expanded around 0 9.9
Simplified9.9
if 0.11891451146914414 < i Initial program 33.7
Taylor expanded around 0 29.8
Final simplification14.6
herbie shell --seed 2020253
(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))))