Average Error: 43.0 → 22.9
Time: 14.9s
Precision: 64
\[100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\]
\[\begin{array}{l} \mathbf{if}\;n \le -7.76693767745361788861631953913126532955 \cdot 10^{94}:\\ \;\;\;\;\left(100 \cdot \frac{\left(1 \cdot i + \left(\sqrt{0.5 \cdot {i}^{2}} \cdot \sqrt{0.5 \cdot {i}^{2}} + \log 1 \cdot n\right)\right) - 0.5 \cdot \left({i}^{2} \cdot \log 1\right)}{i}\right) \cdot n\\ \mathbf{elif}\;n \le -9.519350012649904306163831713839410413139 \cdot 10^{-251}:\\ \;\;\;\;100 \cdot \left(\frac{{\left(1 + \frac{i}{n}\right)}^{n}}{\frac{i}{n}} - \frac{1}{\frac{i}{n}}\right)\\ \mathbf{elif}\;n \le 1.613414883038850832801467887537631845006 \cdot 10^{-130}:\\ \;\;\;\;100 \cdot \frac{\left(1 \cdot i + \left(\log 1 \cdot n + 1\right)\right) - 1}{\frac{i}{n}}\\ \mathbf{else}:\\ \;\;\;\;\left(100 \cdot \frac{\left(1 \cdot i + \left(\sqrt{0.5 \cdot {i}^{2}} \cdot \sqrt{0.5 \cdot {i}^{2}} + \log 1 \cdot n\right)\right) - 0.5 \cdot \left({i}^{2} \cdot \log 1\right)}{i}\right) \cdot n\\ \end{array}\]
100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}
\begin{array}{l}
\mathbf{if}\;n \le -7.76693767745361788861631953913126532955 \cdot 10^{94}:\\
\;\;\;\;\left(100 \cdot \frac{\left(1 \cdot i + \left(\sqrt{0.5 \cdot {i}^{2}} \cdot \sqrt{0.5 \cdot {i}^{2}} + \log 1 \cdot n\right)\right) - 0.5 \cdot \left({i}^{2} \cdot \log 1\right)}{i}\right) \cdot n\\

\mathbf{elif}\;n \le -9.519350012649904306163831713839410413139 \cdot 10^{-251}:\\
\;\;\;\;100 \cdot \left(\frac{{\left(1 + \frac{i}{n}\right)}^{n}}{\frac{i}{n}} - \frac{1}{\frac{i}{n}}\right)\\

\mathbf{elif}\;n \le 1.613414883038850832801467887537631845006 \cdot 10^{-130}:\\
\;\;\;\;100 \cdot \frac{\left(1 \cdot i + \left(\log 1 \cdot n + 1\right)\right) - 1}{\frac{i}{n}}\\

\mathbf{else}:\\
\;\;\;\;\left(100 \cdot \frac{\left(1 \cdot i + \left(\sqrt{0.5 \cdot {i}^{2}} \cdot \sqrt{0.5 \cdot {i}^{2}} + \log 1 \cdot n\right)\right) - 0.5 \cdot \left({i}^{2} \cdot \log 1\right)}{i}\right) \cdot n\\

\end{array}
double f(double i, double n) {
        double r147584 = 100.0;
        double r147585 = 1.0;
        double r147586 = i;
        double r147587 = n;
        double r147588 = r147586 / r147587;
        double r147589 = r147585 + r147588;
        double r147590 = pow(r147589, r147587);
        double r147591 = r147590 - r147585;
        double r147592 = r147591 / r147588;
        double r147593 = r147584 * r147592;
        return r147593;
}

