Average Error: 47.7 → 9.3
Time: 1.4m
Precision: 64
Internal Precision: 3456
\[100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\]
\[\begin{array}{l} \mathbf{if}\;i \le -1.5898280774231214 \cdot 10^{-08}:\\ \;\;\;\;100 \cdot \frac{e^{n \cdot \log_* (1 + \frac{i}{n})} - 1}{\frac{i}{n}}\\ \mathbf{if}\;i \le -2.088551319850114 \cdot 10^{-182}:\\ \;\;\;\;\frac{1}{i} \cdot \frac{(i \cdot \left(\frac{1}{2} \cdot i\right) + i)_*}{\frac{1}{100 \cdot n}}\\ \mathbf{if}\;i \le -1.0987039570203948 \cdot 10^{-277}:\\ \;\;\;\;\frac{(i \cdot \left(\frac{1}{2} \cdot i\right) + i)_*}{i} \cdot \left(100 \cdot n\right)\\ \mathbf{if}\;i \le 8.299692008936171 \cdot 10^{-177}:\\ \;\;\;\;\frac{(i \cdot \left(\frac{1}{2} \cdot i\right) + i)_*}{i} \cdot \left(100 \cdot n\right)\\ \mathbf{if}\;i \le 2.2645427861240446 \cdot 10^{-20}:\\ \;\;\;\;\frac{1}{i} \cdot \frac{(i \cdot \left(\frac{1}{2} \cdot i\right) + i)_*}{\frac{1}{100 \cdot n}}\\ \mathbf{else}:\\ \;\;\;\;(e^{\left(\log i - \log n\right) \cdot n} - 1)^* \cdot \left(\frac{n}{i} \cdot 100\right)\\ \end{array}\]

Error

Bits error versus i

Bits error versus n

Target

Original47.7
Target47.0
Herbie9.3
\[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 < -1.5898280774231214e-08

    1. Initial program 29.7

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

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

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

    if -1.5898280774231214e-08 < i < -2.088551319850114e-182 or 8.299692008936171e-177 < i < 2.2645427861240446e-20

    1. Initial program 55.4

      \[100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\]
    2. Taylor expanded around 0 55.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 simplify24.0

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

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

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

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

    if -2.088551319850114e-182 < i < -1.0987039570203948e-277

    1. Initial program 59.5

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

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

      \[\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/5.0

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

    if -1.0987039570203948e-277 < i < 8.299692008936171e-177

    1. Initial program 60.3

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

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

      \[\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/3.3

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

    if 2.2645427861240446e-20 < i

    1. Initial program 35.1

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

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

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

    \[\leadsto \color{blue}{\begin{array}{l} \mathbf{if}\;i \le -1.5898280774231214 \cdot 10^{-08}:\\ \;\;\;\;100 \cdot \frac{e^{n \cdot \log_* (1 + \frac{i}{n})} - 1}{\frac{i}{n}}\\ \mathbf{if}\;i \le -2.088551319850114 \cdot 10^{-182}:\\ \;\;\;\;\frac{1}{i} \cdot \frac{(i \cdot \left(\frac{1}{2} \cdot i\right) + i)_*}{\frac{1}{100 \cdot n}}\\ \mathbf{if}\;i \le -1.0987039570203948 \cdot 10^{-277}:\\ \;\;\;\;\frac{(i \cdot \left(\frac{1}{2} \cdot i\right) + i)_*}{i} \cdot \left(100 \cdot n\right)\\ \mathbf{if}\;i \le 8.299692008936171 \cdot 10^{-177}:\\ \;\;\;\;\frac{(i \cdot \left(\frac{1}{2} \cdot i\right) + i)_*}{i} \cdot \left(100 \cdot n\right)\\ \mathbf{if}\;i \le 2.2645427861240446 \cdot 10^{-20}:\\ \;\;\;\;\frac{1}{i} \cdot \frac{(i \cdot \left(\frac{1}{2} \cdot i\right) + i)_*}{\frac{1}{100 \cdot n}}\\ \mathbf{else}:\\ \;\;\;\;(e^{\left(\log i - \log n\right) \cdot n} - 1)^* \cdot \left(\frac{n}{i} \cdot 100\right)\\ \end{array}}\]

Runtime

Time bar (total: 1.4m)Debug logProfile

herbie shell --seed '#(1064397287 3527694221 3797617954 1138343853 2854031332 1153838279)' +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))))