Average Error: 47.5 → 14.7
Time: 2.1m
Precision: 64
Internal Precision: 3392
\[100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\]
\[\begin{array}{l} \mathbf{if}\;i \le -1.2308891755979874 \cdot 10^{-05}:\\ \;\;\;\;\frac{{\left(\frac{i}{n}\right)}^{n} - 1}{\frac{i}{100 \cdot n}}\\ \mathbf{if}\;i \le 0.9841164434883862:\\ \;\;\;\;100 \cdot n + \left(100 \cdot n\right) \cdot \left(i \cdot \frac{1}{2}\right)\\ \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.5
Target47.0
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 3 regimes
  2. if i < -1.2308891755979874e-05

    1. Initial program 28.4

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

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

    if -1.2308891755979874e-05 < i < 0.9841164434883862

    1. Initial program 57.7

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

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

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

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

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

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

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

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

    if 0.9841164434883862 < i

    1. Initial program 30.8

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

      \[\leadsto 100 \cdot \color{blue}{\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. Applied simplify30.9

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

    \[\leadsto \color{blue}{\begin{array}{l} \mathbf{if}\;i \le -1.2308891755979874 \cdot 10^{-05}:\\ \;\;\;\;\frac{{\left(\frac{i}{n}\right)}^{n} - 1}{\frac{i}{100 \cdot n}}\\ \mathbf{if}\;i \le 0.9841164434883862:\\ \;\;\;\;100 \cdot n + \left(100 \cdot n\right) \cdot \left(i \cdot \frac{1}{2}\right)\\ \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: 2.1m)Debug logProfile

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