Average Error: 47.3 → 14.6
Time: 1.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 -0.2071158073220815:\\ \;\;\;\;\left({\left(\frac{i}{n}\right)}^{n} - 1\right) \cdot \left(\frac{100}{i} \cdot n\right)\\ \mathbf{elif}\;i \le 2.832244485202547:\\ \;\;\;\;100 \cdot \left({e}^{\left(\log \left(\frac{\left(i \cdot i\right) \cdot \left(i \cdot \frac{1}{6} + \frac{1}{2}\right) + i}{i}\right)\right)} \cdot n\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{100 \cdot 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
Target46.8
Herbie14.6
\[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.2071158073220815

    1. Initial program 26.6

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

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

    if -0.2071158073220815 < i < 2.832244485202547

    1. Initial program 57.6

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

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

      \[\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. Using strategy rm
    5. Applied associate-/r/9.4

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

      \[\leadsto 100 \cdot \left(\color{blue}{e^{\log \left(\frac{i + \left(i \cdot i\right) \cdot \left(\frac{1}{6} \cdot i + \frac{1}{2}\right)}{i}\right)}} \cdot n\right)\]
    8. Using strategy rm
    9. Applied pow19.4

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

      \[\leadsto 100 \cdot \left(e^{\color{blue}{1 \cdot \log \left(\frac{i + \left(i \cdot i\right) \cdot \left(\frac{1}{6} \cdot i + \frac{1}{2}\right)}{i}\right)}} \cdot n\right)\]
    11. Applied exp-prod9.4

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

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

    if 2.832244485202547 < i

    1. Initial program 33.6

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

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

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

Runtime

Time bar (total: 1.1m)Debug logProfile

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