Average Error: 15.0 → 0.3
Time: 12.2s
Precision: 64
\[\frac{\left(x \cdot 2\right) \cdot y}{x - y}\]
\[\begin{array}{l} \mathbf{if}\;x \le -8.65788639203602374867804606149070922026 \cdot 10^{89}:\\ \;\;\;\;\frac{x}{x - y} \cdot \left(2 \cdot y\right)\\ \mathbf{elif}\;x \le 0.03126096436082478891016478428355185315013:\\ \;\;\;\;\left(x \cdot 2\right) \cdot \frac{y}{x - y}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{x - y} \cdot \left(2 \cdot y\right)\\ \end{array}\]
\frac{\left(x \cdot 2\right) \cdot y}{x - y}
\begin{array}{l}
\mathbf{if}\;x \le -8.65788639203602374867804606149070922026 \cdot 10^{89}:\\
\;\;\;\;\frac{x}{x - y} \cdot \left(2 \cdot y\right)\\

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

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

\end{array}
double f(double x, double y) {
        double r268112519 = x;
        double r268112520 = 2.0;
        double r268112521 = r268112519 * r268112520;
        double r268112522 = y;
        double r268112523 = r268112521 * r268112522;
        double r268112524 = r268112519 - r268112522;
        double r268112525 = r268112523 / r268112524;
        return r268112525;
}

double f(double x, double y) {
        double r268112526 = x;
        double r268112527 = -8.657886392036024e+89;
        bool r268112528 = r268112526 <= r268112527;
        double r268112529 = y;
        double r268112530 = r268112526 - r268112529;
        double r268112531 = r268112526 / r268112530;
        double r268112532 = 2.0;
        double r268112533 = r268112532 * r268112529;
        double r268112534 = r268112531 * r268112533;
        double r268112535 = 0.03126096436082479;
        bool r268112536 = r268112526 <= r268112535;
        double r268112537 = r268112526 * r268112532;
        double r268112538 = r268112529 / r268112530;
        double r268112539 = r268112537 * r268112538;
        double r268112540 = r268112536 ? r268112539 : r268112534;
        double r268112541 = r268112528 ? r268112534 : r268112540;
        return r268112541;
}

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.0
Target0.3
Herbie0.3
\[\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 x < -8.657886392036024e+89 or 0.03126096436082479 < x

    1. Initial program 17.9

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

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

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

      \[\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)}\]

    if -8.657886392036024e+89 < x < 0.03126096436082479

    1. Initial program 12.7

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

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

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

Reproduce

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