100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\begin{array}{l}
\mathbf{if}\;i \leq -2.1678153021847697 \cdot 10^{-06}:\\
\;\;\;\;100 \cdot \frac{e^{i} - 1}{\frac{i}{n}}\\
\mathbf{elif}\;i \leq 3.3504134620314933 \cdot 10^{-32}:\\
\;\;\;\;100 \cdot \left(\left(n + 0.5 \cdot \left(i \cdot n\right)\right) - i \cdot 0.5\right)\\
\mathbf{elif}\;i \leq 1.853747270743323 \cdot 10^{+248}:\\
\;\;\;\;100 \cdot \left(\left(\frac{{n}^{3}}{{i}^{2}} + \left(0.5 \cdot \frac{{n}^{3} \cdot {\log i}^{2}}{i} + \left(0.5 \cdot \frac{{n}^{3} \cdot {\log n}^{2}}{i} + \frac{\log i \cdot {n}^{2}}{i}\right)\right)\right) - \left(\frac{\log n \cdot {n}^{2}}{i} + \frac{\log n \cdot \left({n}^{3} \cdot \log i\right)}{i}\right)\right)\\
\mathbf{elif}\;i \leq 2.852084085226162 \cdot 10^{+286}:\\
\;\;\;\;100 \cdot \frac{n \cdot {\left(\frac{i}{n}\right)}^{n} - n}{i}\\
\mathbf{else}:\\
\;\;\;\;\frac{n \cdot \left(100 \cdot n\right)}{\left(n + 0.5 \cdot \left(i \cdot n\right)\right) + i \cdot 0.5}\\
\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 -2.1678153021847697e-06)
(* 100.0 (/ (- (exp i) 1.0) (/ i n)))
(if (<= i 3.3504134620314933e-32)
(* 100.0 (- (+ n (* 0.5 (* i n))) (* i 0.5)))
(if (<= i 1.853747270743323e+248)
(*
100.0
(-
(+
(/ (pow n 3.0) (pow i 2.0))
(+
(* 0.5 (/ (* (pow n 3.0) (pow (log i) 2.0)) i))
(+
(* 0.5 (/ (* (pow n 3.0) (pow (log n) 2.0)) i))
(/ (* (log i) (pow n 2.0)) i))))
(+
(/ (* (log n) (pow n 2.0)) i)
(/ (* (log n) (* (pow n 3.0) (log i))) i))))
(if (<= i 2.852084085226162e+286)
(* 100.0 (/ (- (* n (pow (/ i n) n)) n) i))
(/ (* n (* 100.0 n)) (+ (+ n (* 0.5 (* i n))) (* i 0.5))))))))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 <= -2.1678153021847697e-06) {
tmp = 100.0 * ((exp(i) - 1.0) / (i / n));
} else if (i <= 3.3504134620314933e-32) {
tmp = 100.0 * ((n + (0.5 * (i * n))) - (i * 0.5));
} else if (i <= 1.853747270743323e+248) {
tmp = 100.0 * (((pow(n, 3.0) / pow(i, 2.0)) + ((0.5 * ((pow(n, 3.0) * pow(log(i), 2.0)) / i)) + ((0.5 * ((pow(n, 3.0) * pow(log(n), 2.0)) / i)) + ((log(i) * pow(n, 2.0)) / i)))) - (((log(n) * pow(n, 2.0)) / i) + ((log(n) * (pow(n, 3.0) * log(i))) / i)));
} else if (i <= 2.852084085226162e+286) {
tmp = 100.0 * (((n * pow((i / n), n)) - n) / i);
} else {
tmp = (n * (100.0 * n)) / ((n + (0.5 * (i * n))) + (i * 0.5));
}
return tmp;
}




Bits error versus i




Bits error versus n
Results
| Original | 47.7 |
|---|---|
| Target | 47.5 |
| Herbie | 11.8 |
if i < -2.1678153021847697e-6Initial program 27.9
Taylor expanded around inf 12.2
if -2.1678153021847697e-6 < i < 3.3504134620314933e-32Initial program 58.3
Taylor expanded around 0 8.2
if 3.3504134620314933e-32 < i < 1.85374727074332292e248Initial program 37.2
Taylor expanded around 0 22.7
if 1.85374727074332292e248 < i < 2.8520840852261622e286Initial program 32.1
Taylor expanded around inf 30.7
Simplified32.1
if 2.8520840852261622e286 < i Initial program 33.5
Taylor expanded around 0 63.4
Simplified63.4
rmApplied flip--_binary64_380464.0
Applied associate-*r/_binary64_377164.0
Simplified64.0
Taylor expanded around 0 28.9
Simplified28.9
Final simplification11.8
herbie shell --seed 2021024
(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))))