Average Error: 47.7 → 14.9
Time: 15.2s
Precision: binary64
\[100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\]
\[\begin{array}{l} \mathbf{if}\;i \leq -0.08077746953445203:\\ \;\;\;\;100 \cdot \frac{{\left(\frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\\ \mathbf{elif}\;i \leq 0.12982209090675584:\\ \;\;\;\;\left(100 \cdot \left(\sqrt[3]{\frac{1}{i}} + \left(0.3333333333333333 \cdot \sqrt[3]{i \cdot i} + 0.08333333333333333 \cdot \sqrt[3]{{i}^{5}}\right)\right)\right) \cdot \frac{\sqrt[3]{i + \left(i \cdot i\right) \cdot \left(0.5 + i \cdot 0.16666666666666666\right)}}{\frac{1}{n}}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array}\]
100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}
\begin{array}{l}
\mathbf{if}\;i \leq -0.08077746953445203:\\
\;\;\;\;100 \cdot \frac{{\left(\frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\\

\mathbf{elif}\;i \leq 0.12982209090675584:\\
\;\;\;\;\left(100 \cdot \left(\sqrt[3]{\frac{1}{i}} + \left(0.3333333333333333 \cdot \sqrt[3]{i \cdot i} + 0.08333333333333333 \cdot \sqrt[3]{{i}^{5}}\right)\right)\right) \cdot \frac{\sqrt[3]{i + \left(i \cdot i\right) \cdot \left(0.5 + i \cdot 0.16666666666666666\right)}}{\frac{1}{n}}\\

\mathbf{else}:\\
\;\;\;\;0\\

\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 -0.08077746953445203)
   (* 100.0 (/ (- (pow (/ i n) n) 1.0) (/ i n)))
   (if (<= i 0.12982209090675584)
     (*
      (*
       100.0
       (+
        (cbrt (/ 1.0 i))
        (+
         (* 0.3333333333333333 (cbrt (* i i)))
         (* 0.08333333333333333 (cbrt (pow i 5.0))))))
      (/ (cbrt (+ i (* (* i i) (+ 0.5 (* i 0.16666666666666666))))) (/ 1.0 n)))
     0.0)))
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 <= -0.08077746953445203) {
		tmp = 100.0 * ((pow((i / n), n) - 1.0) / (i / n));
	} else if (i <= 0.12982209090675584) {
		tmp = (100.0 * (cbrt(1.0 / i) + ((0.3333333333333333 * cbrt(i * i)) + (0.08333333333333333 * cbrt(pow(i, 5.0)))))) * (cbrt(i + ((i * i) * (0.5 + (i * 0.16666666666666666)))) / (1.0 / n));
	} else {
		tmp = 0.0;
	}
	return tmp;
}

Error

Bits error versus i

Bits error versus n

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original47.7
Target47.3
Herbie14.9
\[100 \cdot \frac{e^{n \cdot \begin{array}{l} \mathbf{if}\;1 + \frac{i}{n} = 1:\\ \;\;\;\;\frac{i}{n}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{i}{n} \cdot \log \left(1 + \frac{i}{n}\right)}{\left(\frac{i}{n} + 1\right) - 1}\\ \end{array}} - 1}{\frac{i}{n}}\]

