100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\begin{array}{l}
\mathbf{if}\;i \leq -3.311639244018977 \cdot 10^{-06}:\\
\;\;\;\;100 \cdot \frac{e^{i} - 1}{\frac{i}{n}}\\
\mathbf{elif}\;i \leq 8.431981695178327 \cdot 10^{-12}:\\
\;\;\;\;n \cdot \left(100 + i \cdot 50\right)\\
\mathbf{elif}\;i \leq 1.4026681787903786 \cdot 10^{+231}:\\
\;\;\;\;100 \cdot \frac{\left(0.5 \cdot \left({\log n}^{2} \cdot {n}^{2}\right) + \left(n \cdot \log i + \left(\frac{{n}^{2}}{i} + 0.5 \cdot \left({n}^{2} \cdot {\log i}^{2}\right)\right)\right)\right) - \left(\log n \cdot \left({n}^{2} \cdot \log i\right) + n \cdot \log n\right)}{\frac{i}{n}}\\
\mathbf{else}:\\
\;\;\;\;n \cdot \left(100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} + -1}{i}\right)\\
\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.311639244018977e-06)
(* 100.0 (/ (- (exp i) 1.0) (/ i n)))
(if (<= i 8.431981695178327e-12)
(* n (+ 100.0 (* i 50.0)))
(if (<= i 1.4026681787903786e+231)
(*
100.0
(/
(-
(+
(* 0.5 (* (pow (log n) 2.0) (pow n 2.0)))
(+
(* n (log i))
(+ (/ (pow n 2.0) i) (* 0.5 (* (pow n 2.0) (pow (log i) 2.0))))))
(+ (* (log n) (* (pow n 2.0) (log i))) (* n (log n))))
(/ i n)))
(* n (* 100.0 (/ (+ (pow (+ 1.0 (/ i n)) n) -1.0) 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 <= -3.311639244018977e-06) {
tmp = 100.0 * ((exp(i) - 1.0) / (i / n));
} else if (i <= 8.431981695178327e-12) {
tmp = n * (100.0 + (i * 50.0));
} else if (i <= 1.4026681787903786e+231) {
tmp = 100.0 * ((((0.5 * (pow(log(n), 2.0) * pow(n, 2.0))) + ((n * log(i)) + ((pow(n, 2.0) / i) + (0.5 * (pow(n, 2.0) * pow(log(i), 2.0)))))) - ((log(n) * (pow(n, 2.0) * log(i))) + (n * log(n)))) / (i / n));
} else {
tmp = n * (100.0 * ((pow((1.0 + (i / n)), n) + -1.0) / i));
}
return tmp;
}




Bits error versus i




Bits error versus n
Results
| Original | 47.9 |
|---|---|
| Target | 47.7 |
| Herbie | 11.7 |
if i < -3.3116392440189772e-6Initial program 29.0
Taylor expanded around inf 11.6
if -3.3116392440189772e-6 < i < 8.43198169517832741e-12Initial program 58.4
Taylor expanded around 0 9.0
Simplified9.0
Taylor expanded around inf 9.1
if 8.43198169517832741e-12 < i < 1.4026681787903786e231Initial program 32.6
Taylor expanded around 0 20.0
if 1.4026681787903786e231 < i Initial program 32.5
rmApplied associate-/r/_binary6432.5
Applied associate-*r*_binary6432.5
Simplified32.5
Final simplification11.7
herbie shell --seed 2021118
(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))))