100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\begin{array}{l}
\mathbf{if}\;i \le -0.8489635077384908301567634225648362189531:\\
\;\;\;\;\frac{100 \cdot \left({\left(\frac{i}{n}\right)}^{n} - 1\right)}{\frac{i}{n}}\\
\mathbf{elif}\;i \le 0.5476118163719528864064045592385809868574:\\
\;\;\;\;\frac{100}{i} \cdot \left(\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\right)\\
\mathbf{else}:\\
\;\;\;\;100 \cdot \left(\frac{1}{i} \cdot \left(\left({\left(1 + \frac{i}{n}\right)}^{n} - 1\right) \cdot n\right)\right)\\
\end{array}double f(double i, double n) {
double r135644 = 100.0;
double r135645 = 1.0;
double r135646 = i;
double r135647 = n;
double r135648 = r135646 / r135647;
double r135649 = r135645 + r135648;
double r135650 = pow(r135649, r135647);
double r135651 = r135650 - r135645;
double r135652 = r135651 / r135648;
double r135653 = r135644 * r135652;
return r135653;
}
double f(double i, double n) {
double r135654 = i;
double r135655 = -0.8489635077384908;
bool r135656 = r135654 <= r135655;
double r135657 = 100.0;
double r135658 = n;
double r135659 = r135654 / r135658;
double r135660 = pow(r135659, r135658);
double r135661 = 1.0;
double r135662 = r135660 - r135661;
double r135663 = r135657 * r135662;
double r135664 = r135663 / r135659;
double r135665 = 0.5476118163719529;
bool r135666 = r135654 <= r135665;
double r135667 = r135657 / r135654;
double r135668 = 0.5;
double r135669 = 2.0;
double r135670 = pow(r135654, r135669);
double r135671 = log(r135661);
double r135672 = r135671 * r135658;
double r135673 = fma(r135668, r135670, r135672);
double r135674 = fma(r135661, r135654, r135673);
double r135675 = r135670 * r135671;
double r135676 = r135668 * r135675;
double r135677 = r135674 - r135676;
double r135678 = r135677 * r135658;
double r135679 = r135667 * r135678;
double r135680 = 1.0;
double r135681 = r135680 / r135654;
double r135682 = r135661 + r135659;
double r135683 = pow(r135682, r135658);
double r135684 = r135683 - r135661;
double r135685 = r135684 * r135658;
double r135686 = r135681 * r135685;
double r135687 = r135657 * r135686;
double r135688 = r135666 ? r135679 : r135687;
double r135689 = r135656 ? r135664 : r135688;
return r135689;
}




Bits error versus i




Bits error versus n
| Original | 43.0 |
|---|---|
| Target | 43.5 |
| Herbie | 18.8 |
if i < -0.8489635077384908Initial program 27.4
Taylor expanded around inf 64.0
Simplified18.1
if -0.8489635077384908 < 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.8
Simplified15.8
rmApplied associate-*r*16.2
Simplified16.1
if 0.5476118163719529 < i Initial program 32.4
rmApplied div-inv32.4
Applied *-un-lft-identity32.4
Applied times-frac32.4
Simplified32.4
Final simplification18.8
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))))