Average Error: 47.1 → 5.3
Time: 40.1s
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 -6.725346408389431 \cdot 10^{+66}:\\ \;\;\;\;100 \cdot \left(n \cdot \frac{(e^{i} - 1)^*}{i}\right)\\ \mathbf{elif}\;n \le -3.8813837222578165 \cdot 10^{-302}:\\ \;\;\;\;\left(100 \cdot n\right) \cdot \frac{(e^{\log_* (1 + \frac{i}{n}) \cdot n} - 1)^*}{i}\\ \mathbf{elif}\;n \le 6.932603767530431 \cdot 10^{-230}:\\ \;\;\;\;0\\ \mathbf{elif}\;n \le 5.8387002211788805 \cdot 10^{-05}:\\ \;\;\;\;\left(100 \cdot n\right) \cdot \frac{(e^{\log_* (1 + \frac{i}{n}) \cdot n} - 1)^*}{i}\\ \mathbf{else}:\\ \;\;\;\;100 \cdot \left(n \cdot \frac{(e^{i} - 1)^*}{i}\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.1
Target47.0
Herbie5.3
\[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 n < -6.725346408389431e+66 or 5.8387002211788805e-05 < n

    1. Initial program 54.0

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

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

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

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

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

      \[\leadsto 100 \cdot \color{blue}{\left(\frac{(e^{n \cdot \log_* (1 + \frac{i}{n})} - 1)^*}{i} \cdot n\right)}\]
    9. Using strategy rm
    10. Applied *-commutative25.9

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

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

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

    if -6.725346408389431e+66 < n < -3.8813837222578165e-302 or 6.932603767530431e-230 < n < 5.8387002211788805e-05

    1. Initial program 41.4

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

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

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

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

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

      \[\leadsto 100 \cdot \color{blue}{\left(\frac{(e^{n \cdot \log_* (1 + \frac{i}{n})} - 1)^*}{i} \cdot n\right)}\]
    9. Using strategy rm
    10. Applied *-commutative6.4

      \[\leadsto 100 \cdot \color{blue}{\left(n \cdot \frac{(e^{n \cdot \log_* (1 + \frac{i}{n})} - 1)^*}{i}\right)}\]
    11. Using strategy rm
    12. Applied associate-*r*6.3

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

    if -3.8813837222578165e-302 < n < 6.932603767530431e-230

    1. Initial program 34.2

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

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

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

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

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

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

      \[\leadsto \color{blue}{0}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification5.3

    \[\leadsto \begin{array}{l} \mathbf{if}\;n \le -6.725346408389431 \cdot 10^{+66}:\\ \;\;\;\;100 \cdot \left(n \cdot \frac{(e^{i} - 1)^*}{i}\right)\\ \mathbf{elif}\;n \le -3.8813837222578165 \cdot 10^{-302}:\\ \;\;\;\;\left(100 \cdot n\right) \cdot \frac{(e^{\log_* (1 + \frac{i}{n}) \cdot n} - 1)^*}{i}\\ \mathbf{elif}\;n \le 6.932603767530431 \cdot 10^{-230}:\\ \;\;\;\;0\\ \mathbf{elif}\;n \le 5.8387002211788805 \cdot 10^{-05}:\\ \;\;\;\;\left(100 \cdot n\right) \cdot \frac{(e^{\log_* (1 + \frac{i}{n}) \cdot n} - 1)^*}{i}\\ \mathbf{else}:\\ \;\;\;\;100 \cdot \left(n \cdot \frac{(e^{i} - 1)^*}{i}\right)\\ \end{array}\]

Runtime

Time bar (total: 40.1s)Debug logProfile

herbie shell --seed 2018248 +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))))