100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\begin{array}{l}
\mathbf{if}\;i \le -0.14141811154607586:\\
\;\;\;\;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}}\\
\mathbf{elif}\;i \le 0.0090801660236610824:\\
\;\;\;\;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}:\\
\;\;\;\;\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 r140737 = 100.0;
double r140738 = 1.0;
double r140739 = i;
double r140740 = n;
double r140741 = r140739 / r140740;
double r140742 = r140738 + r140741;
double r140743 = pow(r140742, r140740);
double r140744 = r140743 - r140738;
double r140745 = r140744 / r140741;
double r140746 = r140737 * r140745;
return r140746;
}
double f(double i, double n) {
double r140747 = i;
double r140748 = -0.14141811154607586;
bool r140749 = r140747 <= r140748;
double r140750 = 100.0;
double r140751 = 1.0;
double r140752 = n;
double r140753 = r140747 / r140752;
double r140754 = r140751 + r140753;
double r140755 = 2.0;
double r140756 = r140755 * r140752;
double r140757 = pow(r140754, r140756);
double r140758 = r140751 * r140751;
double r140759 = -r140758;
double r140760 = r140757 + r140759;
double r140761 = pow(r140754, r140752);
double r140762 = r140761 + r140751;
double r140763 = r140760 / r140762;
double r140764 = r140763 / r140753;
double r140765 = r140750 * r140764;
double r140766 = 0.009080166023661082;
bool r140767 = r140747 <= r140766;
double r140768 = 0.5;
double r140769 = pow(r140747, r140755);
double r140770 = log(r140751);
double r140771 = r140770 * r140752;
double r140772 = fma(r140768, r140769, r140771);
double r140773 = r140769 * r140770;
double r140774 = r140768 * r140773;
double r140775 = r140772 - r140774;
double r140776 = fma(r140747, r140751, r140775);
double r140777 = r140776 / r140747;
double r140778 = r140777 * r140752;
double r140779 = r140750 * r140778;
double r140780 = r140761 - r140751;
double r140781 = r140780 / r140747;
double r140782 = r140750 * r140781;
double r140783 = r140782 * r140752;
double r140784 = r140767 ? r140779 : r140783;
double r140785 = r140749 ? r140765 : r140784;
return r140785;
}




Bits error versus i




Bits error versus n
| Original | 42.8 |
|---|---|
| Target | 42.5 |
| Herbie | 21.8 |
if i < -0.14141811154607586Initial program 28.6
rmApplied flip--28.6
Simplified28.6
if -0.14141811154607586 < i < 0.009080166023661082Initial program 50.4
Taylor expanded around 0 34.5
Simplified34.5
rmApplied associate-/r/17.1
if 0.009080166023661082 < i Initial program 31.7
rmApplied associate-/r/31.7
Applied associate-*r*31.7
Final simplification21.8
herbie shell --seed 2020049 +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))))