Average Error: 15.0 → 0.6
Time: 12.3s
Precision: 64
\[\frac{\left(x \cdot 2\right) \cdot y}{x - y}\]
\[\begin{array}{l} \mathbf{if}\;y \le -6.28812736973600292546513463779144784486 \cdot 10^{77} \lor \neg \left(y \le 1.368390397641661343136755314604820394056 \cdot 10^{-94}\right):\\ \;\;\;\;\frac{-x \cdot 2}{-\left(\frac{x}{y} - 1\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{x - y} \cdot \left(2 \cdot y\right)\\ \end{array}\]
\frac{\left(x \cdot 2\right) \cdot y}{x - y}
\begin{array}{l}
\mathbf{if}\;y \le -6.28812736973600292546513463779144784486 \cdot 10^{77} \lor \neg \left(y \le 1.368390397641661343136755314604820394056 \cdot 10^{-94}\right):\\
\;\;\;\;\frac{-x \cdot 2}{-\left(\frac{x}{y} - 1\right)}\\

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

\end{array}
double f(double x, double y) {
        double r364879 = x;
        double r364880 = 2.0;
        double r364881 = r364879 * r364880;
        double r364882 = y;
        double r364883 = r364881 * r364882;
        double r364884 = r364879 - r364882;
        double r364885 = r364883 / r364884;
        return r364885;
}

double f(double x, double y) {
        double r364886 = y;
        double r364887 = -6.288127369736003e+77;
        bool r364888 = r364886 <= r364887;
        double r364889 = 1.3683903976416613e-94;
        bool r364890 = r364886 <= r364889;
        double r364891 = !r364890;
        bool r364892 = r364888 || r364891;
        double r364893 = x;
        double r364894 = 2.0;
        double r364895 = r364893 * r364894;
        double r364896 = -r364895;
        double r364897 = r364893 / r364886;
        double r364898 = 1.0;
        double r364899 = r364897 - r364898;
        double r364900 = -r364899;
        double r364901 = r364896 / r364900;
        double r364902 = r364893 - r364886;
        double r364903 = r364893 / r364902;
        double r364904 = r364894 * r364886;
        double r364905 = r364903 * r364904;
        double r364906 = r364892 ? r364901 : r364905;
        return r364906;
}

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.0
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 2 regimes
  2. if y < -6.288127369736003e+77 or 1.3683903976416613e-94 < y

    1. Initial program 15.5

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

      \[\leadsto \color{blue}{\frac{x \cdot 2}{\frac{x - y}{y}}}\]
    4. Using strategy rm
    5. Applied frac-2neg0.8

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

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

    if -6.288127369736003e+77 < y < 1.3683903976416613e-94

    1. Initial program 14.5

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -6.28812736973600292546513463779144784486 \cdot 10^{77} \lor \neg \left(y \le 1.368390397641661343136755314604820394056 \cdot 10^{-94}\right):\\ \;\;\;\;\frac{-x \cdot 2}{-\left(\frac{x}{y} - 1\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{x - y} \cdot \left(2 \cdot y\right)\\ \end{array}\]

Reproduce

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