Average Error: 47.3 → 6.0
Time: 36.2s
Precision: 64
Internal Precision: 3136
\[100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\]
\[\begin{array}{l} \mathbf{if}\;n \le -4.3900474806479446 \cdot 10^{+54} \lor \neg \left(n \le 1.5734256284515255 \cdot 10^{-28}\right):\\ \;\;\;\;100 \cdot \left(n \cdot \frac{(e^{i} - 1)^*}{i}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{(e^{\log_* (1 + \frac{i}{n}) \cdot n} - 1)^* \cdot 100}{\frac{i}{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.9
Herbie6.0
\[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 2 regimes
  2. if n < -4.3900474806479446e+54 or 1.5734256284515255e-28 < n

    1. Initial program 53.3

      \[100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\]
    2. Using strategy rm
    3. Applied add-exp-log53.3

      \[\leadsto 100 \cdot \frac{\color{blue}{e^{\log \left({\left(1 + \frac{i}{n}\right)}^{n}\right)}} - 1}{\frac{i}{n}}\]
    4. Applied expm1-def53.3

      \[\leadsto 100 \cdot \frac{\color{blue}{(e^{\log \left({\left(1 + \frac{i}{n}\right)}^{n}\right)} - 1)^*}}{\frac{i}{n}}\]
    5. Simplified23.3

      \[\leadsto 100 \cdot \frac{(e^{\color{blue}{\log_* (1 + \frac{i}{n}) \cdot n}} - 1)^*}{\frac{i}{n}}\]
    6. Using strategy rm
    7. Applied associate-/r/24.4

      \[\leadsto 100 \cdot \color{blue}{\left(\frac{(e^{\log_* (1 + \frac{i}{n}) \cdot n} - 1)^*}{i} \cdot n\right)}\]
    8. Taylor expanded around 0 4.8

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

    if -4.3900474806479446e+54 < n < 1.5734256284515255e-28

    1. Initial program 41.1

      \[100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\]
    2. Using strategy rm
    3. Applied add-exp-log41.1

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

      \[\leadsto 100 \cdot \frac{\color{blue}{(e^{\log \left({\left(1 + \frac{i}{n}\right)}^{n}\right)} - 1)^*}}{\frac{i}{n}}\]
    5. Simplified7.1

      \[\leadsto 100 \cdot \frac{(e^{\color{blue}{\log_* (1 + \frac{i}{n}) \cdot n}} - 1)^*}{\frac{i}{n}}\]
    6. Using strategy rm
    7. Applied associate-*r/7.2

      \[\leadsto \color{blue}{\frac{100 \cdot (e^{\log_* (1 + \frac{i}{n}) \cdot n} - 1)^*}{\frac{i}{n}}}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification6.0

    \[\leadsto \begin{array}{l} \mathbf{if}\;n \le -4.3900474806479446 \cdot 10^{+54} \lor \neg \left(n \le 1.5734256284515255 \cdot 10^{-28}\right):\\ \;\;\;\;100 \cdot \left(n \cdot \frac{(e^{i} - 1)^*}{i}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{(e^{\log_* (1 + \frac{i}{n}) \cdot n} - 1)^* \cdot 100}{\frac{i}{n}}\\ \end{array}\]

Runtime

Time bar (total: 36.2s)Debug logProfile

herbie shell --seed 2018249 +o rules:numerics
(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))))