Average Error: 47.5 → 16.6
Time: 15.0s
Precision: 64
\[100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\]
\[\begin{array}{l} \mathbf{if}\;i \le -0.67751004118584301:\\ \;\;\;\;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 57533148056912977900:\\ \;\;\;\;\left(100 \cdot \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}\right) \cdot n\\ \mathbf{elif}\;i \le 4.5860988436327915 \cdot 10^{126}:\\ \;\;\;\;100 \cdot \left(\frac{1}{{\left(\sqrt[3]{i}\right)}^{2}} \cdot \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)}{\frac{\log \left(e^{\sqrt[3]{i}}\right)}{n}}\right)\\ \mathbf{else}:\\ \;\;\;\;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}}\\ \end{array}\]
100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}
\begin{array}{l}
\mathbf{if}\;i \le -0.67751004118584301:\\
\;\;\;\;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 57533148056912977900:\\
\;\;\;\;\left(100 \cdot \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}\right) \cdot n\\

\mathbf{elif}\;i \le 4.5860988436327915 \cdot 10^{126}:\\
\;\;\;\;100 \cdot \left(\frac{1}{{\left(\sqrt[3]{i}\right)}^{2}} \cdot \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)}{\frac{\log \left(e^{\sqrt[3]{i}}\right)}{n}}\right)\\

\mathbf{else}:\\
\;\;\;\;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}}\\

\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.677510041185843)) {
		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 <= 5.753314805691298e+19)) {
			VAR_1 = ((100.0 * ((((1.0 * i) + ((0.5 * pow(i, 2.0)) + (log(1.0) * n))) - (0.5 * (pow(i, 2.0) * log(1.0)))) / i)) * n);
		} else {
			double VAR_2;
			if ((i <= 4.5860988436327915e+126)) {
				VAR_2 = (100.0 * ((1.0 / pow(cbrt(i), 2.0)) * ((((1.0 * i) + ((0.5 * pow(i, 2.0)) + (log(1.0) * n))) - (0.5 * (pow(i, 2.0) * log(1.0)))) / (log(exp(cbrt(i))) / n))));
			} else {
				VAR_2 = (100.0 * (((pow((1.0 + (i / n)), (2.0 * n)) + -(1.0 * 1.0)) / (pow((1.0 + (i / n)), n) + 1.0)) / (i / n)));
			}
			VAR_1 = VAR_2;
		}
		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.5
Target47.1
Herbie16.6
\[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.677510041185843 or 4.5860988436327915e+126 < i

    1. Initial program 29.0

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

      \[\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. Simplified29.0

      \[\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.677510041185843 < i < 5.753314805691298e+19

    1. Initial program 57.9

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

      \[\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.6

      \[\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. Applied associate-*r*9.6

      \[\leadsto \color{blue}{\left(100 \cdot \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}\right) \cdot n}\]

    if 5.753314805691298e+19 < i < 4.5860988436327915e+126

    1. Initial program 31.3

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

      \[\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 *-un-lft-identity47.3

      \[\leadsto 100 \cdot \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)}{\frac{i}{\color{blue}{1 \cdot n}}}\]
    5. Applied add-cube-cbrt47.3

      \[\leadsto 100 \cdot \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)}{\frac{\color{blue}{\left(\sqrt[3]{i} \cdot \sqrt[3]{i}\right) \cdot \sqrt[3]{i}}}{1 \cdot n}}\]
    6. Applied times-frac47.3

      \[\leadsto 100 \cdot \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)}{\color{blue}{\frac{\sqrt[3]{i} \cdot \sqrt[3]{i}}{1} \cdot \frac{\sqrt[3]{i}}{n}}}\]
    7. Applied *-un-lft-identity47.3

      \[\leadsto 100 \cdot \frac{\color{blue}{1 \cdot \left(\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)\right)}}{\frac{\sqrt[3]{i} \cdot \sqrt[3]{i}}{1} \cdot \frac{\sqrt[3]{i}}{n}}\]
    8. Applied times-frac55.6

      \[\leadsto 100 \cdot \color{blue}{\left(\frac{1}{\frac{\sqrt[3]{i} \cdot \sqrt[3]{i}}{1}} \cdot \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)}{\frac{\sqrt[3]{i}}{n}}\right)}\]
    9. Simplified55.6

      \[\leadsto 100 \cdot \left(\color{blue}{\frac{1}{{\left(\sqrt[3]{i}\right)}^{2}}} \cdot \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)}{\frac{\sqrt[3]{i}}{n}}\right)\]
    10. Using strategy rm
    11. Applied add-log-exp27.6

      \[\leadsto 100 \cdot \left(\frac{1}{{\left(\sqrt[3]{i}\right)}^{2}} \cdot \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)}{\frac{\color{blue}{\log \left(e^{\sqrt[3]{i}}\right)}}{n}}\right)\]
  3. Recombined 3 regimes into one program.
  4. Final simplification16.6

    \[\leadsto \begin{array}{l} \mathbf{if}\;i \le -0.67751004118584301:\\ \;\;\;\;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 57533148056912977900:\\ \;\;\;\;\left(100 \cdot \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}\right) \cdot n\\ \mathbf{elif}\;i \le 4.5860988436327915 \cdot 10^{126}:\\ \;\;\;\;100 \cdot \left(\frac{1}{{\left(\sqrt[3]{i}\right)}^{2}} \cdot \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)}{\frac{\log \left(e^{\sqrt[3]{i}}\right)}{n}}\right)\\ \mathbf{else}:\\ \;\;\;\;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}}\\ \end{array}\]

Reproduce

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