Average Error: 15.1 → 0.1
Time: 9.5s
Precision: 64
\[\frac{\left(x \cdot 2\right) \cdot y}{x - y}\]
\[\begin{array}{l} \mathbf{if}\;y \le -6.30586821746719046822219898487595819847 \cdot 10^{45}:\\ \;\;\;\;\frac{y}{x - y} \cdot \left(2 \cdot x\right)\\ \mathbf{elif}\;y \le 5.377814118926896018584556610780517528545 \cdot 10^{-32}:\\ \;\;\;\;\frac{x}{x - y} \cdot \left(2 \cdot y\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{x - y} \cdot \left(2 \cdot x\right)\\ \end{array}\]
\frac{\left(x \cdot 2\right) \cdot y}{x - y}
\begin{array}{l}
\mathbf{if}\;y \le -6.30586821746719046822219898487595819847 \cdot 10^{45}:\\
\;\;\;\;\frac{y}{x - y} \cdot \left(2 \cdot x\right)\\

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

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

\end{array}
double f(double x, double y) {
        double r25484000 = x;
        double r25484001 = 2.0;
        double r25484002 = r25484000 * r25484001;
        double r25484003 = y;
        double r25484004 = r25484002 * r25484003;
        double r25484005 = r25484000 - r25484003;
        double r25484006 = r25484004 / r25484005;
        return r25484006;
}

double f(double x, double y) {
        double r25484007 = y;
        double r25484008 = -6.30586821746719e+45;
        bool r25484009 = r25484007 <= r25484008;
        double r25484010 = x;
        double r25484011 = r25484010 - r25484007;
        double r25484012 = r25484007 / r25484011;
        double r25484013 = 2.0;
        double r25484014 = r25484013 * r25484010;
        double r25484015 = r25484012 * r25484014;
        double r25484016 = 5.377814118926896e-32;
        bool r25484017 = r25484007 <= r25484016;
        double r25484018 = r25484010 / r25484011;
        double r25484019 = r25484013 * r25484007;
        double r25484020 = r25484018 * r25484019;
        double r25484021 = r25484017 ? r25484020 : r25484015;
        double r25484022 = r25484009 ? r25484015 : r25484021;
        return r25484022;
}

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.4
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 < -6.30586821746719e+45 or 5.377814118926896e-32 < y

    1. Initial program 16.7

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

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

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

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

    if -6.30586821746719e+45 < y < 5.377814118926896e-32

    1. Initial program 13.6

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

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

      \[\leadsto \frac{x \cdot 2}{\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}{\frac{1}{y}}}\]
    7. Simplified0.1

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

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

Reproduce

herbie shell --seed 2019171 
(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)))