Average Error: 47.6 → 17.4
Time: 16.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.0016013410645367089:\\ \;\;\;\;\frac{100 \cdot \left({\left(1 + \frac{i}{n}\right)}^{n} - 1\right)}{i} \cdot n\\ \mathbf{elif}\;i \le -5.74741920387596963 \cdot 10^{-218}:\\ \;\;\;\;\frac{100}{i} \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{1}{n}}\\ \mathbf{elif}\;i \le 1.11578736812586826 \cdot 10^{43}:\\ \;\;\;\;\frac{100 \cdot \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\\ \mathbf{else}:\\ \;\;\;\;\frac{100 \cdot \left({\left(1 + \frac{i}{n}\right)}^{n} - 1\right)}{i} \cdot 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.0016013410645367089:\\
\;\;\;\;\frac{100 \cdot \left({\left(1 + \frac{i}{n}\right)}^{n} - 1\right)}{i} \cdot n\\

\mathbf{elif}\;i \le -5.74741920387596963 \cdot 10^{-218}:\\
\;\;\;\;\frac{100}{i} \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{1}{n}}\\

\mathbf{elif}\;i \le 1.11578736812586826 \cdot 10^{43}:\\
\;\;\;\;\frac{100 \cdot \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\\

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

\end{array}
double code(double i, double n) {
	return ((double) (100.0 * ((double) (((double) (((double) pow(((double) (1.0 + ((double) (i / n)))), n)) - 1.0)) / ((double) (i / n))))));
}
double code(double i, double n) {
	double VAR;
	if ((i <= -0.001601341064536709)) {
		VAR = ((double) (((double) (((double) (100.0 * ((double) (((double) pow(((double) (1.0 + ((double) (i / n)))), n)) - 1.0)))) / i)) * n));
	} else {
		double VAR_1;
		if ((i <= -5.74741920387597e-218)) {
			VAR_1 = ((double) (((double) (100.0 / i)) * ((double) (((double) fma(i, 1.0, ((double) (((double) fma(0.5, ((double) pow(i, 2.0)), ((double) (((double) log(1.0)) * n)))) - ((double) (0.5 * ((double) (((double) pow(i, 2.0)) * ((double) log(1.0)))))))))) / ((double) (1.0 / n))))));
		} else {
			double VAR_2;
			if ((i <= 1.1157873681258683e+43)) {
				VAR_2 = ((double) (((double) (((double) (100.0 * ((double) fma(i, 1.0, ((double) (((double) fma(0.5, ((double) pow(i, 2.0)), ((double) (((double) log(1.0)) * n)))) - ((double) (0.5 * ((double) (((double) pow(i, 2.0)) * ((double) log(1.0)))))))))))) / i)) * n));
			} else {
				VAR_2 = ((double) (((double) (((double) (100.0 * ((double) (((double) pow(((double) (1.0 + ((double) (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.6
Target47.1
Herbie17.4
\[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.001601341064536709 or 1.1157873681258683e+43 < i

    1. Initial program 29.8

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

      \[\leadsto 100 \cdot \color{blue}{\left(\frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{i} \cdot n\right)}\]
    4. Applied associate-*r*30.4

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

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

    if -0.001601341064536709 < i < -5.74741920387597e-218

    1. Initial program 56.2

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

      \[\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. Simplified24.5

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

      \[\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}{i \cdot \frac{1}{n}}}\]
    6. Applied *-un-lft-identity24.6

      \[\leadsto 100 \cdot \frac{\color{blue}{1 \cdot \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 \frac{1}{n}}\]
    7. Applied times-frac11.1

      \[\leadsto 100 \cdot \color{blue}{\left(\frac{1}{i} \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{1}{n}}\right)}\]
    8. Applied associate-*r*11.2

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

      \[\leadsto \color{blue}{\frac{100}{i}} \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{1}{n}}\]

    if -5.74741920387597e-218 < i < 1.1157873681258683e+43

    1. Initial program 57.6

      \[100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\]
    2. Taylor expanded around 0 28.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. Simplified28.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/10.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)}\]
    6. Applied associate-*r*10.1

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

      \[\leadsto \color{blue}{\frac{100 \cdot \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\]
  3. Recombined 3 regimes into one program.
  4. Final simplification17.4

    \[\leadsto \begin{array}{l} \mathbf{if}\;i \le -0.0016013410645367089:\\ \;\;\;\;\frac{100 \cdot \left({\left(1 + \frac{i}{n}\right)}^{n} - 1\right)}{i} \cdot n\\ \mathbf{elif}\;i \le -5.74741920387596963 \cdot 10^{-218}:\\ \;\;\;\;\frac{100}{i} \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{1}{n}}\\ \mathbf{elif}\;i \le 1.11578736812586826 \cdot 10^{43}:\\ \;\;\;\;\frac{100 \cdot \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\\ \mathbf{else}:\\ \;\;\;\;\frac{100 \cdot \left({\left(1 + \frac{i}{n}\right)}^{n} - 1\right)}{i} \cdot n\\ \end{array}\]

Reproduce

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