100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\begin{array}{l}
\mathbf{if}\;i \le -6.8977356701701615 \cdot 10^{-9}:\\
\;\;\;\;100 \cdot \left(\frac{{\left(1 + \frac{i}{n}\right)}^{n}}{\frac{i}{n}} - \frac{1}{\frac{i}{n}}\right)\\
\mathbf{elif}\;i \le 3.9028797563160959 \cdot 10^{-7}:\\
\;\;\;\;\left(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)}{i}\right) \cdot n\\
\mathbf{else}:\\
\;\;\;\;\left(\left({\left(1 + \frac{i}{n}\right)}^{\left(\frac{n}{2}\right)} + \sqrt{1}\right) \cdot 100\right) \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{\left(\frac{n}{2}\right)} - \sqrt{1}}{\frac{i}{n}}\\
\end{array}double f(double i, double n) {
double r158661 = 100.0;
double r158662 = 1.0;
double r158663 = i;
double r158664 = n;
double r158665 = r158663 / r158664;
double r158666 = r158662 + r158665;
double r158667 = pow(r158666, r158664);
double r158668 = r158667 - r158662;
double r158669 = r158668 / r158665;
double r158670 = r158661 * r158669;
return r158670;
}
double f(double i, double n) {
double r158671 = i;
double r158672 = -6.8977356701701615e-09;
bool r158673 = r158671 <= r158672;
double r158674 = 100.0;
double r158675 = 1.0;
double r158676 = n;
double r158677 = r158671 / r158676;
double r158678 = r158675 + r158677;
double r158679 = pow(r158678, r158676);
double r158680 = r158679 / r158677;
double r158681 = r158675 / r158677;
double r158682 = r158680 - r158681;
double r158683 = r158674 * r158682;
double r158684 = 3.902879756316096e-07;
bool r158685 = r158671 <= r158684;
double r158686 = 0.5;
double r158687 = 2.0;
double r158688 = pow(r158671, r158687);
double r158689 = log(r158675);
double r158690 = r158689 * r158676;
double r158691 = fma(r158686, r158688, r158690);
double r158692 = r158688 * r158689;
double r158693 = r158686 * r158692;
double r158694 = r158691 - r158693;
double r158695 = fma(r158671, r158675, r158694);
double r158696 = r158695 / r158671;
double r158697 = r158674 * r158696;
double r158698 = r158697 * r158676;
double r158699 = r158676 / r158687;
double r158700 = pow(r158678, r158699);
double r158701 = sqrt(r158675);
double r158702 = r158700 + r158701;
double r158703 = r158702 * r158674;
double r158704 = r158700 - r158701;
double r158705 = r158704 / r158677;
double r158706 = r158703 * r158705;
double r158707 = r158685 ? r158698 : r158706;
double r158708 = r158673 ? r158683 : r158707;
return r158708;
}




Bits error versus i




Bits error versus n
| Original | 47.8 |
|---|---|
| Target | 47.4 |
| Herbie | 16.9 |
if i < -6.8977356701701615e-09Initial program 29.3
rmApplied div-sub29.3
if -6.8977356701701615e-09 < i < 3.902879756316096e-07Initial program 58.5
Taylor expanded around 0 26.3
Simplified26.3
rmApplied associate-/r/8.6
Applied associate-*r*8.6
if 3.902879756316096e-07 < i Initial program 32.1
rmApplied *-un-lft-identity32.1
Applied *-un-lft-identity32.1
Applied times-frac32.1
Applied add-sqr-sqrt32.1
Applied sqr-pow32.2
Applied difference-of-squares32.2
Applied times-frac32.2
Applied associate-*r*32.2
Simplified32.2
Final simplification16.9
herbie shell --seed 2020060 +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))))