Average Error: 46.9 → 15.2
Time: 1.2m
Precision: 64
Internal Precision: 2880
\[100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\]
\[\begin{array}{l} \mathbf{if}\;i \le -3.444779348958293 \cdot 10^{-13}:\\ \;\;\;\;100 \cdot \frac{{\left(\frac{i}{n}\right)}^{n} + -1}{\frac{i}{n}}\\ \mathbf{elif}\;i \le 2.6345012252437736:\\ \;\;\;\;100 \cdot \left(\left(i \cdot \frac{1}{6} + \frac{1}{2}\right) \cdot \left(n \cdot i\right) + n\right)\\ \mathbf{else}:\\ \;\;\;\;100 \cdot \frac{\log \left(e^{{\left(1 + \frac{i}{n}\right)}^{n} - 1}\right)}{\frac{i}{n}}\\ \end{array}\]

Error

Bits error versus i

Bits error versus n

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original46.9
Target46.6
Herbie15.2
\[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 < -3.444779348958293e-13

    1. Initial program 28.8

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

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

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

    if -3.444779348958293e-13 < i < 2.6345012252437736

    1. Initial program 57.1

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

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

      \[\leadsto 100 \cdot \frac{\color{blue}{i + \left(i \cdot i\right) \cdot \left(\frac{1}{6} \cdot i + \frac{1}{2}\right)}}{\frac{i}{n}}\]
    4. Taylor expanded around 0 9.8

      \[\leadsto 100 \cdot \color{blue}{\left(\frac{1}{6} \cdot \left({i}^{2} \cdot n\right) + \left(n + \frac{1}{2} \cdot \left(i \cdot n\right)\right)\right)}\]
    5. Simplified9.8

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

    if 2.6345012252437736 < i

    1. Initial program 31.4

      \[100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\]
    2. Using strategy rm
    3. Applied add-log-exp31.5

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;i \le -3.444779348958293 \cdot 10^{-13}:\\ \;\;\;\;100 \cdot \frac{{\left(\frac{i}{n}\right)}^{n} + -1}{\frac{i}{n}}\\ \mathbf{elif}\;i \le 2.6345012252437736:\\ \;\;\;\;100 \cdot \left(\left(i \cdot \frac{1}{6} + \frac{1}{2}\right) \cdot \left(n \cdot i\right) + n\right)\\ \mathbf{else}:\\ \;\;\;\;100 \cdot \frac{\log \left(e^{{\left(1 + \frac{i}{n}\right)}^{n} - 1}\right)}{\frac{i}{n}}\\ \end{array}\]

Runtime

Time bar (total: 1.2m)Debug logProfile

herbie shell --seed 2018251 
(FPCore (i n)
  :name "Compound Interest"

  :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))))