Average Error: 47.2 → 10.2
Time: 1.4m
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 -4.9359736808174155 \cdot 10^{-08}:\\ \;\;\;\;100 \cdot \frac{e^{n \cdot \log_* (1 + \frac{i}{n})} - 1}{\frac{i}{n}}\\ \mathbf{if}\;i \le 0.9123172558959546:\\ \;\;\;\;\left(100 \cdot n\right) \cdot \frac{(i \cdot \left(\frac{1}{2} \cdot i\right) + i)_*}{i}\\ \mathbf{if}\;i \le 1.6685658193722196 \cdot 10^{+212}:\\ \;\;\;\;(e^{\left(\log i - \log n\right) \cdot n} - 1)^* \cdot \frac{n}{\frac{i}{100}}\\ \mathbf{if}\;i \le 1.8549233814257343 \cdot 10^{+257}:\\ \;\;\;\;\frac{100 \cdot \left({\left(1 + \frac{i}{n}\right)}^{n} - 1\right)}{\frac{i}{n}}\\ \mathbf{else}:\\ \;\;\;\;(e^{\left(\log i - \log n\right) \cdot n} - 1)^* \cdot \frac{n}{\frac{i}{100}}\\ \end{array}\]

Error

Bits error versus i

Bits error versus n

Target

Original47.2
Target46.7
Herbie10.2
\[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 5 regimes
  2. if i < -4.9359736808174155e-08

    1. Initial program 28.3

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

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

    if -4.9359736808174155e-08 < i < 0.9123172558959546

    1. Initial program 57.2

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

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

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

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

    if 0.9123172558959546 < i < 1.6685658193722196e+212

    1. Initial program 32.3

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

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

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

    if 1.6685658193722196e+212 < i < 1.8549233814257343e+257

    1. Initial program 30.4

      \[100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\]
    2. Using strategy rm
    3. Applied associate-*r/30.3

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

    if 1.8549233814257343e+257 < i

    1. Initial program 34.4

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

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

      \[\leadsto \color{blue}{\frac{n}{\frac{i}{100}} \cdot (e^{n \cdot \left(\left(\log i + 0\right) - \log n\right)} - 1)^*}\]
  3. Recombined 5 regimes into one program.
  4. Applied simplify10.2

    \[\leadsto \color{blue}{\begin{array}{l} \mathbf{if}\;i \le -4.9359736808174155 \cdot 10^{-08}:\\ \;\;\;\;100 \cdot \frac{e^{n \cdot \log_* (1 + \frac{i}{n})} - 1}{\frac{i}{n}}\\ \mathbf{if}\;i \le 0.9123172558959546:\\ \;\;\;\;\left(100 \cdot n\right) \cdot \frac{(i \cdot \left(\frac{1}{2} \cdot i\right) + i)_*}{i}\\ \mathbf{if}\;i \le 1.6685658193722196 \cdot 10^{+212}:\\ \;\;\;\;(e^{\left(\log i - \log n\right) \cdot n} - 1)^* \cdot \frac{n}{\frac{i}{100}}\\ \mathbf{if}\;i \le 1.8549233814257343 \cdot 10^{+257}:\\ \;\;\;\;\frac{100 \cdot \left({\left(1 + \frac{i}{n}\right)}^{n} - 1\right)}{\frac{i}{n}}\\ \mathbf{else}:\\ \;\;\;\;(e^{\left(\log i - \log n\right) \cdot n} - 1)^* \cdot \frac{n}{\frac{i}{100}}\\ \end{array}}\]

Runtime

Time bar (total: 1.4m)Debug logProfile

herbie shell --seed '#(1070258749 1877548225 2229079127 1588002776 3179087814 1886870650)' +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))))