Average Error: 47.4 → 10.6
Time: 1.5m
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 -6.813735736412871 \cdot 10^{-08}:\\ \;\;\;\;100 \cdot \frac{e^{n \cdot \log_* (1 + \frac{i}{n})} - 1}{\frac{i}{n}}\\ \mathbf{if}\;i \le 0.9343917665617285:\\ \;\;\;\;n \cdot \left(\frac{i}{i} \cdot (50 \cdot i + 100)_*\right)\\ \mathbf{if}\;i \le 1.9656476839528255 \cdot 10^{+98}:\\ \;\;\;\;100 \cdot \frac{(e^{n \cdot \log \left(1 + \frac{i}{n}\right)} - 1)^*}{\frac{i}{n}}\\ \mathbf{else}:\\ \;\;\;\;\frac{(\left(\frac{{i}^{n}}{{n}^{n}}\right) \cdot 100 + -100)_*}{\frac{i}{n}}\\ \end{array}\]

Error

Bits error versus i

Bits error versus n

Target

Original47.4
Target46.8
Herbie10.6
\[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 < -6.813735736412871e-08

    1. Initial program 29.4

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

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

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

    if -6.813735736412871e-08 < i < 0.9343917665617285

    1. Initial program 57.4

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

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

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

      \[\leadsto \frac{(50 \cdot \left(i \cdot i\right) + \left(100 \cdot i\right))_*}{\color{blue}{1 \cdot \frac{i}{n}}}\]
    6. Applied *-un-lft-identity26.2

      \[\leadsto \frac{\color{blue}{1 \cdot (50 \cdot \left(i \cdot i\right) + \left(100 \cdot i\right))_*}}{1 \cdot \frac{i}{n}}\]
    7. Applied times-frac26.2

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

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

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

    if 0.9343917665617285 < i < 1.9656476839528255e+98

    1. Initial program 28.8

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

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

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

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

    if 1.9656476839528255e+98 < i

    1. Initial program 31.3

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

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

      \[\leadsto \color{blue}{\frac{(\left(\frac{{i}^{n}}{{n}^{n}}\right) \cdot 100 + -100)_*}{\frac{i}{n}}}\]
  3. Recombined 4 regimes into one program.
  4. Applied simplify10.6

    \[\leadsto \color{blue}{\begin{array}{l} \mathbf{if}\;i \le -6.813735736412871 \cdot 10^{-08}:\\ \;\;\;\;100 \cdot \frac{e^{n \cdot \log_* (1 + \frac{i}{n})} - 1}{\frac{i}{n}}\\ \mathbf{if}\;i \le 0.9343917665617285:\\ \;\;\;\;n \cdot \left(\frac{i}{i} \cdot (50 \cdot i + 100)_*\right)\\ \mathbf{if}\;i \le 1.9656476839528255 \cdot 10^{+98}:\\ \;\;\;\;100 \cdot \frac{(e^{n \cdot \log \left(1 + \frac{i}{n}\right)} - 1)^*}{\frac{i}{n}}\\ \mathbf{else}:\\ \;\;\;\;\frac{(\left(\frac{{i}^{n}}{{n}^{n}}\right) \cdot 100 + -100)_*}{\frac{i}{n}}\\ \end{array}}\]

Runtime

Time bar (total: 1.5m)Debug logProfile

herbie shell --seed '#(1070991898 1055468627 4280279443 640792587 928206309 3646738750)' +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))))