Average Error: 14.4 → 0.1
Time: 10.8s
Precision: 64
\[\frac{\left(x \cdot 2.0\right) \cdot y}{x - y}\]
\[\begin{array}{l} \mathbf{if}\;y \le -3.0638957814586657 \cdot 10^{-28}:\\ \;\;\;\;\frac{y}{x - y} \cdot \left(2.0 \cdot x\right)\\ \mathbf{elif}\;y \le 1.3615474866246526 \cdot 10^{+17}:\\ \;\;\;\;\frac{x}{x - y} \cdot \left(2.0 \cdot y\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{x - y} \cdot \left(2.0 \cdot x\right)\\ \end{array}\]
\frac{\left(x \cdot 2.0\right) \cdot y}{x - y}
\begin{array}{l}
\mathbf{if}\;y \le -3.0638957814586657 \cdot 10^{-28}:\\
\;\;\;\;\frac{y}{x - y} \cdot \left(2.0 \cdot x\right)\\

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

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

\end{array}
double f(double x, double y) {
        double r26337273 = x;
        double r26337274 = 2.0;
        double r26337275 = r26337273 * r26337274;
        double r26337276 = y;
        double r26337277 = r26337275 * r26337276;
        double r26337278 = r26337273 - r26337276;
        double r26337279 = r26337277 / r26337278;
        return r26337279;
}

double f(double x, double y) {
        double r26337280 = y;
        double r26337281 = -3.0638957814586657e-28;
        bool r26337282 = r26337280 <= r26337281;
        double r26337283 = x;
        double r26337284 = r26337283 - r26337280;
        double r26337285 = r26337280 / r26337284;
        double r26337286 = 2.0;
        double r26337287 = r26337286 * r26337283;
        double r26337288 = r26337285 * r26337287;
        double r26337289 = 1.3615474866246526e+17;
        bool r26337290 = r26337280 <= r26337289;
        double r26337291 = r26337283 / r26337284;
        double r26337292 = r26337286 * r26337280;
        double r26337293 = r26337291 * r26337292;
        double r26337294 = r26337290 ? r26337293 : r26337288;
        double r26337295 = r26337282 ? r26337288 : r26337294;
        return r26337295;
}

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.4
Target0.3
Herbie0.1
\[\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 < -3.0638957814586657e-28 or 1.3615474866246526e+17 < y

    1. Initial program 14.9

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

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

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

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

    if -3.0638957814586657e-28 < y < 1.3615474866246526e+17

    1. Initial program 13.9

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

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

      \[\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.1

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -3.0638957814586657 \cdot 10^{-28}:\\ \;\;\;\;\frac{y}{x - y} \cdot \left(2.0 \cdot x\right)\\ \mathbf{elif}\;y \le 1.3615474866246526 \cdot 10^{+17}:\\ \;\;\;\;\frac{x}{x - y} \cdot \left(2.0 \cdot y\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{x - y} \cdot \left(2.0 \cdot x\right)\\ \end{array}\]

Reproduce

herbie shell --seed 2019162 +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)))