Average Error: 14.1 → 0.6
Time: 1.9s
Precision: binary64
\[\frac{\left(x \cdot 2\right) \cdot y}{x - y} \]
\[\begin{array}{l} t_0 := \frac{\left(x \cdot 2\right) \cdot y}{x - y}\\ \mathbf{if}\;t_0 \leq -15378889091896465000 \lor \neg \left(t_0 \leq -2.3433687086619765 \cdot 10^{-304}\right) \land \left(t_0 \leq 1.1804029642238007 \cdot 10^{-306} \lor \neg \left(t_0 \leq 2.351100509470157 \cdot 10^{-43}\right)\right):\\ \;\;\;\;\frac{x}{\mathsf{fma}\left(0.5, \frac{x}{y}, -0.5\right)}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
\frac{\left(x \cdot 2\right) \cdot y}{x - y}
\begin{array}{l}
t_0 := \frac{\left(x \cdot 2\right) \cdot y}{x - y}\\
\mathbf{if}\;t_0 \leq -15378889091896465000 \lor \neg \left(t_0 \leq -2.3433687086619765 \cdot 10^{-304}\right) \land \left(t_0 \leq 1.1804029642238007 \cdot 10^{-306} \lor \neg \left(t_0 \leq 2.351100509470157 \cdot 10^{-43}\right)\right):\\
\;\;\;\;\frac{x}{\mathsf{fma}\left(0.5, \frac{x}{y}, -0.5\right)}\\

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}
(FPCore (x y) :precision binary64 (/ (* (* x 2.0) y) (- x y)))
(FPCore (x y)
 :precision binary64
 (let* ((t_0 (/ (* (* x 2.0) y) (- x y))))
   (if (or (<= t_0 -15378889091896465000.0)
           (and (not (<= t_0 -2.3433687086619765e-304))
                (or (<= t_0 1.1804029642238007e-306)
                    (not (<= t_0 2.351100509470157e-43)))))
     (/ x (fma 0.5 (/ x y) -0.5))
     t_0)))
double code(double x, double y) {
	return ((x * 2.0) * y) / (x - y);
}
double code(double x, double y) {
	double t_0 = ((x * 2.0) * y) / (x - y);
	double tmp;
	if ((t_0 <= -15378889091896465000.0) || (!(t_0 <= -2.3433687086619765e-304) && ((t_0 <= 1.1804029642238007e-306) || !(t_0 <= 2.351100509470157e-43)))) {
		tmp = x / fma(0.5, (x / y), -0.5);
	} else {
		tmp = t_0;
	}
	return tmp;
}

Error

Bits error versus x

Bits error versus y

Target

Original14.1
Target0.4
Herbie0.6
\[\begin{array}{l} \mathbf{if}\;x < -1.7210442634149447 \cdot 10^{+81}:\\ \;\;\;\;\frac{2 \cdot x}{x - y} \cdot y\\ \mathbf{elif}\;x < 83645045635564430:\\ \;\;\;\;\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 (/.f64 (*.f64 (*.f64 x 2) y) (-.f64 x y)) < -15378889091896465400 or -2.343368708661976e-304 < (/.f64 (*.f64 (*.f64 x 2) y) (-.f64 x y)) < 1.1804029642238007e-306 or 2.35110050947015712e-43 < (/.f64 (*.f64 (*.f64 x 2) y) (-.f64 x y))

    1. Initial program 35.7

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

      \[\leadsto \color{blue}{\frac{x}{\mathsf{fma}\left(0.5, \frac{x}{y}, -0.5\right)}} \]

    if -15378889091896465400 < (/.f64 (*.f64 (*.f64 x 2) y) (-.f64 x y)) < -2.343368708661976e-304 or 1.1804029642238007e-306 < (/.f64 (*.f64 (*.f64 x 2) y) (-.f64 x y)) < 2.35110050947015712e-43

    1. Initial program 0.5

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{\left(x \cdot 2\right) \cdot y}{x - y} \leq -15378889091896465000 \lor \neg \left(\frac{\left(x \cdot 2\right) \cdot y}{x - y} \leq -2.3433687086619765 \cdot 10^{-304}\right) \land \left(\frac{\left(x \cdot 2\right) \cdot y}{x - y} \leq 1.1804029642238007 \cdot 10^{-306} \lor \neg \left(\frac{\left(x \cdot 2\right) \cdot y}{x - y} \leq 2.351100509470157 \cdot 10^{-43}\right)\right):\\ \;\;\;\;\frac{x}{\mathsf{fma}\left(0.5, \frac{x}{y}, -0.5\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(x \cdot 2\right) \cdot y}{x - y}\\ \end{array} \]

Reproduce

herbie shell --seed 2022088 
(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 83645045635564430.0) (/ (* x 2.0) (/ (- x y) y)) (* (/ (* 2.0 x) (- x y)) y)))

  (/ (* (* x 2.0) y) (- x y)))