Average Error: 47.7 → 13.5
Time: 11.0s
Precision: binary64
\[100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\]
\[\begin{array}{l} \mathbf{if}\;i \leq -78308.95981690803:\\ \;\;\;\;100 \cdot \frac{-1 + {\left(\frac{i}{n}\right)}^{n}}{\frac{i}{n}}\\ \mathbf{elif}\;i \leq -1.328223267458416 \cdot 10^{-171}:\\ \;\;\;\;\frac{100}{i} \cdot \frac{i + \left(i \cdot i\right) \cdot \left(0.5 + i \cdot 0.16666666666666666\right)}{\frac{1}{n}}\\ \mathbf{elif}\;i \leq 1.2445990049455903 \cdot 10^{-05}:\\ \;\;\;\;n \cdot \left(i \cdot 50 + \left(100 + e^{\sqrt[3]{\log \left(\left(i \cdot i\right) \cdot 16.666666666666668\right)} \cdot \left(\sqrt[3]{\log \left(\left(i \cdot i\right) \cdot 16.666666666666668\right)} \cdot \sqrt[3]{\log \left(\left(i \cdot i\right) \cdot 16.666666666666668\right)}\right)}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array}\]
100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}
\begin{array}{l}
\mathbf{if}\;i \leq -78308.95981690803:\\
\;\;\;\;100 \cdot \frac{-1 + {\left(\frac{i}{n}\right)}^{n}}{\frac{i}{n}}\\

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

\mathbf{elif}\;i \leq 1.2445990049455903 \cdot 10^{-05}:\\
\;\;\;\;n \cdot \left(i \cdot 50 + \left(100 + e^{\sqrt[3]{\log \left(\left(i \cdot i\right) \cdot 16.666666666666668\right)} \cdot \left(\sqrt[3]{\log \left(\left(i \cdot i\right) \cdot 16.666666666666668\right)} \cdot \sqrt[3]{\log \left(\left(i \cdot i\right) \cdot 16.666666666666668\right)}\right)}\right)\right)\\

\mathbf{else}:\\
\;\;\;\;0\\

\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 -78308.95981690803)
   (* 100.0 (/ (+ -1.0 (pow (/ i n) n)) (/ i n)))
   (if (<= i -1.328223267458416e-171)
     (*
      (/ 100.0 i)
      (/ (+ i (* (* i i) (+ 0.5 (* i 0.16666666666666666)))) (/ 1.0 n)))
     (if (<= i 1.2445990049455903e-05)
       (*
        n
        (+
         (* i 50.0)
         (+
          100.0
          (exp
           (*
            (cbrt (log (* (* i i) 16.666666666666668)))
            (*
             (cbrt (log (* (* i i) 16.666666666666668)))
             (cbrt (log (* (* i i) 16.666666666666668)))))))))
       0.0))))
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 <= -78308.95981690803) {
		tmp = 100.0 * ((-1.0 + pow((i / n), n)) / (i / n));
	} else if (i <= -1.328223267458416e-171) {
		tmp = (100.0 / i) * ((i + ((i * i) * (0.5 + (i * 0.16666666666666666)))) / (1.0 / n));
	} else if (i <= 1.2445990049455903e-05) {
		tmp = n * ((i * 50.0) + (100.0 + exp(cbrt(log((i * i) * 16.666666666666668)) * (cbrt(log((i * i) * 16.666666666666668)) * cbrt(log((i * i) * 16.666666666666668))))));
	} else {
		tmp = 0.0;
	}
	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.4
