Average Error: 47.7 → 14.7
Time: 46.9s
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 -2.9462336778663984 \cdot 10^{-16}:\\ \;\;\;\;\frac{{\left(\frac{i}{n}\right)}^{n} - 1}{\frac{i}{100 \cdot n}}\\ \mathbf{elif}\;i \le 0.04335809508526476:\\ \;\;\;\;100 \cdot n + \left(i \cdot \frac{1}{6} + \frac{1}{2}\right) \cdot \left(i \cdot \left(100 \cdot n\right)\right)\\ \mathbf{elif}\;i \le 1.00300473460916 \cdot 10^{+189} \lor \neg \left(i \le 1.7755133736422301 \cdot 10^{+283}\right):\\ \;\;\;\;0\\ \mathbf{else}:\\ \;\;\;\;\left({\left(\frac{i}{n}\right)}^{n} - 1\right) \cdot \left(\frac{100}{i} \cdot n\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 < -2.9462336778663984e-16

    1. Initial program 29.6

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

      \[\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 -2.9462336778663984e-16 < i < 0.04335809508526476

    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.3

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

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

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

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

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

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

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

    if 0.04335809508526476 < i < 1.00300473460916e+189 or 1.7755133736422301e+283 < i

    1. Initial program 33.7

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

      \[\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 1.00300473460916e+189 < i < 1.7755133736422301e+283

    1. Initial program 32.5

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

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

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

      \[\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 -2.9462336778663984 \cdot 10^{-16}:\\ \;\;\;\;\frac{{\left(\frac{i}{n}\right)}^{n} - 1}{\frac{i}{100 \cdot n}}\\ \mathbf{elif}\;i \le 0.04335809508526476:\\ \;\;\;\;100 \cdot n + \left(i \cdot \frac{1}{6} + \frac{1}{2}\right) \cdot \left(i \cdot \left(100 \cdot n\right)\right)\\ \mathbf{elif}\;i \le 1.00300473460916 \cdot 10^{+189} \lor \neg \left(i \le 1.7755133736422301 \cdot 10^{+283}\right):\\ \;\;\;\;0\\ \mathbf{else}:\\ \;\;\;\;\left({\left(\frac{i}{n}\right)}^{n} - 1\right) \cdot \left(\frac{100}{i} \cdot n\right)\\ \end{array}\]

Runtime

Time bar (total: 46.9s)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))))