Average Error: 14.5 → 0.3
Time: 8.8s
Precision: 64
\[\frac{\left(x \cdot 2.0\right) \cdot y}{x - y}\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.435942788027777 \cdot 10^{+60}:\\ \;\;\;\;\frac{2.0 \cdot x}{x - y} \cdot y\\ \mathbf{elif}\;x \le 1.5452684980844889 \cdot 10^{+57}:\\ \;\;\;\;\frac{2.0 \cdot x}{\frac{x}{y} - 1}\\ \mathbf{else}:\\ \;\;\;\;\frac{2.0 \cdot x}{x - y} \cdot y\\ \end{array}\]
\frac{\left(x \cdot 2.0\right) \cdot y}{x - y}
\begin{array}{l}
\mathbf{if}\;x \le -1.435942788027777 \cdot 10^{+60}:\\
\;\;\;\;\frac{2.0 \cdot x}{x - y} \cdot y\\

\mathbf{elif}\;x \le 1.5452684980844889 \cdot 10^{+57}:\\
\;\;\;\;\frac{2.0 \cdot x}{\frac{x}{y} - 1}\\

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

\end{array}
double f(double x, double y) {
        double r23165321 = x;
        double r23165322 = 2.0;
        double r23165323 = r23165321 * r23165322;
        double r23165324 = y;
        double r23165325 = r23165323 * r23165324;
        double r23165326 = r23165321 - r23165324;
        double r23165327 = r23165325 / r23165326;
        return r23165327;
}

double f(double x, double y) {
        double r23165328 = x;
        double r23165329 = -1.435942788027777e+60;
        bool r23165330 = r23165328 <= r23165329;
        double r23165331 = 2.0;
        double r23165332 = r23165331 * r23165328;
        double r23165333 = y;
        double r23165334 = r23165328 - r23165333;
        double r23165335 = r23165332 / r23165334;
        double r23165336 = r23165335 * r23165333;
        double r23165337 = 1.5452684980844889e+57;
        bool r23165338 = r23165328 <= r23165337;
        double r23165339 = r23165328 / r23165333;
        double r23165340 = 1.0;
        double r23165341 = r23165339 - r23165340;
        double r23165342 = r23165332 / r23165341;
        double r23165343 = r23165338 ? r23165342 : r23165336;
        double r23165344 = r23165330 ? r23165336 : r23165343;
        return r23165344;
}

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.5
Target0.4
Herbie0.3
\[\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 x < -1.435942788027777e+60 or 1.5452684980844889e+57 < x

    1. Initial program 18.6

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

      \[\leadsto \color{blue}{\frac{x \cdot 2.0}{\frac{x - y}{y}}}\]
    4. Using strategy rm
    5. Applied associate-/r/0.0

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

    if -1.435942788027777e+60 < x < 1.5452684980844889e+57

    1. Initial program 11.8

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -1.435942788027777 \cdot 10^{+60}:\\ \;\;\;\;\frac{2.0 \cdot x}{x - y} \cdot y\\ \mathbf{elif}\;x \le 1.5452684980844889 \cdot 10^{+57}:\\ \;\;\;\;\frac{2.0 \cdot x}{\frac{x}{y} - 1}\\ \mathbf{else}:\\ \;\;\;\;\frac{2.0 \cdot x}{x - y} \cdot y\\ \end{array}\]

Reproduce

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