Herbie13.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 < -78308.959816908027

    1. Initial program 27.8

      \[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{\left(e^{\left(\log \left(\frac{1}{n}\right) - \log \left(\frac{1}{i}\right)\right) \cdot n} - 1\right) \cdot n}{i}}\]
    3. Simplified18.3

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

    if -78308.959816908027 < i < -1.3282232674584161e-171

    1. Initial program 55.0

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

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

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

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

      \[\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_binary6411.9

      \[\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*_binary6411.9

      \[\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. Simplified11.9

      \[\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 -1.3282232674584161e-171 < i < 1.24459900494559025e-5

    1. Initial program 59.1

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

      \[\leadsto 100 \cdot \frac{\color{blue}{0.16666666666666666 \cdot {i}^{3} + \left(0.5 \cdot {i}^{2} + i\right)}}{\frac{i}{n}}\]
    3. Simplified26.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 6.8

      \[\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. Simplified6.8

      \[\leadsto \color{blue}{n \cdot \left(i \cdot 50 + \left(100 + \left(i \cdot i\right) \cdot 16.666666666666668\right)\right)}\]
    6. Using strategy rm
    7. Applied add-exp-log_binary646.8

      \[\leadsto n \cdot \left(i \cdot 50 + \left(100 + \left(i \cdot i\right) \cdot \color{blue}{e^{\log 16.666666666666668}}\right)\right)\]
    8. Applied add-exp-log_binary6427.3

      \[\leadsto n \cdot \left(i \cdot 50 + \left(100 + \left(i \cdot \color{blue}{e^{\log i}}\right) \cdot e^{\log 16.666666666666668}\right)\right)\]
    9. Applied add-exp-log_binary6427.3

      \[\leadsto n \cdot \left(i \cdot 50 + \left(100 + \left(\color{blue}{e^{\log i}} \cdot e^{\log i}\right) \cdot e^{\log 16.666666666666668}\right)\right)\]
    10. Applied prod-exp_binary6427.3

      \[\leadsto n \cdot \left(i \cdot 50 + \left(100 + \color{blue}{e^{\log i + \log i}} \cdot e^{\log 16.666666666666668}\right)\right)\]
    11. Applied prod-exp_binary6427.3

      \[\leadsto n \cdot \left(i \cdot 50 + \left(100 + \color{blue}{e^{\left(\log i + \log i\right) + \log 16.666666666666668}}\right)\right)\]
    12. Simplified6.8

      \[\leadsto n \cdot \left(i \cdot 50 + \left(100 + e^{\color{blue}{\log \left(\left(i \cdot i\right) \cdot 16.666666666666668\right)}}\right)\right)\]
    13. Using strategy rm
    14. Applied add-cube-cbrt_binary646.8

      \[\leadsto n \cdot \left(i \cdot 50 + \left(100 + e^{\color{blue}{\left(\sqrt[3]{\log \left(\left(i \cdot i\right) \cdot 16.666666666666668\right)} \cdot \sqrt[3]{\log \left(\left(i \cdot i\right) \cdot 16.666666666666668\right)}\right) \cdot \sqrt[3]{\log \left(\left(i \cdot i\right) \cdot 16.666666666666668\right)}}}\right)\right)\]

    if 1.24459900494559025e-5 < i

    1. Initial program 32.6

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

      \[\leadsto \color{blue}{0}\]
  3. Recombined 4 regimes into one program.
  4. Final simplification13.5

    \[\leadsto \begin{array}{l} \mathbf{if}\;i \leq -78308.95981690803:\\ \;\;\;\;100 \cdot \frac{-1 + {\left(\frac{i}{n}\right)}^{n}}{\frac{i}{n}}\\ \mathbf{elif}\;i \leq -1.328223267458416 \cdot 10^{-171}:\\ \;\;\;\;\frac{100}{i} \cdot \frac{i + \left(i \cdot i\right) \cdot \left(0.5 + i \cdot 0.16666666666666666\right)}{\frac{1}{n}}\\ \mathbf{elif}\;i \leq 1.2445990049455903 \cdot 10^{-05}:\\ \;\;\;\;n \cdot \left(i \cdot 50 + \left(100 + e^{\sqrt[3]{\log \left(\left(i \cdot i\right) \cdot 16.666666666666668\right)} \cdot \left(\sqrt[3]{\log \left(\left(i \cdot i\right) \cdot 16.666666666666668\right)} \cdot \sqrt[3]{\log \left(\left(i \cdot i\right) \cdot 16.666666666666668\right)}\right)}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array}\]

Reproduce

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