Average Error: 47.5 → 16.2
Time: 2.3m
Precision: 64
Internal Precision: 3200
\[100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\]
\[\begin{array}{l} \mathbf{if}\;\log \left(1 + \frac{1}{2} \cdot i\right) \le 12.76141262437896:\\ \;\;\;\;\frac{\left(1 + \frac{1}{3} \cdot i\right) - \frac{1}{36} \cdot {i}^{2}}{\frac{1}{100}} \cdot \left(\left(\left(\sqrt[3]{\sqrt[3]{1 + \frac{1}{2} \cdot i}} \cdot \sqrt[3]{\sqrt[3]{1 + \frac{1}{2} \cdot i}}\right) \cdot \sqrt[3]{\sqrt[3]{1 + \frac{1}{2} \cdot i}}\right) \cdot n\right)\\ \mathbf{if}\;\log \left(1 + \frac{1}{2} \cdot i\right) \le 340.18920259497804:\\ \;\;\;\;\frac{100 \cdot \left({\left(1 + \frac{i}{n}\right)}^{n} - 1\right)}{\frac{i}{n}}\\ \mathbf{if}\;\log \left(1 + \frac{1}{2} \cdot i\right) \le 700.1159411623439:\\ \;\;\;\;\left(\frac{100}{i} \cdot n\right) \cdot \left(\frac{{i}^{n}}{{n}^{n}} - 1\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{100 \cdot \left({\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.2
Herbie16.2
\[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 (log (+ 1 (* 1/2 i))) < 12.76141262437896

    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.4

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

      \[\leadsto \color{blue}{\frac{i \cdot \frac{1}{2} + 1}{\frac{\frac{i}{n}}{100 \cdot i}}}\]
    4. Using strategy rm
    5. Applied *-un-lft-identity25.2

      \[\leadsto \frac{i \cdot \frac{1}{2} + 1}{\frac{\color{blue}{1 \cdot \frac{i}{n}}}{100 \cdot i}}\]
    6. Applied times-frac25.2

      \[\leadsto \frac{i \cdot \frac{1}{2} + 1}{\color{blue}{\frac{1}{100} \cdot \frac{\frac{i}{n}}{i}}}\]
    7. Applied add-cube-cbrt25.2

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

      \[\leadsto \color{blue}{\frac{\sqrt[3]{i \cdot \frac{1}{2} + 1} \cdot \sqrt[3]{i \cdot \frac{1}{2} + 1}}{\frac{1}{100}} \cdot \frac{\sqrt[3]{i \cdot \frac{1}{2} + 1}}{\frac{\frac{i}{n}}{i}}}\]
    9. Applied simplify9.4

      \[\leadsto \frac{\sqrt[3]{i \cdot \frac{1}{2} + 1} \cdot \sqrt[3]{i \cdot \frac{1}{2} + 1}}{\frac{1}{100}} \cdot \color{blue}{\left(\sqrt[3]{1 + \frac{1}{2} \cdot i} \cdot n\right)}\]
    10. Taylor expanded around 0 9.4

      \[\leadsto \frac{\color{blue}{\left(1 + \frac{1}{3} \cdot i\right) - \frac{1}{36} \cdot {i}^{2}}}{\frac{1}{100}} \cdot \left(\sqrt[3]{1 + \frac{1}{2} \cdot i} \cdot n\right)\]
    11. Using strategy rm
    12. Applied add-cube-cbrt9.4

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

    if 12.76141262437896 < (log (+ 1 (* 1/2 i))) < 340.18920259497804 or 700.1159411623439 < (log (+ 1 (* 1/2 i)))

    1. Initial program 28.6

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

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

    if 340.18920259497804 < (log (+ 1 (* 1/2 i))) < 700.1159411623439

    1. Initial program 30.5

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

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

      \[\leadsto \color{blue}{\left(\frac{100}{i} \cdot n\right) \cdot \left(\frac{{i}^{n}}{{n}^{n}} - 1\right)}\]
  3. Recombined 3 regimes into one program.

Runtime

Time bar (total: 2.3m)Debug logProfile

herbie shell --seed '#(1070578969 3140398606 632207097 462683394 1189254563 964980650)' 
(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))))