Average Error: 15.0 → 0.1
Time: 11.3s
Precision: 64
\[\frac{\left(x \cdot 2\right) \cdot y}{x - y}\]
\[\begin{array}{l} \mathbf{if}\;y \le -316431240279237349867520:\\ \;\;\;\;\frac{x \cdot 2}{\frac{x - y}{y}}\\ \mathbf{elif}\;y \le 1.595212172464986205719205231531851770116 \cdot 10^{-42}:\\ \;\;\;\;\frac{x}{x - y} \cdot \left(2 \cdot y\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot 2}{\frac{x - y}{y}}\\ \end{array}\]
\frac{\left(x \cdot 2\right) \cdot y}{x - y}
\begin{array}{l}
\mathbf{if}\;y \le -316431240279237349867520:\\
\;\;\;\;\frac{x \cdot 2}{\frac{x - y}{y}}\\

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

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

\end{array}
double f(double x, double y) {
        double r17682410 = x;
        double r17682411 = 2.0;
        double r17682412 = r17682410 * r17682411;
        double r17682413 = y;
        double r17682414 = r17682412 * r17682413;
        double r17682415 = r17682410 - r17682413;
        double r17682416 = r17682414 / r17682415;
        return r17682416;
}

double f(double x, double y) {
        double r17682417 = y;
        double r17682418 = -3.1643124027923735e+23;
        bool r17682419 = r17682417 <= r17682418;
        double r17682420 = x;
        double r17682421 = 2.0;
        double r17682422 = r17682420 * r17682421;
        double r17682423 = r17682420 - r17682417;
        double r17682424 = r17682423 / r17682417;
        double r17682425 = r17682422 / r17682424;
        double r17682426 = 1.5952121724649862e-42;
        bool r17682427 = r17682417 <= r17682426;
        double r17682428 = r17682420 / r17682423;
        double r17682429 = r17682421 * r17682417;
        double r17682430 = r17682428 * r17682429;
        double r17682431 = r17682427 ? r17682430 : r17682425;
        double r17682432 = r17682419 ? r17682425 : r17682431;
        return r17682432;
}

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.1
\[\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 < -3.1643124027923735e+23 or 1.5952121724649862e-42 < y

    1. Initial program 15.6

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

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

    if -3.1643124027923735e+23 < y < 1.5952121724649862e-42

    1. Initial program 14.4

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -316431240279237349867520:\\ \;\;\;\;\frac{x \cdot 2}{\frac{x - y}{y}}\\ \mathbf{elif}\;y \le 1.595212172464986205719205231531851770116 \cdot 10^{-42}:\\ \;\;\;\;\frac{x}{x - y} \cdot \left(2 \cdot y\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot 2}{\frac{x - y}{y}}\\ \end{array}\]

Reproduce

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