100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\begin{array}{l}
\mathbf{if}\;i \le -0.0390445009989891442:\\
\;\;\;\;\frac{100}{i} \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{1}{n}}\\
\mathbf{elif}\;i \le 22.1533166385413587:\\
\;\;\;\;\mathsf{fma}\left(i, 50, \mathsf{fma}\left(100, \frac{\log 1 \cdot n}{i}, 100\right) - 50 \cdot \left(i \cdot \log 1\right)\right) \cdot n\\
\mathbf{else}:\\
\;\;\;\;100 \cdot \frac{\frac{{\left(1 + \frac{i}{n}\right)}^{\left(2 \cdot n\right)} + \left(-1 \cdot 1\right)}{{\left(1 + \frac{i}{n}\right)}^{n} + 1}}{\frac{i}{n}}\\
\end{array}double f(double i, double n) {
double r125602 = 100.0;
double r125603 = 1.0;
double r125604 = i;
double r125605 = n;
double r125606 = r125604 / r125605;
double r125607 = r125603 + r125606;
double r125608 = pow(r125607, r125605);
double r125609 = r125608 - r125603;
double r125610 = r125609 / r125606;
double r125611 = r125602 * r125610;
return r125611;
}
double f(double i, double n) {
double r125612 = i;
double r125613 = -0.039044500998989144;
bool r125614 = r125612 <= r125613;
double r125615 = 100.0;
double r125616 = r125615 / r125612;
double r125617 = 1.0;
double r125618 = n;
double r125619 = r125612 / r125618;
double r125620 = r125617 + r125619;
double r125621 = pow(r125620, r125618);
double r125622 = r125621 - r125617;
double r125623 = 1.0;
double r125624 = r125623 / r125618;
double r125625 = r125622 / r125624;
double r125626 = r125616 * r125625;
double r125627 = 22.15331663854136;
bool r125628 = r125612 <= r125627;
double r125629 = 50.0;
double r125630 = log(r125617);
double r125631 = r125630 * r125618;
double r125632 = r125631 / r125612;
double r125633 = fma(r125615, r125632, r125615);
double r125634 = r125612 * r125630;
double r125635 = r125629 * r125634;
double r125636 = r125633 - r125635;
double r125637 = fma(r125612, r125629, r125636);
double r125638 = r125637 * r125618;
double r125639 = 2.0;
double r125640 = r125639 * r125618;
double r125641 = pow(r125620, r125640);
double r125642 = r125617 * r125617;
double r125643 = -r125642;
double r125644 = r125641 + r125643;
double r125645 = r125621 + r125617;
double r125646 = r125644 / r125645;
double r125647 = r125646 / r125619;
double r125648 = r125615 * r125647;
double r125649 = r125628 ? r125638 : r125648;
double r125650 = r125614 ? r125626 : r125649;
return r125650;
}




Bits error versus i




Bits error versus n
| Original | 47.1 |
|---|---|
| Target | 46.8 |
| Herbie | 16.9 |
if i < -0.039044500998989144Initial program 27.3
rmApplied div-inv27.3
Applied *-un-lft-identity27.3
Applied times-frac27.8
Applied associate-*r*27.8
Simplified27.8
if -0.039044500998989144 < i < 22.15331663854136Initial program 57.8
Taylor expanded around 0 26.8
Simplified26.8
rmApplied associate-/r/9.8
Applied associate-*r*9.8
Taylor expanded around 0 9.8
Simplified9.8
if 22.15331663854136 < i Initial program 31.6
rmApplied flip--31.6
Simplified31.6
Final simplification16.9
herbie shell --seed 2020062 +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))))