Average Error: 47.0 → 16.7
Time: 1.7m
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.7803691883423303:\\ \;\;\;\;\frac{\log \left(e^{{\left(1 + \frac{i}{n}\right)}^{n} - 1}\right)}{\frac{i}{n}} \cdot 100\\ \mathbf{if}\;i \le 1.7282900838364337 \cdot 10^{+22}:\\ \;\;\;\;\frac{\left(100 \cdot n\right) \cdot \left(1 + \frac{1}{2} \cdot i\right)}{1}\\ \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.0
Target46.4
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.7803691883423303

    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 add-log-exp28.1

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

    if -0.7803691883423303 < i < 1.7282900838364337e+22

    1. Initial program 57.0

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

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

    if 1.7282900838364337e+22 < i

    1. Initial program 30.2

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

      \[\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 simplify29.9

      \[\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.7803691883423303:\\ \;\;\;\;\frac{\log \left(e^{{\left(1 + \frac{i}{n}\right)}^{n} - 1}\right)}{\frac{i}{n}} \cdot 100\\ \mathbf{if}\;i \le 1.7282900838364337 \cdot 10^{+22}:\\ \;\;\;\;\frac{\left(100 \cdot n\right) \cdot \left(1 + \frac{1}{2} \cdot i\right)}{1}\\ \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.7m)Debug logProfile

herbie shell --seed '#(1070100504 930361288 1279167582 284574201 1450237281 2578255382)' 
(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))))