Average Error: 47.2 → 16.7
Time: 1.9m
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 -0.020377340814253832:\\ \;\;\;\;\frac{\left({\left(1 + \frac{i}{n}\right)}^{n} - 1\right) \cdot 100}{\frac{i}{n}}\\ \mathbf{if}\;i \le 2.4695557279739083 \cdot 10^{+28}:\\ \;\;\;\;\frac{\left(100 \cdot n\right) \cdot \left(1 + \frac{1}{2} \cdot i\right)}{1}\\ \mathbf{if}\;i \le 1.1918327281230139 \cdot 10^{+212}:\\ \;\;\;\;\left(n \cdot \frac{100}{i}\right) \cdot \left({\left(e^{n}\right)}^{\left(\log i - \log n\right)} - 1\right)\\ \mathbf{if}\;i \le 9.983371006406189 \cdot 10^{+256}:\\ \;\;\;\;\frac{\left({\left(1 + \frac{i}{n}\right)}^{n} - 1\right) \cdot 100}{\frac{i}{n}}\\ \mathbf{else}:\\ \;\;\;\;\left(n \cdot \frac{100}{i}\right) \cdot \left({\left(e^{n}\right)}^{\left(\log i - \log n\right)} - 1\right)\\ \end{array}\]

Error

Bits error versus i

Bits error versus n

Target

Original47.2
Target46.7
Herbie16.7
\[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 < -0.020377340814253832 or 1.1918327281230139e+212 < i < 9.983371006406189e+256

    1. Initial program 28.1

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

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

    if -0.020377340814253832 < i < 2.4695557279739083e+28

    1. Initial program 56.8

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

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

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

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

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

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

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

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

    if 2.4695557279739083e+28 < i < 1.1918327281230139e+212 or 9.983371006406189e+256 < i

    1. Initial program 32.3

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

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

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

    \[\leadsto \color{blue}{\begin{array}{l} \mathbf{if}\;i \le -0.020377340814253832:\\ \;\;\;\;\frac{\left({\left(1 + \frac{i}{n}\right)}^{n} - 1\right) \cdot 100}{\frac{i}{n}}\\ \mathbf{if}\;i \le 2.4695557279739083 \cdot 10^{+28}:\\ \;\;\;\;\frac{\left(100 \cdot n\right) \cdot \left(1 + \frac{1}{2} \cdot i\right)}{1}\\ \mathbf{if}\;i \le 1.1918327281230139 \cdot 10^{+212}:\\ \;\;\;\;\left(n \cdot \frac{100}{i}\right) \cdot \left({\left(e^{n}\right)}^{\left(\log i - \log n\right)} - 1\right)\\ \mathbf{if}\;i \le 9.983371006406189 \cdot 10^{+256}:\\ \;\;\;\;\frac{\left({\left(1 + \frac{i}{n}\right)}^{n} - 1\right) \cdot 100}{\frac{i}{n}}\\ \mathbf{else}:\\ \;\;\;\;\left(n \cdot \frac{100}{i}\right) \cdot \left({\left(e^{n}\right)}^{\left(\log i - \log n\right)} - 1\right)\\ \end{array}}\]

Runtime

Time bar (total: 1.9m)Debug logProfile

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