100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\begin{array}{l}
\mathbf{if}\;i \leq -78308.95981690803:\\
\;\;\;\;100 \cdot \frac{-1 + {\left(\frac{i}{n}\right)}^{n}}{\frac{i}{n}}\\
\mathbf{elif}\;i \leq -1.328223267458416 \cdot 10^{-171}:\\
\;\;\;\;\frac{100}{i} \cdot \frac{i + \left(i \cdot i\right) \cdot \left(0.5 + i \cdot 0.16666666666666666\right)}{\frac{1}{n}}\\
\mathbf{elif}\;i \leq 1.2445990049455903 \cdot 10^{-05}:\\
\;\;\;\;n \cdot \left(i \cdot 50 + \left(100 + e^{\sqrt[3]{\log \left(\left(i \cdot i\right) \cdot 16.666666666666668\right)} \cdot \left(\sqrt[3]{\log \left(\left(i \cdot i\right) \cdot 16.666666666666668\right)} \cdot \sqrt[3]{\log \left(\left(i \cdot i\right) \cdot 16.666666666666668\right)}\right)}\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 -78308.95981690803)
(* 100.0 (/ (+ -1.0 (pow (/ i n) n)) (/ i n)))
(if (<= i -1.328223267458416e-171)
(*
(/ 100.0 i)
(/ (+ i (* (* i i) (+ 0.5 (* i 0.16666666666666666)))) (/ 1.0 n)))
(if (<= i 1.2445990049455903e-05)
(*
n
(+
(* i 50.0)
(+
100.0
(exp
(*
(cbrt (log (* (* i i) 16.666666666666668)))
(*
(cbrt (log (* (* i i) 16.666666666666668)))
(cbrt (log (* (* 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 <= -78308.95981690803) {
tmp = 100.0 * ((-1.0 + pow((i / n), n)) / (i / n));
} else if (i <= -1.328223267458416e-171) {
tmp = (100.0 / i) * ((i + ((i * i) * (0.5 + (i * 0.16666666666666666)))) / (1.0 / n));
} else if (i <= 1.2445990049455903e-05) {
tmp = n * ((i * 50.0) + (100.0 + exp(cbrt(log((i * i) * 16.666666666666668)) * (cbrt(log((i * i) * 16.666666666666668)) * cbrt(log((i * i) * 16.666666666666668))))));
} else {
tmp = 0.0;
}
return tmp;
}




Bits error versus i




Bits error versus n
Results
| Original | 47.7 |
|---|---|
| Target | 47.4 |
| Herbie | 13.5 |
if i < -78308.959816908027Initial program 27.8
Taylor expanded around inf 64.0
Simplified18.3
if -78308.959816908027 < i < -1.3282232674584161e-171Initial program 55.0
Taylor expanded around 0 24.6
Simplified24.6
rmApplied div-inv_binary6424.7
Applied *-un-lft-identity_binary6424.7
Applied times-frac_binary6411.9
Applied associate-*r*_binary6411.9
Simplified11.9
if -1.3282232674584161e-171 < i < 1.24459900494559025e-5Initial program 59.1
Taylor expanded around 0 26.9
Simplified26.9
Taylor expanded around 0 6.8
Simplified6.8
rmApplied add-exp-log_binary646.8
Applied add-exp-log_binary6427.3
Applied add-exp-log_binary6427.3
Applied prod-exp_binary6427.3
Applied prod-exp_binary6427.3
Simplified6.8
rmApplied add-cube-cbrt_binary646.8
if 1.24459900494559025e-5 < i Initial program 32.6
Taylor expanded around 0 29.9
Final simplification13.5
herbie shell --seed 2020233
(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))))