Average Error: 43.3 → 20.0
Time: 33.1s
Precision: 64
\[100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\]
\[\begin{array}{l} \mathbf{if}\;i \le -0.3499720027197658622775122694292804226279:\\ \;\;\;\;\frac{\frac{n}{\frac{1}{\sqrt{100}}}}{\frac{\frac{i}{\sqrt{100}}}{{\left(\frac{i}{n} + 1\right)}^{n} - 1}}\\ \mathbf{elif}\;i \le 3.427314966810909420478563204128016522016 \cdot 10^{-18}:\\ \;\;\;\;\frac{1}{i} \cdot \left(\left(n \cdot 100\right) \cdot \left(\mathsf{fma}\left(n, \log 1, \mathsf{fma}\left(1, i, 0.5 \cdot \left(i \cdot i\right)\right)\right) - \left(\left(i \cdot i\right) \cdot \log 1\right) \cdot 0.5\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{\left(\log i \cdot {\left(\log n\right)}^{2}\right) \cdot {n}^{4}}{i}, 33.3333333333333285963817615993320941925, \mathsf{fma}\left(16.66666666666666429819088079966604709625, \frac{\left(\log i \cdot {\left(\log n\right)}^{2}\right) \cdot {n}^{4}}{i}, \mathsf{fma}\left(16.66666666666666429819088079966604709625, \frac{{n}^{4}}{\frac{i}{{\left(\log i\right)}^{3}}}, \mathsf{fma}\left(100, \frac{n \cdot n}{\frac{i}{\log i}}, 50 \cdot \left(\frac{{n}^{3}}{\frac{i}{{\left(\log n\right)}^{2}}} + \frac{{n}^{3}}{\frac{i}{{\left(\log i\right)}^{2}}}\right)\right)\right)\right) - \mathsf{fma}\left(\frac{{n}^{4}}{\frac{i}{{\left(\log n\right)}^{3}}}, 16.66666666666666429819088079966604709625, \mathsf{fma}\left(16.66666666666666429819088079966604709625, \frac{\log n \cdot \left({\left(\log i\right)}^{2} \cdot {n}^{4}\right)}{i}, \mathsf{fma}\left(\frac{{n}^{3}}{\frac{i}{\log n \cdot \log i}}, 50, \mathsf{fma}\left(\frac{\log n \cdot \left({\left(\log i\right)}^{2} \cdot {n}^{4}\right)}{i}, 33.3333333333333285963817615993320941925, \mathsf{fma}\left(50, \frac{{n}^{3}}{\frac{i}{\log n \cdot \log i}}, \frac{100 \cdot \left(\log n \cdot \left(n \cdot n\right)\right)}{i}\right)\right)\right)\right)\right)\right)\\ \end{array}\]
100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}
\begin{array}{l}
\mathbf{if}\;i \le -0.3499720027197658622775122694292804226279:\\
\;\;\;\;\frac{\frac{n}{\frac{1}{\sqrt{100}}}}{\frac{\frac{i}{\sqrt{100}}}{{\left(\frac{i}{n} + 1\right)}^{n} - 1}}\\

\mathbf{elif}\;i \le 3.427314966810909420478563204128016522016 \cdot 10^{-18}:\\
\;\;\;\;\frac{1}{i} \cdot \left(\left(n \cdot 100\right) \cdot \left(\mathsf{fma}\left(n, \log 1, \mathsf{fma}\left(1, i, 0.5 \cdot \left(i \cdot i\right)\right)\right) - \left(\left(i \cdot i\right) \cdot \log 1\right) \cdot 0.5\right)\right)\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{\left(\log i \cdot {\left(\log n\right)}^{2}\right) \cdot {n}^{4}}{i}, 33.3333333333333285963817615993320941925, \mathsf{fma}\left(16.66666666666666429819088079966604709625, \frac{\left(\log i \cdot {\left(\log n\right)}^{2}\right) \cdot {n}^{4}}{i}, \mathsf{fma}\left(16.66666666666666429819088079966604709625, \frac{{n}^{4}}{\frac{i}{{\left(\log i\right)}^{3}}}, \mathsf{fma}\left(100, \frac{n \cdot n}{\frac{i}{\log i}}, 50 \cdot \left(\frac{{n}^{3}}{\frac{i}{{\left(\log n\right)}^{2}}} + \frac{{n}^{3}}{\frac{i}{{\left(\log i\right)}^{2}}}\right)\right)\right)\right) - \mathsf{fma}\left(\frac{{n}^{4}}{\frac{i}{{\left(\log n\right)}^{3}}}, 16.66666666666666429819088079966604709625, \mathsf{fma}\left(16.66666666666666429819088079966604709625, \frac{\log n \cdot \left({\left(\log i\right)}^{2} \cdot {n}^{4}\right)}{i}, \mathsf{fma}\left(\frac{{n}^{3}}{\frac{i}{\log n \cdot \log i}}, 50, \mathsf{fma}\left(\frac{\log n \cdot \left({\left(\log i\right)}^{2} \cdot {n}^{4}\right)}{i}, 33.3333333333333285963817615993320941925, \mathsf{fma}\left(50, \frac{{n}^{3}}{\frac{i}{\log n \cdot \log i}}, \frac{100 \cdot \left(\log n \cdot \left(n \cdot n\right)\right)}{i}\right)\right)\right)\right)\right)\right)\\

