Average Error: 46.5 → 11.6
Time: 2.2m
Precision: 64
Internal Precision: 3392
\[100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\]
\[\begin{array}{l} \mathbf{if}\;(i \cdot \frac{1}{2} + 1)_* \cdot 100 \le 99.9999999999856:\\ \;\;\;\;\frac{e^{\log_* (1 + \frac{i}{n}) \cdot n} - 1}{\frac{i}{n}} \cdot 100\\ \mathbf{if}\;(i \cdot \frac{1}{2} + 1)_* \cdot 100 \le 100.0000000000032:\\ \;\;\;\;\left(n \cdot \frac{1}{2}\right) \cdot \left(i \cdot 100\right) + n \cdot 100\\ \mathbf{if}\;(i \cdot \frac{1}{2} + 1)_* \cdot 100 \le 2.4734050452575835 \cdot 10^{+226}:\\ \;\;\;\;100 \cdot \frac{(e^{\log \left(\frac{i}{n} + 1\right) \cdot n} - 1)^*}{\frac{i}{n}}\\ \mathbf{else}:\\ \;\;\;\;\left(\frac{100}{i} \cdot n\right) \cdot \left(\frac{{i}^{n}}{{n}^{n}} - 1\right)\\ \end{array}\]

Error

Bits error versus i

Bits error versus n

Target

Original46.5
Target46.6
Herbie11.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 (* (/ 100 1) (fma i 1/2 1)) < 99.9999999999856

    1. Initial program 28.1

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

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

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

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

    if 99.9999999999856 < (* (/ 100 1) (fma i 1/2 1)) < 100.0000000000032

    1. Initial program 57.6

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

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

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

      \[\leadsto \frac{100}{\frac{i}{n}} \cdot \color{blue}{\left(i \cdot \left(i \cdot \frac{1}{2}\right) + i\right)}\]
    6. Applied distribute-lft-in26.6

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

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

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

    if 100.0000000000032 < (* (/ 100 1) (fma i 1/2 1)) < 2.4734050452575835e+226

    1. Initial program 33.0

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

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

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

    if 2.4734050452575835e+226 < (* (/ 100 1) (fma i 1/2 1))

    1. Initial program 29.1

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

      \[\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 simplify31.5

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

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

Runtime

Time bar (total: 2.2m)Debug logProfile

herbie shell --seed '#(1071821486 549052472 3784827256 1559736200 3548510075 881134285)' +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))))