Average Error: 42.5 → 25.2
Time: 1.8m
Precision: 64
\[100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\]
\[\begin{array}{l} \mathbf{if}\;i \le -8.289427775447091 \cdot 10^{-05}:\\ \;\;\;\;n \cdot \frac{\log \left(\sqrt[3]{e^{\mathsf{fma}\left(100, \left(e^{\mathsf{log1p}\left(\left(\frac{i}{n}\right)\right) \cdot n}\right), -100\right)}} \cdot \sqrt[3]{e^{\mathsf{fma}\left(100, \left(e^{\mathsf{log1p}\left(\left(\frac{i}{n}\right)\right) \cdot n}\right), -100\right)}}\right) + \log \left(\sqrt[3]{e^{\mathsf{fma}\left(100, \left(e^{\mathsf{log1p}\left(\left(\frac{i}{n}\right)\right) \cdot n}\right), -100\right)}}\right)}{i}\\ \mathbf{elif}\;i \le 3.8569470324880954 \cdot 10^{-10}:\\ \;\;\;\;\frac{i \cdot \mathsf{fma}\left(i, \left(\mathsf{fma}\left(i, \frac{50}{3}, 50\right)\right), 100\right)}{\frac{i}{n}}\\ \mathbf{else}:\\ \;\;\;\;n \cdot \frac{\mathsf{fma}\left(50, \left(\left(\log n \cdot n\right) \cdot \left(\log n \cdot n\right)\right), \left(\mathsf{fma}\left(\frac{50}{3}, \left(\log i \cdot \left(\left(\left(\log i \cdot n\right) \cdot \left(\log i \cdot n\right)\right) \cdot n\right)\right), \left(\mathsf{fma}\left(100, \left(\log i \cdot n\right), \left(\left(\left(\left(\left(\log n \cdot n\right) \cdot \left(\log n \cdot n\right)\right) \cdot n\right) \cdot \log i\right) \cdot 50 + 50 \cdot \left(\left(\log i \cdot n\right) \cdot \left(\log i \cdot n\right)\right)\right)\right)\right)\right)\right)\right) - \left(\mathsf{fma}\left(\frac{50}{3}, \left(\log n \cdot \left(\left(\left(\log n \cdot n\right) \cdot \left(\log n \cdot n\right)\right) \cdot n\right)\right), \left(\mathsf{fma}\left(\left(\left(\left(\log n \cdot n\right) \cdot \left(n \cdot n\right)\right) \cdot \left(\log i \cdot \log i\right)\right), \frac{50}{3}, \left(\left(\log n \cdot n\right) \cdot 100\right)\right)\right)\right) + \left(\left(50 \cdot \log i\right) \cdot \left(\left(n \cdot n\right) \cdot \log n\right) + \mathsf{fma}\left(\left(\left(\left(\log n \cdot n\right) \cdot \left(n \cdot n\right)\right) \cdot \left(\log i \cdot \log i\right)\right), \frac{100}{3}, \left(\left(50 \cdot \log i\right) \cdot \left(\left(n \cdot n\right) \cdot \log n\right)\right)\right)\right)\right)}{i}\\ \end{array}\]
100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}
\begin{array}{l}
\mathbf{if}\;i \le -8.289427775447091 \cdot 10^{-05}:\\
\;\;\;\;n \cdot \frac{\log \left(\sqrt[3]{e^{\mathsf{fma}\left(100, \left(e^{\mathsf{log1p}\left(\left(\frac{i}{n}\right)\right) \cdot n}\right), -100\right)}} \cdot \sqrt[3]{e^{\mathsf{fma}\left(100, \left(e^{\mathsf{log1p}\left(\left(\frac{i}{n}\right)\right) \cdot n}\right), -100\right)}}\right) + \log \left(\sqrt[3]{e^{\mathsf{fma}\left(100, \left(e^{\mathsf{log1p}\left(\left(\frac{i}{n}\right)\right) \cdot n}\right), -100\right)}}\right)}{i}\\

\mathbf{elif}\;i \le 3.8569470324880954 \cdot 10^{-10}:\\
\;\;\;\;\frac{i \cdot \mathsf{fma}\left(i, \left(\mathsf{fma}\left(i, \frac{50}{3}, 50\right)\right), 100\right)}{\frac{i}{n}}\\

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

