100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\begin{array}{l}
\mathbf{if}\;i \le -0.003542899967172804479714764980258223658893:\\
\;\;\;\;100 \cdot \frac{\frac{{\left(1 + \frac{i}{n}\right)}^{\left(2 \cdot n\right)} - 1 \cdot 1}{{\left(1 + \frac{i}{n}\right)}^{n} + 1}}{\frac{i}{n}}\\
\mathbf{elif}\;i \le 1.164724267812725200244017287332098931074:\\
\;\;\;\;\frac{100}{i} \cdot \frac{\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)}{\frac{1}{n}}\\
\mathbf{elif}\;i \le 5.534188978290047690365799985685838194202 \cdot 10^{103}:\\
\;\;\;\;100 \cdot \frac{\log \left(e^{{\left(1 + \frac{i}{n}\right)}^{n} - 1}\right)}{\frac{i}{n}}\\
\mathbf{else}:\\
\;\;\;\;100 \cdot \frac{\mathsf{fma}\left(1, i, \mathsf{fma}\left(\log 1, n, 1\right)\right) - 1}{\frac{i}{n}}\\
\end{array}double f(double i, double n) {
double r144470 = 100.0;
double r144471 = 1.0;
double r144472 = i;
double r144473 = n;
double r144474 = r144472 / r144473;
double r144475 = r144471 + r144474;
double r144476 = pow(r144475, r144473);
double r144477 = r144476 - r144471;
double r144478 = r144477 / r144474;
double r144479 = r144470 * r144478;
return r144479;
}
double f(double i, double n) {
double r144480 = i;
double r144481 = -0.0035428999671728045;
bool r144482 = r144480 <= r144481;
double r144483 = 100.0;
double r144484 = 1.0;
double r144485 = n;
double r144486 = r144480 / r144485;
double r144487 = r144484 + r144486;
double r144488 = 2.0;
double r144489 = r144488 * r144485;
double r144490 = pow(r144487, r144489);
double r144491 = r144484 * r144484;
double r144492 = r144490 - r144491;
double r144493 = pow(r144487, r144485);
double r144494 = r144493 + r144484;
double r144495 = r144492 / r144494;
double r144496 = r144495 / r144486;
double r144497 = r144483 * r144496;
double r144498 = 1.1647242678127252;
bool r144499 = r144480 <= r144498;
double r144500 = r144483 / r144480;
double r144501 = 0.5;
double r144502 = pow(r144480, r144488);
double r144503 = log(r144484);
double r144504 = r144503 * r144485;
double r144505 = fma(r144501, r144502, r144504);
double r144506 = fma(r144484, r144480, r144505);
double r144507 = r144502 * r144503;
double r144508 = r144501 * r144507;
double r144509 = r144506 - r144508;
double r144510 = 1.0;
double r144511 = r144510 / r144485;
double r144512 = r144509 / r144511;
double r144513 = r144500 * r144512;
double r144514 = 5.534188978290048e+103;
bool r144515 = r144480 <= r144514;
double r144516 = r144493 - r144484;
double r144517 = exp(r144516);
double r144518 = log(r144517);
double r144519 = r144518 / r144486;
double r144520 = r144483 * r144519;
double r144521 = fma(r144503, r144485, r144510);
double r144522 = fma(r144484, r144480, r144521);
double r144523 = r144522 - r144484;
double r144524 = r144523 / r144486;
double r144525 = r144483 * r144524;
double r144526 = r144515 ? r144520 : r144525;
double r144527 = r144499 ? r144513 : r144526;
double r144528 = r144482 ? r144497 : r144527;
return r144528;
}




Bits error versus i




Bits error versus n
| Original | 43.0 |
|---|---|
| Target | 42.4 |
| Herbie | 21.6 |
if i < -0.0035428999671728045Initial program 29.5
rmApplied flip--29.5
Simplified29.4
if -0.0035428999671728045 < i < 1.1647242678127252Initial program 50.3
Taylor expanded around 0 33.5
Simplified33.5
rmApplied div-inv33.5
Applied *-un-lft-identity33.5
Applied times-frac15.4
Applied associate-*r*15.7
Simplified15.7
if 1.1647242678127252 < i < 5.534188978290048e+103Initial program 33.7
rmApplied add-log-exp33.7
Applied add-log-exp34.0
Applied diff-log34.0
Simplified34.0
if 5.534188978290048e+103 < i Initial program 32.2
Taylor expanded around 0 36.1
Simplified36.1
Final simplification21.6
herbie shell --seed 2019209 +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))))