100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\begin{array}{l}
\mathbf{if}\;n \le -8.046837769241036 \cdot 10^{81}:\\
\;\;\;\;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{elif}\;n \le -4.5306115068498307 \cdot 10^{56}:\\
\;\;\;\;\frac{100}{i} \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{1}{n}}\\
\mathbf{elif}\;n \le -15831.5864445897478:\\
\;\;\;\;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{elif}\;n \le 8.1979849820500912 \cdot 10^{-194}:\\
\;\;\;\;\left(100 \cdot \frac{\sqrt[3]{{\left(1 + \frac{i}{n}\right)}^{n} - 1} \cdot \sqrt[3]{\log \left(e^{{\left(1 + \frac{i}{n}\right)}^{n} - 1}\right)}}{i}\right) \cdot \frac{\sqrt[3]{{\left(1 + \frac{i}{n}\right)}^{n} - 1}}{\frac{1}{n}}\\
\mathbf{else}:\\
\;\;\;\;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}}\\
\end{array}double f(double i, double n) {
double r128823 = 100.0;
double r128824 = 1.0;
double r128825 = i;
double r128826 = n;
double r128827 = r128825 / r128826;
double r128828 = r128824 + r128827;
double r128829 = pow(r128828, r128826);
double r128830 = r128829 - r128824;
double r128831 = r128830 / r128827;
double r128832 = r128823 * r128831;
return r128832;
}
double f(double i, double n) {
double r128833 = n;
double r128834 = -8.046837769241036e+81;
bool r128835 = r128833 <= r128834;
double r128836 = 100.0;
double r128837 = i;
double r128838 = 1.0;
double r128839 = 0.5;
double r128840 = 2.0;
double r128841 = pow(r128837, r128840);
double r128842 = log(r128838);
double r128843 = r128842 * r128833;
double r128844 = fma(r128839, r128841, r128843);
double r128845 = r128841 * r128842;
double r128846 = r128839 * r128845;
double r128847 = r128844 - r128846;
double r128848 = fma(r128837, r128838, r128847);
double r128849 = r128837 / r128833;
double r128850 = r128848 / r128849;
double r128851 = r128836 * r128850;
double r128852 = -4.530611506849831e+56;
bool r128853 = r128833 <= r128852;
double r128854 = r128836 / r128837;
double r128855 = r128838 + r128849;
double r128856 = pow(r128855, r128833);
double r128857 = r128856 - r128838;
double r128858 = 1.0;
double r128859 = r128858 / r128833;
double r128860 = r128857 / r128859;
double r128861 = r128854 * r128860;
double r128862 = -15831.586444589748;
bool r128863 = r128833 <= r128862;
double r128864 = 8.197984982050091e-194;
bool r128865 = r128833 <= r128864;
double r128866 = cbrt(r128857);
double r128867 = exp(r128857);
double r128868 = log(r128867);
double r128869 = cbrt(r128868);
double r128870 = r128866 * r128869;
double r128871 = r128870 / r128837;
double r128872 = r128836 * r128871;
double r128873 = r128866 / r128859;
double r128874 = r128872 * r128873;
double r128875 = r128865 ? r128874 : r128851;
double r128876 = r128863 ? r128851 : r128875;
double r128877 = r128853 ? r128861 : r128876;
double r128878 = r128835 ? r128851 : r128877;
return r128878;
}




Bits error versus i




Bits error versus n
| Original | 43.1 |
|---|---|
| Target | 43.0 |
| Herbie | 34.1 |
if n < -8.046837769241036e+81 or -4.530611506849831e+56 < n < -15831.586444589748 or 8.197984982050091e-194 < n Initial program 53.1
Taylor expanded around 0 39.4
Simplified39.4
if -8.046837769241036e+81 < n < -4.530611506849831e+56Initial program 33.4
rmApplied div-inv33.5
Applied *-un-lft-identity33.5
Applied times-frac33.3
Applied associate-*r*33.3
Simplified33.2
if -15831.586444589748 < n < 8.197984982050091e-194Initial program 21.8
rmApplied div-inv21.8
Applied add-cube-cbrt21.8
Applied times-frac22.3
Applied associate-*r*22.4
rmApplied add-cbrt-cube22.4
Simplified22.4
rmApplied add-log-exp22.4
Applied add-log-exp22.4
Applied diff-log22.4
Simplified22.4
Final simplification34.1
herbie shell --seed 2020083 +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))))