Average Error: 42.5 → 17.1
Time: 24.1s
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 -2.3645625334258858 \cdot 10^{-06}:\\ \;\;\;\;\frac{(\left(e^{n \cdot \log_* (1 + \frac{i}{n})}\right) \cdot 100 + -100)_*}{\frac{i}{n}}\\ \mathbf{elif}\;i \le -1.6783295347621967 \cdot 10^{-169}:\\ \;\;\;\;n \cdot (i \cdot \left((\frac{50}{3} \cdot i + 50)_*\right) + 100)_*\\ \mathbf{elif}\;i \le -3.131012744836481 \cdot 10^{-200}:\\ \;\;\;\;\frac{(\left({\left(\frac{i}{n}\right)}^{n}\right) \cdot 100 + -100)_*}{\frac{i}{n}}\\ \mathbf{elif}\;i \le 0.9345852301016351:\\ \;\;\;\;n \cdot (i \cdot \left((\frac{50}{3} \cdot i + 50)_*\right) + 100)_*\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array}\]

Error

Bits error versus i

Bits error versus n

Target

Original42.5
Target42.0
Herbie17.1
\[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 < -2.3645625334258858e-06

    1. Initial program 28.4

      \[100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\]
    2. Simplified28.4

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

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

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

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

    if -2.3645625334258858e-06 < i < -1.6783295347621967e-169 or -3.131012744836481e-200 < i < 0.9345852301016351

    1. Initial program 50.1

      \[100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\]
    2. Simplified50.1

      \[\leadsto \color{blue}{\frac{(\left({\left(1 + \frac{i}{n}\right)}^{n}\right) \cdot 100 + -100)_*}{\frac{i}{n}}}\]
    3. Taylor expanded around 0 33.0

      \[\leadsto \frac{\color{blue}{100 \cdot i + \left(50 \cdot {i}^{2} + \frac{50}{3} \cdot {i}^{3}\right)}}{\frac{i}{n}}\]
    4. Simplified33.0

      \[\leadsto \frac{\color{blue}{i \cdot (\left((i \cdot \frac{50}{3} + 50)_*\right) \cdot i + 100)_*}}{\frac{i}{n}}\]
    5. Taylor expanded around -inf 17.2

      \[\leadsto \color{blue}{\frac{50}{3} \cdot \left({i}^{2} \cdot n\right) + \left(100 \cdot n + 50 \cdot \left(i \cdot n\right)\right)}\]
    6. Simplified17.2

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

    if -1.6783295347621967e-169 < i < -3.131012744836481e-200

    1. Initial program 46.1

      \[100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\]
    2. Simplified46.1

      \[\leadsto \color{blue}{\frac{(\left({\left(1 + \frac{i}{n}\right)}^{n}\right) \cdot 100 + -100)_*}{\frac{i}{n}}}\]
    3. Taylor expanded around inf 62.6

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

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

    if 0.9345852301016351 < i

    1. Initial program 30.8

      \[100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\]
    2. Simplified30.8

      \[\leadsto \color{blue}{\frac{(\left({\left(1 + \frac{i}{n}\right)}^{n}\right) \cdot 100 + -100)_*}{\frac{i}{n}}}\]
    3. Taylor expanded around 0 30.3

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;i \le -2.3645625334258858 \cdot 10^{-06}:\\ \;\;\;\;\frac{(\left(e^{n \cdot \log_* (1 + \frac{i}{n})}\right) \cdot 100 + -100)_*}{\frac{i}{n}}\\ \mathbf{elif}\;i \le -1.6783295347621967 \cdot 10^{-169}:\\ \;\;\;\;n \cdot (i \cdot \left((\frac{50}{3} \cdot i + 50)_*\right) + 100)_*\\ \mathbf{elif}\;i \le -3.131012744836481 \cdot 10^{-200}:\\ \;\;\;\;\frac{(\left({\left(\frac{i}{n}\right)}^{n}\right) \cdot 100 + -100)_*}{\frac{i}{n}}\\ \mathbf{elif}\;i \le 0.9345852301016351:\\ \;\;\;\;n \cdot (i \cdot \left((\frac{50}{3} \cdot i + 50)_*\right) + 100)_*\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array}\]

Reproduce

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