Average Error: 47.8 → 17.2
Time: 1.9m
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 -1.5476696670308332 \cdot 10^{+27}:\\ \;\;\;\;100 \cdot \frac{\sqrt[3]{{\left({\left(1 + \frac{i}{n}\right)}^{n} - 1\right)}^{3}}}{\frac{i}{n}}\\ \mathbf{if}\;i \le 5.432341925666689 \cdot 10^{-07}:\\ \;\;\;\;\frac{\left(1 + \frac{1}{3} \cdot i\right) - \frac{1}{36} \cdot {i}^{2}}{\frac{1}{100}} \cdot \left(\left(\left(1 + \frac{1}{6} \cdot i\right) - \frac{1}{36} \cdot {i}^{2}\right) \cdot n\right)\\ \mathbf{if}\;i \le 4.1148737877191585 \cdot 10^{+240}:\\ \;\;\;\;\left(100 \cdot \frac{\sqrt[3]{{\left(1 + \frac{i}{n}\right)}^{n} - 1} \cdot \sqrt[3]{{\left(1 + \frac{i}{n}\right)}^{n} - 1}}{i}\right) \cdot \frac{\sqrt[3]{{\left(1 + \frac{i}{n}\right)}^{n} - 1}}{\frac{1}{n}}\\ \mathbf{if}\;i \le 1.0144732353523543 \cdot 10^{+280}:\\ \;\;\;\;\frac{\sqrt[3]{i \cdot \frac{1}{2} + 1} \cdot \sqrt[3]{i \cdot \frac{1}{2} + 1}}{\frac{\sqrt[3]{\frac{i}{n}} \cdot \sqrt[3]{\frac{i}{n}}}{100}} \cdot \frac{\sqrt[3]{i \cdot \frac{1}{2} + 1}}{\frac{\sqrt[3]{\frac{i}{n}}}{i}}\\ \mathbf{else}:\\ \;\;\;\;\left(100 \cdot \frac{\sqrt[3]{{\left(1 + \frac{i}{n}\right)}^{n} - 1} \cdot \sqrt[3]{{\left(1 + \frac{i}{n}\right)}^{n} - 1}}{i}\right) \cdot \frac{\sqrt[3]{{\left(1 + \frac{i}{n}\right)}^{n} - 1}}{\frac{1}{n}}\\ \end{array}\]

Error

Bits error versus i

Bits error versus n

Target

Original47.8
Target47.3
Herbie17.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 4 regimes
  2. if i < -1.5476696670308332e+27

    1. Initial program 25.9

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

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

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

    if -1.5476696670308332e+27 < i < 5.432341925666689e-07

    1. Initial program 57.6

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

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

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

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

      \[\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-frac26.8

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

      \[\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 10.9

      \[\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. Taylor expanded around 0 10.9

      \[\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(1 + \frac{1}{6} \cdot i\right) - \frac{1}{36} \cdot {i}^{2}\right)} \cdot n\right)\]

    if 5.432341925666689e-07 < i < 4.1148737877191585e+240 or 1.0144732353523543e+280 < i

    1. Initial program 33.7

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

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

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

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

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

    if 4.1148737877191585e+240 < i < 1.0144732353523543e+280

    1. Initial program 32.5

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

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

      \[\leadsto \color{blue}{\frac{i \cdot \frac{1}{2} + 1}{\frac{\frac{i}{n}}{100 \cdot i}}}\]
    4. Using strategy rm
    5. Applied add-cube-cbrt32.7

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

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

      \[\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{\sqrt[3]{\frac{i}{n}} \cdot \sqrt[3]{\frac{i}{n}}}{100} \cdot \frac{\sqrt[3]{\frac{i}{n}}}{i}}\]
    8. Applied times-frac32.7

      \[\leadsto \color{blue}{\frac{\sqrt[3]{i \cdot \frac{1}{2} + 1} \cdot \sqrt[3]{i \cdot \frac{1}{2} + 1}}{\frac{\sqrt[3]{\frac{i}{n}} \cdot \sqrt[3]{\frac{i}{n}}}{100}} \cdot \frac{\sqrt[3]{i \cdot \frac{1}{2} + 1}}{\frac{\sqrt[3]{\frac{i}{n}}}{i}}}\]
  3. Recombined 4 regimes into one program.

Runtime

Time bar (total: 1.9m)Debug logProfile

herbie shell --seed '#(1070864556 424010669 783715395 1203517814 4070606583 4107618214)' 
(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))))