Average Error: 14.7 → 0.1
Time: 31.1s
Precision: 64
\[\frac{\left(x \cdot 2\right) \cdot y}{x - y}\]
\[\begin{array}{l} \mathbf{if}\;y \le -66445643085124824111628188385280 \lor \neg \left(y \le 295250056767246134706811437056\right):\\ \;\;\;\;\left(x \cdot 2\right) \cdot \frac{1}{\frac{x}{y} - 1}\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot 2}{x - y} \cdot y\\ \end{array}\]
\frac{\left(x \cdot 2\right) \cdot y}{x - y}
\begin{array}{l}
\mathbf{if}\;y \le -66445643085124824111628188385280 \lor \neg \left(y \le 295250056767246134706811437056\right):\\
\;\;\;\;\left(x \cdot 2\right) \cdot \frac{1}{\frac{x}{y} - 1}\\

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

\end{array}
double f(double x, double y) {
        double r402318 = x;
        double r402319 = 2.0;
        double r402320 = r402318 * r402319;
        double r402321 = y;
        double r402322 = r402320 * r402321;
        double r402323 = r402318 - r402321;
        double r402324 = r402322 / r402323;
        return r402324;
}

double f(double x, double y) {
        double r402325 = y;
        double r402326 = -6.644564308512482e+31;
        bool r402327 = r402325 <= r402326;
        double r402328 = 2.9525005676724613e+29;
        bool r402329 = r402325 <= r402328;
        double r402330 = !r402329;
        bool r402331 = r402327 || r402330;
        double r402332 = x;
        double r402333 = 2.0;
        double r402334 = r402332 * r402333;
        double r402335 = 1.0;
        double r402336 = r402332 / r402325;
        double r402337 = r402336 - r402335;
        double r402338 = r402335 / r402337;
        double r402339 = r402334 * r402338;
        double r402340 = r402332 - r402325;
        double r402341 = r402334 / r402340;
        double r402342 = r402341 * r402325;
        double r402343 = r402331 ? r402339 : r402342;
        return r402343;
}

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.7
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.644564308512482e+31 or 2.9525005676724613e+29 < y

    1. Initial program 17.5

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

      \[\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(x \cdot 2\right)} \cdot \frac{y}{x - y}\]
    6. Using strategy rm
    7. Applied clear-num0.1

      \[\leadsto \left(x \cdot 2\right) \cdot \color{blue}{\frac{1}{\frac{x - y}{y}}}\]
    8. Using strategy rm
    9. Applied div-sub0.1

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

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

    if -6.644564308512482e+31 < y < 2.9525005676724613e+29

    1. Initial program 12.3

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

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

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

      \[\leadsto \color{blue}{\left(x \cdot 2\right)} \cdot \frac{y}{x - y}\]
    6. Using strategy rm
    7. Applied clear-num14.3

      \[\leadsto \left(x \cdot 2\right) \cdot \color{blue}{\frac{1}{\frac{x - y}{y}}}\]
    8. Using strategy rm
    9. Applied associate-/r/13.5

      \[\leadsto \left(x \cdot 2\right) \cdot \color{blue}{\left(\frac{1}{x - y} \cdot y\right)}\]
    10. Applied associate-*r*0.3

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -66445643085124824111628188385280 \lor \neg \left(y \le 295250056767246134706811437056\right):\\ \;\;\;\;\left(x \cdot 2\right) \cdot \frac{1}{\frac{x}{y} - 1}\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot 2}{x - y} \cdot y\\ \end{array}\]

Reproduce

herbie shell --seed 2019212 +o rules:numerics
(FPCore (x y)
  :name "Linear.Projection:perspective from linear-1.19.1.3, B"
  :precision binary64

  :herbie-target
  (if (< x -1.7210442634149447e81) (* (/ (* 2 x) (- x y)) y) (if (< x 83645045635564432) (/ (* x 2) (/ (- x y) y)) (* (/ (* 2 x) (- x y)) y)))

  (/ (* (* x 2) y) (- x y)))