Average Error: 46.9 → 11.5
Time: 2.2m
Precision: 64
Internal Precision: 3200
\[100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\]
\[\begin{array}{l} \mathbf{if}\;i \le -1.904359019756817 \cdot 10^{-06}:\\ \;\;\;\;100 \cdot \frac{e^{n \cdot \log_* (1 + \frac{i}{n})} - 1}{\frac{i}{n}}\\ \mathbf{if}\;i \le 2.5183180654669837 \cdot 10^{-42}:\\ \;\;\;\;n \cdot \left(\frac{100}{1} \cdot (\frac{1}{2} \cdot i + 1)_*\right)\\ \mathbf{if}\;i \le 1.3244726976094244 \cdot 10^{+43}:\\ \;\;\;\;100 \cdot \frac{(e^{n \cdot \log \left(1 + \frac{i}{n}\right)} - 1)^*}{\frac{i}{n}}\\ \mathbf{else}:\\ \;\;\;\;\left(\frac{{i}^{n}}{{n}^{n}} - 1\right) \cdot \left(\frac{100}{i} \cdot n\right)\\ \end{array}\]

Error

Bits error versus i

Bits error versus n

Target

Original46.9
Target46.8
Herbie11.5
\[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.904359019756817e-06

    1. Initial program 26.7

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

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

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

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

    if -1.904359019756817e-06 < i < 2.5183180654669837e-42

    1. Initial program 57.9

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

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

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

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

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

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

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

    if 2.5183180654669837e-42 < i < 1.3244726976094244e+43

    1. Initial program 46.3

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

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

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

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

    if 1.3244726976094244e+43 < i

    1. Initial program 32.3

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

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

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

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

Runtime

Time bar (total: 2.2m)Debug logProfile

herbie shell --seed '#(1070833653 108281690 3330367898 3632331308 3494323072 43156186)' +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))))