\end{array}
double f(double i, double n) {
        double r187729 = 100.0;
        double r187730 = 1.0;
        double r187731 = i;
        double r187732 = n;
        double r187733 = r187731 / r187732;
        double r187734 = r187730 + r187733;
        double r187735 = pow(r187734, r187732);
        double r187736 = r187735 - r187730;
        double r187737 = r187736 / r187733;
        double r187738 = r187729 * r187737;
        return r187738;
}

double f(double i, double n) {
        double r187739 = i;
        double r187740 = -0.34997200271976586;
        bool r187741 = r187739 <= r187740;
        double r187742 = n;
        double r187743 = 1.0;
        double r187744 = 100.0;
        double r187745 = sqrt(r187744);
        double r187746 = r187743 / r187745;
        double r187747 = r187742 / r187746;
        double r187748 = r187739 / r187745;
        double r187749 = r187739 / r187742;
        double r187750 = 1.0;
        double r187751 = r187749 + r187750;
        double r187752 = pow(r187751, r187742);
        double r187753 = r187752 - r187750;
        double r187754 = r187748 / r187753;
        double r187755 = r187747 / r187754;
        double r187756 = 3.4273149668109094e-18;
        bool r187757 = r187739 <= r187756;
        double r187758 = r187743 / r187739;
        double r187759 = r187742 * r187744;
        double r187760 = log(r187750);
        double r187761 = 0.5;
        double r187762 = r187739 * r187739;
        double r187763 = r187761 * r187762;
        double r187764 = fma(r187750, r187739, r187763);
        double r187765 = fma(r187742, r187760, r187764);
        double r187766 = r187762 * r187760;
        double r187767 = r187766 * r187761;
        double r187768 = r187765 - r187767;
        double r187769 = r187759 * r187768;
        double r187770 = r187758 * r187769;
        double r187771 = log(r187739);
        double r187772 = log(r187742);
        double r187773 = 2.0;
        double r187774 = pow(r187772, r187773);
        double r187775 = r187771 * r187774;
        double r187776 = 4.0;
        double r187777 = pow(r187742, r187776);
        double r187778 = r187775 * r187777;
        double r187779 = r187778 / r187739;
        double r187780 = 33.33333333333333;
        double r187781 = 16.666666666666664;
        double r187782 = 3.0;
        double r187783 = pow(r187771, r187782);
        double r187784 = r187739 / r187783;
        double r187785 = r187777 / r187784;
        double r187786 = r187742 * r187742;
        double r187787 = r187739 / r187771;
        double r187788 = r187786 / r187787;
        double r187789 = 50.0;
        double r187790 = pow(r187742, r187782);
        double r187791 = r187739 / r187774;
        double r187792 = r187790 / r187791;
        double r187793 = pow(r187771, r187773);
        double r187794 = r187739 / r187793;
        double r187795 = r187790 / r187794;
        double r187796 = r187792 + r187795;
        double r187797 = r187789 * r187796;
        double r187798 = fma(r187744, r187788, r187797);
        double r187799 = fma(r187781, r187785, r187798);
        double r187800 = fma(r187781, r187779, r187799);
        double r187801 = pow(r187772, r187782);
        double r187802 = r187739 / r187801;
        double r187803 = r187777 / r187802;
        double r187804 = r187793 * r187777;
        double r187805 = r187772 * r187804;
        double r187806 = r187805 / r187739;
        double r187807 = r187772 * r187771;
        double r187808 = r187739 / r187807;
        double r187809 = r187790 / r187808;
        double r187810 = r187772 * r187786;
        double r187811 = r187744 * r187810;
        double r187812 = r187811 / r187739;
        double r187813 = fma(r187789, r187809, r187812);
        double r187814 = fma(r187806, r187780, r187813);
        double r187815 = fma(r187809, r187789, r187814);
        double r187816 = fma(r187781, r187806, r187815);
        double r187817 = fma(r187803, r187781, r187816);
        double r187818 = r187800 - r187817;
        double r187819 = fma(r187779, r187780, r187818);
        double r187820 = r187757 ? r187770 : r187819;
        double r187821 = r187741 ? r187755 : r187820;
        return r187821;
}

