Average Error: 14.9 → 0.6
Time: 10.5s
Precision: 64
\[\frac{\left(x \cdot 2\right) \cdot y}{x - y}\]
\[\begin{array}{l} \mathbf{if}\;\frac{\left(x \cdot 2\right) \cdot y}{x - y} \le -3.302272323166789625129135265296185343759 \cdot 10^{-28}:\\ \;\;\;\;\left(x \cdot 2\right) \cdot \frac{y}{x - y}\\ \mathbf{elif}\;\frac{\left(x \cdot 2\right) \cdot y}{x - y} \le -5.298932597959136209382922379774980860889 \cdot 10^{-305}:\\ \;\;\;\;\frac{\left(x \cdot 2\right) \cdot y}{x - y}\\ \mathbf{elif}\;\frac{\left(x \cdot 2\right) \cdot y}{x - y} \le -0.0:\\ \;\;\;\;\left(x \cdot 2\right) \cdot \frac{y}{x - y}\\ \mathbf{elif}\;\frac{\left(x \cdot 2\right) \cdot y}{x - y} \le 2.187968701250411981151631046847998371838 \cdot 10^{-44}:\\ \;\;\;\;\frac{\left(x \cdot 2\right) \cdot y}{x - y}\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot 2}{\frac{x}{y} - 1}\\ \end{array}\]
\frac{\left(x \cdot 2\right) \cdot y}{x - y}
\begin{array}{l}
\mathbf{if}\;\frac{\left(x \cdot 2\right) \cdot y}{x - y} \le -3.302272323166789625129135265296185343759 \cdot 10^{-28}:\\
\;\;\;\;\left(x \cdot 2\right) \cdot \frac{y}{x - y}\\

\mathbf{elif}\;\frac{\left(x \cdot 2\right) \cdot y}{x - y} \le -5.298932597959136209382922379774980860889 \cdot 10^{-305}:\\
\;\;\;\;\frac{\left(x \cdot 2\right) \cdot y}{x - y}\\

\mathbf{elif}\;\frac{\left(x \cdot 2\right) \cdot y}{x - y} \le -0.0:\\
\;\;\;\;\left(x \cdot 2\right) \cdot \frac{y}{x - y}\\

\mathbf{elif}\;\frac{\left(x \cdot 2\right) \cdot y}{x - y} \le 2.187968701250411981151631046847998371838 \cdot 10^{-44}:\\
\;\;\;\;\frac{\left(x \cdot 2\right) \cdot y}{x - y}\\

\mathbf{else}:\\
\;\;\;\;\frac{x \cdot 2}{\frac{x}{y} - 1}\\

\end{array}
double f(double x, double y) {
        double r349626 = x;
        double r349627 = 2.0;
        double r349628 = r349626 * r349627;
        double r349629 = y;
        double r349630 = r349628 * r349629;
        double r349631 = r349626 - r349629;
        double r349632 = r349630 / r349631;
        return r349632;
}

double f(double x, double y) {
        double r349633 = x;
        double r349634 = 2.0;
        double r349635 = r349633 * r349634;
        double r349636 = y;
        double r349637 = r349635 * r349636;
        double r349638 = r349633 - r349636;
        double r349639 = r349637 / r349638;
        double r349640 = -3.3022723231667896e-28;
        bool r349641 = r349639 <= r349640;
        double r349642 = r349636 / r349638;
        double r349643 = r349635 * r349642;
        double r349644 = -5.298932597959136e-305;
        bool r349645 = r349639 <= r349644;
        double r349646 = -0.0;
        bool r349647 = r349639 <= r349646;
        double r349648 = 2.187968701250412e-44;
        bool r349649 = r349639 <= r349648;
        double r349650 = r349633 / r349636;
        double r349651 = 1.0;
        double r349652 = r349650 - r349651;
        double r349653 = r349635 / r349652;
        double r349654 = r349649 ? r349639 : r349653;
        double r349655 = r349647 ? r349643 : r349654;
        double r349656 = r349645 ? r349639 : r349655;
        double r349657 = r349641 ? r349643 : r349656;
        return r349657;
}

