Average Error: 47.4 → 17.9
Time: 12.3s
Precision: 64
\[100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\]
\[\begin{array}{l} \mathbf{if}\;i \le -0.24222034813966126:\\ \;\;\;\;100 \cdot \frac{\frac{{\left(1 + \frac{i}{n}\right)}^{\left(2 \cdot n\right)} + \left(-1 \cdot 1\right)}{{\left(1 + \frac{i}{n}\right)}^{n} + 1}}{\frac{i}{n}}\\ \mathbf{elif}\;i \le 0.011056763714875576:\\ \;\;\;\;100 \cdot \left(\frac{\left(1 \cdot i + \left(\left(2 \cdot \log \left(\sqrt[3]{e^{0.5 \cdot {i}^{2}}}\right) + \log \left(\sqrt[3]{e^{0.5 \cdot {i}^{2}}}\right)\right) + \log 1 \cdot n\right)\right) - 0.5 \cdot \left({i}^{2} \cdot \log 1\right)}{i} \cdot n\right)\\ \mathbf{else}:\\ \;\;\;\;100 \cdot \frac{\left(1 \cdot i + \left(\log 1 \cdot n + 1\right)\right) - 1}{\frac{i}{n}}\\ \end{array}\]
100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}
\begin{array}{l}
\mathbf{if}\;i \le -0.24222034813966126:\\
\;\;\;\;100 \cdot \frac{\frac{{\left(1 + \frac{i}{n}\right)}^{\left(2 \cdot n\right)} + \left(-1 \cdot 1\right)}{{\left(1 + \frac{i}{n}\right)}^{n} + 1}}{\frac{i}{n}}\\

\mathbf{elif}\;i \le 0.011056763714875576:\\
\;\;\;\;100 \cdot \left(\frac{\left(1 \cdot i + \left(\left(2 \cdot \log \left(\sqrt[3]{e^{0.5 \cdot {i}^{2}}}\right) + \log \left(\sqrt[3]{e^{0.5 \cdot {i}^{2}}}\right)\right) + \log 1 \cdot n\right)\right) - 0.5 \cdot \left({i}^{2} \cdot \log 1\right)}{i} \cdot n\right)\\

\mathbf{else}:\\
\;\;\;\;100 \cdot \frac{\left(1 \cdot i + \left(\log 1 \cdot n + 1\right)\right) - 1}{\frac{i}{n}}\\

