Average Error: 47.6 → 11.1
Time: 2.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 -2.1298733363134765 \cdot 10^{-05}:\\ \;\;\;\;100 \cdot \frac{e^{n \cdot \log_* (1 + \frac{i}{n})} - 1}{\frac{i}{n}}\\ \mathbf{if}\;i \le 3.981814690958117 \cdot 10^{+21}:\\ \;\;\;\;\frac{100 \cdot (i \cdot \frac{1}{6} + \frac{1}{2})_*}{\frac{\frac{1}{i}}{n}} + 100 \cdot n\\ \mathbf{if}\;i \le 1.1064619840788213 \cdot 10^{+128}:\\ \;\;\;\;100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\\ \mathbf{else}:\\ \;\;\;\;\frac{100 \cdot n}{i} \cdot (e^{\left(\log i - \log n\right) \cdot n} - 1)^*\\ \end{array}\]

Error

Bits error versus i

Bits error versus n

Target

Original47.6
Target46.5
Herbie11.1
\[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 < -2.1298733363134765e-05

    1. Initial program 29.9

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

      \[\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 -2.1298733363134765e-05 < i < 3.981814690958117e+21

    1. Initial program 57.3

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

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

      \[\leadsto \color{blue}{\left(n \cdot \frac{100}{i}\right) \cdot (\left(i \cdot i\right) \cdot \left((i \cdot \frac{1}{6} + \frac{1}{2})_*\right) + i)_*}\]
    4. Using strategy rm
    5. Applied fma-udef26.9

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

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

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

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

    if 3.981814690958117e+21 < i < 1.1064619840788213e+128

    1. Initial program 32.5

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

    if 1.1064619840788213e+128 < i

    1. Initial program 31.7

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

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

    \[\leadsto \color{blue}{\begin{array}{l} \mathbf{if}\;i \le -2.1298733363134765 \cdot 10^{-05}:\\ \;\;\;\;100 \cdot \frac{e^{n \cdot \log_* (1 + \frac{i}{n})} - 1}{\frac{i}{n}}\\ \mathbf{if}\;i \le 3.981814690958117 \cdot 10^{+21}:\\ \;\;\;\;\frac{100 \cdot (i \cdot \frac{1}{6} + \frac{1}{2})_*}{\frac{\frac{1}{i}}{n}} + 100 \cdot n\\ \mathbf{if}\;i \le 1.1064619840788213 \cdot 10^{+128}:\\ \;\;\;\;100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\\ \mathbf{else}:\\ \;\;\;\;\frac{100 \cdot n}{i} \cdot (e^{\left(\log i - \log n\right) \cdot n} - 1)^*\\ \end{array}}\]

Runtime

Time bar (total: 2.4m)Debug logProfile

herbie shell --seed '#(1070355188 2193211668 3977393919 3454156579 3755371326 1656365382)' +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))))