Average Error: 14.6 → 0.4
Time: 24.9s
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 r20551821 = x;
        double r20551822 = 2.0;
        double r20551823 = r20551821 * r20551822;
        double r20551824 = y;
        double r20551825 = r20551823 * r20551824;
        double r20551826 = r20551821 - r20551824;
        double r20551827 = r20551825 / r20551826;
        return r20551827;
}

double f(double x, double y) {
        double r20551828 = y;
        double r20551829 = -1.4392061780489917e-16;
        bool r20551830 = r20551828 <= r20551829;
        double r20551831 = x;
        double r20551832 = 2.0;
        double r20551833 = r20551831 * r20551832;
        double r20551834 = r20551831 / r20551828;
        double r20551835 = 1.0;
        double r20551836 = r20551834 - r20551835;
        double r20551837 = r20551833 / r20551836;
        double r20551838 = 2.279321042838855e-104;
        bool r20551839 = r20551828 <= r20551838;
        double r20551840 = r20551832 * r20551828;
        double r20551841 = r20551831 - r20551828;
        double r20551842 = r20551831 / r20551841;
        double r20551843 = r20551840 * r20551842;
        double r20551844 = r20551839 ? r20551843 : r20551837;
        double r20551845 = r20551830 ? r20551837 : r20551844;
        return r20551845;
}

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.6
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 13.5

      \[\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(2.0 \cdot y\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)))