Average Error: 14.5 → 0.7
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 -1.3542256305448586 \cdot 10^{-31}:\\ \;\;\;\;\frac{x}{\mathsf{fma}\left(0.5, \frac{x}{y}, -0.5\right)}\\ \mathbf{elif}\;t_0 \leq -1.0227884392421375 \cdot 10^{-307}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\begin{array}{l} t_1 := \left(x \cdot 2\right) \cdot \frac{y}{x - y}\\ \mathbf{if}\;t_0 \leq 5.12291751958135 \cdot 10^{-306}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_0 \leq 1.0237315575092723 \cdot 10^{-53}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array}\\ \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 -1.3542256305448586 \cdot 10^{-31}:\\
\;\;\;\;\frac{x}{\mathsf{fma}\left(0.5, \frac{x}{y}, -0.5\right)}\\

\mathbf{elif}\;t_0 \leq -1.0227884392421375 \cdot 10^{-307}:\\
\;\;\;\;t_0\\

\mathbf{else}:\\
\;\;\;\;\begin{array}{l}
t_1 := \left(x \cdot 2\right) \cdot \frac{y}{x - y}\\
\mathbf{if}\;t_0 \leq 5.12291751958135 \cdot 10^{-306}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;t_0 \leq 1.0237315575092723 \cdot 10^{-53}:\\
\;\;\;\;t_0\\

\mathbf{else}:\\
\;\;\;\;t_1\\


\end{array}\\


\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 (<= t_0 -1.3542256305448586e-31)
     (/ x (fma 0.5 (/ x y) -0.5))
     (if (<= t_0 -1.0227884392421375e-307)
       t_0
       (let* ((t_1 (* (* x 2.0) (/ y (- x y)))))
         (if (<= t_0 5.12291751958135e-306)
           t_1
           (if (<= t_0 1.0237315575092723e-53) t_0 t_1)))))))
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 <= -1.3542256305448586e-31) {
		tmp = x / fma(0.5, (x / y), -0.5);
	} else if (t_0 <= -1.0227884392421375e-307) {
		tmp = t_0;
	} else {
		double t_1 = (x * 2.0) * (y / (x - y));
		double tmp_1;
		if (t_0 <= 5.12291751958135e-306) {
			tmp_1 = t_1;
		} else if (t_0 <= 1.0237315575092723e-53) {
			tmp_1 = t_0;
		} else {
			tmp_1 = t_1;
		}
		tmp = tmp_1;
	}
	return tmp;
}

Error

Bits error versus x

Bits error versus y

Target

Original14.5
Target0.3
Herbie0.7
\[\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 3 regimes
  2. if (/.f64 (*.f64 (*.f64 x 2) y) (-.f64 x y)) < -1.3542256305448586e-31

    1. Initial program 27.0

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

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

    if -1.3542256305448586e-31 < (/.f64 (*.f64 (*.f64 x 2) y) (-.f64 x y)) < -1.0227884392421375e-307 or 5.1229175195813498e-306 < (/.f64 (*.f64 (*.f64 x 2) y) (-.f64 x y)) < 1.02373155750927235e-53

    1. Initial program 0.7

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

    if -1.0227884392421375e-307 < (/.f64 (*.f64 (*.f64 x 2) y) (-.f64 x y)) < 5.1229175195813498e-306 or 1.02373155750927235e-53 < (/.f64 (*.f64 (*.f64 x 2) y) (-.f64 x y))

    1. Initial program 35.6

      \[\frac{\left(x \cdot 2\right) \cdot y}{x - y} \]
    2. Applied *-un-lft-identity_binary6435.6

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

      \[\leadsto \color{blue}{\frac{x \cdot 2}{1} \cdot \frac{y}{x - y}} \]
    4. Simplified0.8

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{\left(x \cdot 2\right) \cdot y}{x - y} \leq -1.3542256305448586 \cdot 10^{-31}:\\ \;\;\;\;\frac{x}{\mathsf{fma}\left(0.5, \frac{x}{y}, -0.5\right)}\\ \mathbf{elif}\;\frac{\left(x \cdot 2\right) \cdot y}{x - y} \leq -1.0227884392421375 \cdot 10^{-307}:\\ \;\;\;\;\frac{\left(x \cdot 2\right) \cdot y}{x - y}\\ \mathbf{elif}\;\frac{\left(x \cdot 2\right) \cdot y}{x - y} \leq 5.12291751958135 \cdot 10^{-306}:\\ \;\;\;\;\left(x \cdot 2\right) \cdot \frac{y}{x - y}\\ \mathbf{elif}\;\frac{\left(x \cdot 2\right) \cdot y}{x - y} \leq 1.0237315575092723 \cdot 10^{-53}:\\ \;\;\;\;\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 2022076 
(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)))