100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\begin{array}{l}
\mathbf{if}\;i \le -3.7966848740325338 \cdot 10^{-12}:\\
\;\;\;\;\frac{100 \cdot \left({\left(\frac{i}{n}\right)}^{n} - 1\right)}{\frac{i}{n}}\\
\mathbf{elif}\;i \le 2.52939612132628033:\\
\;\;\;\;100 \cdot \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)}{\frac{i}{n}}\\
\mathbf{else}:\\
\;\;\;\;\left(100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{i}\right) \cdot n\\
\end{array}double f(double i, double n) {
double r188632 = 100.0;
double r188633 = 1.0;
double r188634 = i;
double r188635 = n;
double r188636 = r188634 / r188635;
double r188637 = r188633 + r188636;
double r188638 = pow(r188637, r188635);
double r188639 = r188638 - r188633;
double r188640 = r188639 / r188636;
double r188641 = r188632 * r188640;
return r188641;
}
double f(double i, double n) {
double r188642 = i;
double r188643 = -3.796684874032534e-12;
bool r188644 = r188642 <= r188643;
double r188645 = 100.0;
double r188646 = n;
double r188647 = r188642 / r188646;
double r188648 = pow(r188647, r188646);
double r188649 = 1.0;
double r188650 = r188648 - r188649;
double r188651 = r188645 * r188650;
double r188652 = r188651 / r188647;
double r188653 = 2.5293961213262803;
bool r188654 = r188642 <= r188653;
double r188655 = 0.5;
double r188656 = 2.0;
double r188657 = pow(r188642, r188656);
double r188658 = log(r188649);
double r188659 = r188658 * r188646;
double r188660 = fma(r188655, r188657, r188659);
double r188661 = r188657 * r188658;
double r188662 = r188655 * r188661;
double r188663 = r188660 - r188662;
double r188664 = fma(r188642, r188649, r188663);
double r188665 = r188664 / r188647;
double r188666 = r188645 * r188665;
double r188667 = r188649 + r188647;
double r188668 = pow(r188667, r188646);
double r188669 = r188668 - r188649;
double r188670 = r188669 / r188642;
double r188671 = r188645 * r188670;
double r188672 = r188671 * r188646;
double r188673 = r188654 ? r188666 : r188672;
double r188674 = r188644 ? r188652 : r188673;
return r188674;
}




Bits error versus i




Bits error versus n
| Original | 42.9 |
|---|---|
| Target | 42.4 |
| Herbie | 30.8 |
if i < -3.796684874032534e-12Initial program 29.1
rmApplied associate-*r/29.1
Taylor expanded around inf 64.0
Simplified19.3
if -3.796684874032534e-12 < i < 2.5293961213262803Initial program 50.2
Taylor expanded around 0 34.5
Simplified34.5
if 2.5293961213262803 < i Initial program 33.3
rmApplied associate-/r/33.3
Applied associate-*r*33.3
Final simplification30.8
herbie shell --seed 2020003 +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))))