100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\begin{array}{l}
\mathbf{if}\;i \le -1.49613502984700486:\\
\;\;\;\;100 \cdot \left(\frac{{\left(1 + \frac{i}{n}\right)}^{n}}{\frac{i}{n}} - \frac{1}{\frac{i}{n}}\right)\\
\mathbf{elif}\;i \le 2.7217117903300314 \cdot 10^{-9}:\\
\;\;\;\;\left(100 \cdot \left(\mathsf{fma}\left(0.5, i, \frac{\log 1 \cdot n}{i} + 1\right) - 0.5 \cdot \left(i \cdot \log 1\right)\right)\right) \cdot n\\
\mathbf{else}:\\
\;\;\;\;\left(100 \cdot \frac{\mathsf{fma}\left({\left(\sqrt[3]{1 + \frac{i}{n}} \cdot \sqrt[3]{1 + \frac{i}{n}}\right)}^{n}, {\left(\sqrt[3]{1 + \frac{i}{n}}\right)}^{n}, -1\right)}{i}\right) \cdot n\\
\end{array}double f(double i, double n) {
double r133317 = 100.0;
double r133318 = 1.0;
double r133319 = i;
double r133320 = n;
double r133321 = r133319 / r133320;
double r133322 = r133318 + r133321;
double r133323 = pow(r133322, r133320);
double r133324 = r133323 - r133318;
double r133325 = r133324 / r133321;
double r133326 = r133317 * r133325;
return r133326;
}
double f(double i, double n) {
double r133327 = i;
double r133328 = -1.4961350298470049;
bool r133329 = r133327 <= r133328;
double r133330 = 100.0;
double r133331 = 1.0;
double r133332 = n;
double r133333 = r133327 / r133332;
double r133334 = r133331 + r133333;
double r133335 = pow(r133334, r133332);
double r133336 = r133335 / r133333;
double r133337 = r133331 / r133333;
double r133338 = r133336 - r133337;
double r133339 = r133330 * r133338;
double r133340 = 2.7217117903300314e-09;
bool r133341 = r133327 <= r133340;
double r133342 = 0.5;
double r133343 = log(r133331);
double r133344 = r133343 * r133332;
double r133345 = r133344 / r133327;
double r133346 = r133345 + r133331;
double r133347 = fma(r133342, r133327, r133346);
double r133348 = r133327 * r133343;
double r133349 = r133342 * r133348;
double r133350 = r133347 - r133349;
double r133351 = r133330 * r133350;
double r133352 = r133351 * r133332;
double r133353 = cbrt(r133334);
double r133354 = r133353 * r133353;
double r133355 = pow(r133354, r133332);
double r133356 = pow(r133353, r133332);
double r133357 = -r133331;
double r133358 = fma(r133355, r133356, r133357);
double r133359 = r133358 / r133327;
double r133360 = r133330 * r133359;
double r133361 = r133360 * r133332;
double r133362 = r133341 ? r133352 : r133361;
double r133363 = r133329 ? r133339 : r133362;
return r133363;
}




Bits error versus i




Bits error versus n
| Original | 42.4 |
|---|---|
| Target | 42.5 |
| Herbie | 21.4 |
if i < -1.4961350298470049Initial program 26.7
rmApplied div-sub26.8
if -1.4961350298470049 < i < 2.7217117903300314e-09Initial program 50.4
rmApplied associate-/r/50.1
Applied associate-*r*50.1
Taylor expanded around 0 17.1
Simplified17.1
Taylor expanded around 0 17.1
Simplified17.1
if 2.7217117903300314e-09 < i Initial program 32.0
rmApplied associate-/r/32.0
Applied associate-*r*32.0
rmApplied add-cube-cbrt32.0
Applied unpow-prod-down32.0
Applied fma-neg32.0
Final simplification21.4
herbie shell --seed 2020045 +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))))