100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\begin{array}{l}
\mathbf{if}\;i \leq -6.720774155076935 \cdot 10^{-07}:\\
\;\;\;\;100 \cdot \frac{-1 + {\left(\frac{i}{n}\right)}^{n}}{\frac{i}{n}}\\
\mathbf{elif}\;i \leq 2.7352102327349535 \cdot 10^{-06}:\\
\;\;\;\;\sqrt[3]{\left(i \cdot n\right) \cdot 50} \cdot \left(\sqrt[3]{\left(i \cdot n\right) \cdot 50} \cdot \sqrt[3]{\left(i \cdot n\right) \cdot 50}\right) + 100 \cdot n\\
\mathbf{else}:\\
\;\;\;\;\frac{100 \cdot \left(-1 + {\left(\frac{i}{n} + 1\right)}^{n}\right)}{\frac{i}{n}}\\
\end{array}(FPCore (i n) :precision binary64 (* 100.0 (/ (- (pow (+ 1.0 (/ i n)) n) 1.0) (/ i n))))
(FPCore (i n)
:precision binary64
(if (<= i -6.720774155076935e-07)
(* 100.0 (/ (+ -1.0 (pow (/ i n) n)) (/ i n)))
(if (<= i 2.7352102327349535e-06)
(+
(*
(cbrt (* (* i n) 50.0))
(* (cbrt (* (* i n) 50.0)) (cbrt (* (* i n) 50.0))))
(* 100.0 n))
(/ (* 100.0 (+ -1.0 (pow (+ (/ i n) 1.0) n))) (/ i n)))))double code(double i, double n) {
return 100.0 * ((pow((1.0 + (i / n)), n) - 1.0) / (i / n));
}
double code(double i, double n) {
double tmp;
if (i <= -6.720774155076935e-07) {
tmp = 100.0 * ((-1.0 + pow((i / n), n)) / (i / n));
} else if (i <= 2.7352102327349535e-06) {
tmp = (cbrt((i * n) * 50.0) * (cbrt((i * n) * 50.0) * cbrt((i * n) * 50.0))) + (100.0 * n);
} else {
tmp = (100.0 * (-1.0 + pow(((i / n) + 1.0), n))) / (i / n);
}
return tmp;
}




Bits error versus i




Bits error versus n
Results
| Original | 48.2 |
|---|---|
| Target | 47.6 |
| Herbie | 14.8 |
if i < -6.72077415507693457e-7Initial program 29.1
Taylor expanded around inf 64.0
Simplified19.4
if -6.72077415507693457e-7 < i < 2.73521023273495348e-6Initial program 58.3
Taylor expanded around 0 25.7
Simplified25.7
Taylor expanded around 0 8.6
Simplified8.6
Taylor expanded around 0 8.6
Simplified8.6
rmApplied add-cube-cbrt_binary648.6
if 2.73521023273495348e-6 < i Initial program 34.5
rmApplied associate-*r/_binary6434.5
Simplified34.5
Final simplification14.8
herbie shell --seed 2020224
(FPCore (i n)
:name "Compound Interest"
:precision binary64
:herbie-target
(* 100.0 (/ (- (exp (* n (if (== (+ 1.0 (/ i n)) 1.0) (/ i n) (/ (* (/ i n) (log (+ 1.0 (/ i n)))) (- (+ (/ i n) 1.0) 1.0))))) 1.0) (/ i n)))
(* 100.0 (/ (- (pow (+ 1.0 (/ i n)) n) 1.0) (/ i n))))