Average Error: 47.1 → 3.6
Time: 44.6s
Precision: 64
Internal Precision: 3392
\[100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\]
\[\begin{array}{l} \mathbf{if}\;\frac{{\left(\frac{i}{n} + 1\right)}^{n} - 1}{\frac{i}{n}} \le 0.0:\\ \;\;\;\;\frac{(e^{\log_* (1 + \frac{i}{n}) \cdot n} - 1)^*}{\frac{i}{n}} \cdot 100\\ \mathbf{elif}\;\frac{{\left(\frac{i}{n} + 1\right)}^{n} - 1}{\frac{i}{n}} \le 2.034636162987458 \cdot 10^{-10}:\\ \;\;\;\;100 \cdot \left(\sqrt{\frac{{\left(\frac{i}{n} + 1\right)}^{n} - 1}{\frac{i}{n}}} \cdot \sqrt{\frac{{\left(\frac{i}{n} + 1\right)}^{n} - 1}{\frac{i}{n}}}\right)\\ \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

Original47.1
Target47.1
Herbie3.6
\[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 (/ (- (pow (+ 1 (/ i n)) n) 1) (/ i n)) < 0.0

    1. Initial program 46.3

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

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

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

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

    if 0.0 < (/ (- (pow (+ 1 (/ i n)) n) 1) (/ i n)) < 2.034636162987458e-10

    1. Initial program 3.2

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

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

    if 2.034636162987458e-10 < (/ (- (pow (+ 1 (/ i n)) n) 1) (/ i n))

    1. Initial program 59.5

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

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

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

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

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

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

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

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

Runtime

Time bar (total: 44.6s)Debug logProfile

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