Average Error: 47.5 → 17.6
Time: 1.8m
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 -1.150583104375246:\\ \;\;\;\;100 \cdot \left(\frac{{\left(1 + \frac{i}{n}\right)}^{n}}{\frac{i}{n}} - \frac{n}{i}\right)\\ \mathbf{if}\;i \le 4.546231158396709 \cdot 10^{-28}:\\ \;\;\;\;\frac{\left(100 \cdot n\right) \cdot \left(1 + \frac{1}{2} \cdot i\right)}{1}\\ \mathbf{if}\;i \le 6.742418005112878 \cdot 10^{+132}:\\ \;\;\;\;\log \left(e^{\sqrt[3]{\frac{1 + \frac{1}{2} \cdot i}{1} \cdot \left(100 \cdot n\right)} \cdot \sqrt[3]{\frac{1 + \frac{1}{2} \cdot i}{1} \cdot \left(100 \cdot n\right)}}\right) \cdot \sqrt[3]{\frac{\left(100 \cdot n\right) \cdot \left(1 + \frac{1}{2} \cdot i\right)}{1}}\\ \mathbf{else}:\\ \;\;\;\;100 \cdot \frac{\log \left(e^{{\left(1 + \frac{i}{n}\right)}^{n} - 1}\right)}{\frac{i}{n}}\\ \end{array}\]

Error

Bits error versus i

Bits error versus n

Target

Original47.5
Target47.0
Herbie17.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 i < -1.150583104375246

    1. Initial program 27.9

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

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

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

    if -1.150583104375246 < i < 4.546231158396709e-28

    1. Initial program 57.8

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

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

      \[\leadsto \color{blue}{\frac{i + i \cdot \left(i \cdot \frac{1}{2}\right)}{\frac{\frac{i}{n}}{100}}}\]
    4. Using strategy rm
    5. Applied *-un-lft-identity26.0

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

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

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

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

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

    if 4.546231158396709e-28 < i < 6.742418005112878e+132

    1. Initial program 39.3

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

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

      \[\leadsto \color{blue}{\frac{i + i \cdot \left(i \cdot \frac{1}{2}\right)}{\frac{\frac{i}{n}}{100}}}\]
    4. Using strategy rm
    5. Applied add-cube-cbrt41.6

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

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

      \[\leadsto \left(\sqrt[3]{\frac{\frac{1}{2} \cdot i + 1}{1} \cdot \left(n \cdot 100\right)} \cdot \sqrt[3]{\frac{\frac{1}{2} \cdot i + 1}{1} \cdot \left(n \cdot 100\right)}\right) \cdot \color{blue}{\sqrt[3]{\frac{\left(n \cdot 100\right) \cdot \left(1 + \frac{1}{2} \cdot i\right)}{1}}}\]
    8. Using strategy rm
    9. Applied add-log-exp39.2

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

    if 6.742418005112878e+132 < i

    1. Initial program 32.9

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

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

    \[\leadsto \color{blue}{\begin{array}{l} \mathbf{if}\;i \le -1.150583104375246:\\ \;\;\;\;100 \cdot \left(\frac{{\left(1 + \frac{i}{n}\right)}^{n}}{\frac{i}{n}} - \frac{n}{i}\right)\\ \mathbf{if}\;i \le 4.546231158396709 \cdot 10^{-28}:\\ \;\;\;\;\frac{\left(100 \cdot n\right) \cdot \left(1 + \frac{1}{2} \cdot i\right)}{1}\\ \mathbf{if}\;i \le 6.742418005112878 \cdot 10^{+132}:\\ \;\;\;\;\log \left(e^{\sqrt[3]{\frac{1 + \frac{1}{2} \cdot i}{1} \cdot \left(100 \cdot n\right)} \cdot \sqrt[3]{\frac{1 + \frac{1}{2} \cdot i}{1} \cdot \left(100 \cdot n\right)}}\right) \cdot \sqrt[3]{\frac{\left(100 \cdot n\right) \cdot \left(1 + \frac{1}{2} \cdot i\right)}{1}}\\ \mathbf{else}:\\ \;\;\;\;100 \cdot \frac{\log \left(e^{{\left(1 + \frac{i}{n}\right)}^{n} - 1}\right)}{\frac{i}{n}}\\ \end{array}}\]

Runtime

Time bar (total: 1.8m)Debug logProfile

herbie shell --seed '#(1070227846 1561819246 480764335 4016816270 2602869839 2117310382)' 
(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))))