Average Error: 47.6 → 14.5
Time: 13.2s
Precision: binary64
\[100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\]
\[\begin{array}{l} \mathbf{if}\;i \leq -1587.2666382638245:\\ \;\;\;\;100 \cdot \left(\frac{n}{i} \cdot \left(-1 + {\left(\frac{i}{n}\right)}^{n}\right)\right)\\ \mathbf{elif}\;i \leq 1.206767779907382 \cdot 10^{-183}:\\ \;\;\;\;n \cdot \left(100 + i \cdot \left(50 + i \cdot 16.666666666666668\right)\right)\\ \mathbf{elif}\;i \leq 3.344734511806178 \cdot 10^{-18}:\\ \;\;\;\;\frac{100}{i} \cdot \frac{i + \left(i \cdot i\right) \cdot \left(0.5 + i \cdot 0.16666666666666666\right)}{\frac{1}{n}}\\ \mathbf{else}:\\ \;\;\;\;\frac{100 \cdot \left(-1 + {\left(\frac{i}{n} + 1\right)}^{n}\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 \leq -1587.2666382638245:\\
\;\;\;\;100 \cdot \left(\frac{n}{i} \cdot \left(-1 + {\left(\frac{i}{n}\right)}^{n}\right)\right)\\

\mathbf{elif}\;i \leq 1.206767779907382 \cdot 10^{-183}:\\
\;\;\;\;n \cdot \left(100 + i \cdot \left(50 + i \cdot 16.666666666666668\right)\right)\\

\mathbf{elif}\;i \leq 3.344734511806178 \cdot 10^{-18}:\\
\;\;\;\;\frac{100}{i} \cdot \frac{i + \left(i \cdot i\right) \cdot \left(0.5 + i \cdot 0.16666666666666666\right)}{\frac{1}{n}}\\

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

\end{array}
(FPCore (i n)
 :precision binary64
 (* 100.0 (/ (- (pow (+ 1.0 (/ i n)) n) 1.0) (/ i n))))
(FPCore (i n)
 :precision binary64
 (if (<= i -1587.2666382638245)
   (* 100.0 (* (/ n i) (+ -1.0 (pow (/ i n) n))))
   (if (<= i 1.206767779907382e-183)
     (* n (+ 100.0 (* i (+ 50.0 (* i 16.666666666666668)))))
     (if (<= i 3.344734511806178e-18)
       (*
        (/ 100.0 i)
        (/ (+ i (* (* i i) (+ 0.5 (* i 0.16666666666666666)))) (/ 1.0 n)))
       (/ (* 100.0 (+ -1.0 (pow (+ (/ i n) 1.0) n))) (/ i n))))))
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 tmp;
	if (i <= -1587.2666382638245) {
		tmp = 100.0 * ((n / i) * (-1.0 + pow((i / n), n)));
	} else if (i <= 1.206767779907382e-183) {
		tmp = n * (100.0 + (i * (50.0 + (i * 16.666666666666668))));
	} else if (i <= 3.344734511806178e-18) {
		tmp = (100.0 / i) * ((i + ((i * i) * (0.5 + (i * 0.16666666666666666)))) / (1.0 / n));
	} else {
		tmp = (100.0 * (-1.0 + pow(((i / n) + 1.0), n))) / (i / n);
	}
	return tmp;
}

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

    1. Initial program 26.7

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

      \[\leadsto 100 \cdot \color{blue}{\frac{n \cdot \left(e^{\left(\log \left(\frac{1}{n}\right) - \log \left(\frac{1}{i}\right)\right) \cdot n} - 1\right)}{i}}\]
    3. Simplified19.0

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

    if -1587.2666382638245 < i < 1.20676777990738197e-183

    1. Initial program 59.0

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

      \[\leadsto 100 \cdot \frac{\color{blue}{i + \left(0.16666666666666666 \cdot {i}^{3} + 0.5 \cdot {i}^{2}\right)}}{\frac{i}{n}}\]
    3. Simplified27.9

      \[\leadsto 100 \cdot \frac{\color{blue}{i + \left(i \cdot i\right) \cdot \left(0.5 + 0.16666666666666666 \cdot i\right)}}{\frac{i}{n}}\]
    4. Taylor expanded around 0 8.0

      \[\leadsto \color{blue}{50 \cdot \left(i \cdot n\right) + \left(100 \cdot n + 16.666666666666668 \cdot \left({i}^{2} \cdot n\right)\right)}\]
    5. Simplified8.0

      \[\leadsto \color{blue}{n \cdot \left(100 + i \cdot \left(50 + 16.666666666666668 \cdot i\right)\right)}\]

    if 1.20676777990738197e-183 < i < 3.34473451180617793e-18

    1. Initial program 56.6

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

      \[\leadsto 100 \cdot \frac{\color{blue}{i + \left(0.16666666666666666 \cdot {i}^{3} + 0.5 \cdot {i}^{2}\right)}}{\frac{i}{n}}\]
    3. Simplified24.0

      \[\leadsto 100 \cdot \frac{\color{blue}{i + \left(i \cdot i\right) \cdot \left(0.5 + 0.16666666666666666 \cdot i\right)}}{\frac{i}{n}}\]
    4. Using strategy rm
    5. Applied div-inv_binary64_243324.1

      \[\leadsto 100 \cdot \frac{i + \left(i \cdot i\right) \cdot \left(0.5 + 0.16666666666666666 \cdot i\right)}{\color{blue}{i \cdot \frac{1}{n}}}\]
    6. Applied *-un-lft-identity_binary64_243624.1

      \[\leadsto 100 \cdot \frac{\color{blue}{1 \cdot \left(i + \left(i \cdot i\right) \cdot \left(0.5 + 0.16666666666666666 \cdot i\right)\right)}}{i \cdot \frac{1}{n}}\]
    7. Applied times-frac_binary64_24429.0

      \[\leadsto 100 \cdot \color{blue}{\left(\frac{1}{i} \cdot \frac{i + \left(i \cdot i\right) \cdot \left(0.5 + 0.16666666666666666 \cdot i\right)}{\frac{1}{n}}\right)}\]
    8. Applied associate-*r*_binary64_23789.1

      \[\leadsto \color{blue}{\left(100 \cdot \frac{1}{i}\right) \cdot \frac{i + \left(i \cdot i\right) \cdot \left(0.5 + 0.16666666666666666 \cdot i\right)}{\frac{1}{n}}}\]
    9. Simplified9.0

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

    if 3.34473451180617793e-18 < i

    1. Initial program 34.1

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;i \leq -1587.2666382638245:\\ \;\;\;\;100 \cdot \left(\frac{n}{i} \cdot \left(-1 + {\left(\frac{i}{n}\right)}^{n}\right)\right)\\ \mathbf{elif}\;i \leq 1.206767779907382 \cdot 10^{-183}:\\ \;\;\;\;n \cdot \left(100 + i \cdot \left(50 + i \cdot 16.666666666666668\right)\right)\\ \mathbf{elif}\;i \leq 3.344734511806178 \cdot 10^{-18}:\\ \;\;\;\;\frac{100}{i} \cdot \frac{i + \left(i \cdot i\right) \cdot \left(0.5 + i \cdot 0.16666666666666666\right)}{\frac{1}{n}}\\ \mathbf{else}:\\ \;\;\;\;\frac{100 \cdot \left(-1 + {\left(\frac{i}{n} + 1\right)}^{n}\right)}{\frac{i}{n}}\\ \end{array}\]

Reproduce

herbie shell --seed 2020281 
(FPCore (i n)
  :name "Compound Interest"
  :precision binary64

  :herbie-target
  (* 100.0 (/ (- (exp (* n (if (== (+ 1.0 (/ i n)) 1.0) (/ i n) (/ (* (/ i n) (log (+ 1.0 (/ i n)))) (- (+ (/ i n) 1.0) 1.0))))) 1.0) (/ i n)))

  (* 100.0 (/ (- (pow (+ 1.0 (/ i n)) n) 1.0) (/ i n))))