100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\begin{array}{l}
\mathbf{if}\;i \le -1.74625455624762593309640124061843380332:\\
\;\;\;\;100 \cdot \frac{\mathsf{fma}\left(\sqrt[3]{{\left(1 + \frac{i}{n}\right)}^{n}} \cdot \sqrt[3]{{\left(1 + \frac{i}{n}\right)}^{n}}, \sqrt[3]{{\left(1 + \frac{i}{n}\right)}^{n}}, -1\right) + \left(\left(-1\right) + 1\right)}{\frac{i}{n}}\\
\mathbf{elif}\;i \le 0.5476118163719528864064045592385809868574:\\
\;\;\;\;\frac{100}{\frac{i}{\left(\mathsf{fma}\left(1, i, \mathsf{fma}\left(0.5, {i}^{2}, \log 1 \cdot n\right)\right) - 0.5 \cdot \left({i}^{2} \cdot \log 1\right)\right) \cdot 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 r99863 = 100.0;
double r99864 = 1.0;
double r99865 = i;
double r99866 = n;
double r99867 = r99865 / r99866;
double r99868 = r99864 + r99867;
double r99869 = pow(r99868, r99866);
double r99870 = r99869 - r99864;
double r99871 = r99870 / r99867;
double r99872 = r99863 * r99871;
return r99872;
}
double f(double i, double n) {
double r99873 = i;
double r99874 = -1.746254556247626;
bool r99875 = r99873 <= r99874;
double r99876 = 100.0;
double r99877 = 1.0;
double r99878 = n;
double r99879 = r99873 / r99878;
double r99880 = r99877 + r99879;
double r99881 = pow(r99880, r99878);
double r99882 = cbrt(r99881);
double r99883 = r99882 * r99882;
double r99884 = -r99877;
double r99885 = fma(r99883, r99882, r99884);
double r99886 = r99884 + r99877;
double r99887 = r99885 + r99886;
double r99888 = r99887 / r99879;
double r99889 = r99876 * r99888;
double r99890 = 0.5476118163719529;
bool r99891 = r99873 <= r99890;
double r99892 = 0.5;
double r99893 = 2.0;
double r99894 = pow(r99873, r99893);
double r99895 = log(r99877);
double r99896 = r99895 * r99878;
double r99897 = fma(r99892, r99894, r99896);
double r99898 = fma(r99877, r99873, r99897);
double r99899 = r99894 * r99895;
double r99900 = r99892 * r99899;
double r99901 = r99898 - r99900;
double r99902 = r99901 * r99878;
double r99903 = r99873 / r99902;
double r99904 = r99876 / r99903;
double r99905 = r99881 - r99877;
double r99906 = r99905 / r99873;
double r99907 = r99876 * r99906;
double r99908 = r99907 * r99878;
double r99909 = r99891 ? r99904 : r99908;
double r99910 = r99875 ? r99889 : r99909;
return r99910;
}




Bits error versus i




Bits error versus n
| Original | 43.0 |
|---|---|
| Target | 43.5 |
| Herbie | 20.7 |
if i < -1.746254556247626Initial program 27.3
rmApplied add-cube-cbrt27.3
Applied add-cube-cbrt27.4
Applied prod-diff27.4
Simplified27.4
Simplified27.4
if -1.746254556247626 < i < 0.5476118163719529Initial program 50.8
Taylor expanded around 0 34.2
Simplified34.2
rmApplied div-inv34.3
Applied *-un-lft-identity34.3
Applied times-frac15.9
Simplified15.8
rmApplied associate-*l/15.7
Applied associate-*r/15.8
Simplified15.8
rmApplied associate-/l*15.8
if 0.5476118163719529 < i Initial program 32.4
rmApplied associate-/r/32.4
Applied associate-*r*32.4
Final simplification20.7
herbie shell --seed 2019323 +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))))