100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\begin{array}{l}
\mathbf{if}\;i \le -1.17879906071750874 \cdot 10^{-7}:\\
\;\;\;\;100 \cdot \frac{\log \left(e^{{\left(1 + \frac{i}{n}\right)}^{n} - 1}\right)}{\frac{i}{n}}\\
\mathbf{elif}\;i \le 8.74609462986419547 \cdot 10^{-16}:\\
\;\;\;\;100 \cdot \left(\frac{\mathsf{fma}\left(i, 1, \mathsf{fma}\left(0.5, {i}^{2}, \log 1 \cdot n\right) - 0.5 \cdot \left({i}^{2} \cdot \log 1\right)\right)}{i} \cdot n\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{100}{i} \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{1}{n}}\\
\end{array}double f(double i, double n) {
double r155693 = 100.0;
double r155694 = 1.0;
double r155695 = i;
double r155696 = n;
double r155697 = r155695 / r155696;
double r155698 = r155694 + r155697;
double r155699 = pow(r155698, r155696);
double r155700 = r155699 - r155694;
double r155701 = r155700 / r155697;
double r155702 = r155693 * r155701;
return r155702;
}
double f(double i, double n) {
double r155703 = i;
double r155704 = -1.1787990607175087e-07;
bool r155705 = r155703 <= r155704;
double r155706 = 100.0;
double r155707 = 1.0;
double r155708 = n;
double r155709 = r155703 / r155708;
double r155710 = r155707 + r155709;
double r155711 = pow(r155710, r155708);
double r155712 = r155711 - r155707;
double r155713 = exp(r155712);
double r155714 = log(r155713);
double r155715 = r155714 / r155709;
double r155716 = r155706 * r155715;
double r155717 = 8.746094629864195e-16;
bool r155718 = r155703 <= r155717;
double r155719 = 0.5;
double r155720 = 2.0;
double r155721 = pow(r155703, r155720);
double r155722 = log(r155707);
double r155723 = r155722 * r155708;
double r155724 = fma(r155719, r155721, r155723);
double r155725 = r155721 * r155722;
double r155726 = r155719 * r155725;
double r155727 = r155724 - r155726;
double r155728 = fma(r155703, r155707, r155727);
double r155729 = r155728 / r155703;
double r155730 = r155729 * r155708;
double r155731 = r155706 * r155730;
double r155732 = r155706 / r155703;
double r155733 = 1.0;
double r155734 = r155733 / r155708;
double r155735 = r155712 / r155734;
double r155736 = r155732 * r155735;
double r155737 = r155718 ? r155731 : r155736;
double r155738 = r155705 ? r155716 : r155737;
return r155738;
}




Bits error versus i




Bits error versus n
| Original | 47.3 |
|---|---|
| Target | 47.0 |
| Herbie | 17.3 |
if i < -1.1787990607175087e-07Initial program 29.1
rmApplied add-log-exp29.1
Applied add-log-exp29.1
Applied diff-log29.1
Simplified29.1
if -1.1787990607175087e-07 < i < 8.746094629864195e-16Initial program 57.8
Taylor expanded around 0 27.1
Simplified27.1
rmApplied associate-/r/9.2
if 8.746094629864195e-16 < i Initial program 32.5
rmApplied div-inv32.6
Applied *-un-lft-identity32.6
Applied times-frac32.6
Applied associate-*r*32.6
Simplified32.5
Final simplification17.3
herbie shell --seed 2020100 +o rules:numerics
(FPCore (i n)
:name "Compound Interest"
:precision binary64
:herbie-target
(* 100 (/ (- (exp (* n (if (== (+ 1 (/ i n)) 1) (/ i n) (/ (* (/ i n) (log (+ 1 (/ i n)))) (- (+ (/ i n) 1) 1))))) 1) (/ i n)))
(* 100 (/ (- (pow (+ 1 (/ i n)) n) 1) (/ i n))))