Error

Bits error versus i

Bits error versus n

Target

Original43.3
Target43.1
Herbie20.0
\[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.34997200271976586

    1. Initial program 28.2

      \[100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\]
    2. Simplified28.8

      \[\leadsto \color{blue}{\frac{n}{\frac{\frac{i}{100}}{{\left(1 + \frac{i}{n}\right)}^{n} - 1}}}\]
    3. Using strategy rm
    4. Applied *-un-lft-identity28.8

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

      \[\leadsto \frac{n}{\frac{\frac{i}{\color{blue}{\sqrt{100} \cdot \sqrt{100}}}}{1 \cdot \left({\left(1 + \frac{i}{n}\right)}^{n} - 1\right)}}\]
    6. Applied *-un-lft-identity28.8

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

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

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

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

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

    if -0.34997200271976586 < i < 3.4273149668109094e-18

    1. Initial program 51.0

      \[100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\]
    2. Simplified50.7

      \[\leadsto \color{blue}{\frac{n}{\frac{\frac{i}{100}}{{\left(1 + \frac{i}{n}\right)}^{n} - 1}}}\]
    3. Taylor expanded around 0 16.5

      \[\leadsto \frac{n}{\frac{\frac{i}{100}}{\color{blue}{\left(\log 1 \cdot n + \left(1 \cdot i + 0.5 \cdot {i}^{2}\right)\right) - 0.5 \cdot \left(\log 1 \cdot {i}^{2}\right)}}}\]
    4. Simplified16.5

      \[\leadsto \frac{n}{\frac{\frac{i}{100}}{\color{blue}{\mathsf{fma}\left(\log 1, n, \mathsf{fma}\left(1, i, 0.5 \cdot {i}^{2}\right)\right) - 0.5 \cdot \left(\log 1 \cdot {i}^{2}\right)}}}\]
    5. Using strategy rm
    6. Applied *-un-lft-identity16.5

      \[\leadsto \frac{n}{\frac{\frac{i}{100}}{\color{blue}{1 \cdot \left(\mathsf{fma}\left(\log 1, n, \mathsf{fma}\left(1, i, 0.5 \cdot {i}^{2}\right)\right) - 0.5 \cdot \left(\log 1 \cdot {i}^{2}\right)\right)}}}\]
    7. Applied div-inv16.5

      \[\leadsto \frac{n}{\frac{\color{blue}{i \cdot \frac{1}{100}}}{1 \cdot \left(\mathsf{fma}\left(\log 1, n, \mathsf{fma}\left(1, i, 0.5 \cdot {i}^{2}\right)\right) - 0.5 \cdot \left(\log 1 \cdot {i}^{2}\right)\right)}}\]
    8. Applied times-frac16.5

      \[\leadsto \frac{n}{\color{blue}{\frac{i}{1} \cdot \frac{\frac{1}{100}}{\mathsf{fma}\left(\log 1, n, \mathsf{fma}\left(1, i, 0.5 \cdot {i}^{2}\right)\right) - 0.5 \cdot \left(\log 1 \cdot {i}^{2}\right)}}}\]
    9. Simplified16.5

      \[\leadsto \frac{n}{\color{blue}{i} \cdot \frac{\frac{1}{100}}{\mathsf{fma}\left(\log 1, n, \mathsf{fma}\left(1, i, 0.5 \cdot {i}^{2}\right)\right) - 0.5 \cdot \left(\log 1 \cdot {i}^{2}\right)}}\]
    10. Simplified16.5

      \[\leadsto \frac{n}{i \cdot \color{blue}{\frac{\frac{1}{100}}{\mathsf{fma}\left(\log 1, n, \mathsf{fma}\left(1, i, 0.5 \cdot \left(i \cdot i\right)\right)\right) - 0.5 \cdot \left(\log 1 \cdot \left(i \cdot i\right)\right)}}}\]
    11. Using strategy rm
    12. Applied *-un-lft-identity16.5

      \[\leadsto \frac{\color{blue}{1 \cdot n}}{i \cdot \frac{\frac{1}{100}}{\mathsf{fma}\left(\log 1, n, \mathsf{fma}\left(1, i, 0.5 \cdot \left(i \cdot i\right)\right)\right) - 0.5 \cdot \left(\log 1 \cdot \left(i \cdot i\right)\right)}}\]
    13. Applied times-frac15.9

      \[\leadsto \color{blue}{\frac{1}{i} \cdot \frac{n}{\frac{\frac{1}{100}}{\mathsf{fma}\left(\log 1, n, \mathsf{fma}\left(1, i, 0.5 \cdot \left(i \cdot i\right)\right)\right) - 0.5 \cdot \left(\log 1 \cdot \left(i \cdot i\right)\right)}}}\]
    14. Simplified15.8

      \[\leadsto \frac{1}{i} \cdot \color{blue}{\left(\left(\frac{n}{1} \cdot 100\right) \cdot \left(\mathsf{fma}\left(n, \log 1, \mathsf{fma}\left(1, i, \left(i \cdot i\right) \cdot 0.5\right)\right) - 0.5 \cdot \left(\log 1 \cdot \left(i \cdot i\right)\right)\right)\right)}\]

    if 3.4273149668109094e-18 < i

    1. Initial program 34.4

      \[100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\]
    2. Simplified34.3

      \[\leadsto \color{blue}{\frac{n}{\frac{\frac{i}{100}}{{\left(1 + \frac{i}{n}\right)}^{n} - 1}}}\]
    3. Taylor expanded around 0 24.2

      \[\leadsto \color{blue}{\left(33.3333333333333285963817615993320941925 \cdot \frac{{n}^{4} \cdot \left({\left(\log n\right)}^{2} \cdot \log i\right)}{i} + \left(16.66666666666666429819088079966604709625 \cdot \frac{{n}^{4} \cdot \left(\log i \cdot {\left(\log n\right)}^{2}\right)}{i} + \left(16.66666666666666429819088079966604709625 \cdot \frac{{n}^{4} \cdot {\left(\log i\right)}^{3}}{i} + \left(100 \cdot \frac{{n}^{2} \cdot \log i}{i} + \left(50 \cdot \frac{{n}^{3} \cdot {\left(\log i\right)}^{2}}{i} + 50 \cdot \frac{{n}^{3} \cdot {\left(\log n\right)}^{2}}{i}\right)\right)\right)\right)\right) - \left(16.66666666666666429819088079966604709625 \cdot \frac{{n}^{4} \cdot {\left(\log n\right)}^{3}}{i} + \left(16.66666666666666429819088079966604709625 \cdot \frac{{n}^{4} \cdot \left(\log n \cdot {\left(\log i\right)}^{2}\right)}{i} + \left(50 \cdot \frac{{n}^{3} \cdot \left(\log n \cdot \log i\right)}{i} + \left(33.3333333333333285963817615993320941925 \cdot \frac{{n}^{4} \cdot \left({\left(\log i\right)}^{2} \cdot \log n\right)}{i} + \left(100 \cdot \frac{{n}^{2} \cdot \log n}{i} + 50 \cdot \frac{{n}^{3} \cdot \left(\log i \cdot \log n\right)}{i}\right)\right)\right)\right)\right)}\]
    4. Simplified24.2

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{{n}^{4} \cdot \left({\left(\log n\right)}^{2} \cdot \log i\right)}{i}, 33.3333333333333285963817615993320941925, \mathsf{fma}\left(16.66666666666666429819088079966604709625, \frac{{n}^{4} \cdot \left({\left(\log n\right)}^{2} \cdot \log i\right)}{i}, \mathsf{fma}\left(16.66666666666666429819088079966604709625, \frac{{n}^{4}}{\frac{i}{{\left(\log i\right)}^{3}}}, \mathsf{fma}\left(100, \frac{n \cdot n}{\frac{i}{\log i}}, 50 \cdot \left(\frac{{n}^{3}}{\frac{i}{{\left(\log i\right)}^{2}}} + \frac{{n}^{3}}{\frac{i}{{\left(\log n\right)}^{2}}}\right)\right)\right)\right) - \mathsf{fma}\left(\frac{{n}^{4}}{\frac{i}{{\left(\log n\right)}^{3}}}, 16.66666666666666429819088079966604709625, \mathsf{fma}\left(16.66666666666666429819088079966604709625, \frac{\left({n}^{4} \cdot {\left(\log i\right)}^{2}\right) \cdot \log n}{i}, \mathsf{fma}\left(\frac{{n}^{3}}{\frac{i}{\log i \cdot \log n}}, 50, \mathsf{fma}\left(\frac{\left({n}^{4} \cdot {\left(\log i\right)}^{2}\right) \cdot \log n}{i}, 33.3333333333333285963817615993320941925, \mathsf{fma}\left(50, \frac{{n}^{3}}{\frac{i}{\log i \cdot \log n}}, \frac{100 \cdot \left(\log n \cdot \left(n \cdot n\right)\right)}{i}\right)\right)\right)\right)\right)\right)}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification20.0

    \[\leadsto \begin{array}{l} \mathbf{if}\;i \le -0.3499720027197658622775122694292804226279:\\ \;\;\;\;\frac{\frac{n}{\frac{1}{\sqrt{100}}}}{\frac{\frac{i}{\sqrt{100}}}{{\left(\frac{i}{n} + 1\right)}^{n} - 1}}\\ \mathbf{elif}\;i \le 3.427314966810909420478563204128016522016 \cdot 10^{-18}:\\ \;\;\;\;\frac{1}{i} \cdot \left(\left(n \cdot 100\right) \cdot \left(\mathsf{fma}\left(n, \log 1, \mathsf{fma}\left(1, i, 0.5 \cdot \left(i \cdot i\right)\right)\right) - \left(\left(i \cdot i\right) \cdot \log 1\right) \cdot 0.5\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{\left(\log i \cdot {\left(\log n\right)}^{2}\right) \cdot {n}^{4}}{i}, 33.3333333333333285963817615993320941925, \mathsf{fma}\left(16.66666666666666429819088079966604709625, \frac{\left(\log i \cdot {\left(\log n\right)}^{2}\right) \cdot {n}^{4}}{i}, \mathsf{fma}\left(16.66666666666666429819088079966604709625, \frac{{n}^{4}}{\frac{i}{{\left(\log i\right)}^{3}}}, \mathsf{fma}\left(100, \frac{n \cdot n}{\frac{i}{\log i}}, 50 \cdot \left(\frac{{n}^{3}}{\frac{i}{{\left(\log n\right)}^{2}}} + \frac{{n}^{3}}{\frac{i}{{\left(\log i\right)}^{2}}}\right)\right)\right)\right) - \mathsf{fma}\left(\frac{{n}^{4}}{\frac{i}{{\left(\log n\right)}^{3}}}, 16.66666666666666429819088079966604709625, \mathsf{fma}\left(16.66666666666666429819088079966604709625, \frac{\log n \cdot \left({\left(\log i\right)}^{2} \cdot {n}^{4}\right)}{i}, \mathsf{fma}\left(\frac{{n}^{3}}{\frac{i}{\log n \cdot \log i}}, 50, \mathsf{fma}\left(\frac{\log n \cdot \left({\left(\log i\right)}^{2} \cdot {n}^{4}\right)}{i}, 33.3333333333333285963817615993320941925, \mathsf{fma}\left(50, \frac{{n}^{3}}{\frac{i}{\log n \cdot \log i}}, \frac{100 \cdot \left(\log n \cdot \left(n \cdot n\right)\right)}{i}\right)\right)\right)\right)\right)\right)\\ \end{array}\]

Reproduce

herbie shell --seed 2019196 +o rules:numerics
(FPCore (i n)
  :name "Compound Interest"

  :herbie-target
  (* 100.0 (/ (- (exp (* n (if (== (+ 1.0 (/ i n)) 1.0) (/ i n) (/ (* (/ i n) (log (+ 1.0 (/ i n)))) (- (+ (/ i n) 1.0) 1.0))))) 1.0) (/ i n)))

  (* 100.0 (/ (- (pow (+ 1.0 (/ i n)) n) 1.0) (/ i n))))