Average Error: 42.1 → 18.3
Time: 40.6s
Precision: 64
Internal Precision: 128
\[100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\]
\[\begin{array}{l} \mathbf{if}\;n \le -1.9959112682211866:\\ \;\;\;\;100 \cdot \frac{(e^{i} - 1)^*}{\frac{i}{n}}\\ \mathbf{elif}\;n \le -2.5875851879278052 \cdot 10^{-67}:\\ \;\;\;\;n \cdot \left(\frac{{\left(\frac{i}{n} + 1\right)}^{n} - 1}{i} \cdot 100\right)\\ \mathbf{elif}\;n \le -3.843767469236074 \cdot 10^{-200}:\\ \;\;\;\;\left((e^{\log_* (1 + \frac{i}{n}) \cdot n} - 1)^* \cdot n\right) \cdot \frac{100}{i}\\ \mathbf{else}:\\ \;\;\;\;\frac{(e^{\log_* (1 + \frac{i}{n}) \cdot n} - 1)^*}{\frac{i}{n}} \cdot 100\\ \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

Original42.1
Target41.8
Herbie18.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 4 regimes
  2. if n < -1.9959112682211866

    1. Initial program 44.9

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

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

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

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

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

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

    if -1.9959112682211866 < n < -2.5875851879278052e-67

    1. Initial program 17.9

      \[100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\]
    2. Using strategy rm
    3. Applied associate-/r/18.2

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

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

    if -2.5875851879278052e-67 < n < -3.843767469236074e-200

    1. Initial program 16.9

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

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

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

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

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

      \[\leadsto \frac{100 \cdot (e^{n \cdot \log_* (1 + \frac{i}{n})} - 1)^*}{\color{blue}{i \cdot \frac{1}{n}}}\]
    10. Applied times-frac14.8

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

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

    if -3.843767469236074e-200 < n

    1. Initial program 48.0

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;n \le -1.9959112682211866:\\ \;\;\;\;100 \cdot \frac{(e^{i} - 1)^*}{\frac{i}{n}}\\ \mathbf{elif}\;n \le -2.5875851879278052 \cdot 10^{-67}:\\ \;\;\;\;n \cdot \left(\frac{{\left(\frac{i}{n} + 1\right)}^{n} - 1}{i} \cdot 100\right)\\ \mathbf{elif}\;n \le -3.843767469236074 \cdot 10^{-200}:\\ \;\;\;\;\left((e^{\log_* (1 + \frac{i}{n}) \cdot n} - 1)^* \cdot n\right) \cdot \frac{100}{i}\\ \mathbf{else}:\\ \;\;\;\;\frac{(e^{\log_* (1 + \frac{i}{n}) \cdot n} - 1)^*}{\frac{i}{n}} \cdot 100\\ \end{array}\]

Runtime

Time bar (total: 40.6s)Debug logProfile

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