Average Error: 47.2 → 8.2
Time: 43.7s
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.663235049845083 \cdot 10^{-202}:\\ \;\;\;\;100 \cdot \frac{(e^{\log_* (1 + \frac{i}{n}) \cdot n} - 1)^*}{\frac{i}{n}}\\ \mathbf{elif}\;i \le 2.9705069655040925 \cdot 10^{-187}:\\ \;\;\;\;100 \cdot (\left(n \cdot i\right) \cdot \left((i \cdot \frac{1}{6} + \frac{1}{2})_*\right) + n)_*\\ \mathbf{elif}\;i \le 1.5659021402349018 \cdot 10^{+88}:\\ \;\;\;\;100 \cdot \frac{(e^{\log_* (1 + \frac{i}{n}) \cdot n} - 1)^*}{\frac{i}{n}}\\ \mathbf{else}:\\ \;\;\;\;0 \cdot 100\\ \end{array}\]

Error

Bits error versus i

Bits error versus n

Target

Original47.2
Target46.7
Herbie8.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 3 regimes
  2. if i < -1.663235049845083e-202 or 2.9705069655040925e-187 < i < 1.5659021402349018e+88

    1. Initial program 44.6

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

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

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

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

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

    if -1.663235049845083e-202 < i < 2.9705069655040925e-187

    1. Initial program 60.4

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

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

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

      \[\leadsto 100 \cdot \frac{(e^{\color{blue}{n \cdot \log_* (1 + \frac{i}{n})}} - 1)^*}{\frac{i}{n}}\]
    7. Using strategy rm
    8. Applied *-un-lft-identity24.9

      \[\leadsto 100 \cdot \frac{(e^{n \cdot \log_* (1 + \frac{i}{n})} - 1)^*}{\color{blue}{1 \cdot \frac{i}{n}}}\]
    9. Applied add-cube-cbrt25.7

      \[\leadsto 100 \cdot \frac{\color{blue}{\left(\sqrt[3]{(e^{n \cdot \log_* (1 + \frac{i}{n})} - 1)^*} \cdot \sqrt[3]{(e^{n \cdot \log_* (1 + \frac{i}{n})} - 1)^*}\right) \cdot \sqrt[3]{(e^{n \cdot \log_* (1 + \frac{i}{n})} - 1)^*}}}{1 \cdot \frac{i}{n}}\]
    10. Applied times-frac25.7

      \[\leadsto 100 \cdot \color{blue}{\left(\frac{\sqrt[3]{(e^{n \cdot \log_* (1 + \frac{i}{n})} - 1)^*} \cdot \sqrt[3]{(e^{n \cdot \log_* (1 + \frac{i}{n})} - 1)^*}}{1} \cdot \frac{\sqrt[3]{(e^{n \cdot \log_* (1 + \frac{i}{n})} - 1)^*}}{\frac{i}{n}}\right)}\]
    11. Simplified25.7

      \[\leadsto 100 \cdot \left(\color{blue}{\left(\sqrt[3]{(e^{\log_* (1 + \frac{i}{n}) \cdot n} - 1)^*} \cdot \sqrt[3]{(e^{\log_* (1 + \frac{i}{n}) \cdot n} - 1)^*}\right)} \cdot \frac{\sqrt[3]{(e^{n \cdot \log_* (1 + \frac{i}{n})} - 1)^*}}{\frac{i}{n}}\right)\]
    12. Taylor expanded around 0 3.3

      \[\leadsto 100 \cdot \color{blue}{\left(\frac{1}{6} \cdot \left({i}^{2} \cdot n\right) + \left(n + \frac{1}{2} \cdot \left(i \cdot n\right)\right)\right)}\]
    13. Simplified3.3

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

    if 1.5659021402349018e+88 < i

    1. Initial program 31.6

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

      \[\leadsto 100 \cdot \color{blue}{0}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification8.2

    \[\leadsto \begin{array}{l} \mathbf{if}\;i \le -1.663235049845083 \cdot 10^{-202}:\\ \;\;\;\;100 \cdot \frac{(e^{\log_* (1 + \frac{i}{n}) \cdot n} - 1)^*}{\frac{i}{n}}\\ \mathbf{elif}\;i \le 2.9705069655040925 \cdot 10^{-187}:\\ \;\;\;\;100 \cdot (\left(n \cdot i\right) \cdot \left((i \cdot \frac{1}{6} + \frac{1}{2})_*\right) + n)_*\\ \mathbf{elif}\;i \le 1.5659021402349018 \cdot 10^{+88}:\\ \;\;\;\;100 \cdot \frac{(e^{\log_* (1 + \frac{i}{n}) \cdot n} - 1)^*}{\frac{i}{n}}\\ \mathbf{else}:\\ \;\;\;\;0 \cdot 100\\ \end{array}\]

Runtime

Time bar (total: 43.7s)Debug logProfile

herbie shell --seed 2018219 +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))))