\end{array}
double f(double i, double n) {
        double r19742756 = 100.0;
        double r19742757 = 1.0;
        double r19742758 = i;
        double r19742759 = n;
        double r19742760 = r19742758 / r19742759;
        double r19742761 = r19742757 + r19742760;
        double r19742762 = pow(r19742761, r19742759);
        double r19742763 = r19742762 - r19742757;
        double r19742764 = r19742763 / r19742760;
        double r19742765 = r19742756 * r19742764;
        return r19742765;
}

double f(double i, double n) {
        double r19742766 = i;
        double r19742767 = -8.289427775447091e-05;
        bool r19742768 = r19742766 <= r19742767;
        double r19742769 = n;
        double r19742770 = 100.0;
        double r19742771 = r19742766 / r19742769;
        double r19742772 = log1p(r19742771);
        double r19742773 = r19742772 * r19742769;
        double r19742774 = exp(r19742773);
        double r19742775 = -100.0;
        double r19742776 = fma(r19742770, r19742774, r19742775);
        double r19742777 = exp(r19742776);
        double r19742778 = cbrt(r19742777);
        double r19742779 = r19742778 * r19742778;
        double r19742780 = log(r19742779);
        double r19742781 = log(r19742778);
        double r19742782 = r19742780 + r19742781;
        double r19742783 = r19742782 / r19742766;
        double r19742784 = r19742769 * r19742783;
        double r19742785 = 3.8569470324880954e-10;
        bool r19742786 = r19742766 <= r19742785;
        double r19742787 = 16.666666666666668;
        double r19742788 = 50.0;
        double r19742789 = fma(r19742766, r19742787, r19742788);
        double r19742790 = fma(r19742766, r19742789, r19742770);
        double r19742791 = r19742766 * r19742790;
        double r19742792 = r19742791 / r19742771;
        double r19742793 = log(r19742769);
        double r19742794 = r19742793 * r19742769;
        double r19742795 = r19742794 * r19742794;
        double r19742796 = log(r19742766);
        double r19742797 = r19742796 * r19742769;
        double r19742798 = r19742797 * r19742797;
        double r19742799 = r19742798 * r19742769;
        double r19742800 = r19742796 * r19742799;
        double r19742801 = r19742795 * r19742769;
        double r19742802 = r19742801 * r19742796;
        double r19742803 = r19742802 * r19742788;
        double r19742804 = r19742788 * r19742798;
        double r19742805 = r19742803 + r19742804;
        double r19742806 = fma(r19742770, r19742797, r19742805);
        double r19742807 = fma(r19742787, r19742800, r19742806);
        double r19742808 = fma(r19742788, r19742795, r19742807);
        double r19742809 = r19742793 * r19742801;
        double r19742810 = r19742769 * r19742769;
        double r19742811 = r19742794 * r19742810;
        double r19742812 = r19742796 * r19742796;
        double r19742813 = r19742811 * r19742812;
        double r19742814 = r19742794 * r19742770;
        double r19742815 = fma(r19742813, r19742787, r19742814);
        double r19742816 = fma(r19742787, r19742809, r19742815);
        double r19742817 = r19742788 * r19742796;
        double r19742818 = r19742810 * r19742793;
        double r19742819 = r19742817 * r19742818;
        double r19742820 = 33.333333333333336;
        double r19742821 = fma(r19742813, r19742820, r19742819);
        double r19742822 = r19742819 + r19742821;
        double r19742823 = r19742816 + r19742822;
        double r19742824 = r19742808 - r19742823;
        double r19742825 = r19742824 / r19742766;
        double r19742826 = r19742769 * r19742825;
        double r19742827 = r19742786 ? r19742792 : r19742826;
        double r19742828 = r19742768 ? r19742784 : r19742827;
        return r19742828;
}

Error

Bits error versus i

Bits error versus n

Target

