Average Error: 42.4 → 17.9
Time: 35.3s
Precision: 64
Internal Precision: 128
\[100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\]
\[\begin{array}{l} \mathbf{if}\;i \le 3.565415956589531 \cdot 10^{+121}:\\ \;\;\;\;\frac{(e^{\log_* (1 + \frac{i}{n}) \cdot n} - 1)^* \cdot 100}{\frac{i}{n}}\\ \mathbf{elif}\;i \le 2.0502939598821437 \cdot 10^{+247} \lor \neg \left(i \le 6.009420036080202 \cdot 10^{+278}\right):\\ \;\;\;\;0\\ \mathbf{else}:\\ \;\;\;\;\left(\frac{{\left(1 + \frac{i}{n}\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

Original42.4
Target42.4
Herbie17.9
\[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 < 3.565415956589531e+121

    1. Initial program 43.5

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

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

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

      \[\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/16.7

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

    if 3.565415956589531e+121 < i < 2.0502939598821437e+247 or 6.009420036080202e+278 < i

    1. Initial program 33.3

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

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

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

      \[\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/50.4

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

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

    if 2.0502939598821437e+247 < i < 6.009420036080202e+278

    1. Initial program 26.0

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

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

      \[\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 simplification17.9

    \[\leadsto \begin{array}{l} \mathbf{if}\;i \le 3.565415956589531 \cdot 10^{+121}:\\ \;\;\;\;\frac{(e^{\log_* (1 + \frac{i}{n}) \cdot n} - 1)^* \cdot 100}{\frac{i}{n}}\\ \mathbf{elif}\;i \le 2.0502939598821437 \cdot 10^{+247} \lor \neg \left(i \le 6.009420036080202 \cdot 10^{+278}\right):\\ \;\;\;\;0\\ \mathbf{else}:\\ \;\;\;\;\left(\frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{i} \cdot 100\right) \cdot n\\ \end{array}\]

Runtime

Time bar (total: 35.3s)Debug logProfile

BaselineHerbieOracleSpan%
Regimes20.217.99.510.721.8%
herbie shell --seed 2018353 +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))))