Average Error: 47.6 → 14.5
Time: 13.0s
Precision: binary64
\[100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\]
\[\begin{array}{l} \mathbf{if}\;i \leq -3606.923004814872:\\ \;\;\;\;100 \cdot \left(\frac{n}{i} \cdot \left(-1 + {\left(\frac{i}{n}\right)}^{n}\right)\right)\\ \mathbf{elif}\;i \leq 1.5181636956965362 \cdot 10^{-175}:\\ \;\;\;\;n \cdot \left(100 + i \cdot \left(50 + i \cdot 16.666666666666668\right)\right)\\ \mathbf{elif}\;i \leq 8.787233895042543 \cdot 10^{-13}:\\ \;\;\;\;100 \cdot \left(\frac{1}{i} \cdot \left(n \cdot \left(i + \left(i \cdot i\right) \cdot \left(0.5 + i \cdot 0.16666666666666666\right)\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;100 \cdot \left(\frac{n}{i} \cdot \left(-1 + {\left(\frac{i}{n} + 1\right)}^{n}\right)\right)\\ \end{array}\]
100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}
\begin{array}{l}
\mathbf{if}\;i \leq -3606.923004814872:\\
\;\;\;\;100 \cdot \left(\frac{n}{i} \cdot \left(-1 + {\left(\frac{i}{n}\right)}^{n}\right)\right)\\

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

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

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

\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 -3606.923004814872)
   (* 100.0 (* (/ n i) (+ -1.0 (pow (/ i n) n))))
   (if (<= i 1.5181636956965362e-175)
     (* n (+ 100.0 (* i (+ 50.0 (* i 16.666666666666668)))))
     (if (<= i 8.787233895042543e-13)
       (*
        100.0
        (*
         (/ 1.0 i)
         (* n (+ i (* (* i i) (+ 0.5 (* i 0.16666666666666666)))))))
       (* 100.0 (* (/ n i) (+ -1.0 (pow (+ (/ i n) 1.0) 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 <= -3606.923004814872) {
		tmp = 100.0 * ((n / i) * (-1.0 + pow((i / n), n)));
	} else if (i <= 1.5181636956965362e-175) {
		tmp = n * (100.0 + (i * (50.0 + (i * 16.666666666666668))));
	} else if (i <= 8.787233895042543e-13) {
		tmp = 100.0 * ((1.0 / i) * (n * (i + ((i * i) * (0.5 + (i * 0.16666666666666666))))));
	} else {
		tmp = 100.0 * ((n / i) * (-1.0 + pow(((i / n) + 1.0), 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.1
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 < -3606.923004814872

    1. Initial program 28.2

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

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

    if -3606.923004814872 < i < 1.5181636956965362e-175

    1. Initial program 59.2

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

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

      \[\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.5181636956965362e-175 < i < 8.78723389504254335e-13

    1. Initial program 55.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_178024.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_178324.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_178910.4

      \[\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. Simplified10.3

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

    if 8.78723389504254335e-13 < i

    1. Initial program 31.9

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;i \leq -3606.923004814872:\\ \;\;\;\;100 \cdot \left(\frac{n}{i} \cdot \left(-1 + {\left(\frac{i}{n}\right)}^{n}\right)\right)\\ \mathbf{elif}\;i \leq 1.5181636956965362 \cdot 10^{-175}:\\ \;\;\;\;n \cdot \left(100 + i \cdot \left(50 + i \cdot 16.666666666666668\right)\right)\\ \mathbf{elif}\;i \leq 8.787233895042543 \cdot 10^{-13}:\\ \;\;\;\;100 \cdot \left(\frac{1}{i} \cdot \left(n \cdot \left(i + \left(i \cdot i\right) \cdot \left(0.5 + i \cdot 0.16666666666666666\right)\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;100 \cdot \left(\frac{n}{i} \cdot \left(-1 + {\left(\frac{i}{n} + 1\right)}^{n}\right)\right)\\ \end{array}\]

Reproduce

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