double f(double i, double n) {
        double r147594 = n;
        double r147595 = -7.766937677453618e+94;
        bool r147596 = r147594 <= r147595;
        double r147597 = 100.0;
        double r147598 = 1.0;
        double r147599 = i;
        double r147600 = r147598 * r147599;
        double r147601 = 0.5;
        double r147602 = 2.0;
        double r147603 = pow(r147599, r147602);
        double r147604 = r147601 * r147603;
        double r147605 = sqrt(r147604);
        double r147606 = r147605 * r147605;
        double r147607 = log(r147598);
        double r147608 = r147607 * r147594;
        double r147609 = r147606 + r147608;
        double r147610 = r147600 + r147609;
        double r147611 = r147603 * r147607;
        double r147612 = r147601 * r147611;
        double r147613 = r147610 - r147612;
        double r147614 = r147613 / r147599;
        double r147615 = r147597 * r147614;
        double r147616 = r147615 * r147594;
        double r147617 = -9.519350012649904e-251;
        bool r147618 = r147594 <= r147617;
        double r147619 = r147599 / r147594;
        double r147620 = r147598 + r147619;
        double r147621 = pow(r147620, r147594);
        double r147622 = r147621 / r147619;
        double r147623 = r147598 / r147619;
        double r147624 = r147622 - r147623;
        double r147625 = r147597 * r147624;
        double r147626 = 1.6134148830388508e-130;
        bool r147627 = r147594 <= r147626;
        double r147628 = 1.0;
        double r147629 = r147608 + r147628;
        double r147630 = r147600 + r147629;
        double r147631 = r147630 - r147598;
        double r147632 = r147631 / r147619;
        double r147633 = r147597 * r147632;
        double r147634 = r147627 ? r147633 : r147616;
        double r147635 = r147618 ? r147625 : r147634;
        double r147636 = r147596 ? r147616 : r147635;
        return r147636;
}

Error

Bits error versus i

Bits error versus n

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original43.0
Target42.8
Herbie22.9
\[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 n < -7.766937677453618e+94 or 1.6134148830388508e-130 < n

    1. Initial program 55.3

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

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

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

      \[\leadsto \left(100 \cdot \frac{\color{blue}{\left(1 \cdot i + \left(0.5 \cdot {i}^{2} + \log 1 \cdot n\right)\right) - 0.5 \cdot \left({i}^{2} \cdot \log 1\right)}}{i}\right) \cdot n\]
    6. Using strategy rm
    7. Applied add-sqr-sqrt21.5

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

    if -7.766937677453618e+94 < n < -9.519350012649904e-251

    1. Initial program 23.8

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

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

    if -9.519350012649904e-251 < n < 1.6134148830388508e-130

    1. Initial program 35.4

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

      \[\leadsto 100 \cdot \frac{\color{blue}{\left(1 \cdot i + \left(\log 1 \cdot n + 1\right)\right)} - 1}{\frac{i}{n}}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification22.9

    \[\leadsto \begin{array}{l} \mathbf{if}\;n \le -7.76693767745361788861631953913126532955 \cdot 10^{94}:\\ \;\;\;\;\left(100 \cdot \frac{\left(1 \cdot i + \left(\sqrt{0.5 \cdot {i}^{2}} \cdot \sqrt{0.5 \cdot {i}^{2}} + \log 1 \cdot n\right)\right) - 0.5 \cdot \left({i}^{2} \cdot \log 1\right)}{i}\right) \cdot n\\ \mathbf{elif}\;n \le -9.519350012649904306163831713839410413139 \cdot 10^{-251}:\\ \;\;\;\;100 \cdot \left(\frac{{\left(1 + \frac{i}{n}\right)}^{n}}{\frac{i}{n}} - \frac{1}{\frac{i}{n}}\right)\\ \mathbf{elif}\;n \le 1.613414883038850832801467887537631845006 \cdot 10^{-130}:\\ \;\;\;\;100 \cdot \frac{\left(1 \cdot i + \left(\log 1 \cdot n + 1\right)\right) - 1}{\frac{i}{n}}\\ \mathbf{else}:\\ \;\;\;\;\left(100 \cdot \frac{\left(1 \cdot i + \left(\sqrt{0.5 \cdot {i}^{2}} \cdot \sqrt{0.5 \cdot {i}^{2}} + \log 1 \cdot n\right)\right) - 0.5 \cdot \left({i}^{2} \cdot \log 1\right)}{i}\right) \cdot n\\ \end{array}\]

Reproduce

herbie shell --seed 2019353 
(FPCore (i n)
  :name "Compound Interest"
  :precision binary64

  :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))))