Average Error: 14.8 → 0.6
Time: 5.1s
Precision: 64
\[\frac{\left(x \cdot 2.0\right) \cdot y}{x - y}\]
\[\begin{array}{l} \mathbf{if}\;x \le -9.50828047314787 \cdot 10^{+45}:\\ \;\;\;\;\frac{2.0 \cdot x}{x - y} \cdot y\\ \mathbf{elif}\;x \le 9.799425869832502 \cdot 10^{+101}:\\ \;\;\;\;\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 -9.50828047314787 \cdot 10^{+45}:\\
\;\;\;\;\frac{2.0 \cdot x}{x - y} \cdot y\\

\mathbf{elif}\;x \le 9.799425869832502 \cdot 10^{+101}:\\
\;\;\;\;\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 r10353648 = x;
        double r10353649 = 2.0;
        double r10353650 = r10353648 * r10353649;
        double r10353651 = y;
        double r10353652 = r10353650 * r10353651;
        double r10353653 = r10353648 - r10353651;
        double r10353654 = r10353652 / r10353653;
        return r10353654;
}

double f(double x, double y) {
        double r10353655 = x;
        double r10353656 = -9.50828047314787e+45;
        bool r10353657 = r10353655 <= r10353656;
        double r10353658 = 2.0;
        double r10353659 = r10353658 * r10353655;
        double r10353660 = y;
        double r10353661 = r10353655 - r10353660;
        double r10353662 = r10353659 / r10353661;
        double r10353663 = r10353662 * r10353660;
        double r10353664 = 9.799425869832502e+101;
        bool r10353665 = r10353655 <= r10353664;
        double r10353666 = r10353655 / r10353660;
        double r10353667 = 1.0;
        double r10353668 = r10353666 - r10353667;
        double r10353669 = r10353659 / r10353668;
        double r10353670 = r10353665 ? r10353669 : r10353663;
        double r10353671 = r10353657 ? r10353663 : r10353670;
        return r10353671;
}

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.8
Target0.4
Herbie0.6
\[\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 < -9.50828047314787e+45 or 9.799425869832502e+101 < x

    1. Initial program 18.7

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

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

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

    if -9.50828047314787e+45 < x < 9.799425869832502e+101

    1. Initial program 12.4

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -9.50828047314787 \cdot 10^{+45}:\\ \;\;\;\;\frac{2.0 \cdot x}{x - y} \cdot y\\ \mathbf{elif}\;x \le 9.799425869832502 \cdot 10^{+101}:\\ \;\;\;\;\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 2019156 
(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)))