Average Error: 47.0 → 12.2
Time: 55.1s
Precision: 64
Internal Precision: 3392
\[100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\]
\[\begin{array}{l} \mathbf{if}\;100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}} \le 3.1903195975620304 \cdot 10^{-203}:\\ \;\;\;\;\sqrt[3]{\frac{(e^{\log_* (1 + \frac{i}{n}) \cdot n} - 1)^*}{\frac{i}{n}}} \cdot \left(100 \cdot \left(\sqrt[3]{\frac{(e^{\log_* (1 + \frac{i}{n}) \cdot n} - 1)^*}{\frac{i}{n}}} \cdot \sqrt[3]{\frac{(e^{\log_* (1 + \frac{i}{n}) \cdot n} - 1)^*}{\frac{i}{n}}}\right)\right)\\ \mathbf{elif}\;100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}} \le 7.058601280960488 \cdot 10^{-35}:\\ \;\;\;\;\left({\left(\frac{i}{n}\right)}^{n} - 1\right) \cdot \left(n \cdot \frac{100}{i}\right)\\ \mathbf{else}:\\ \;\;\;\;0 \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

Original47.0
Target47.3
Herbie12.2
\[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 (* 100 (/ (- (pow (+ 1 (/ i n)) n) 1) (/ i n))) < 3.1903195975620304e-203

    1. Initial program 45.7

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

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

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

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

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

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

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

    if 3.1903195975620304e-203 < (* 100 (/ (- (pow (+ 1 (/ i n)) n) 1) (/ i n))) < 7.058601280960488e-35

    1. Initial program 2.3

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

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

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

    if 7.058601280960488e-35 < (* 100 (/ (- (pow (+ 1 (/ i n)) n) 1) (/ i n)))

    1. Initial program 57.8

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

      \[\leadsto 100 \cdot \color{blue}{0}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification12.2

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

Runtime

Time bar (total: 55.1s)Debug logProfile

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