Average Error: 47.0 → 14.8
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.0010600513951207684:\\ \;\;\;\;100 \cdot \frac{{\left(\frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\\ \mathbf{elif}\;i \le 5.532726887693463 \cdot 10^{-17}:\\ \;\;\;\;\left({e}^{\left(\log \left(\frac{i + \left(i \cdot i\right) \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot i\right)}{i}\right)\right)} \cdot n\right) \cdot 100\\ \mathbf{elif}\;i \le 4.098636349098681 \cdot 10^{+169} \lor \neg \left(i \le 7.178805138420747 \cdot 10^{+222}\right):\\ \;\;\;\;0 \cdot 100\\ \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.0
Target47.3
Herbie14.8
\[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 < -0.0010600513951207684

    1. Initial program 27.2

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

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

    if -0.0010600513951207684 < i < 5.532726887693463e-17

    1. Initial program 57.8

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

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

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

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

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

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

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

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

      \[\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 5.532726887693463e-17 < i < 4.098636349098681e+169 or 7.178805138420747e+222 < i

    1. Initial program 34.0

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

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

    if 4.098636349098681e+169 < i < 7.178805138420747e+222

    1. Initial program 27.4

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

      \[\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. Simplified27.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.8

    \[\leadsto \begin{array}{l} \mathbf{if}\;i \le -0.0010600513951207684:\\ \;\;\;\;100 \cdot \frac{{\left(\frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\\ \mathbf{elif}\;i \le 5.532726887693463 \cdot 10^{-17}:\\ \;\;\;\;\left({e}^{\left(\log \left(\frac{i + \left(i \cdot i\right) \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot i\right)}{i}\right)\right)} \cdot n\right) \cdot 100\\ \mathbf{elif}\;i \le 4.098636349098681 \cdot 10^{+169} \lor \neg \left(i \le 7.178805138420747 \cdot 10^{+222}\right):\\ \;\;\;\;0 \cdot 100\\ \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: 1.1m)Debug logProfile

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