Average Error: 15.1 → 0.4
Time: 22.3s
Precision: 64
\[\frac{\left(x \cdot 2.0\right) \cdot y}{x - y}\]
\[\begin{array}{l} \mathbf{if}\;y \le -1.4392061780489917 \cdot 10^{-16}:\\ \;\;\;\;\frac{x \cdot 2.0}{\frac{x}{y} - 1}\\ \mathbf{elif}\;y \le 2.279321042838855 \cdot 10^{-104}:\\ \;\;\;\;\left(2.0 \cdot y\right) \cdot \frac{x}{x - y}\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot 2.0}{\frac{x}{y} - 1}\\ \end{array}\]
\frac{\left(x \cdot 2.0\right) \cdot y}{x - y}
\begin{array}{l}
\mathbf{if}\;y \le -1.4392061780489917 \cdot 10^{-16}:\\
\;\;\;\;\frac{x \cdot 2.0}{\frac{x}{y} - 1}\\

\mathbf{elif}\;y \le 2.279321042838855 \cdot 10^{-104}:\\
\;\;\;\;\left(2.0 \cdot y\right) \cdot \frac{x}{x - y}\\

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

\end{array}
double f(double x, double y) {
        double r25174760 = x;
        double r25174761 = 2.0;
        double r25174762 = r25174760 * r25174761;
        double r25174763 = y;
        double r25174764 = r25174762 * r25174763;
        double r25174765 = r25174760 - r25174763;
        double r25174766 = r25174764 / r25174765;
        return r25174766;
}

double f(double x, double y) {
        double r25174767 = y;
        double r25174768 = -1.4392061780489917e-16;
        bool r25174769 = r25174767 <= r25174768;
        double r25174770 = x;
        double r25174771 = 2.0;
        double r25174772 = r25174770 * r25174771;
        double r25174773 = r25174770 / r25174767;
        double r25174774 = 1.0;
        double r25174775 = r25174773 - r25174774;
        double r25174776 = r25174772 / r25174775;
        double r25174777 = 2.279321042838855e-104;
        bool r25174778 = r25174767 <= r25174777;
        double r25174779 = r25174771 * r25174767;
        double r25174780 = r25174770 - r25174767;
        double r25174781 = r25174770 / r25174780;
        double r25174782 = r25174779 * r25174781;
        double r25174783 = r25174778 ? r25174782 : r25174776;
        double r25174784 = r25174769 ? r25174776 : r25174783;
        return r25174784;
}

Error

Bits error versus x

Bits error versus y

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original15.1
Target0.3
Herbie0.4
\[\begin{array}{l} \mathbf{if}\;x \lt -1.7210442634149447 \cdot 10^{+81}:\\ \;\;\;\;\frac{2.0 \cdot x}{x - y} \cdot y\\ \mathbf{elif}\;x \lt 8.364504563556443 \cdot 10^{+16}:\\ \;\;\;\;\frac{x \cdot 2.0}{\frac{x - y}{y}}\\ \mathbf{else}:\\ \;\;\;\;\frac{2.0 \cdot x}{x - y} \cdot y\\ \end{array}\]

Derivation

  1. Split input into 2 regimes
  2. if y < -1.4392061780489917e-16 or 2.279321042838855e-104 < y

    1. Initial program 14.2

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

      \[\leadsto \color{blue}{\frac{x \cdot 2.0}{\frac{x - y}{y}}}\]
    4. Using strategy rm
    5. Applied div-sub0.6

      \[\leadsto \frac{x \cdot 2.0}{\color{blue}{\frac{x}{y} - \frac{y}{y}}}\]
    6. Simplified0.6

      \[\leadsto \frac{x \cdot 2.0}{\frac{x}{y} - \color{blue}{1}}\]

    if -1.4392061780489917e-16 < y < 2.279321042838855e-104

    1. Initial program 16.4

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

      \[\leadsto \color{blue}{\frac{x \cdot 2.0}{\frac{x - y}{y}}}\]
    4. Using strategy rm
    5. Applied div-inv17.6

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

      \[\leadsto \color{blue}{\frac{x}{x - y} \cdot \frac{2.0}{\frac{1}{y}}}\]
    7. Simplified0.0

      \[\leadsto \frac{x}{x - y} \cdot \color{blue}{\left(y \cdot 2.0\right)}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.4

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -1.4392061780489917 \cdot 10^{-16}:\\ \;\;\;\;\frac{x \cdot 2.0}{\frac{x}{y} - 1}\\ \mathbf{elif}\;y \le 2.279321042838855 \cdot 10^{-104}:\\ \;\;\;\;\left(2.0 \cdot y\right) \cdot \frac{x}{x - y}\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot 2.0}{\frac{x}{y} - 1}\\ \end{array}\]

Reproduce

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

  :herbie-target
  (if (< x -1.7210442634149447e+81) (* (/ (* 2.0 x) (- x y)) y) (if (< x 8.364504563556443e+16) (/ (* x 2.0) (/ (- x y) y)) (* (/ (* 2.0 x) (- x y)) y)))

  (/ (* (* x 2.0) y) (- x y)))