Average Error: 47.4 → 16.6
Time: 15.9s
Precision: 64
\[100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\]
\[\begin{array}{l} \mathbf{if}\;i \le -4.37516501457815845 \cdot 10^{-8}:\\ \;\;\;\;100 \cdot \frac{\mathsf{fma}\left({\left(\sqrt[3]{1 + \frac{i}{n}} \cdot \sqrt[3]{1 + \frac{i}{n}}\right)}^{n}, {\left(\sqrt[3]{1 + \frac{i}{n}}\right)}^{n}, -1\right)}{\frac{i}{n}}\\ \mathbf{elif}\;i \le 11.0464671956874145:\\ \;\;\;\;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 2.11377803746243355 \cdot 10^{196}:\\ \;\;\;\;100 \cdot \frac{{\left({\left(1 + \frac{i}{n}\right)}^{n}\right)}^{3} - {1}^{3}}{\frac{\mathsf{fma}\left(1, {\left(1 + \frac{i}{n}\right)}^{n} + 1, {\left(1 + \frac{i}{n}\right)}^{\left(2 \cdot n\right)}\right) \cdot i}{n}}\\ \mathbf{elif}\;i \le 1.1844385083165567 \cdot 10^{288}:\\ \;\;\;\;100 \cdot \frac{\mathsf{fma}\left(1, i, \mathsf{fma}\left(\log 1, n, 1\right)\right) - 1}{\frac{i}{n}}\\ \mathbf{else}:\\ \;\;\;\;100 \cdot \frac{\mathsf{fma}\left({\left(\sqrt[3]{1 + \frac{i}{n}} \cdot \sqrt[3]{1 + \frac{i}{n}}\right)}^{n}, {\left(\sqrt[3]{1 + \frac{i}{n}}\right)}^{n}, -1\right)}{\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 -4.37516501457815845 \cdot 10^{-8}:\\
\;\;\;\;100 \cdot \frac{\mathsf{fma}\left({\left(\sqrt[3]{1 + \frac{i}{n}} \cdot \sqrt[3]{1 + \frac{i}{n}}\right)}^{n}, {\left(\sqrt[3]{1 + \frac{i}{n}}\right)}^{n}, -1\right)}{\frac{i}{n}}\\

\mathbf{elif}\;i \le 11.0464671956874145:\\
\;\;\;\;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 2.11377803746243355 \cdot 10^{196}:\\
\;\;\;\;100 \cdot \frac{{\left({\left(1 + \frac{i}{n}\right)}^{n}\right)}^{3} - {1}^{3}}{\frac{\mathsf{fma}\left(1, {\left(1 + \frac{i}{n}\right)}^{n} + 1, {\left(1 + \frac{i}{n}\right)}^{\left(2 \cdot n\right)}\right) \cdot i}{n}}\\

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

\mathbf{else}:\\
\;\;\;\;100 \cdot \frac{\mathsf{fma}\left({\left(\sqrt[3]{1 + \frac{i}{n}} \cdot \sqrt[3]{1 + \frac{i}{n}}\right)}^{n}, {\left(\sqrt[3]{1 + \frac{i}{n}}\right)}^{n}, -1\right)}{\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 <= -4.3751650145781584e-08)) {
		VAR = (100.0 * (fma(pow((cbrt((1.0 + (i / n))) * cbrt((1.0 + (i / n)))), n), pow(cbrt((1.0 + (i / n))), n), -1.0) / (i / n)));
	} else {
		double VAR_1;
		if ((i <= 11.046467195687415)) {
			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))))) / i) * n));
		} else {
			double VAR_2;
			if ((i <= 2.1137780374624336e+196)) {
				VAR_2 = (100.0 * ((pow(pow((1.0 + (i / n)), n), 3.0) - pow(1.0, 3.0)) / ((fma(1.0, (pow((1.0 + (i / n)), n) + 1.0), pow((1.0 + (i / n)), (2.0 * n))) * i) / n)));
			} else {
				double VAR_3;
				if ((i <= 1.1844385083165567e+288)) {
					VAR_3 = (100.0 * ((fma(1.0, i, fma(log(1.0), n, 1.0)) - 1.0) / (i / n)));
				} else {
					VAR_3 = (100.0 * (fma(pow((cbrt((1.0 + (i / n))) * cbrt((1.0 + (i / n)))), n), pow(cbrt((1.0 + (i / n))), n), -1.0) / (i / n)));
				}
				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.2
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 4 regimes
  2. if i < -4.3751650145781584e-08 or 1.1844385083165567e+288 < i

    1. Initial program 28.1

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

      \[\leadsto 100 \cdot \frac{{\color{blue}{\left(\left(\sqrt[3]{1 + \frac{i}{n}} \cdot \sqrt[3]{1 + \frac{i}{n}}\right) \cdot \sqrt[3]{1 + \frac{i}{n}}\right)}}^{n} - 1}{\frac{i}{n}}\]
    4. Applied unpow-prod-down28.2

      \[\leadsto 100 \cdot \frac{\color{blue}{{\left(\sqrt[3]{1 + \frac{i}{n}} \cdot \sqrt[3]{1 + \frac{i}{n}}\right)}^{n} \cdot {\left(\sqrt[3]{1 + \frac{i}{n}}\right)}^{n}} - 1}{\frac{i}{n}}\]
    5. Applied fma-neg28.2

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

    if -4.3751650145781584e-08 < i < 11.046467195687415

    1. Initial program 58.0

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

      \[\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/9.1

      \[\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 11.046467195687415 < i < 2.1137780374624336e+196

    1. Initial program 31.2

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

      \[\leadsto 100 \cdot \frac{\color{blue}{\frac{{\left({\left(1 + \frac{i}{n}\right)}^{n}\right)}^{3} - {1}^{3}}{{\left(1 + \frac{i}{n}\right)}^{n} \cdot {\left(1 + \frac{i}{n}\right)}^{n} + \left(1 \cdot 1 + {\left(1 + \frac{i}{n}\right)}^{n} \cdot 1\right)}}}{\frac{i}{n}}\]
    4. Applied associate-/l/31.2

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

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

    if 2.1137780374624336e+196 < i < 1.1844385083165567e+288

    1. Initial program 31.2

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

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

      \[\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 4 regimes into one program.
  4. Final simplification16.6

    \[\leadsto \begin{array}{l} \mathbf{if}\;i \le -4.37516501457815845 \cdot 10^{-8}:\\ \;\;\;\;100 \cdot \frac{\mathsf{fma}\left({\left(\sqrt[3]{1 + \frac{i}{n}} \cdot \sqrt[3]{1 + \frac{i}{n}}\right)}^{n}, {\left(\sqrt[3]{1 + \frac{i}{n}}\right)}^{n}, -1\right)}{\frac{i}{n}}\\ \mathbf{elif}\;i \le 11.0464671956874145:\\ \;\;\;\;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 2.11377803746243355 \cdot 10^{196}:\\ \;\;\;\;100 \cdot \frac{{\left({\left(1 + \frac{i}{n}\right)}^{n}\right)}^{3} - {1}^{3}}{\frac{\mathsf{fma}\left(1, {\left(1 + \frac{i}{n}\right)}^{n} + 1, {\left(1 + \frac{i}{n}\right)}^{\left(2 \cdot n\right)}\right) \cdot i}{n}}\\ \mathbf{elif}\;i \le 1.1844385083165567 \cdot 10^{288}:\\ \;\;\;\;100 \cdot \frac{\mathsf{fma}\left(1, i, \mathsf{fma}\left(\log 1, n, 1\right)\right) - 1}{\frac{i}{n}}\\ \mathbf{else}:\\ \;\;\;\;100 \cdot \frac{\mathsf{fma}\left({\left(\sqrt[3]{1 + \frac{i}{n}} \cdot \sqrt[3]{1 + \frac{i}{n}}\right)}^{n}, {\left(\sqrt[3]{1 + \frac{i}{n}}\right)}^{n}, -1\right)}{\frac{i}{n}}\\ \end{array}\]

Reproduce

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