\end{array}
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 VAR;
	if ((i <= -0.24222034813966126)) {
		VAR = (100.0 * (((pow((1.0 + (i / n)), (2.0 * n)) + -(1.0 * 1.0)) / (pow((1.0 + (i / n)), n) + 1.0)) / (i / n)));
	} else {
		double VAR_1;
		if ((i <= 0.011056763714875576)) {
			VAR_1 = (100.0 * (((((1.0 * i) + (((2.0 * log(cbrt(exp((0.5 * pow(i, 2.0)))))) + log(cbrt(exp((0.5 * pow(i, 2.0)))))) + (log(1.0) * n))) - (0.5 * (pow(i, 2.0) * log(1.0)))) / i) * n));
		} else {
			VAR_1 = (100.0 * ((((1.0 * i) + ((log(1.0) * n) + 1.0)) - 1.0) / (i / n)));
		}
		VAR = VAR_1;
	}
	return VAR;
}

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.4
Target47.7
Herbie17.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.24222034813966126

    1. Initial program 27.1

      \[100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\]
    2. Using strategy rm
    3. Applied flip--27.1

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

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

    if -0.24222034813966126 < i < 0.011056763714875576

    1. Initial program 58.3

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

      \[\leadsto 100 \cdot \frac{\color{blue}{\left(1 \cdot i + \left(0.5 \cdot {i}^{2} + \log 1 \cdot n\right)\right) - 0.5 \cdot \left({i}^{2} \cdot \log 1\right)}}{\frac{i}{n}}\]
    3. Using strategy rm
    4. Applied associate-/r/9.2

      \[\leadsto 100 \cdot \color{blue}{\left(\frac{\left(1 \cdot i + \left(0.5 \cdot {i}^{2} + \log 1 \cdot n\right)\right) - 0.5 \cdot \left({i}^{2} \cdot \log 1\right)}{i} \cdot n\right)}\]
    5. Using strategy rm
    6. Applied add-log-exp9.4

      \[\leadsto 100 \cdot \left(\frac{\left(1 \cdot i + \left(\color{blue}{\log \left(e^{0.5 \cdot {i}^{2}}\right)} + \log 1 \cdot n\right)\right) - 0.5 \cdot \left({i}^{2} \cdot \log 1\right)}{i} \cdot n\right)\]
    7. Using strategy rm
    8. Applied add-cube-cbrt9.4

      \[\leadsto 100 \cdot \left(\frac{\left(1 \cdot i + \left(\log \color{blue}{\left(\left(\sqrt[3]{e^{0.5 \cdot {i}^{2}}} \cdot \sqrt[3]{e^{0.5 \cdot {i}^{2}}}\right) \cdot \sqrt[3]{e^{0.5 \cdot {i}^{2}}}\right)} + \log 1 \cdot n\right)\right) - 0.5 \cdot \left({i}^{2} \cdot \log 1\right)}{i} \cdot n\right)\]
    9. Applied log-prod9.4

      \[\leadsto 100 \cdot \left(\frac{\left(1 \cdot i + \left(\color{blue}{\left(\log \left(\sqrt[3]{e^{0.5 \cdot {i}^{2}}} \cdot \sqrt[3]{e^{0.5 \cdot {i}^{2}}}\right) + \log \left(\sqrt[3]{e^{0.5 \cdot {i}^{2}}}\right)\right)} + \log 1 \cdot n\right)\right) - 0.5 \cdot \left({i}^{2} \cdot \log 1\right)}{i} \cdot n\right)\]
    10. Simplified9.4

      \[\leadsto 100 \cdot \left(\frac{\left(1 \cdot i + \left(\left(\color{blue}{2 \cdot \log \left(\sqrt[3]{e^{0.5 \cdot {i}^{2}}}\right)} + \log \left(\sqrt[3]{e^{0.5 \cdot {i}^{2}}}\right)\right) + \log 1 \cdot n\right)\right) - 0.5 \cdot \left({i}^{2} \cdot \log 1\right)}{i} \cdot n\right)\]

    if 0.011056763714875576 < i

    1. Initial program 31.3

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

      \[\leadsto 100 \cdot \frac{\color{blue}{\left(1 \cdot i + \left(\log 1 \cdot n + 1\right)\right)} - 1}{\frac{i}{n}}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification17.9

    \[\leadsto \begin{array}{l} \mathbf{if}\;i \le -0.24222034813966126:\\ \;\;\;\;100 \cdot \frac{\frac{{\left(1 + \frac{i}{n}\right)}^{\left(2 \cdot n\right)} + \left(-1 \cdot 1\right)}{{\left(1 + \frac{i}{n}\right)}^{n} + 1}}{\frac{i}{n}}\\ \mathbf{elif}\;i \le 0.011056763714875576:\\ \;\;\;\;100 \cdot \left(\frac{\left(1 \cdot i + \left(\left(2 \cdot \log \left(\sqrt[3]{e^{0.5 \cdot {i}^{2}}}\right) + \log \left(\sqrt[3]{e^{0.5 \cdot {i}^{2}}}\right)\right) + \log 1 \cdot n\right)\right) - 0.5 \cdot \left({i}^{2} \cdot \log 1\right)}{i} \cdot n\right)\\ \mathbf{else}:\\ \;\;\;\;100 \cdot \frac{\left(1 \cdot i + \left(\log 1 \cdot n + 1\right)\right) - 1}{\frac{i}{n}}\\ \end{array}\]

Reproduce

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