Average Error: 47.2 → 13.3
Time: 1.2m
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 6.795944297847626 \cdot 10^{+73}:\\ \;\;\;\;100 \cdot \frac{(e^{n \cdot \log_* (1 + \frac{i}{n})} - 1)^*}{\frac{i}{n}}\\ \mathbf{elif}\;i \le 1.7085371803805802 \cdot 10^{+252} \lor \neg \left(i \le 2.9255058228020052 \cdot 10^{+305}\right):\\ \;\;\;\;0\\ \mathbf{else}:\\ \;\;\;\;\left(\frac{{\left(\frac{i}{n} + 1\right)}^{n} - 1}{i} \cdot 100\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

Original47.2
Target46.7
Herbie13.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 i < 6.795944297847626e+73

    1. Initial program 49.2

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

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

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

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

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

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

    if 6.795944297847626e+73 < i < 1.7085371803805802e+252 or 2.9255058228020052e+305 < i

    1. Initial program 30.8

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

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

    if 1.7085371803805802e+252 < i < 2.9255058228020052e+305

    1. Initial program 30.3

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;i \le 6.795944297847626 \cdot 10^{+73}:\\ \;\;\;\;100 \cdot \frac{(e^{n \cdot \log_* (1 + \frac{i}{n})} - 1)^*}{\frac{i}{n}}\\ \mathbf{elif}\;i \le 1.7085371803805802 \cdot 10^{+252} \lor \neg \left(i \le 2.9255058228020052 \cdot 10^{+305}\right):\\ \;\;\;\;0\\ \mathbf{else}:\\ \;\;\;\;\left(\frac{{\left(\frac{i}{n} + 1\right)}^{n} - 1}{i} \cdot 100\right) \cdot n\\ \end{array}\]

Runtime

Time bar (total: 1.2m)Debug logProfile

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