Average Error: 47.3 → 14.4
Time: 48.6s
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.03175122153496683:\\ \;\;\;\;\left({\left(\frac{i}{n}\right)}^{n} + -1\right) \cdot \frac{100}{\frac{i}{n}}\\ \mathbf{elif}\;i \le 0.826772452655147:\\ \;\;\;\;100 \cdot n + \left(\frac{50}{3} \cdot i + 50\right) \cdot \left(n \cdot i\right)\\ \mathbf{else}:\\ \;\;\;\;100 \cdot \frac{\log \left(e^{{\left(\frac{i}{n} + 1\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

Original47.3
Target47.3
Herbie14.4
\[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.03175122153496683

    1. Initial program 27.7

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

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

    if -0.03175122153496683 < i < 0.826772452655147

    1. Initial program 57.5

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

      \[\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. Simplified25.5

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

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

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

    if 0.826772452655147 < i

    1. Initial program 31.7

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

      \[\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 simplification14.4

    \[\leadsto \begin{array}{l} \mathbf{if}\;i \le -0.03175122153496683:\\ \;\;\;\;\left({\left(\frac{i}{n}\right)}^{n} + -1\right) \cdot \frac{100}{\frac{i}{n}}\\ \mathbf{elif}\;i \le 0.826772452655147:\\ \;\;\;\;100 \cdot n + \left(\frac{50}{3} \cdot i + 50\right) \cdot \left(n \cdot i\right)\\ \mathbf{else}:\\ \;\;\;\;100 \cdot \frac{\log \left(e^{{\left(\frac{i}{n} + 1\right)}^{n} - 1}\right)}{\frac{i}{n}}\\ \end{array}\]

Runtime

Time bar (total: 48.6s)Debug logProfile

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