Average Error: 15.3 → 1.6
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} \leq -2.4543606734273243 \cdot 10^{-132}:\\ \;\;\;\;\frac{x \cdot 2}{\frac{x - y}{y}}\\ \mathbf{elif}\;\frac{\left(x \cdot 2\right) \cdot y}{x - y} \leq -1.8649338853222587 \cdot 10^{-293}:\\ \;\;\;\;\frac{\left(x \cdot 2\right) \cdot y}{x - y}\\ \mathbf{elif}\;\frac{\left(x \cdot 2\right) \cdot y}{x - y} \leq 0:\\ \;\;\;\;\frac{x \cdot 2}{\frac{x - y}{y}}\\ \mathbf{elif}\;\frac{\left(x \cdot 2\right) \cdot y}{x - y} \leq 9.2288577322726 \cdot 10^{-101}:\\ \;\;\;\;\frac{\left(x \cdot 2\right) \cdot y}{x - y}\\ \mathbf{else}:\\ \;\;\;\;\left(x \cdot 2\right) \cdot \frac{y}{x - y}\\ \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} \leq -2.4543606734273243 \cdot 10^{-132}:\\
\;\;\;\;\frac{x \cdot 2}{\frac{x - y}{y}}\\

\mathbf{elif}\;\frac{\left(x \cdot 2\right) \cdot y}{x - y} \leq -1.8649338853222587 \cdot 10^{-293}:\\
\;\;\;\;\frac{\left(x \cdot 2\right) \cdot y}{x - y}\\

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

\mathbf{elif}\;\frac{\left(x \cdot 2\right) \cdot y}{x - y} \leq 9.2288577322726 \cdot 10^{-101}:\\
\;\;\;\;\frac{\left(x \cdot 2\right) \cdot y}{x - y}\\

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

\end{array}
(FPCore (x y) :precision binary64 (/ (* (* x 2.0) y) (- x y)))
(FPCore (x y)
 :precision binary64
 (if (<= (/ (* (* x 2.0) y) (- x y)) -2.4543606734273243e-132)
   (/ (* x 2.0) (/ (- x y) y))
   (if (<= (/ (* (* x 2.0) y) (- x y)) -1.8649338853222587e-293)
     (/ (* (* x 2.0) y) (- x y))
     (if (<= (/ (* (* x 2.0) y) (- x y)) 0.0)
       (/ (* x 2.0) (/ (- x y) y))
       (if (<= (/ (* (* x 2.0) y) (- x y)) 9.2288577322726e-101)
         (/ (* (* x 2.0) y) (- x y))
         (* (* x 2.0) (/ y (- x y))))))))
double code(double x, double y) {
	return ((x * 2.0) * y) / (x - y);
}
double code(double x, double y) {
	double tmp;
	if ((((x * 2.0) * y) / (x - y)) <= -2.4543606734273243e-132) {
		tmp = (x * 2.0) / ((x - y) / y);
	} else if ((((x * 2.0) * y) / (x - y)) <= -1.8649338853222587e-293) {
		tmp = ((x * 2.0) * y) / (x - y);
	} else if ((((x * 2.0) * y) / (x - y)) <= 0.0) {
		tmp = (x * 2.0) / ((x - y) / y);
	} else if ((((x * 2.0) * y) / (x - y)) <= 9.2288577322726e-101) {
		tmp = ((x * 2.0) * y) / (x - y);
	} else {
		tmp = (x * 2.0) * (y / (x - y));
	}
	return tmp;
}

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.3
Target0.3
Herbie1.6
\[\begin{array}{l} \mathbf{if}\;x < -1.7210442634149447 \cdot 10^{+81}:\\ \;\;\;\;\frac{2 \cdot x}{x - y} \cdot y\\ \mathbf{elif}\;x < 8.364504563556443 \cdot 10^{+16}:\\ \;\;\;\;\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 (/.f64 (*.f64 (*.f64 x 2) y) (-.f64 x y)) < -2.4543606734273243e-132 or -1.8649338853222587e-293 < (/.f64 (*.f64 (*.f64 x 2) y) (-.f64 x y)) < -0.0

    1. Initial program 28.3

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

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

    if -2.4543606734273243e-132 < (/.f64 (*.f64 (*.f64 x 2) y) (-.f64 x y)) < -1.8649338853222587e-293 or -0.0 < (/.f64 (*.f64 (*.f64 x 2) y) (-.f64 x y)) < 9.2288577322726003e-101

    1. Initial program 0.8

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

    if 9.2288577322726003e-101 < (/.f64 (*.f64 (*.f64 x 2) y) (-.f64 x y))

    1. Initial program 18.3

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

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

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

      \[\leadsto \color{blue}{\left(x \cdot 2\right)} \cdot \frac{y}{x - y}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification1.6

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{\left(x \cdot 2\right) \cdot y}{x - y} \leq -2.4543606734273243 \cdot 10^{-132}:\\ \;\;\;\;\frac{x \cdot 2}{\frac{x - y}{y}}\\ \mathbf{elif}\;\frac{\left(x \cdot 2\right) \cdot y}{x - y} \leq -1.8649338853222587 \cdot 10^{-293}:\\ \;\;\;\;\frac{\left(x \cdot 2\right) \cdot y}{x - y}\\ \mathbf{elif}\;\frac{\left(x \cdot 2\right) \cdot y}{x - y} \leq 0:\\ \;\;\;\;\frac{x \cdot 2}{\frac{x - y}{y}}\\ \mathbf{elif}\;\frac{\left(x \cdot 2\right) \cdot y}{x - y} \leq 9.2288577322726 \cdot 10^{-101}:\\ \;\;\;\;\frac{\left(x \cdot 2\right) \cdot y}{x - y}\\ \mathbf{else}:\\ \;\;\;\;\left(x \cdot 2\right) \cdot \frac{y}{x - y}\\ \end{array}\]

Reproduce

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