Average Error: 47.4 → 17.7
Time: 14.1s
Precision: 64
\[100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\]
\[\begin{array}{l} \mathbf{if}\;i \le -0.94939736135755615:\\ \;\;\;\;\frac{100 \cdot \left({\left(1 + \frac{i}{n}\right)}^{n} - 1\right)}{\frac{i}{n}}\\ \mathbf{elif}\;i \le -4.23204137081444262 \cdot 10^{-190}:\\ \;\;\;\;\frac{100 \cdot \left(\mathsf{fma}\left(i, 1, \mathsf{fma}\left(0.5, {i}^{2}, \log 1 \cdot n\right) - 0.5 \cdot \left({i}^{2} \cdot \log 1\right)\right) \cdot n\right)}{i}\\ \mathbf{elif}\;i \le -3.31557411309755 \cdot 10^{-239}:\\ \;\;\;\;100 \cdot \left(\left(\left(\sqrt[3]{\mathsf{fma}\left(i, 1, \mathsf{fma}\left(0.5, {i}^{2}, \log 1 \cdot n\right) - 0.5 \cdot \left({i}^{2} \cdot \log 1\right)\right)} \cdot \sqrt[3]{\mathsf{fma}\left(i, 1, \mathsf{fma}\left(0.5, {i}^{2}, \log 1 \cdot n\right) - 0.5 \cdot \left({i}^{2} \cdot \log 1\right)\right)}\right) \cdot \left(\sqrt[3]{n} \cdot \sqrt[3]{n}\right)\right) \cdot \frac{\sqrt[3]{\mathsf{fma}\left(i, 1, \mathsf{fma}\left(0.5, {i}^{2}, \log 1 \cdot n\right) - 0.5 \cdot \left({i}^{2} \cdot \log 1\right)\right)}}{\frac{i}{\sqrt[3]{n}}}\right)\\ \mathbf{elif}\;i \le 6.0258825700655812 \cdot 10^{-214}:\\ \;\;\;\;100 \cdot \left(\frac{\mathsf{fma}\left(i, 1, \mathsf{fma}\left(0.5, {i}^{2}, \log 1 \cdot n\right) - 0.5 \cdot \left({i}^{2} \cdot \log 1\right)\right)}{i} \cdot n\right)\\ \mathbf{elif}\;i \le 203.39871032850647:\\ \;\;\;\;\frac{100 \cdot \left(\mathsf{fma}\left(i, 1, \mathsf{fma}\left(0.5, {i}^{2}, \log 1 \cdot n\right) - 0.5 \cdot \left({i}^{2} \cdot \log 1\right)\right) \cdot n\right)}{i}\\ \mathbf{else}:\\ \;\;\;\;100 \cdot \frac{\mathsf{fma}\left(1, i, \mathsf{fma}\left(\log 1, 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.94939736135755615:\\
\;\;\;\;\frac{100 \cdot \left({\left(1 + \frac{i}{n}\right)}^{n} - 1\right)}{\frac{i}{n}}\\

\mathbf{elif}\;i \le -4.23204137081444262 \cdot 10^{-190}:\\
\;\;\;\;\frac{100 \cdot \left(\mathsf{fma}\left(i, 1, \mathsf{fma}\left(0.5, {i}^{2}, \log 1 \cdot n\right) - 0.5 \cdot \left({i}^{2} \cdot \log 1\right)\right) \cdot n\right)}{i}\\

\mathbf{elif}\;i \le -3.31557411309755 \cdot 10^{-239}:\\
\;\;\;\;100 \cdot \left(\left(\left(\sqrt[3]{\mathsf{fma}\left(i, 1, \mathsf{fma}\left(0.5, {i}^{2}, \log 1 \cdot n\right) - 0.5 \cdot \left({i}^{2} \cdot \log 1\right)\right)} \cdot \sqrt[3]{\mathsf{fma}\left(i, 1, \mathsf{fma}\left(0.5, {i}^{2}, \log 1 \cdot n\right) - 0.5 \cdot \left({i}^{2} \cdot \log 1\right)\right)}\right) \cdot \left(\sqrt[3]{n} \cdot \sqrt[3]{n}\right)\right) \cdot \frac{\sqrt[3]{\mathsf{fma}\left(i, 1, \mathsf{fma}\left(0.5, {i}^{2}, \log 1 \cdot n\right) - 0.5 \cdot \left({i}^{2} \cdot \log 1\right)\right)}}{\frac{i}{\sqrt[3]{n}}}\right)\\

\mathbf{elif}\;i \le 6.0258825700655812 \cdot 10^{-214}:\\
\;\;\;\;100 \cdot \left(\frac{\mathsf{fma}\left(i, 1, \mathsf{fma}\left(0.5, {i}^{2}, \log 1 \cdot n\right) - 0.5 \cdot \left({i}^{2} \cdot \log 1\right)\right)}{i} \cdot n\right)\\

\mathbf{elif}\;i \le 203.39871032850647:\\
\;\;\;\;\frac{100 \cdot \left(\mathsf{fma}\left(i, 1, \mathsf{fma}\left(0.5, {i}^{2}, \log 1 \cdot n\right) - 0.5 \cdot \left({i}^{2} \cdot \log 1\right)\right) \cdot n\right)}{i}\\

\mathbf{else}:\\
\;\;\;\;100 \cdot \frac{\mathsf{fma}\left(1, i, \mathsf{fma}\left(\log 1, 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.9493973613575561)) {
		VAR = ((100.0 * (pow((1.0 + (i / n)), n) - 1.0)) / (i / n));
	} else {
		double VAR_1;
		if ((i <= -4.2320413708144426e-190)) {
			VAR_1 = ((100.0 * (fma(i, 1.0, (fma(0.5, pow(i, 2.0), (log(1.0) * n)) - (0.5 * (pow(i, 2.0) * log(1.0))))) * n)) / i);
		} else {
			double VAR_2;
			if ((i <= -3.31557411309755e-239)) {
				VAR_2 = (100.0 * (((cbrt(fma(i, 1.0, (fma(0.5, pow(i, 2.0), (log(1.0) * n)) - (0.5 * (pow(i, 2.0) * log(1.0)))))) * cbrt(fma(i, 1.0, (fma(0.5, pow(i, 2.0), (log(1.0) * n)) - (0.5 * (pow(i, 2.0) * log(1.0))))))) * (cbrt(n) * cbrt(n))) * (cbrt(fma(i, 1.0, (fma(0.5, pow(i, 2.0), (log(1.0) * n)) - (0.5 * (pow(i, 2.0) * log(1.0)))))) / (i / cbrt(n)))));
			} else {
				double VAR_3;
				if ((i <= 6.025882570065581e-214)) {
					VAR_3 = (100.0 * ((fma(i, 1.0, (fma(0.5, pow(i, 2.0), (log(1.0) * n)) - (0.5 * (pow(i, 2.0) * log(1.0))))) / i) * n));
				} else {
					double VAR_4;
					if ((i <= 203.39871032850647)) {
						VAR_4 = ((100.0 * (fma(i, 1.0, (fma(0.5, pow(i, 2.0), (log(1.0) * n)) - (0.5 * (pow(i, 2.0) * log(1.0))))) * n)) / i);
					} else {
						VAR_4 = (100.0 * ((fma(1.0, i, fma(log(1.0), n, 1.0)) - 1.0) / (i / n)));
					}
					VAR_3 = VAR_4;
				}
				VAR_2 = VAR_3;
			}
			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.4
Target47.5
Herbie17.7
\[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 5 regimes
  2. if i < -0.9493973613575561

    1. Initial program 27.6

      \[100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\]
    2. Using strategy rm
    3. Applied associate-*r/27.6

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

    if -0.9493973613575561 < i < -4.2320413708144426e-190 or 6.025882570065581e-214 < i < 203.39871032850647

    1. Initial program 56.1

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

      \[\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. Simplified25.2

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

      \[\leadsto 100 \cdot \color{blue}{\left(\frac{\mathsf{fma}\left(i, 1, \mathsf{fma}\left(0.5, {i}^{2}, \log 1 \cdot n\right) - 0.5 \cdot \left({i}^{2} \cdot \log 1\right)\right)}{i} \cdot n\right)}\]
    6. Using strategy rm
    7. Applied associate-*l/12.1

      \[\leadsto 100 \cdot \color{blue}{\frac{\mathsf{fma}\left(i, 1, \mathsf{fma}\left(0.5, {i}^{2}, \log 1 \cdot n\right) - 0.5 \cdot \left({i}^{2} \cdot \log 1\right)\right) \cdot n}{i}}\]
    8. Applied associate-*r/12.2

      \[\leadsto \color{blue}{\frac{100 \cdot \left(\mathsf{fma}\left(i, 1, \mathsf{fma}\left(0.5, {i}^{2}, \log 1 \cdot n\right) - 0.5 \cdot \left({i}^{2} \cdot \log 1\right)\right) \cdot n\right)}{i}}\]

    if -4.2320413708144426e-190 < i < -3.31557411309755e-239

    1. Initial program 60.4

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

      \[\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. Simplified27.4

      \[\leadsto 100 \cdot \frac{\color{blue}{\mathsf{fma}\left(i, 1, \mathsf{fma}\left(0.5, {i}^{2}, \log 1 \cdot n\right) - 0.5 \cdot \left({i}^{2} \cdot \log 1\right)\right)}}{\frac{i}{n}}\]
    4. Using strategy rm
    5. Applied add-cube-cbrt28.0

      \[\leadsto 100 \cdot \frac{\mathsf{fma}\left(i, 1, \mathsf{fma}\left(0.5, {i}^{2}, \log 1 \cdot n\right) - 0.5 \cdot \left({i}^{2} \cdot \log 1\right)\right)}{\frac{i}{\color{blue}{\left(\sqrt[3]{n} \cdot \sqrt[3]{n}\right) \cdot \sqrt[3]{n}}}}\]
    6. Applied *-un-lft-identity28.0

      \[\leadsto 100 \cdot \frac{\mathsf{fma}\left(i, 1, \mathsf{fma}\left(0.5, {i}^{2}, \log 1 \cdot n\right) - 0.5 \cdot \left({i}^{2} \cdot \log 1\right)\right)}{\frac{\color{blue}{1 \cdot i}}{\left(\sqrt[3]{n} \cdot \sqrt[3]{n}\right) \cdot \sqrt[3]{n}}}\]
    7. Applied times-frac28.0

      \[\leadsto 100 \cdot \frac{\mathsf{fma}\left(i, 1, \mathsf{fma}\left(0.5, {i}^{2}, \log 1 \cdot n\right) - 0.5 \cdot \left({i}^{2} \cdot \log 1\right)\right)}{\color{blue}{\frac{1}{\sqrt[3]{n} \cdot \sqrt[3]{n}} \cdot \frac{i}{\sqrt[3]{n}}}}\]
    8. Applied add-cube-cbrt28.3

      \[\leadsto 100 \cdot \frac{\color{blue}{\left(\sqrt[3]{\mathsf{fma}\left(i, 1, \mathsf{fma}\left(0.5, {i}^{2}, \log 1 \cdot n\right) - 0.5 \cdot \left({i}^{2} \cdot \log 1\right)\right)} \cdot \sqrt[3]{\mathsf{fma}\left(i, 1, \mathsf{fma}\left(0.5, {i}^{2}, \log 1 \cdot n\right) - 0.5 \cdot \left({i}^{2} \cdot \log 1\right)\right)}\right) \cdot \sqrt[3]{\mathsf{fma}\left(i, 1, \mathsf{fma}\left(0.5, {i}^{2}, \log 1 \cdot n\right) - 0.5 \cdot \left({i}^{2} \cdot \log 1\right)\right)}}}{\frac{1}{\sqrt[3]{n} \cdot \sqrt[3]{n}} \cdot \frac{i}{\sqrt[3]{n}}}\]
    9. Applied times-frac9.0

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

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

    if -3.31557411309755e-239 < i < 6.025882570065581e-214

    1. Initial program 61.6

      \[100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\]
    2. Taylor expanded around 0 31.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. Simplified31.1

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

      \[\leadsto 100 \cdot \color{blue}{\left(\frac{\mathsf{fma}\left(i, 1, \mathsf{fma}\left(0.5, {i}^{2}, \log 1 \cdot n\right) - 0.5 \cdot \left({i}^{2} \cdot \log 1\right)\right)}{i} \cdot n\right)}\]

    if 203.39871032850647 < i

    1. Initial program 29.7

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

      \[\leadsto 100 \cdot \frac{\color{blue}{\left(1 \cdot i + \left(\log 1 \cdot n + 1\right)\right)} - 1}{\frac{i}{n}}\]
    3. Simplified41.7

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;i \le -0.94939736135755615:\\ \;\;\;\;\frac{100 \cdot \left({\left(1 + \frac{i}{n}\right)}^{n} - 1\right)}{\frac{i}{n}}\\ \mathbf{elif}\;i \le -4.23204137081444262 \cdot 10^{-190}:\\ \;\;\;\;\frac{100 \cdot \left(\mathsf{fma}\left(i, 1, \mathsf{fma}\left(0.5, {i}^{2}, \log 1 \cdot n\right) - 0.5 \cdot \left({i}^{2} \cdot \log 1\right)\right) \cdot n\right)}{i}\\ \mathbf{elif}\;i \le -3.31557411309755 \cdot 10^{-239}:\\ \;\;\;\;100 \cdot \left(\left(\left(\sqrt[3]{\mathsf{fma}\left(i, 1, \mathsf{fma}\left(0.5, {i}^{2}, \log 1 \cdot n\right) - 0.5 \cdot \left({i}^{2} \cdot \log 1\right)\right)} \cdot \sqrt[3]{\mathsf{fma}\left(i, 1, \mathsf{fma}\left(0.5, {i}^{2}, \log 1 \cdot n\right) - 0.5 \cdot \left({i}^{2} \cdot \log 1\right)\right)}\right) \cdot \left(\sqrt[3]{n} \cdot \sqrt[3]{n}\right)\right) \cdot \frac{\sqrt[3]{\mathsf{fma}\left(i, 1, \mathsf{fma}\left(0.5, {i}^{2}, \log 1 \cdot n\right) - 0.5 \cdot \left({i}^{2} \cdot \log 1\right)\right)}}{\frac{i}{\sqrt[3]{n}}}\right)\\ \mathbf{elif}\;i \le 6.0258825700655812 \cdot 10^{-214}:\\ \;\;\;\;100 \cdot \left(\frac{\mathsf{fma}\left(i, 1, \mathsf{fma}\left(0.5, {i}^{2}, \log 1 \cdot n\right) - 0.5 \cdot \left({i}^{2} \cdot \log 1\right)\right)}{i} \cdot n\right)\\ \mathbf{elif}\;i \le 203.39871032850647:\\ \;\;\;\;\frac{100 \cdot \left(\mathsf{fma}\left(i, 1, \mathsf{fma}\left(0.5, {i}^{2}, \log 1 \cdot n\right) - 0.5 \cdot \left({i}^{2} \cdot \log 1\right)\right) \cdot n\right)}{i}\\ \mathbf{else}:\\ \;\;\;\;100 \cdot \frac{\mathsf{fma}\left(1, i, \mathsf{fma}\left(\log 1, n, 1\right)\right) - 1}{\frac{i}{n}}\\ \end{array}\]

Reproduce

herbie shell --seed 2020106 +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))))