100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\begin{array}{l}
\mathbf{if}\;i \le -0.00389737092593035782:\\
\;\;\;\;100 \cdot \left(\frac{\sqrt{{\left(1 + \frac{i}{n}\right)}^{n}} + \sqrt{1}}{i} \cdot \left(\left(\sqrt{{\left(1 + \frac{i}{n}\right)}^{n}} - \sqrt{1}\right) \cdot n\right)\right)\\
\mathbf{elif}\;i \le 1.5425208996765195 \cdot 10^{-7}:\\
\;\;\;\;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) \cdot n}{i}\\
\mathbf{elif}\;i \le 1.22437183208912241 \cdot 10^{53}:\\
\;\;\;\;\frac{100}{\frac{\sqrt[3]{i} \cdot \sqrt[3]{i}}{\sqrt[3]{n} \cdot \sqrt[3]{n}}} \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{\sqrt[3]{i}}{\sqrt[3]{n}}}\\
\mathbf{elif}\;i \le 5.6632912188108867 \cdot 10^{265}:\\
\;\;\;\;100 \cdot \frac{\mathsf{fma}\left(1, i, \mathsf{fma}\left(\log 1, n, 1\right)\right) - 1}{\frac{i}{n}}\\
\mathbf{else}:\\
\;\;\;\;\frac{100}{i} \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{1}{n}}\\
\end{array}double f(double i, double n) {
double r162040 = 100.0;
double r162041 = 1.0;
double r162042 = i;
double r162043 = n;
double r162044 = r162042 / r162043;
double r162045 = r162041 + r162044;
double r162046 = pow(r162045, r162043);
double r162047 = r162046 - r162041;
double r162048 = r162047 / r162044;
double r162049 = r162040 * r162048;
return r162049;
}
double f(double i, double n) {
double r162050 = i;
double r162051 = -0.003897370925930358;
bool r162052 = r162050 <= r162051;
double r162053 = 100.0;
double r162054 = 1.0;
double r162055 = n;
double r162056 = r162050 / r162055;
double r162057 = r162054 + r162056;
double r162058 = pow(r162057, r162055);
double r162059 = sqrt(r162058);
double r162060 = sqrt(r162054);
double r162061 = r162059 + r162060;
double r162062 = r162061 / r162050;
double r162063 = r162059 - r162060;
double r162064 = r162063 * r162055;
double r162065 = r162062 * r162064;
double r162066 = r162053 * r162065;
double r162067 = 1.5425208996765195e-07;
bool r162068 = r162050 <= r162067;
double r162069 = 0.5;
double r162070 = 2.0;
double r162071 = pow(r162050, r162070);
double r162072 = log(r162054);
double r162073 = r162072 * r162055;
double r162074 = fma(r162069, r162071, r162073);
double r162075 = r162071 * r162072;
double r162076 = r162069 * r162075;
double r162077 = r162074 - r162076;
double r162078 = fma(r162050, r162054, r162077);
double r162079 = r162078 * r162055;
double r162080 = r162079 / r162050;
double r162081 = r162053 * r162080;
double r162082 = 1.2243718320891224e+53;
bool r162083 = r162050 <= r162082;
double r162084 = cbrt(r162050);
double r162085 = r162084 * r162084;
double r162086 = cbrt(r162055);
double r162087 = r162086 * r162086;
double r162088 = r162085 / r162087;
double r162089 = r162053 / r162088;
double r162090 = r162058 - r162054;
double r162091 = r162084 / r162086;
double r162092 = r162090 / r162091;
double r162093 = r162089 * r162092;
double r162094 = 5.663291218810887e+265;
bool r162095 = r162050 <= r162094;
double r162096 = 1.0;
double r162097 = fma(r162072, r162055, r162096);
double r162098 = fma(r162054, r162050, r162097);
double r162099 = r162098 - r162054;
double r162100 = r162099 / r162056;
double r162101 = r162053 * r162100;
double r162102 = r162053 / r162050;
double r162103 = r162096 / r162055;
double r162104 = r162090 / r162103;
double r162105 = r162102 * r162104;
double r162106 = r162095 ? r162101 : r162105;
double r162107 = r162083 ? r162093 : r162106;
double r162108 = r162068 ? r162081 : r162107;
double r162109 = r162052 ? r162066 : r162108;
return r162109;
}




Bits error versus i




Bits error versus n
| Original | 43.0 |
|---|---|
| Target | 42.4 |
| Herbie | 21.6 |
if i < -0.003897370925930358Initial program 28.4
rmApplied div-inv28.4
Applied add-sqr-sqrt28.4
Applied add-sqr-sqrt28.4
Applied difference-of-squares28.4
Applied times-frac28.8
Simplified28.8
if -0.003897370925930358 < i < 1.5425208996765195e-07Initial program 50.8
Taylor expanded around 0 34.1
Simplified34.1
rmApplied div-inv34.2
Applied *-un-lft-identity34.2
Applied times-frac15.7
Applied associate-*r*16.1
Simplified16.1
rmApplied *-un-lft-identity16.1
Applied add-sqr-sqrt16.1
Applied times-frac16.1
Applied *-un-lft-identity16.1
Applied times-frac16.1
Simplified16.1
Simplified16.0
rmApplied div-inv16.1
Applied associate-*l*15.7
Simplified15.5
if 1.5425208996765195e-07 < i < 1.2243718320891224e+53Initial program 34.7
rmApplied add-cube-cbrt34.7
Applied add-cube-cbrt34.8
Applied times-frac34.8
Applied *-un-lft-identity34.8
Applied times-frac34.8
Applied associate-*r*34.8
Simplified34.8
if 1.2243718320891224e+53 < i < 5.663291218810887e+265Initial program 31.8
Taylor expanded around 0 39.6
Simplified39.6
if 5.663291218810887e+265 < i Initial program 30.0
rmApplied div-inv30.1
Applied *-un-lft-identity30.1
Applied times-frac30.1
Applied associate-*r*30.1
Simplified30.1
Final simplification21.6
herbie shell --seed 2020033 +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))))