Average Error: 47.7 → 11.9
Time: 17.9s
Precision: binary64
\[100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\]
\[\begin{array}{l} \mathbf{if}\;i \leq -4.540451682214554 \cdot 10^{-26}:\\ \;\;\;\;100 \cdot \frac{e^{i} - 1}{\frac{i}{n}}\\ \mathbf{elif}\;i \leq 0.0003472903295357634:\\ \;\;\;\;\left(n \cdot \left(i \cdot 50 + 16.666666666666668 \cdot \left(i \cdot i\right)\right) + \left(100 \cdot n + \frac{i}{\frac{n}{i}} \cdot 33.333333333333336\right)\right) + -50 \cdot \left(i + i \cdot i\right)\\ \mathbf{else}:\\ \;\;\;\;100 \cdot \frac{\left(0.5 \cdot \left({\log n}^{2} \cdot {n}^{2}\right) + \left(n \cdot \log i + \left(\frac{{n}^{2}}{i} + 0.5 \cdot \left({n}^{2} \cdot {\log i}^{2}\right)\right)\right)\right) - \left(\log n \cdot \left({n}^{2} \cdot \log i\right) + n \cdot \log 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 -4.540451682214554 \cdot 10^{-26}:\\
\;\;\;\;100 \cdot \frac{e^{i} - 1}{\frac{i}{n}}\\

\mathbf{elif}\;i \leq 0.0003472903295357634:\\
\;\;\;\;\left(n \cdot \left(i \cdot 50 + 16.666666666666668 \cdot \left(i \cdot i\right)\right) + \left(100 \cdot n + \frac{i}{\frac{n}{i}} \cdot 33.333333333333336\right)\right) + -50 \cdot \left(i + i \cdot i\right)\\

\mathbf{else}:\\
\;\;\;\;100 \cdot \frac{\left(0.5 \cdot \left({\log n}^{2} \cdot {n}^{2}\right) + \left(n \cdot \log i + \left(\frac{{n}^{2}}{i} + 0.5 \cdot \left({n}^{2} \cdot {\log i}^{2}\right)\right)\right)\right) - \left(\log n \cdot \left({n}^{2} \cdot \log i\right) + n \cdot \log 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 -4.540451682214554e-26)
   (* 100.0 (/ (- (exp i) 1.0) (/ i n)))
   (if (<= i 0.0003472903295357634)
     (+
      (+
       (* n (+ (* i 50.0) (* 16.666666666666668 (* i i))))
       (+ (* 100.0 n) (* (/ i (/ n i)) 33.333333333333336)))
      (* -50.0 (+ i (* i i))))
     (*
      100.0
      (/
       (-
        (+
         (* 0.5 (* (pow (log n) 2.0) (pow n 2.0)))
         (+
          (* n (log i))
          (+ (/ (pow n 2.0) i) (* 0.5 (* (pow n 2.0) (pow (log i) 2.0))))))
        (+ (* (log n) (* (pow n 2.0) (log i))) (* n (log 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 <= -4.540451682214554e-26) {
		tmp = 100.0 * ((exp(i) - 1.0) / (i / n));
	} else if (i <= 0.0003472903295357634) {
		tmp = ((n * ((i * 50.0) + (16.666666666666668 * (i * i)))) + ((100.0 * n) + ((i / (n / i)) * 33.333333333333336))) + (-50.0 * (i + (i * i)));
	} else {
		tmp = 100.0 * ((((0.5 * (pow(log(n), 2.0) * pow(n, 2.0))) + ((n * log(i)) + ((pow(n, 2.0) / i) + (0.5 * (pow(n, 2.0) * pow(log(i), 2.0)))))) - ((log(n) * (pow(n, 2.0) * log(i))) + (n * log(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.7
Target47.7
Herbie11.9
\[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 < -4.54045168221455413e-26

    1. Initial program 29.9

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

      \[\leadsto 100 \cdot \frac{\color{blue}{e^{i}} - 1}{\frac{i}{n}}\]

    if -4.54045168221455413e-26 < i < 3.47290329535763413e-4

    1. Initial program 58.4

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

      \[\leadsto \color{blue}{\left(50 \cdot \left(i \cdot n\right) + \left(16.666666666666668 \cdot \left({i}^{2} \cdot n\right) + \left(33.333333333333336 \cdot \frac{{i}^{2}}{n} + 100 \cdot n\right)\right)\right) - \left(50 \cdot {i}^{2} + 50 \cdot i\right)}\]
    3. Simplified9.0

      \[\leadsto \color{blue}{\left(n \cdot \left(i \cdot 50 + 16.666666666666668 \cdot \left(i \cdot i\right)\right) + \left(n \cdot 100 + \frac{i \cdot i}{n} \cdot 33.333333333333336\right)\right) + -50 \cdot \left(i + i \cdot i\right)}\]
    4. Using strategy rm
    5. Applied associate-/l*_binary64_34338.9

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

    if 3.47290329535763413e-4 < i

    1. Initial program 32.4

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

      \[\leadsto 100 \cdot \frac{\color{blue}{\left(0.5 \cdot \left({\log n}^{2} \cdot {n}^{2}\right) + \left(\log i \cdot n + \left(\frac{{n}^{2}}{i} + 0.5 \cdot \left({\log i}^{2} \cdot {n}^{2}\right)\right)\right)\right) - \left(\log n \cdot \left({n}^{2} \cdot \log i\right) + \log n \cdot n\right)}}{\frac{i}{n}}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification11.9

    \[\leadsto \begin{array}{l} \mathbf{if}\;i \leq -4.540451682214554 \cdot 10^{-26}:\\ \;\;\;\;100 \cdot \frac{e^{i} - 1}{\frac{i}{n}}\\ \mathbf{elif}\;i \leq 0.0003472903295357634:\\ \;\;\;\;\left(n \cdot \left(i \cdot 50 + 16.666666666666668 \cdot \left(i \cdot i\right)\right) + \left(100 \cdot n + \frac{i}{\frac{n}{i}} \cdot 33.333333333333336\right)\right) + -50 \cdot \left(i + i \cdot i\right)\\ \mathbf{else}:\\ \;\;\;\;100 \cdot \frac{\left(0.5 \cdot \left({\log n}^{2} \cdot {n}^{2}\right) + \left(n \cdot \log i + \left(\frac{{n}^{2}}{i} + 0.5 \cdot \left({n}^{2} \cdot {\log i}^{2}\right)\right)\right)\right) - \left(\log n \cdot \left({n}^{2} \cdot \log i\right) + n \cdot \log n\right)}{\frac{i}{n}}\\ \end{array}\]

Reproduce

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