Average Error: 14.5 → 1.5
Time: 2.0s
Precision: binary64
\[\frac{\left(x \cdot 2\right) \cdot y}{x - y}\]
\[\begin{array}{l} \mathbf{if}\;\frac{\left(x \cdot 2\right) \cdot y}{x - y} = -inf.0:\\ \;\;\;\;x \cdot \left(2 \cdot \frac{y}{x - y}\right)\\ \mathbf{elif}\;\frac{\left(x \cdot 2\right) \cdot y}{x - y} \le -5.47750244133651812 \cdot 10^{-280} \lor \neg \left(\frac{\left(x \cdot 2\right) \cdot y}{x - y} \le 0.0\right) \land \frac{\left(x \cdot 2\right) \cdot y}{x - y} \le 1.3094332505667219 \cdot 10^{-117}:\\ \;\;\;\;\frac{\left(x \cdot 2\right) \cdot y}{x - y}\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot 2}{\frac{x}{y} + -1}\\ \end{array}\]
\frac{\left(x \cdot 2\right) \cdot y}{x - y}
\begin{array}{l}
\mathbf{if}\;\frac{\left(x \cdot 2\right) \cdot y}{x - y} = -inf.0:\\
\;\;\;\;x \cdot \left(2 \cdot \frac{y}{x - y}\right)\\

\mathbf{elif}\;\frac{\left(x \cdot 2\right) \cdot y}{x - y} \le -5.47750244133651812 \cdot 10^{-280} \lor \neg \left(\frac{\left(x \cdot 2\right) \cdot y}{x - y} \le 0.0\right) \land \frac{\left(x \cdot 2\right) \cdot y}{x - y} \le 1.3094332505667219 \cdot 10^{-117}:\\
\;\;\;\;\frac{\left(x \cdot 2\right) \cdot y}{x - y}\\

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

\end{array}
double code(double x, double y) {
	return ((double) (((double) (((double) (x * 2.0)) * y)) / ((double) (x - y))));
}
double code(double x, double y) {
	double VAR;
	if ((((double) (((double) (((double) (x * 2.0)) * y)) / ((double) (x - y)))) <= -inf.0)) {
		VAR = ((double) (x * ((double) (2.0 * ((double) (y / ((double) (x - y))))))));
	} else {
		double VAR_1;
		if (((((double) (((double) (((double) (x * 2.0)) * y)) / ((double) (x - y)))) <= -5.477502441336518e-280) || (!(((double) (((double) (((double) (x * 2.0)) * y)) / ((double) (x - y)))) <= 0.0) && (((double) (((double) (((double) (x * 2.0)) * y)) / ((double) (x - y)))) <= 1.3094332505667219e-117)))) {
			VAR_1 = ((double) (((double) (((double) (x * 2.0)) * y)) / ((double) (x - y))));
		} else {
			VAR_1 = ((double) (((double) (x * 2.0)) / ((double) (((double) (x / y)) + -1.0))));
		}
		VAR = VAR_1;
	}
	return VAR;
}

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.3
Herbie1.5
\[\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 3 regimes
  2. if (/ (* (* x 2.0) y) (- x y)) < -inf.0

    1. Initial program 64.0

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

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

    if -inf.0 < (/ (* (* x 2.0) y) (- x y)) < -5.47750244133651812e-280 or 0.0 < (/ (* (* x 2.0) y) (- x y)) < 1.3094332505667219e-117

    1. Initial program 0.5

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

    if -5.47750244133651812e-280 < (/ (* (* x 2.0) y) (- x y)) < 0.0 or 1.3094332505667219e-117 < (/ (* (* x 2.0) y) (- x y))

    1. Initial program 28.1

      \[\frac{\left(x \cdot 2\right) \cdot y}{x - y}\]
    2. Simplified3.0

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

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

      \[\leadsto x \cdot \left(2 \cdot \frac{1}{\color{blue}{\frac{x}{y} + -1}}\right)\]
    6. Using strategy rm
    7. Applied un-div-inv3.3

      \[\leadsto x \cdot \color{blue}{\frac{2}{\frac{x}{y} + -1}}\]
    8. Applied associate-*r/3.2

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{\left(x \cdot 2\right) \cdot y}{x - y} = -inf.0:\\ \;\;\;\;x \cdot \left(2 \cdot \frac{y}{x - y}\right)\\ \mathbf{elif}\;\frac{\left(x \cdot 2\right) \cdot y}{x - y} \le -5.47750244133651812 \cdot 10^{-280} \lor \neg \left(\frac{\left(x \cdot 2\right) \cdot y}{x - y} \le 0.0\right) \land \frac{\left(x \cdot 2\right) \cdot y}{x - y} \le 1.3094332505667219 \cdot 10^{-117}:\\ \;\;\;\;\frac{\left(x \cdot 2\right) \cdot y}{x - y}\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot 2}{\frac{x}{y} + -1}\\ \end{array}\]

Reproduce

herbie shell --seed 2020179 
(FPCore (x y)
  :name "Linear.Projection:perspective from linear-1.19.1.3, B"
  :precision binary64

  :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)))