Original42.5
Target42.3
Herbie25.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 i < -8.289427775447091e-05

    1. Initial program 28.1

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

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(100, \left({\left(1 + \frac{i}{n}\right)}^{n}\right), -100\right)}{\frac{i}{n}}}\]
    3. Using strategy rm
    4. Applied add-exp-log28.1

      \[\leadsto \frac{\mathsf{fma}\left(100, \left({\color{blue}{\left(e^{\log \left(1 + \frac{i}{n}\right)}\right)}}^{n}\right), -100\right)}{\frac{i}{n}}\]
    5. Applied pow-exp28.1

      \[\leadsto \frac{\mathsf{fma}\left(100, \color{blue}{\left(e^{\log \left(1 + \frac{i}{n}\right) \cdot n}\right)}, -100\right)}{\frac{i}{n}}\]
    6. Simplified6.0

      \[\leadsto \frac{\mathsf{fma}\left(100, \left(e^{\color{blue}{n \cdot \mathsf{log1p}\left(\left(\frac{i}{n}\right)\right)}}\right), -100\right)}{\frac{i}{n}}\]
    7. Using strategy rm
    8. Applied add-log-exp6.0

      \[\leadsto \frac{\color{blue}{\log \left(e^{\mathsf{fma}\left(100, \left(e^{n \cdot \mathsf{log1p}\left(\left(\frac{i}{n}\right)\right)}\right), -100\right)}\right)}}{\frac{i}{n}}\]
    9. Using strategy rm
    10. Applied associate-/r/6.5

      \[\leadsto \color{blue}{\frac{\log \left(e^{\mathsf{fma}\left(100, \left(e^{n \cdot \mathsf{log1p}\left(\left(\frac{i}{n}\right)\right)}\right), -100\right)}\right)}{i} \cdot n}\]
    11. Using strategy rm
    12. Applied add-cube-cbrt6.5

      \[\leadsto \frac{\log \color{blue}{\left(\left(\sqrt[3]{e^{\mathsf{fma}\left(100, \left(e^{n \cdot \mathsf{log1p}\left(\left(\frac{i}{n}\right)\right)}\right), -100\right)}} \cdot \sqrt[3]{e^{\mathsf{fma}\left(100, \left(e^{n \cdot \mathsf{log1p}\left(\left(\frac{i}{n}\right)\right)}\right), -100\right)}}\right) \cdot \sqrt[3]{e^{\mathsf{fma}\left(100, \left(e^{n \cdot \mathsf{log1p}\left(\left(\frac{i}{n}\right)\right)}\right), -100\right)}}\right)}}{i} \cdot n\]
    13. Applied log-prod6.5

      \[\leadsto \frac{\color{blue}{\log \left(\sqrt[3]{e^{\mathsf{fma}\left(100, \left(e^{n \cdot \mathsf{log1p}\left(\left(\frac{i}{n}\right)\right)}\right), -100\right)}} \cdot \sqrt[3]{e^{\mathsf{fma}\left(100, \left(e^{n \cdot \mathsf{log1p}\left(\left(\frac{i}{n}\right)\right)}\right), -100\right)}}\right) + \log \left(\sqrt[3]{e^{\mathsf{fma}\left(100, \left(e^{n \cdot \mathsf{log1p}\left(\left(\frac{i}{n}\right)\right)}\right), -100\right)}}\right)}}{i} \cdot n\]

    if -8.289427775447091e-05 < i < 3.8569470324880954e-10

    1. Initial program 50.2

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

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

      \[\leadsto \frac{\color{blue}{100 \cdot i + \left(50 \cdot {i}^{2} + \frac{50}{3} \cdot {i}^{3}\right)}}{\frac{i}{n}}\]
    4. Simplified32.8

      \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(i, \left(\mathsf{fma}\left(i, \frac{50}{3}, 50\right)\right), 100\right) \cdot i}}{\frac{i}{n}}\]

    if 3.8569470324880954e-10 < i

    1. Initial program 32.0

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

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(100, \left({\left(1 + \frac{i}{n}\right)}^{n}\right), -100\right)}{\frac{i}{n}}}\]
    3. Using strategy rm
    4. Applied add-exp-log49.4

      \[\leadsto \frac{\mathsf{fma}\left(100, \left({\color{blue}{\left(e^{\log \left(1 + \frac{i}{n}\right)}\right)}}^{n}\right), -100\right)}{\frac{i}{n}}\]
    5. Applied pow-exp49.4

      \[\leadsto \frac{\mathsf{fma}\left(100, \color{blue}{\left(e^{\log \left(1 + \frac{i}{n}\right) \cdot n}\right)}, -100\right)}{\frac{i}{n}}\]
    6. Simplified46.9

      \[\leadsto \frac{\mathsf{fma}\left(100, \left(e^{\color{blue}{n \cdot \mathsf{log1p}\left(\left(\frac{i}{n}\right)\right)}}\right), -100\right)}{\frac{i}{n}}\]
    7. Using strategy rm
    8. Applied add-log-exp47.9

      \[\leadsto \frac{\color{blue}{\log \left(e^{\mathsf{fma}\left(100, \left(e^{n \cdot \mathsf{log1p}\left(\left(\frac{i}{n}\right)\right)}\right), -100\right)}\right)}}{\frac{i}{n}}\]
    9. Using strategy rm
    10. Applied associate-/r/47.9

      \[\leadsto \color{blue}{\frac{\log \left(e^{\mathsf{fma}\left(100, \left(e^{n \cdot \mathsf{log1p}\left(\left(\frac{i}{n}\right)\right)}\right), -100\right)}\right)}{i} \cdot n}\]
    11. Taylor expanded around 0 21.2

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;i \le -8.289427775447091 \cdot 10^{-05}:\\ \;\;\;\;n \cdot \frac{\log \left(\sqrt[3]{e^{\mathsf{fma}\left(100, \left(e^{\mathsf{log1p}\left(\left(\frac{i}{n}\right)\right) \cdot n}\right), -100\right)}} \cdot \sqrt[3]{e^{\mathsf{fma}\left(100, \left(e^{\mathsf{log1p}\left(\left(\frac{i}{n}\right)\right) \cdot n}\right), -100\right)}}\right) + \log \left(\sqrt[3]{e^{\mathsf{fma}\left(100, \left(e^{\mathsf{log1p}\left(\left(\frac{i}{n}\right)\right) \cdot n}\right), -100\right)}}\right)}{i}\\ \mathbf{elif}\;i \le 3.8569470324880954 \cdot 10^{-10}:\\ \;\;\;\;\frac{i \cdot \mathsf{fma}\left(i, \left(\mathsf{fma}\left(i, \frac{50}{3}, 50\right)\right), 100\right)}{\frac{i}{n}}\\ \mathbf{else}:\\ \;\;\;\;n \cdot \frac{\mathsf{fma}\left(50, \left(\left(\log n \cdot n\right) \cdot \left(\log n \cdot n\right)\right), \left(\mathsf{fma}\left(\frac{50}{3}, \left(\log i \cdot \left(\left(\left(\log i \cdot n\right) \cdot \left(\log i \cdot n\right)\right) \cdot n\right)\right), \left(\mathsf{fma}\left(100, \left(\log i \cdot n\right), \left(\left(\left(\left(\left(\log n \cdot n\right) \cdot \left(\log n \cdot n\right)\right) \cdot n\right) \cdot \log i\right) \cdot 50 + 50 \cdot \left(\left(\log i \cdot n\right) \cdot \left(\log i \cdot n\right)\right)\right)\right)\right)\right)\right)\right) - \left(\mathsf{fma}\left(\frac{50}{3}, \left(\log n \cdot \left(\left(\left(\log n \cdot n\right) \cdot \left(\log n \cdot n\right)\right) \cdot n\right)\right), \left(\mathsf{fma}\left(\left(\left(\left(\log n \cdot n\right) \cdot \left(n \cdot n\right)\right) \cdot \left(\log i \cdot \log i\right)\right), \frac{50}{3}, \left(\left(\log n \cdot n\right) \cdot 100\right)\right)\right)\right) + \left(\left(50 \cdot \log i\right) \cdot \left(\left(n \cdot n\right) \cdot \log n\right) + \mathsf{fma}\left(\left(\left(\left(\log n \cdot n\right) \cdot \left(n \cdot n\right)\right) \cdot \left(\log i \cdot \log i\right)\right), \frac{100}{3}, \left(\left(50 \cdot \log i\right) \cdot \left(\left(n \cdot n\right) \cdot \log n\right)\right)\right)\right)\right)}{i}\\ \end{array}\]

Reproduce

herbie shell --seed 2019121 +o rules:numerics
(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))))