Average Error: 47.5 → 11.3
Time: 1.7m
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 -1.004116165320672 \cdot 10^{-06}:\\ \;\;\;\;100 \cdot \frac{e^{\log_* (1 + \frac{i}{n}) \cdot n} - 1}{\frac{i}{n}}\\ \mathbf{if}\;i \le 1.0012536959012732:\\ \;\;\;\;(i \cdot \frac{1}{2} + 1)_* \cdot \left(100 \cdot n\right)\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array}\]

Error

Bits error versus i

Bits error versus n

Target

Original47.5
Target47.0
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 < -1.004116165320672e-06

    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 simplify5.6

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

    if -1.004116165320672e-06 < i < 1.0012536959012732

    1. Initial program 57.7

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

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

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

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

      \[\leadsto \color{blue}{{\left(\frac{100}{\frac{i}{n}}\right)}^{1}} \cdot {\left((\frac{1}{2} \cdot \left(i \cdot i\right) + i)_*\right)}^{1}\]
    7. Applied pow-prod-down26.8

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

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

    if 1.0012536959012732 < i

    1. Initial program 30.8

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

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

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

    \[\leadsto \color{blue}{\begin{array}{l} \mathbf{if}\;i \le -1.004116165320672 \cdot 10^{-06}:\\ \;\;\;\;100 \cdot \frac{e^{\log_* (1 + \frac{i}{n}) \cdot n} - 1}{\frac{i}{n}}\\ \mathbf{if}\;i \le 1.0012536959012732:\\ \;\;\;\;(i \cdot \frac{1}{2} + 1)_* \cdot \left(100 \cdot n\right)\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array}}\]

Runtime

Time bar (total: 1.7m)Debug logProfile

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))))