Average Error: 46.9 → 11.3
Time: 57.4s
Precision: 64
Internal Precision: 2944
\[100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\]
\[\begin{array}{l} \mathbf{if}\;i \le -1.1380411540023518 \cdot 10^{-08}:\\ \;\;\;\;100 \cdot \frac{e^{n \cdot \log_* (1 + \frac{i}{n})} - 1}{\frac{i}{n}}\\ \mathbf{if}\;i \le 1.4594955125845637 \cdot 10^{-22}:\\ \;\;\;\;(\left(\left(i \cdot i\right) \cdot n\right) \cdot \frac{50}{3} + \left(n \cdot (i \cdot 50 + 100)_*\right))_*\\ \mathbf{if}\;i \le 2.1020695442444676 \cdot 10^{+101}:\\ \;\;\;\;100 \cdot \frac{(e^{\log \left(1 + \frac{i}{n}\right) \cdot n} - 1)^*}{\frac{i}{n}}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array}\]

Error

Bits error versus i

Bits error versus n

Target

Original46.9
Target46.9
Herbie11.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 4 regimes
  2. if i < -1.1380411540023518e-08

    1. Initial program 28.3

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

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

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

    if -1.1380411540023518e-08 < i < 1.4594955125845637e-22

    1. Initial program 57.4

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

      \[\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 simplify26.0

      \[\leadsto \color{blue}{\frac{(\left(i \cdot i\right) \cdot \left((i \cdot \frac{1}{6} + \frac{1}{2})_*\right) + i)_*}{\frac{\frac{i}{100}}{n}}}\]
    4. Taylor expanded around 0 8.9

      \[\leadsto \color{blue}{100 \cdot n + \left(\frac{50}{3} \cdot \left(n \cdot {i}^{2}\right) + 50 \cdot \left(n \cdot i\right)\right)}\]
    5. Applied simplify8.9

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

    if 1.4594955125845637e-22 < i < 2.1020695442444676e+101

    1. Initial program 37.7

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

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

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

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

    if 2.1020695442444676e+101 < i

    1. Initial program 31.0

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

      \[\leadsto 100 \cdot \color{blue}{0}\]
    3. Applied simplify28.9

      \[\leadsto \color{blue}{0}\]
  3. Recombined 4 regimes into one program.

Runtime

Time bar (total: 57.4s)Debug logProfile

herbie shell --seed '#(1064173506 2580572819 2847706409 4129882574 1125180799 1845288547)' +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))))