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 r152925 = 100.0;
double r152926 = 1.0;
double r152927 = i;
double r152928 = n;
double r152929 = r152927 / r152928;
double r152930 = r152926 + r152929;
double r152931 = pow(r152930, r152928);
double r152932 = r152931 - r152926;
double r152933 = r152932 / r152929;
double r152934 = r152925 * r152933;
return r152934;
}
double f(double i, double n) {
double r152935 = i;
double r152936 = -0.039044500998989144;
bool r152937 = r152935 <= r152936;
double r152938 = 100.0;
double r152939 = r152938 / r152935;
double r152940 = 1.0;
double r152941 = n;
double r152942 = r152935 / r152941;
double r152943 = r152940 + r152942;
double r152944 = pow(r152943, r152941);
double r152945 = r152944 - r152940;
double r152946 = 1.0;
double r152947 = r152946 / r152941;
double r152948 = r152945 / r152947;
double r152949 = r152939 * r152948;
double r152950 = 22.15331663854136;
bool r152951 = r152935 <= r152950;
double r152952 = 50.0;
double r152953 = log(r152940);
double r152954 = r152953 * r152941;
double r152955 = r152954 / r152935;
double r152956 = fma(r152938, r152955, r152938);
double r152957 = r152935 * r152953;
double r152958 = r152952 * r152957;
double r152959 = r152956 - r152958;
double r152960 = fma(r152935, r152952, r152959);
double r152961 = r152960 * r152941;
double r152962 = 2.0;
double r152963 = r152962 * r152941;
double r152964 = pow(r152943, r152963);
double r152965 = r152940 * r152940;
double r152966 = -r152965;
double r152967 = r152964 + r152966;
double r152968 = r152944 + r152940;
double r152969 = r152967 / r152968;
double r152970 = r152969 / r152942;
double r152971 = r152938 * r152970;
double r152972 = r152951 ? r152961 : r152971;
double r152973 = r152937 ? r152949 : r152972;
return r152973;
}




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))))