Average Error: 46.9 → 6.1
Time: 39.7s
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 -7.436426181453747 \cdot 10^{+45}:\\ \;\;\;\;\left(100 \cdot \frac{(e^{i} - 1)^*}{i}\right) \cdot n\\ \mathbf{elif}\;n \le 8.298202248326911 \cdot 10^{-251}:\\ \;\;\;\;\frac{(e^{\log_* (1 + \frac{i}{n}) \cdot n} - 1)^*}{\frac{i}{n}} \cdot 100\\ \mathbf{elif}\;n \le 2.4769975322682055 \cdot 10^{-175}:\\ \;\;\;\;0\\ \mathbf{elif}\;n \le 1014549038.6750512:\\ \;\;\;\;\frac{(e^{\log_* (1 + \frac{i}{n}) \cdot n} - 1)^*}{\frac{i}{n}} \cdot 100\\ \mathbf{else}:\\ \;\;\;\;\left(100 \cdot \frac{(e^{i} - 1)^*}{i}\right) \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

Original46.9
Target46.7
Herbie6.1
\[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 < -7.436426181453747e+45 or 1014549038.6750512 < n

    1. Initial program 51.8

      \[100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\]
    2. Using strategy rm
    3. Applied pow-to-exp56.4

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

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

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

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

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

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

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

    if -7.436426181453747e+45 < n < 8.298202248326911e-251 or 2.4769975322682055e-175 < n < 1014549038.6750512

    1. Initial program 41.8

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

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

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

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

    if 8.298202248326911e-251 < n < 2.4769975322682055e-175

    1. Initial program 45.9

      \[100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\]
    2. Using strategy rm
    3. Applied pow-to-exp45.9

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;n \le -7.436426181453747 \cdot 10^{+45}:\\ \;\;\;\;\left(100 \cdot \frac{(e^{i} - 1)^*}{i}\right) \cdot n\\ \mathbf{elif}\;n \le 8.298202248326911 \cdot 10^{-251}:\\ \;\;\;\;\frac{(e^{\log_* (1 + \frac{i}{n}) \cdot n} - 1)^*}{\frac{i}{n}} \cdot 100\\ \mathbf{elif}\;n \le 2.4769975322682055 \cdot 10^{-175}:\\ \;\;\;\;0\\ \mathbf{elif}\;n \le 1014549038.6750512:\\ \;\;\;\;\frac{(e^{\log_* (1 + \frac{i}{n}) \cdot n} - 1)^*}{\frac{i}{n}} \cdot 100\\ \mathbf{else}:\\ \;\;\;\;\left(100 \cdot \frac{(e^{i} - 1)^*}{i}\right) \cdot n\\ \end{array}\]

Runtime

Time bar (total: 39.7s)Debug logProfile

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