Average Error: 47.4 → 11.3
Time: 47.4s
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 -4.2115984806157235 \cdot 10^{-05}:\\ \;\;\;\;\frac{(\left(e^{n \cdot \log_* (1 + \frac{i}{n})}\right) \cdot 100 + -100)_*}{\frac{i}{n}}\\ \mathbf{elif}\;i \le 0.15844506048134294:\\ \;\;\;\;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

Original47.4
Target47.1
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 3 regimes
  2. if i < -4.2115984806157235e-05

    1. Initial program 28.9

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

      \[\leadsto \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.9

      \[\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.9

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

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

    if -4.2115984806157235e-05 < i < 0.15844506048134294

    1. Initial program 57.8

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

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

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

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

      \[\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. Simplified9.1

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

    if 0.15844506048134294 < i

    1. Initial program 31.1

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;i \le -4.2115984806157235 \cdot 10^{-05}:\\ \;\;\;\;\frac{(\left(e^{n \cdot \log_* (1 + \frac{i}{n})}\right) \cdot 100 + -100)_*}{\frac{i}{n}}\\ \mathbf{elif}\;i \le 0.15844506048134294:\\ \;\;\;\;n \cdot (i \cdot \left((\frac{50}{3} \cdot i + 50)_*\right) + 100)_*\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array}\]

Runtime

Time bar (total: 47.4s)Debug logProfile

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