Average Error: 14.9 → 0.3
Time: 1.8s
Precision: 64
\[\frac{\left(x \cdot 2\right) \cdot y}{x - y}\]
\[\begin{array}{l} \mathbf{if}\;y \le -1.29415460230555196 \cdot 10^{36} \lor \neg \left(y \le 2.4012122731381248 \cdot 10^{-81}\right):\\ \;\;\;\;\left(x \cdot 2\right) \cdot \frac{y}{x - y}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{x - y} \cdot \left(y \cdot 2\right)\\ \end{array}\]
\frac{\left(x \cdot 2\right) \cdot y}{x - y}
\begin{array}{l}
\mathbf{if}\;y \le -1.29415460230555196 \cdot 10^{36} \lor \neg \left(y \le 2.4012122731381248 \cdot 10^{-81}\right):\\
\;\;\;\;\left(x \cdot 2\right) \cdot \frac{y}{x - y}\\

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

\end{array}
double f(double x, double y) {
        double r595298 = x;
        double r595299 = 2.0;
        double r595300 = r595298 * r595299;
        double r595301 = y;
        double r595302 = r595300 * r595301;
        double r595303 = r595298 - r595301;
        double r595304 = r595302 / r595303;
        return r595304;
}

double f(double x, double y) {
        double r595305 = y;
        double r595306 = -1.294154602305552e+36;
        bool r595307 = r595305 <= r595306;
        double r595308 = 2.401212273138125e-81;
        bool r595309 = r595305 <= r595308;
        double r595310 = !r595309;
        bool r595311 = r595307 || r595310;
        double r595312 = x;
        double r595313 = 2.0;
        double r595314 = r595312 * r595313;
        double r595315 = r595312 - r595305;
        double r595316 = r595305 / r595315;
        double r595317 = r595314 * r595316;
        double r595318 = r595312 / r595315;
        double r595319 = r595305 * r595313;
        double r595320 = r595318 * r595319;
        double r595321 = r595311 ? r595317 : r595320;
        return r595321;
}

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.9
Target0.3
Herbie0.3
\[\begin{array}{l} \mathbf{if}\;x \lt -1.7210442634149447 \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 < -1.294154602305552e+36 or 2.401212273138125e-81 < y

    1. Initial program 15.3

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

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

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

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

    if -1.294154602305552e+36 < y < 2.401212273138125e-81

    1. Initial program 14.5

      \[\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.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(y \cdot 2\right)}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.3

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -1.29415460230555196 \cdot 10^{36} \lor \neg \left(y \le 2.4012122731381248 \cdot 10^{-81}\right):\\ \;\;\;\;\left(x \cdot 2\right) \cdot \frac{y}{x - y}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{x - y} \cdot \left(y \cdot 2\right)\\ \end{array}\]

Reproduce

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