Error

Bits error versus x

Bits error versus y

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original14.9
Target0.3
Herbie0.6
\[\begin{array}{l} \mathbf{if}\;x \lt -1.721044263414944729490876394165887012892 \cdot 10^{81}:\\ \;\;\;\;\frac{2 \cdot x}{x - y} \cdot y\\ \mathbf{elif}\;x \lt 83645045635564432:\\ \;\;\;\;\frac{x \cdot 2}{\frac{x - y}{y}}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot x}{x - y} \cdot y\\ \end{array}\]

Derivation

  1. Split input into 3 regimes
  2. if (/ (* (* x 2.0) y) (- x y)) < -3.3022723231667896e-28 or -5.298932597959136e-305 < (/ (* (* x 2.0) y) (- x y)) < -0.0

    1. Initial program 35.2

      \[\frac{\left(x \cdot 2\right) \cdot y}{x - y}\]
    2. Using strategy rm
    3. Applied *-un-lft-identity35.2

      \[\leadsto \frac{\left(x \cdot 2\right) \cdot y}{\color{blue}{1 \cdot \left(x - y\right)}}\]
    4. Applied times-frac0.4

      \[\leadsto \color{blue}{\frac{x \cdot 2}{1} \cdot \frac{y}{x - y}}\]
    5. Simplified0.4

      \[\leadsto \color{blue}{\left(x \cdot 2\right)} \cdot \frac{y}{x - y}\]

    if -3.3022723231667896e-28 < (/ (* (* x 2.0) y) (- x y)) < -5.298932597959136e-305 or -0.0 < (/ (* (* x 2.0) y) (- x y)) < 2.187968701250412e-44

    1. Initial program 5.8

      \[\frac{\left(x \cdot 2\right) \cdot y}{x - y}\]

    if 2.187968701250412e-44 < (/ (* (* x 2.0) y) (- x y))

    1. Initial program 24.7

      \[\frac{\left(x \cdot 2\right) \cdot y}{x - y}\]
    2. Using strategy rm
    3. Applied associate-/l*0.5

      \[\leadsto \color{blue}{\frac{x \cdot 2}{\frac{x - y}{y}}}\]
    4. Simplified0.5

      \[\leadsto \frac{x \cdot 2}{\color{blue}{\frac{x}{y} - 1}}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification0.6

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{\left(x \cdot 2\right) \cdot y}{x - y} \le -3.302272323166789625129135265296185343759 \cdot 10^{-28}:\\ \;\;\;\;\left(x \cdot 2\right) \cdot \frac{y}{x - y}\\ \mathbf{elif}\;\frac{\left(x \cdot 2\right) \cdot y}{x - y} \le -5.298932597959136209382922379774980860889 \cdot 10^{-305}:\\ \;\;\;\;\frac{\left(x \cdot 2\right) \cdot y}{x - y}\\ \mathbf{elif}\;\frac{\left(x \cdot 2\right) \cdot y}{x - y} \le -0.0:\\ \;\;\;\;\left(x \cdot 2\right) \cdot \frac{y}{x - y}\\ \mathbf{elif}\;\frac{\left(x \cdot 2\right) \cdot y}{x - y} \le 2.187968701250411981151631046847998371838 \cdot 10^{-44}:\\ \;\;\;\;\frac{\left(x \cdot 2\right) \cdot y}{x - y}\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot 2}{\frac{x}{y} - 1}\\ \end{array}\]

Reproduce

herbie shell --seed 2019325 
(FPCore (x y)
  :name "Linear.Projection:perspective from linear-1.19.1.3, B"
  :precision binary64

  :herbie-target
  (if (< x -1.7210442634149447e+81) (* (/ (* 2 x) (- x y)) y) (if (< x 83645045635564432) (/ (* x 2) (/ (- x y) y)) (* (/ (* 2 x) (- x y)) y)))

  (/ (* (* x 2) y) (- x y)))