Average Error: 47.7 → 14.7
Time: 43.5s
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 -1.1079556446910253 \cdot 10^{-16}:\\ \;\;\;\;\frac{{\left(\frac{i}{n}\right)}^{n} - 1}{\frac{i}{100 \cdot n}}\\ \mathbf{elif}\;i \le 0.014778033933887576:\\ \;\;\;\;\left(100 \cdot n\right) \cdot e^{e^{\log \left(\log \left(\left(1 + \frac{1}{2} \cdot i\right) + i \cdot \left(i \cdot \frac{1}{6}\right)\right)\right)}}\\ \mathbf{elif}\;i \le 2.3281031367793534 \cdot 10^{+188} \lor \neg \left(i \le 2.051662504242298 \cdot 10^{+283}\right):\\ \;\;\;\;0\\ \mathbf{else}:\\ \;\;\;\;\left(n \cdot \frac{100}{i}\right) \cdot \left({\left(\frac{i}{n}\right)}^{n} - 1\right)\\ \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.7
Target46.8
Herbie14.7
\[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 < -1.1079556446910253e-16

    1. Initial program 29.7

      \[100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\]
    2. Initial simplification30.0

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

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

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

    if -1.1079556446910253e-16 < i < 0.014778033933887576

    1. Initial program 57.8

      \[100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\]
    2. Initial simplification57.8

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

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

      \[\leadsto \frac{\color{blue}{i + \left(i \cdot i\right) \cdot \left(\frac{1}{6} \cdot i + \frac{1}{2}\right)}}{\frac{i}{n \cdot 100}}\]
    5. Using strategy rm
    6. Applied *-un-lft-identity25.2

      \[\leadsto \frac{i + \left(i \cdot i\right) \cdot \left(\frac{1}{6} \cdot i + \frac{1}{2}\right)}{\color{blue}{1 \cdot \frac{i}{n \cdot 100}}}\]
    7. Applied *-un-lft-identity25.2

      \[\leadsto \frac{\color{blue}{1 \cdot \left(i + \left(i \cdot i\right) \cdot \left(\frac{1}{6} \cdot i + \frac{1}{2}\right)\right)}}{1 \cdot \frac{i}{n \cdot 100}}\]
    8. Applied times-frac25.2

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

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

      \[\leadsto 1 \cdot \color{blue}{\left(\left(100 \cdot n\right) \cdot \left(\left(1 + \frac{1}{2} \cdot i\right) + \left(i \cdot \frac{1}{6}\right) \cdot i\right)\right)}\]
    11. Using strategy rm
    12. Applied add-exp-log8.8

      \[\leadsto 1 \cdot \left(\left(100 \cdot n\right) \cdot \color{blue}{e^{\log \left(\left(1 + \frac{1}{2} \cdot i\right) + \left(i \cdot \frac{1}{6}\right) \cdot i\right)}}\right)\]
    13. Using strategy rm
    14. Applied add-exp-log8.8

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

    if 0.014778033933887576 < i < 2.3281031367793534e+188 or 2.051662504242298e+283 < i

    1. Initial program 33.8

      \[100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\]
    2. Initial simplification33.8

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

      \[\leadsto \color{blue}{0}\]

    if 2.3281031367793534e+188 < i < 2.051662504242298e+283

    1. Initial program 32.4

      \[100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\]
    2. Initial simplification32.4

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

      \[\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}}\]
    4. Simplified32.4

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;i \le -1.1079556446910253 \cdot 10^{-16}:\\ \;\;\;\;\frac{{\left(\frac{i}{n}\right)}^{n} - 1}{\frac{i}{100 \cdot n}}\\ \mathbf{elif}\;i \le 0.014778033933887576:\\ \;\;\;\;\left(100 \cdot n\right) \cdot e^{e^{\log \left(\log \left(\left(1 + \frac{1}{2} \cdot i\right) + i \cdot \left(i \cdot \frac{1}{6}\right)\right)\right)}}\\ \mathbf{elif}\;i \le 2.3281031367793534 \cdot 10^{+188} \lor \neg \left(i \le 2.051662504242298 \cdot 10^{+283}\right):\\ \;\;\;\;0\\ \mathbf{else}:\\ \;\;\;\;\left(n \cdot \frac{100}{i}\right) \cdot \left({\left(\frac{i}{n}\right)}^{n} - 1\right)\\ \end{array}\]

Runtime

Time bar (total: 43.5s)Debug logProfile

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