Average Error: 47.4 → 11.0
Time: 2.0m
Precision: 64
Internal Precision: 3136
\[100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\]
\[\begin{array}{l} \mathbf{if}\;i \le -5.732026414222925 \cdot 10^{-07}:\\ \;\;\;\;100 \cdot \frac{e^{n \cdot \log_* (1 + \frac{i}{n})} - 1}{\frac{i}{n}}\\ \mathbf{if}\;i \le 6.305972386755532 \cdot 10^{-07}:\\ \;\;\;\;n \cdot \left(100 \cdot (\left((\frac{1}{6} \cdot i + \frac{1}{2})_*\right) \cdot i + 1)_*\right)\\ \mathbf{if}\;i \le 1.3029078707659525 \cdot 10^{+98}:\\ \;\;\;\;\frac{(e^{\log \left(1 + \frac{i}{n}\right) \cdot n} - 1)^*}{\frac{i}{n}} \cdot 100\\ \mathbf{else}:\\ \;\;\;\;\frac{\left({\left(1 + \frac{i}{n}\right)}^{n} - 1\right) \cdot 100}{\frac{i}{n}}\\ \end{array}\]

Error

Bits error versus i

Bits error versus n

Target

Original47.4
Target47.2
Herbie11.0
\[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 i < -5.732026414222925e-07

    1. Initial program 28.4

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

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

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

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

    if -5.732026414222925e-07 < i < 6.305972386755532e-07

    1. Initial program 57.6

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

      \[\leadsto 100 \cdot \frac{\color{blue}{\frac{1}{2} \cdot {i}^{2} + \left(\frac{1}{6} \cdot {i}^{3} + i\right)}}{\frac{i}{n}}\]
    3. Applied simplify27.0

      \[\leadsto \color{blue}{\left(n \cdot \frac{100}{i}\right) \cdot (\left(i \cdot i\right) \cdot \left((i \cdot \frac{1}{6} + \frac{1}{2})_*\right) + i)_*}\]
    4. Using strategy rm
    5. Applied associate-*l*9.6

      \[\leadsto \color{blue}{n \cdot \left(\frac{100}{i} \cdot (\left(i \cdot i\right) \cdot \left((i \cdot \frac{1}{6} + \frac{1}{2})_*\right) + i)_*\right)}\]
    6. Applied simplify9.1

      \[\leadsto n \cdot \color{blue}{\left((\left((\frac{1}{6} \cdot i + \frac{1}{2})_*\right) \cdot i + 1)_* \cdot \left(1 \cdot 100\right)\right)}\]

    if 6.305972386755532e-07 < i < 1.3029078707659525e+98

    1. Initial program 38.1

      \[100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\]
    2. Using strategy rm
    3. Applied add-exp-log43.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-exp43.1

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

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

    if 1.3029078707659525e+98 < i

    1. Initial program 30.0

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

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

    \[\leadsto \color{blue}{\begin{array}{l} \mathbf{if}\;i \le -5.732026414222925 \cdot 10^{-07}:\\ \;\;\;\;100 \cdot \frac{e^{n \cdot \log_* (1 + \frac{i}{n})} - 1}{\frac{i}{n}}\\ \mathbf{if}\;i \le 6.305972386755532 \cdot 10^{-07}:\\ \;\;\;\;n \cdot \left(100 \cdot (\left((\frac{1}{6} \cdot i + \frac{1}{2})_*\right) \cdot i + 1)_*\right)\\ \mathbf{if}\;i \le 1.3029078707659525 \cdot 10^{+98}:\\ \;\;\;\;\frac{(e^{\log \left(1 + \frac{i}{n}\right) \cdot n} - 1)^*}{\frac{i}{n}} \cdot 100\\ \mathbf{else}:\\ \;\;\;\;\frac{\left({\left(1 + \frac{i}{n}\right)}^{n} - 1\right) \cdot 100}{\frac{i}{n}}\\ \end{array}}\]

Runtime

Time bar (total: 2.0m)Debug logProfile

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