Average Error: 46.9 → 15.3
Time: 2.9m
Precision: 64
Internal Precision: 3136
\[100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\]
\[\begin{array}{l} \mathbf{if}\;i \le -0.04885614718136047:\\ \;\;\;\;\frac{\left({\left(\frac{1}{n} \cdot i\right)}^{n} - 1\right) \cdot 100}{\frac{i}{n}}\\ \mathbf{elif}\;i \le 1.3527856789294112 \cdot 10^{-17}:\\ \;\;\;\;100 \cdot \left(e^{\log \left(\frac{\frac{1}{2} \cdot {i}^{2} + \left(i + \frac{1}{6} \cdot {i}^{3}\right)}{i}\right)} \cdot n\right)\\ \mathbf{else}:\\ \;\;\;\;100 \cdot 0\\ \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.5
Herbie15.3
\[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 < -0.04885614718136047

    1. Initial program 27.5

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

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

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

    if -0.04885614718136047 < i < 1.3527856789294112e-17

    1. Initial program 57.4

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

      \[\leadsto 100 \cdot \frac{\color{blue}{\frac{1}{2} \cdot {i}^{2} + \left(\frac{1}{6} \cdot {i}^{3} + i\right)}}{\frac{i}{n}}\]
    3. Using strategy rm
    4. Applied associate-/r/9.5

      \[\leadsto 100 \cdot \color{blue}{\left(\frac{\frac{1}{2} \cdot {i}^{2} + \left(\frac{1}{6} \cdot {i}^{3} + i\right)}{i} \cdot n\right)}\]
    5. Using strategy rm
    6. Applied add-exp-log9.5

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

    if 1.3527856789294112e-17 < i

    1. Initial program 33.6

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

      \[\leadsto 100 \cdot \color{blue}{0}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification15.3

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

Runtime

Time bar (total: 2.9m)Debug logProfile

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