Derivation

  1. Split input into 3 regimes
  2. if i < -0.080777469534452029

    1. Initial program 28.7

      \[100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\]
    2. Taylor expanded around inf 64.0

      \[\leadsto 100 \cdot \frac{\color{blue}{e^{\left(\log \left(\frac{1}{n}\right) - \log \left(\frac{1}{i}\right)\right) \cdot n}} - 1}{\frac{i}{n}}\]
    3. Simplified18.6

      \[\leadsto 100 \cdot \frac{\color{blue}{{\left(\frac{i}{n}\right)}^{n}} - 1}{\frac{i}{n}}\]

    if -0.080777469534452029 < i < 0.12982209090675584

    1. Initial program 58.1

      \[100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\]
    2. Taylor expanded around 0 26.8

      \[\leadsto 100 \cdot \frac{\color{blue}{i + \left(0.16666666666666666 \cdot {i}^{3} + 0.5 \cdot {i}^{2}\right)}}{\frac{i}{n}}\]
    3. Simplified26.8

      \[\leadsto 100 \cdot \frac{\color{blue}{i + \left(i \cdot i\right) \cdot \left(0.5 + 0.16666666666666666 \cdot i\right)}}{\frac{i}{n}}\]
    4. Using strategy rm
    5. Applied div-inv_binary64_179626.8

      \[\leadsto 100 \cdot \frac{i + \left(i \cdot i\right) \cdot \left(0.5 + 0.16666666666666666 \cdot i\right)}{\color{blue}{i \cdot \frac{1}{n}}}\]
    6. Applied add-cube-cbrt_binary64_183427.5

      \[\leadsto 100 \cdot \frac{\color{blue}{\left(\sqrt[3]{i + \left(i \cdot i\right) \cdot \left(0.5 + 0.16666666666666666 \cdot i\right)} \cdot \sqrt[3]{i + \left(i \cdot i\right) \cdot \left(0.5 + 0.16666666666666666 \cdot i\right)}\right) \cdot \sqrt[3]{i + \left(i \cdot i\right) \cdot \left(0.5 + 0.16666666666666666 \cdot i\right)}}}{i \cdot \frac{1}{n}}\]
    7. Applied times-frac_binary64_180510.3

      \[\leadsto 100 \cdot \color{blue}{\left(\frac{\sqrt[3]{i + \left(i \cdot i\right) \cdot \left(0.5 + 0.16666666666666666 \cdot i\right)} \cdot \sqrt[3]{i + \left(i \cdot i\right) \cdot \left(0.5 + 0.16666666666666666 \cdot i\right)}}{i} \cdot \frac{\sqrt[3]{i + \left(i \cdot i\right) \cdot \left(0.5 + 0.16666666666666666 \cdot i\right)}}{\frac{1}{n}}\right)}\]
    8. Applied associate-*r*_binary64_173910.3

      \[\leadsto \color{blue}{\left(100 \cdot \frac{\sqrt[3]{i + \left(i \cdot i\right) \cdot \left(0.5 + 0.16666666666666666 \cdot i\right)} \cdot \sqrt[3]{i + \left(i \cdot i\right) \cdot \left(0.5 + 0.16666666666666666 \cdot i\right)}}{i}\right) \cdot \frac{\sqrt[3]{i + \left(i \cdot i\right) \cdot \left(0.5 + 0.16666666666666666 \cdot i\right)}}{\frac{1}{n}}}\]
    9. Simplified10.3

      \[\leadsto \color{blue}{\left(\frac{\sqrt[3]{i + \left(i \cdot i\right) \cdot \left(0.5 + i \cdot 0.16666666666666666\right)} \cdot \sqrt[3]{i + \left(i \cdot i\right) \cdot \left(0.5 + i \cdot 0.16666666666666666\right)}}{i} \cdot 100\right)} \cdot \frac{\sqrt[3]{i + \left(i \cdot i\right) \cdot \left(0.5 + 0.16666666666666666 \cdot i\right)}}{\frac{1}{n}}\]
    10. Taylor expanded around 0 38.5

      \[\leadsto \left(\color{blue}{\left({\left(\frac{1}{i}\right)}^{0.3333333333333333} + \left(0.3333333333333333 \cdot {\left({i}^{2}\right)}^{0.3333333333333333} + 0.08333333333333333 \cdot {\left({i}^{5}\right)}^{0.3333333333333333}\right)\right)} \cdot 100\right) \cdot \frac{\sqrt[3]{i + \left(i \cdot i\right) \cdot \left(0.5 + 0.16666666666666666 \cdot i\right)}}{\frac{1}{n}}\]
    11. Simplified9.8

      \[\leadsto \left(\color{blue}{\left(\sqrt[3]{\frac{1}{i}} + \left(0.3333333333333333 \cdot \sqrt[3]{i \cdot i} + 0.08333333333333333 \cdot \sqrt[3]{{i}^{5}}\right)\right)} \cdot 100\right) \cdot \frac{\sqrt[3]{i + \left(i \cdot i\right) \cdot \left(0.5 + 0.16666666666666666 \cdot i\right)}}{\frac{1}{n}}\]

    if 0.12982209090675584 < i

    1. Initial program 33.1

      \[100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\]
    2. Taylor expanded around 0 31.1

      \[\leadsto \color{blue}{0}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification14.9

    \[\leadsto \begin{array}{l} \mathbf{if}\;i \leq -0.08077746953445203:\\ \;\;\;\;100 \cdot \frac{{\left(\frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\\ \mathbf{elif}\;i \leq 0.12982209090675584:\\ \;\;\;\;\left(100 \cdot \left(\sqrt[3]{\frac{1}{i}} + \left(0.3333333333333333 \cdot \sqrt[3]{i \cdot i} + 0.08333333333333333 \cdot \sqrt[3]{{i}^{5}}\right)\right)\right) \cdot \frac{\sqrt[3]{i + \left(i \cdot i\right) \cdot \left(0.5 + i \cdot 0.16666666666666666\right)}}{\frac{1}{n}}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array}\]

Reproduce

herbie shell --seed 2020289 
(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))))