100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\begin{array}{l}
\mathbf{if}\;i \leq -69221321268138.08:\\
\;\;\;\;100 \cdot \frac{{\left(\frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\\
\mathbf{elif}\;i \leq 0.05443781441738046:\\
\;\;\;\;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 -69221321268138.08)
(* 100.0 (/ (- (pow (/ i n) n) 1.0) (/ i n)))
(if (<= i 0.05443781441738046)
(* 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 <= -69221321268138.08) {
tmp = 100.0 * ((pow((i / n), n) - 1.0) / (i / n));
} else if (i <= 0.05443781441738046) {
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.6 |
|---|---|
| Target | 47.3 |
| Herbie | 14.7 |
if i < -69221321268138.078Initial program 28.0
Taylor expanded around inf 64.0
Simplified18.7
if -69221321268138.078 < i < 0.0544378144173804576Initial program 57.6
Taylor expanded around 0 27.2
Simplified27.2
Taylor expanded around 0 10.2
Simplified10.2
if 0.0544378144173804576 < i Initial program 32.1
Taylor expanded around 0 29.6
Final simplification14.7
herbie shell --seed 2020346
(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))))