Average Error: 47.5 → 17.6
Time: 2.7m
Precision: 64
Internal Precision: 3456
\[100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\]
\[\begin{array}{l} \mathbf{if}\;i \le -4.3730030050425 \cdot 10^{-14}:\\ \;\;\;\;\left(100 \cdot \frac{{\left(\sqrt{1 + \frac{i}{n}}\right)}^{n} + 1}{1}\right) \cdot \frac{{\left(\sqrt{1 + \frac{i}{n}}\right)}^{n} - 1}{\frac{i}{n}}\\ \mathbf{if}\;i \le 3.252761626681501:\\ \;\;\;\;\left(50 \cdot i + 100\right) \cdot n\\ \mathbf{if}\;i \le 3.354860243102428 \cdot 10^{+51}:\\ \;\;\;\;\left(100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{i}\right) \cdot n\\ \mathbf{else}:\\ \;\;\;\;100 \cdot \frac{e^{\frac{\log n - \log i}{n}} - 1}{\frac{i}{n}}\\ \end{array}\]

Error

Bits error versus i

Bits error versus n

Target

Original47.5
Target47.1
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 < -4.3730030050425e-14

    1. Initial program 29.2

      \[100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\]
    2. Using strategy rm
    3. Applied *-un-lft-identity29.2

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

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

      \[\leadsto 100 \cdot \frac{\color{blue}{{\left(\sqrt{1 + \frac{i}{n}}\right)}^{n} \cdot {\left(\sqrt{1 + \frac{i}{n}}\right)}^{n}} - 1}{1 \cdot \frac{i}{n}}\]
    6. Applied difference-of-sqr-129.3

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

      \[\leadsto 100 \cdot \color{blue}{\left(\frac{{\left(\sqrt{1 + \frac{i}{n}}\right)}^{n} + 1}{1} \cdot \frac{{\left(\sqrt{1 + \frac{i}{n}}\right)}^{n} - 1}{\frac{i}{n}}\right)}\]
    8. Applied associate-*r*29.3

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

    if -4.3730030050425e-14 < i < 3.252761626681501

    1. Initial program 57.7

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

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

      \[\leadsto \color{blue}{100 \cdot n + 50 \cdot \left(n \cdot i\right)}\]
    5. Applied simplify9.2

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

    if 3.252761626681501 < i < 3.354860243102428e+51

    1. Initial program 33.4

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

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

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

    if 3.354860243102428e+51 < i

    1. Initial program 32.7

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

      \[\leadsto 100 \cdot \frac{\color{blue}{e^{\frac{\log n - \log i}{n}} - 1}}{\frac{i}{n}}\]
  3. Recombined 4 regimes into one program.

Runtime

Time bar (total: 2.7m)Debug logProfile

herbie shell --seed '#(1064269945 2896236262 301053905 1701069080 1701464310 1614783279)' 
(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))))