Graphics.Rendering.Chart.Plot.AreaSpots:renderSpotLegend from Chart-1.5.3

Percentage Accurate: 99.9% → 99.9%
Time: 5.8s
Alternatives: 6
Speedup: 1.7×

Specification

?
\[\begin{array}{l} \\ x + \frac{\left|y - x\right|}{2} \end{array} \]
(FPCore (x y) :precision binary64 (+ x (/ (fabs (- y x)) 2.0)))
double code(double x, double y) {
	return x + (fabs((y - x)) / 2.0);
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    code = x + (abs((y - x)) / 2.0d0)
end function
public static double code(double x, double y) {
	return x + (Math.abs((y - x)) / 2.0);
}
def code(x, y):
	return x + (math.fabs((y - x)) / 2.0)
function code(x, y)
	return Float64(x + Float64(abs(Float64(y - x)) / 2.0))
end
function tmp = code(x, y)
	tmp = x + (abs((y - x)) / 2.0);
end
code[x_, y_] := N[(x + N[(N[Abs[N[(y - x), $MachinePrecision]], $MachinePrecision] / 2.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
x + \frac{\left|y - x\right|}{2}
\end{array}

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 6 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 99.9% accurate, 1.0× speedup?

\[\begin{array}{l} \\ x + \frac{\left|y - x\right|}{2} \end{array} \]
(FPCore (x y) :precision binary64 (+ x (/ (fabs (- y x)) 2.0)))
double code(double x, double y) {
	return x + (fabs((y - x)) / 2.0);
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    code = x + (abs((y - x)) / 2.0d0)
end function
public static double code(double x, double y) {
	return x + (Math.abs((y - x)) / 2.0);
}
def code(x, y):
	return x + (math.fabs((y - x)) / 2.0)
function code(x, y)
	return Float64(x + Float64(abs(Float64(y - x)) / 2.0))
end
function tmp = code(x, y)
	tmp = x + (abs((y - x)) / 2.0);
end
code[x_, y_] := N[(x + N[(N[Abs[N[(y - x), $MachinePrecision]], $MachinePrecision] / 2.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
x + \frac{\left|y - x\right|}{2}
\end{array}

Alternative 1: 99.9% accurate, 1.7× speedup?

\[\begin{array}{l} \\ \mathsf{fma}\left(\left|y - x\right|, 0.5, x\right) \end{array} \]
(FPCore (x y) :precision binary64 (fma (fabs (- y x)) 0.5 x))
double code(double x, double y) {
	return fma(fabs((y - x)), 0.5, x);
}
function code(x, y)
	return fma(abs(Float64(y - x)), 0.5, x)
end
code[x_, y_] := N[(N[Abs[N[(y - x), $MachinePrecision]], $MachinePrecision] * 0.5 + x), $MachinePrecision]
\begin{array}{l}

\\
\mathsf{fma}\left(\left|y - x\right|, 0.5, x\right)
\end{array}
Derivation
  1. Initial program 99.9%

    \[x + \frac{\left|y - x\right|}{2} \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. lift-+.f64N/A

      \[\leadsto \color{blue}{x + \frac{\left|y - x\right|}{2}} \]
    2. +-commutativeN/A

      \[\leadsto \color{blue}{\frac{\left|y - x\right|}{2} + x} \]
    3. lift-/.f64N/A

      \[\leadsto \color{blue}{\frac{\left|y - x\right|}{2}} + x \]
    4. div-invN/A

      \[\leadsto \color{blue}{\left|y - x\right| \cdot \frac{1}{2}} + x \]
    5. lower-fma.f64N/A

      \[\leadsto \color{blue}{\mathsf{fma}\left(\left|y - x\right|, \frac{1}{2}, x\right)} \]
    6. lift-fabs.f64N/A

      \[\leadsto \mathsf{fma}\left(\color{blue}{\left|y - x\right|}, \frac{1}{2}, x\right) \]
    7. neg-fabsN/A

      \[\leadsto \mathsf{fma}\left(\color{blue}{\left|\mathsf{neg}\left(\left(y - x\right)\right)\right|}, \frac{1}{2}, x\right) \]
    8. lower-fabs.f64N/A

      \[\leadsto \mathsf{fma}\left(\color{blue}{\left|\mathsf{neg}\left(\left(y - x\right)\right)\right|}, \frac{1}{2}, x\right) \]
    9. lift--.f64N/A

      \[\leadsto \mathsf{fma}\left(\left|\mathsf{neg}\left(\color{blue}{\left(y - x\right)}\right)\right|, \frac{1}{2}, x\right) \]
    10. sub-negN/A

      \[\leadsto \mathsf{fma}\left(\left|\mathsf{neg}\left(\color{blue}{\left(y + \left(\mathsf{neg}\left(x\right)\right)\right)}\right)\right|, \frac{1}{2}, x\right) \]
    11. +-commutativeN/A

      \[\leadsto \mathsf{fma}\left(\left|\mathsf{neg}\left(\color{blue}{\left(\left(\mathsf{neg}\left(x\right)\right) + y\right)}\right)\right|, \frac{1}{2}, x\right) \]
    12. distribute-neg-inN/A

      \[\leadsto \mathsf{fma}\left(\left|\color{blue}{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(x\right)\right)\right)\right) + \left(\mathsf{neg}\left(y\right)\right)}\right|, \frac{1}{2}, x\right) \]
    13. remove-double-negN/A

      \[\leadsto \mathsf{fma}\left(\left|\color{blue}{x} + \left(\mathsf{neg}\left(y\right)\right)\right|, \frac{1}{2}, x\right) \]
    14. sub-negN/A

      \[\leadsto \mathsf{fma}\left(\left|\color{blue}{x - y}\right|, \frac{1}{2}, x\right) \]
    15. lower--.f64N/A

      \[\leadsto \mathsf{fma}\left(\left|\color{blue}{x - y}\right|, \frac{1}{2}, x\right) \]
    16. metadata-eval99.9

      \[\leadsto \mathsf{fma}\left(\left|x - y\right|, \color{blue}{0.5}, x\right) \]
  4. Applied rewrites99.9%

    \[\leadsto \color{blue}{\mathsf{fma}\left(\left|x - y\right|, 0.5, x\right)} \]
  5. Final simplification99.9%

    \[\leadsto \mathsf{fma}\left(\left|y - x\right|, 0.5, x\right) \]
  6. Add Preprocessing

Alternative 2: 71.2% accurate, 1.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq 1.75 \cdot 10^{-218}:\\ \;\;\;\;\mathsf{fma}\left(1.5, x, -0.5 \cdot y\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\left|-y\right|, 0.5, x\right)\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (if (<= y 1.75e-218) (fma 1.5 x (* -0.5 y)) (fma (fabs (- y)) 0.5 x)))
double code(double x, double y) {
	double tmp;
	if (y <= 1.75e-218) {
		tmp = fma(1.5, x, (-0.5 * y));
	} else {
		tmp = fma(fabs(-y), 0.5, x);
	}
	return tmp;
}
function code(x, y)
	tmp = 0.0
	if (y <= 1.75e-218)
		tmp = fma(1.5, x, Float64(-0.5 * y));
	else
		tmp = fma(abs(Float64(-y)), 0.5, x);
	end
	return tmp
end
code[x_, y_] := If[LessEqual[y, 1.75e-218], N[(1.5 * x + N[(-0.5 * y), $MachinePrecision]), $MachinePrecision], N[(N[Abs[(-y)], $MachinePrecision] * 0.5 + x), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.75 \cdot 10^{-218}:\\
\;\;\;\;\mathsf{fma}\left(1.5, x, -0.5 \cdot y\right)\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\left|-y\right|, 0.5, x\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < 1.75e-218

    1. Initial program 99.9%

      \[x + \frac{\left|y - x\right|}{2} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. lift-+.f64N/A

        \[\leadsto \color{blue}{x + \frac{\left|y - x\right|}{2}} \]
      2. +-commutativeN/A

        \[\leadsto \color{blue}{\frac{\left|y - x\right|}{2} + x} \]
      3. lift-/.f64N/A

        \[\leadsto \color{blue}{\frac{\left|y - x\right|}{2}} + x \]
      4. div-invN/A

        \[\leadsto \color{blue}{\left|y - x\right| \cdot \frac{1}{2}} + x \]
      5. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(\left|y - x\right|, \frac{1}{2}, x\right)} \]
      6. lift-fabs.f64N/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{\left|y - x\right|}, \frac{1}{2}, x\right) \]
      7. neg-fabsN/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{\left|\mathsf{neg}\left(\left(y - x\right)\right)\right|}, \frac{1}{2}, x\right) \]
      8. lower-fabs.f64N/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{\left|\mathsf{neg}\left(\left(y - x\right)\right)\right|}, \frac{1}{2}, x\right) \]
      9. lift--.f64N/A

        \[\leadsto \mathsf{fma}\left(\left|\mathsf{neg}\left(\color{blue}{\left(y - x\right)}\right)\right|, \frac{1}{2}, x\right) \]
      10. sub-negN/A

        \[\leadsto \mathsf{fma}\left(\left|\mathsf{neg}\left(\color{blue}{\left(y + \left(\mathsf{neg}\left(x\right)\right)\right)}\right)\right|, \frac{1}{2}, x\right) \]
      11. +-commutativeN/A

        \[\leadsto \mathsf{fma}\left(\left|\mathsf{neg}\left(\color{blue}{\left(\left(\mathsf{neg}\left(x\right)\right) + y\right)}\right)\right|, \frac{1}{2}, x\right) \]
      12. distribute-neg-inN/A

        \[\leadsto \mathsf{fma}\left(\left|\color{blue}{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(x\right)\right)\right)\right) + \left(\mathsf{neg}\left(y\right)\right)}\right|, \frac{1}{2}, x\right) \]
      13. remove-double-negN/A

        \[\leadsto \mathsf{fma}\left(\left|\color{blue}{x} + \left(\mathsf{neg}\left(y\right)\right)\right|, \frac{1}{2}, x\right) \]
      14. sub-negN/A

        \[\leadsto \mathsf{fma}\left(\left|\color{blue}{x - y}\right|, \frac{1}{2}, x\right) \]
      15. lower--.f64N/A

        \[\leadsto \mathsf{fma}\left(\left|\color{blue}{x - y}\right|, \frac{1}{2}, x\right) \]
      16. metadata-eval99.9

        \[\leadsto \mathsf{fma}\left(\left|x - y\right|, \color{blue}{0.5}, x\right) \]
    4. Applied rewrites99.9%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\left|x - y\right|, 0.5, x\right)} \]
    5. Step-by-step derivation
      1. lift-fma.f64N/A

        \[\leadsto \color{blue}{\left|x - y\right| \cdot \frac{1}{2} + x} \]
      2. *-commutativeN/A

        \[\leadsto \color{blue}{\frac{1}{2} \cdot \left|x - y\right|} + x \]
      3. lift-*.f64N/A

        \[\leadsto \color{blue}{\frac{1}{2} \cdot \left|x - y\right|} + x \]
      4. rem-square-sqrtN/A

        \[\leadsto \color{blue}{\sqrt{\frac{1}{2} \cdot \left|x - y\right|} \cdot \sqrt{\frac{1}{2} \cdot \left|x - y\right|}} + x \]
      5. sqrt-unprodN/A

        \[\leadsto \color{blue}{\sqrt{\left(\frac{1}{2} \cdot \left|x - y\right|\right) \cdot \left(\frac{1}{2} \cdot \left|x - y\right|\right)}} + x \]
      6. lift-*.f64N/A

        \[\leadsto \sqrt{\color{blue}{\left(\frac{1}{2} \cdot \left|x - y\right|\right)} \cdot \left(\frac{1}{2} \cdot \left|x - y\right|\right)} + x \]
      7. *-commutativeN/A

        \[\leadsto \sqrt{\color{blue}{\left(\left|x - y\right| \cdot \frac{1}{2}\right)} \cdot \left(\frac{1}{2} \cdot \left|x - y\right|\right)} + x \]
      8. associate-*l*N/A

        \[\leadsto \sqrt{\color{blue}{\left|x - y\right| \cdot \left(\frac{1}{2} \cdot \left(\frac{1}{2} \cdot \left|x - y\right|\right)\right)}} + x \]
      9. sqrt-prodN/A

        \[\leadsto \color{blue}{\sqrt{\left|x - y\right|} \cdot \sqrt{\frac{1}{2} \cdot \left(\frac{1}{2} \cdot \left|x - y\right|\right)}} + x \]
      10. unpow1/2N/A

        \[\leadsto \color{blue}{{\left(\left|x - y\right|\right)}^{\frac{1}{2}}} \cdot \sqrt{\frac{1}{2} \cdot \left(\frac{1}{2} \cdot \left|x - y\right|\right)} + x \]
      11. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left({\left(\left|x - y\right|\right)}^{\frac{1}{2}}, \sqrt{\frac{1}{2} \cdot \left(\frac{1}{2} \cdot \left|x - y\right|\right)}, x\right)} \]
    6. Applied rewrites73.7%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\sqrt{x - y}, \sqrt{0.5 \cdot \left(0.5 \cdot \left(x - y\right)\right)}, x\right)} \]
    7. Taylor expanded in x around 0

      \[\leadsto \color{blue}{\frac{-1}{2} \cdot y + \frac{3}{2} \cdot x} \]
    8. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto \color{blue}{\frac{3}{2} \cdot x + \frac{-1}{2} \cdot y} \]
      2. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{3}{2}, x, \frac{-1}{2} \cdot y\right)} \]
      3. lower-*.f6478.7

        \[\leadsto \mathsf{fma}\left(1.5, x, \color{blue}{-0.5 \cdot y}\right) \]
    9. Applied rewrites78.7%

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

    if 1.75e-218 < y

    1. Initial program 99.9%

      \[x + \frac{\left|y - x\right|}{2} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. lift-+.f64N/A

        \[\leadsto \color{blue}{x + \frac{\left|y - x\right|}{2}} \]
      2. +-commutativeN/A

        \[\leadsto \color{blue}{\frac{\left|y - x\right|}{2} + x} \]
      3. lift-/.f64N/A

        \[\leadsto \color{blue}{\frac{\left|y - x\right|}{2}} + x \]
      4. div-invN/A

        \[\leadsto \color{blue}{\left|y - x\right| \cdot \frac{1}{2}} + x \]
      5. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(\left|y - x\right|, \frac{1}{2}, x\right)} \]
      6. lift-fabs.f64N/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{\left|y - x\right|}, \frac{1}{2}, x\right) \]
      7. neg-fabsN/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{\left|\mathsf{neg}\left(\left(y - x\right)\right)\right|}, \frac{1}{2}, x\right) \]
      8. lower-fabs.f64N/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{\left|\mathsf{neg}\left(\left(y - x\right)\right)\right|}, \frac{1}{2}, x\right) \]
      9. lift--.f64N/A

        \[\leadsto \mathsf{fma}\left(\left|\mathsf{neg}\left(\color{blue}{\left(y - x\right)}\right)\right|, \frac{1}{2}, x\right) \]
      10. sub-negN/A

        \[\leadsto \mathsf{fma}\left(\left|\mathsf{neg}\left(\color{blue}{\left(y + \left(\mathsf{neg}\left(x\right)\right)\right)}\right)\right|, \frac{1}{2}, x\right) \]
      11. +-commutativeN/A

        \[\leadsto \mathsf{fma}\left(\left|\mathsf{neg}\left(\color{blue}{\left(\left(\mathsf{neg}\left(x\right)\right) + y\right)}\right)\right|, \frac{1}{2}, x\right) \]
      12. distribute-neg-inN/A

        \[\leadsto \mathsf{fma}\left(\left|\color{blue}{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(x\right)\right)\right)\right) + \left(\mathsf{neg}\left(y\right)\right)}\right|, \frac{1}{2}, x\right) \]
      13. remove-double-negN/A

        \[\leadsto \mathsf{fma}\left(\left|\color{blue}{x} + \left(\mathsf{neg}\left(y\right)\right)\right|, \frac{1}{2}, x\right) \]
      14. sub-negN/A

        \[\leadsto \mathsf{fma}\left(\left|\color{blue}{x - y}\right|, \frac{1}{2}, x\right) \]
      15. lower--.f64N/A

        \[\leadsto \mathsf{fma}\left(\left|\color{blue}{x - y}\right|, \frac{1}{2}, x\right) \]
      16. metadata-eval99.9

        \[\leadsto \mathsf{fma}\left(\left|x - y\right|, \color{blue}{0.5}, x\right) \]
    4. Applied rewrites99.9%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\left|x - y\right|, 0.5, x\right)} \]
    5. Taylor expanded in x around 0

      \[\leadsto \mathsf{fma}\left(\left|\color{blue}{-1 \cdot y}\right|, \frac{1}{2}, x\right) \]
    6. Step-by-step derivation
      1. mul-1-negN/A

        \[\leadsto \mathsf{fma}\left(\left|\color{blue}{\mathsf{neg}\left(y\right)}\right|, \frac{1}{2}, x\right) \]
      2. lower-neg.f6469.1

        \[\leadsto \mathsf{fma}\left(\left|\color{blue}{-y}\right|, 0.5, x\right) \]
    7. Applied rewrites69.1%

      \[\leadsto \mathsf{fma}\left(\left|\color{blue}{-y}\right|, 0.5, x\right) \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 3: 71.2% accurate, 1.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq 1.75 \cdot 10^{-218}:\\ \;\;\;\;\mathsf{fma}\left(x - y, 0.5, x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\left|-y\right|, 0.5, x\right)\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (if (<= y 1.75e-218) (fma (- x y) 0.5 x) (fma (fabs (- y)) 0.5 x)))
double code(double x, double y) {
	double tmp;
	if (y <= 1.75e-218) {
		tmp = fma((x - y), 0.5, x);
	} else {
		tmp = fma(fabs(-y), 0.5, x);
	}
	return tmp;
}
function code(x, y)
	tmp = 0.0
	if (y <= 1.75e-218)
		tmp = fma(Float64(x - y), 0.5, x);
	else
		tmp = fma(abs(Float64(-y)), 0.5, x);
	end
	return tmp
end
code[x_, y_] := If[LessEqual[y, 1.75e-218], N[(N[(x - y), $MachinePrecision] * 0.5 + x), $MachinePrecision], N[(N[Abs[(-y)], $MachinePrecision] * 0.5 + x), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.75 \cdot 10^{-218}:\\
\;\;\;\;\mathsf{fma}\left(x - y, 0.5, x\right)\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\left|-y\right|, 0.5, x\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < 1.75e-218

    1. Initial program 99.9%

      \[x + \frac{\left|y - x\right|}{2} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. lift-+.f64N/A

        \[\leadsto \color{blue}{x + \frac{\left|y - x\right|}{2}} \]
      2. +-commutativeN/A

        \[\leadsto \color{blue}{\frac{\left|y - x\right|}{2} + x} \]
      3. lift-/.f64N/A

        \[\leadsto \color{blue}{\frac{\left|y - x\right|}{2}} + x \]
      4. div-invN/A

        \[\leadsto \color{blue}{\left|y - x\right| \cdot \frac{1}{2}} + x \]
      5. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(\left|y - x\right|, \frac{1}{2}, x\right)} \]
      6. lift-fabs.f64N/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{\left|y - x\right|}, \frac{1}{2}, x\right) \]
      7. neg-fabsN/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{\left|\mathsf{neg}\left(\left(y - x\right)\right)\right|}, \frac{1}{2}, x\right) \]
      8. lower-fabs.f64N/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{\left|\mathsf{neg}\left(\left(y - x\right)\right)\right|}, \frac{1}{2}, x\right) \]
      9. lift--.f64N/A

        \[\leadsto \mathsf{fma}\left(\left|\mathsf{neg}\left(\color{blue}{\left(y - x\right)}\right)\right|, \frac{1}{2}, x\right) \]
      10. sub-negN/A

        \[\leadsto \mathsf{fma}\left(\left|\mathsf{neg}\left(\color{blue}{\left(y + \left(\mathsf{neg}\left(x\right)\right)\right)}\right)\right|, \frac{1}{2}, x\right) \]
      11. +-commutativeN/A

        \[\leadsto \mathsf{fma}\left(\left|\mathsf{neg}\left(\color{blue}{\left(\left(\mathsf{neg}\left(x\right)\right) + y\right)}\right)\right|, \frac{1}{2}, x\right) \]
      12. distribute-neg-inN/A

        \[\leadsto \mathsf{fma}\left(\left|\color{blue}{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(x\right)\right)\right)\right) + \left(\mathsf{neg}\left(y\right)\right)}\right|, \frac{1}{2}, x\right) \]
      13. remove-double-negN/A

        \[\leadsto \mathsf{fma}\left(\left|\color{blue}{x} + \left(\mathsf{neg}\left(y\right)\right)\right|, \frac{1}{2}, x\right) \]
      14. sub-negN/A

        \[\leadsto \mathsf{fma}\left(\left|\color{blue}{x - y}\right|, \frac{1}{2}, x\right) \]
      15. lower--.f64N/A

        \[\leadsto \mathsf{fma}\left(\left|\color{blue}{x - y}\right|, \frac{1}{2}, x\right) \]
      16. metadata-eval99.9

        \[\leadsto \mathsf{fma}\left(\left|x - y\right|, \color{blue}{0.5}, x\right) \]
    4. Applied rewrites99.9%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\left|x - y\right|, 0.5, x\right)} \]
    5. Step-by-step derivation
      1. lift-fabs.f64N/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{\left|x - y\right|}, \frac{1}{2}, x\right) \]
      2. unpow1N/A

        \[\leadsto \mathsf{fma}\left(\left|\color{blue}{{\left(x - y\right)}^{1}}\right|, \frac{1}{2}, x\right) \]
      3. sqr-powN/A

        \[\leadsto \mathsf{fma}\left(\left|\color{blue}{{\left(x - y\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(x - y\right)}^{\left(\frac{1}{2}\right)}}\right|, \frac{1}{2}, x\right) \]
      4. fabs-sqrN/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{{\left(x - y\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(x - y\right)}^{\left(\frac{1}{2}\right)}}, \frac{1}{2}, x\right) \]
      5. sqr-powN/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{{\left(x - y\right)}^{1}}, \frac{1}{2}, x\right) \]
      6. unpow178.6

        \[\leadsto \mathsf{fma}\left(\color{blue}{x - y}, 0.5, x\right) \]
    6. Applied rewrites78.6%

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

    if 1.75e-218 < y

    1. Initial program 99.9%

      \[x + \frac{\left|y - x\right|}{2} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. lift-+.f64N/A

        \[\leadsto \color{blue}{x + \frac{\left|y - x\right|}{2}} \]
      2. +-commutativeN/A

        \[\leadsto \color{blue}{\frac{\left|y - x\right|}{2} + x} \]
      3. lift-/.f64N/A

        \[\leadsto \color{blue}{\frac{\left|y - x\right|}{2}} + x \]
      4. div-invN/A

        \[\leadsto \color{blue}{\left|y - x\right| \cdot \frac{1}{2}} + x \]
      5. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(\left|y - x\right|, \frac{1}{2}, x\right)} \]
      6. lift-fabs.f64N/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{\left|y - x\right|}, \frac{1}{2}, x\right) \]
      7. neg-fabsN/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{\left|\mathsf{neg}\left(\left(y - x\right)\right)\right|}, \frac{1}{2}, x\right) \]
      8. lower-fabs.f64N/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{\left|\mathsf{neg}\left(\left(y - x\right)\right)\right|}, \frac{1}{2}, x\right) \]
      9. lift--.f64N/A

        \[\leadsto \mathsf{fma}\left(\left|\mathsf{neg}\left(\color{blue}{\left(y - x\right)}\right)\right|, \frac{1}{2}, x\right) \]
      10. sub-negN/A

        \[\leadsto \mathsf{fma}\left(\left|\mathsf{neg}\left(\color{blue}{\left(y + \left(\mathsf{neg}\left(x\right)\right)\right)}\right)\right|, \frac{1}{2}, x\right) \]
      11. +-commutativeN/A

        \[\leadsto \mathsf{fma}\left(\left|\mathsf{neg}\left(\color{blue}{\left(\left(\mathsf{neg}\left(x\right)\right) + y\right)}\right)\right|, \frac{1}{2}, x\right) \]
      12. distribute-neg-inN/A

        \[\leadsto \mathsf{fma}\left(\left|\color{blue}{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(x\right)\right)\right)\right) + \left(\mathsf{neg}\left(y\right)\right)}\right|, \frac{1}{2}, x\right) \]
      13. remove-double-negN/A

        \[\leadsto \mathsf{fma}\left(\left|\color{blue}{x} + \left(\mathsf{neg}\left(y\right)\right)\right|, \frac{1}{2}, x\right) \]
      14. sub-negN/A

        \[\leadsto \mathsf{fma}\left(\left|\color{blue}{x - y}\right|, \frac{1}{2}, x\right) \]
      15. lower--.f64N/A

        \[\leadsto \mathsf{fma}\left(\left|\color{blue}{x - y}\right|, \frac{1}{2}, x\right) \]
      16. metadata-eval99.9

        \[\leadsto \mathsf{fma}\left(\left|x - y\right|, \color{blue}{0.5}, x\right) \]
    4. Applied rewrites99.9%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\left|x - y\right|, 0.5, x\right)} \]
    5. Taylor expanded in x around 0

      \[\leadsto \mathsf{fma}\left(\left|\color{blue}{-1 \cdot y}\right|, \frac{1}{2}, x\right) \]
    6. Step-by-step derivation
      1. mul-1-negN/A

        \[\leadsto \mathsf{fma}\left(\left|\color{blue}{\mathsf{neg}\left(y\right)}\right|, \frac{1}{2}, x\right) \]
      2. lower-neg.f6469.1

        \[\leadsto \mathsf{fma}\left(\left|\color{blue}{-y}\right|, 0.5, x\right) \]
    7. Applied rewrites69.1%

      \[\leadsto \mathsf{fma}\left(\left|\color{blue}{-y}\right|, 0.5, x\right) \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 4: 45.8% accurate, 1.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -1.04 \cdot 10^{-100}:\\ \;\;\;\;-0.5 \cdot y\\ \mathbf{else}:\\ \;\;\;\;1.5 \cdot x\\ \end{array} \end{array} \]
(FPCore (x y) :precision binary64 (if (<= y -1.04e-100) (* -0.5 y) (* 1.5 x)))
double code(double x, double y) {
	double tmp;
	if (y <= -1.04e-100) {
		tmp = -0.5 * y;
	} else {
		tmp = 1.5 * x;
	}
	return tmp;
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8) :: tmp
    if (y <= (-1.04d-100)) then
        tmp = (-0.5d0) * y
    else
        tmp = 1.5d0 * x
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double tmp;
	if (y <= -1.04e-100) {
		tmp = -0.5 * y;
	} else {
		tmp = 1.5 * x;
	}
	return tmp;
}
def code(x, y):
	tmp = 0
	if y <= -1.04e-100:
		tmp = -0.5 * y
	else:
		tmp = 1.5 * x
	return tmp
function code(x, y)
	tmp = 0.0
	if (y <= -1.04e-100)
		tmp = Float64(-0.5 * y);
	else
		tmp = Float64(1.5 * x);
	end
	return tmp
end
function tmp_2 = code(x, y)
	tmp = 0.0;
	if (y <= -1.04e-100)
		tmp = -0.5 * y;
	else
		tmp = 1.5 * x;
	end
	tmp_2 = tmp;
end
code[x_, y_] := If[LessEqual[y, -1.04e-100], N[(-0.5 * y), $MachinePrecision], N[(1.5 * x), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.04 \cdot 10^{-100}:\\
\;\;\;\;-0.5 \cdot y\\

\mathbf{else}:\\
\;\;\;\;1.5 \cdot x\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -1.04e-100

    1. Initial program 99.9%

      \[x + \frac{\left|y - x\right|}{2} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. lift-+.f64N/A

        \[\leadsto \color{blue}{x + \frac{\left|y - x\right|}{2}} \]
      2. +-commutativeN/A

        \[\leadsto \color{blue}{\frac{\left|y - x\right|}{2} + x} \]
      3. lift-/.f64N/A

        \[\leadsto \color{blue}{\frac{\left|y - x\right|}{2}} + x \]
      4. div-invN/A

        \[\leadsto \color{blue}{\left|y - x\right| \cdot \frac{1}{2}} + x \]
      5. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(\left|y - x\right|, \frac{1}{2}, x\right)} \]
      6. lift-fabs.f64N/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{\left|y - x\right|}, \frac{1}{2}, x\right) \]
      7. neg-fabsN/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{\left|\mathsf{neg}\left(\left(y - x\right)\right)\right|}, \frac{1}{2}, x\right) \]
      8. lower-fabs.f64N/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{\left|\mathsf{neg}\left(\left(y - x\right)\right)\right|}, \frac{1}{2}, x\right) \]
      9. lift--.f64N/A

        \[\leadsto \mathsf{fma}\left(\left|\mathsf{neg}\left(\color{blue}{\left(y - x\right)}\right)\right|, \frac{1}{2}, x\right) \]
      10. sub-negN/A

        \[\leadsto \mathsf{fma}\left(\left|\mathsf{neg}\left(\color{blue}{\left(y + \left(\mathsf{neg}\left(x\right)\right)\right)}\right)\right|, \frac{1}{2}, x\right) \]
      11. +-commutativeN/A

        \[\leadsto \mathsf{fma}\left(\left|\mathsf{neg}\left(\color{blue}{\left(\left(\mathsf{neg}\left(x\right)\right) + y\right)}\right)\right|, \frac{1}{2}, x\right) \]
      12. distribute-neg-inN/A

        \[\leadsto \mathsf{fma}\left(\left|\color{blue}{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(x\right)\right)\right)\right) + \left(\mathsf{neg}\left(y\right)\right)}\right|, \frac{1}{2}, x\right) \]
      13. remove-double-negN/A

        \[\leadsto \mathsf{fma}\left(\left|\color{blue}{x} + \left(\mathsf{neg}\left(y\right)\right)\right|, \frac{1}{2}, x\right) \]
      14. sub-negN/A

        \[\leadsto \mathsf{fma}\left(\left|\color{blue}{x - y}\right|, \frac{1}{2}, x\right) \]
      15. lower--.f64N/A

        \[\leadsto \mathsf{fma}\left(\left|\color{blue}{x - y}\right|, \frac{1}{2}, x\right) \]
      16. metadata-eval99.9

        \[\leadsto \mathsf{fma}\left(\left|x - y\right|, \color{blue}{0.5}, x\right) \]
    4. Applied rewrites99.9%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\left|x - y\right|, 0.5, x\right)} \]
    5. Step-by-step derivation
      1. lift-fma.f64N/A

        \[\leadsto \color{blue}{\left|x - y\right| \cdot \frac{1}{2} + x} \]
      2. *-commutativeN/A

        \[\leadsto \color{blue}{\frac{1}{2} \cdot \left|x - y\right|} + x \]
      3. lift-*.f64N/A

        \[\leadsto \color{blue}{\frac{1}{2} \cdot \left|x - y\right|} + x \]
      4. rem-square-sqrtN/A

        \[\leadsto \color{blue}{\sqrt{\frac{1}{2} \cdot \left|x - y\right|} \cdot \sqrt{\frac{1}{2} \cdot \left|x - y\right|}} + x \]
      5. sqrt-unprodN/A

        \[\leadsto \color{blue}{\sqrt{\left(\frac{1}{2} \cdot \left|x - y\right|\right) \cdot \left(\frac{1}{2} \cdot \left|x - y\right|\right)}} + x \]
      6. lift-*.f64N/A

        \[\leadsto \sqrt{\color{blue}{\left(\frac{1}{2} \cdot \left|x - y\right|\right)} \cdot \left(\frac{1}{2} \cdot \left|x - y\right|\right)} + x \]
      7. *-commutativeN/A

        \[\leadsto \sqrt{\color{blue}{\left(\left|x - y\right| \cdot \frac{1}{2}\right)} \cdot \left(\frac{1}{2} \cdot \left|x - y\right|\right)} + x \]
      8. associate-*l*N/A

        \[\leadsto \sqrt{\color{blue}{\left|x - y\right| \cdot \left(\frac{1}{2} \cdot \left(\frac{1}{2} \cdot \left|x - y\right|\right)\right)}} + x \]
      9. sqrt-prodN/A

        \[\leadsto \color{blue}{\sqrt{\left|x - y\right|} \cdot \sqrt{\frac{1}{2} \cdot \left(\frac{1}{2} \cdot \left|x - y\right|\right)}} + x \]
      10. unpow1/2N/A

        \[\leadsto \color{blue}{{\left(\left|x - y\right|\right)}^{\frac{1}{2}}} \cdot \sqrt{\frac{1}{2} \cdot \left(\frac{1}{2} \cdot \left|x - y\right|\right)} + x \]
      11. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left({\left(\left|x - y\right|\right)}^{\frac{1}{2}}, \sqrt{\frac{1}{2} \cdot \left(\frac{1}{2} \cdot \left|x - y\right|\right)}, x\right)} \]
    6. Applied rewrites87.7%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\sqrt{x - y}, \sqrt{0.5 \cdot \left(0.5 \cdot \left(x - y\right)\right)}, x\right)} \]
    7. Taylor expanded in x around 0

      \[\leadsto \color{blue}{\frac{-1}{2} \cdot y} \]
    8. Step-by-step derivation
      1. lower-*.f6473.6

        \[\leadsto \color{blue}{-0.5 \cdot y} \]
    9. Applied rewrites73.6%

      \[\leadsto \color{blue}{-0.5 \cdot y} \]

    if -1.04e-100 < y

    1. Initial program 99.9%

      \[x + \frac{\left|y - x\right|}{2} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. lift-+.f64N/A

        \[\leadsto \color{blue}{x + \frac{\left|y - x\right|}{2}} \]
      2. +-commutativeN/A

        \[\leadsto \color{blue}{\frac{\left|y - x\right|}{2} + x} \]
      3. lift-/.f64N/A

        \[\leadsto \color{blue}{\frac{\left|y - x\right|}{2}} + x \]
      4. div-invN/A

        \[\leadsto \color{blue}{\left|y - x\right| \cdot \frac{1}{2}} + x \]
      5. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(\left|y - x\right|, \frac{1}{2}, x\right)} \]
      6. lift-fabs.f64N/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{\left|y - x\right|}, \frac{1}{2}, x\right) \]
      7. neg-fabsN/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{\left|\mathsf{neg}\left(\left(y - x\right)\right)\right|}, \frac{1}{2}, x\right) \]
      8. lower-fabs.f64N/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{\left|\mathsf{neg}\left(\left(y - x\right)\right)\right|}, \frac{1}{2}, x\right) \]
      9. lift--.f64N/A

        \[\leadsto \mathsf{fma}\left(\left|\mathsf{neg}\left(\color{blue}{\left(y - x\right)}\right)\right|, \frac{1}{2}, x\right) \]
      10. sub-negN/A

        \[\leadsto \mathsf{fma}\left(\left|\mathsf{neg}\left(\color{blue}{\left(y + \left(\mathsf{neg}\left(x\right)\right)\right)}\right)\right|, \frac{1}{2}, x\right) \]
      11. +-commutativeN/A

        \[\leadsto \mathsf{fma}\left(\left|\mathsf{neg}\left(\color{blue}{\left(\left(\mathsf{neg}\left(x\right)\right) + y\right)}\right)\right|, \frac{1}{2}, x\right) \]
      12. distribute-neg-inN/A

        \[\leadsto \mathsf{fma}\left(\left|\color{blue}{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(x\right)\right)\right)\right) + \left(\mathsf{neg}\left(y\right)\right)}\right|, \frac{1}{2}, x\right) \]
      13. remove-double-negN/A

        \[\leadsto \mathsf{fma}\left(\left|\color{blue}{x} + \left(\mathsf{neg}\left(y\right)\right)\right|, \frac{1}{2}, x\right) \]
      14. sub-negN/A

        \[\leadsto \mathsf{fma}\left(\left|\color{blue}{x - y}\right|, \frac{1}{2}, x\right) \]
      15. lower--.f64N/A

        \[\leadsto \mathsf{fma}\left(\left|\color{blue}{x - y}\right|, \frac{1}{2}, x\right) \]
      16. metadata-eval99.9

        \[\leadsto \mathsf{fma}\left(\left|x - y\right|, \color{blue}{0.5}, x\right) \]
    4. Applied rewrites99.9%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\left|x - y\right|, 0.5, x\right)} \]
    5. Step-by-step derivation
      1. lift-fma.f64N/A

        \[\leadsto \color{blue}{\left|x - y\right| \cdot \frac{1}{2} + x} \]
      2. *-commutativeN/A

        \[\leadsto \color{blue}{\frac{1}{2} \cdot \left|x - y\right|} + x \]
      3. lift-*.f64N/A

        \[\leadsto \color{blue}{\frac{1}{2} \cdot \left|x - y\right|} + x \]
      4. rem-square-sqrtN/A

        \[\leadsto \color{blue}{\sqrt{\frac{1}{2} \cdot \left|x - y\right|} \cdot \sqrt{\frac{1}{2} \cdot \left|x - y\right|}} + x \]
      5. sqrt-unprodN/A

        \[\leadsto \color{blue}{\sqrt{\left(\frac{1}{2} \cdot \left|x - y\right|\right) \cdot \left(\frac{1}{2} \cdot \left|x - y\right|\right)}} + x \]
      6. lift-*.f64N/A

        \[\leadsto \sqrt{\color{blue}{\left(\frac{1}{2} \cdot \left|x - y\right|\right)} \cdot \left(\frac{1}{2} \cdot \left|x - y\right|\right)} + x \]
      7. *-commutativeN/A

        \[\leadsto \sqrt{\color{blue}{\left(\left|x - y\right| \cdot \frac{1}{2}\right)} \cdot \left(\frac{1}{2} \cdot \left|x - y\right|\right)} + x \]
      8. associate-*l*N/A

        \[\leadsto \sqrt{\color{blue}{\left|x - y\right| \cdot \left(\frac{1}{2} \cdot \left(\frac{1}{2} \cdot \left|x - y\right|\right)\right)}} + x \]
      9. sqrt-prodN/A

        \[\leadsto \color{blue}{\sqrt{\left|x - y\right|} \cdot \sqrt{\frac{1}{2} \cdot \left(\frac{1}{2} \cdot \left|x - y\right|\right)}} + x \]
      10. unpow1/2N/A

        \[\leadsto \color{blue}{{\left(\left|x - y\right|\right)}^{\frac{1}{2}}} \cdot \sqrt{\frac{1}{2} \cdot \left(\frac{1}{2} \cdot \left|x - y\right|\right)} + x \]
      11. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left({\left(\left|x - y\right|\right)}^{\frac{1}{2}}, \sqrt{\frac{1}{2} \cdot \left(\frac{1}{2} \cdot \left|x - y\right|\right)}, x\right)} \]
    6. Applied rewrites30.5%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\sqrt{x - y}, \sqrt{0.5 \cdot \left(0.5 \cdot \left(x - y\right)\right)}, x\right)} \]
    7. Taylor expanded in x around inf

      \[\leadsto \color{blue}{\frac{3}{2} \cdot x} \]
    8. Step-by-step derivation
      1. lower-*.f6435.5

        \[\leadsto \color{blue}{1.5 \cdot x} \]
    9. Applied rewrites35.5%

      \[\leadsto \color{blue}{1.5 \cdot x} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 5: 54.6% accurate, 2.0× speedup?

\[\begin{array}{l} \\ \mathsf{fma}\left(x - y, 0.5, x\right) \end{array} \]
(FPCore (x y) :precision binary64 (fma (- x y) 0.5 x))
double code(double x, double y) {
	return fma((x - y), 0.5, x);
}
function code(x, y)
	return fma(Float64(x - y), 0.5, x)
end
code[x_, y_] := N[(N[(x - y), $MachinePrecision] * 0.5 + x), $MachinePrecision]
\begin{array}{l}

\\
\mathsf{fma}\left(x - y, 0.5, x\right)
\end{array}
Derivation
  1. Initial program 99.9%

    \[x + \frac{\left|y - x\right|}{2} \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. lift-+.f64N/A

      \[\leadsto \color{blue}{x + \frac{\left|y - x\right|}{2}} \]
    2. +-commutativeN/A

      \[\leadsto \color{blue}{\frac{\left|y - x\right|}{2} + x} \]
    3. lift-/.f64N/A

      \[\leadsto \color{blue}{\frac{\left|y - x\right|}{2}} + x \]
    4. div-invN/A

      \[\leadsto \color{blue}{\left|y - x\right| \cdot \frac{1}{2}} + x \]
    5. lower-fma.f64N/A

      \[\leadsto \color{blue}{\mathsf{fma}\left(\left|y - x\right|, \frac{1}{2}, x\right)} \]
    6. lift-fabs.f64N/A

      \[\leadsto \mathsf{fma}\left(\color{blue}{\left|y - x\right|}, \frac{1}{2}, x\right) \]
    7. neg-fabsN/A

      \[\leadsto \mathsf{fma}\left(\color{blue}{\left|\mathsf{neg}\left(\left(y - x\right)\right)\right|}, \frac{1}{2}, x\right) \]
    8. lower-fabs.f64N/A

      \[\leadsto \mathsf{fma}\left(\color{blue}{\left|\mathsf{neg}\left(\left(y - x\right)\right)\right|}, \frac{1}{2}, x\right) \]
    9. lift--.f64N/A

      \[\leadsto \mathsf{fma}\left(\left|\mathsf{neg}\left(\color{blue}{\left(y - x\right)}\right)\right|, \frac{1}{2}, x\right) \]
    10. sub-negN/A

      \[\leadsto \mathsf{fma}\left(\left|\mathsf{neg}\left(\color{blue}{\left(y + \left(\mathsf{neg}\left(x\right)\right)\right)}\right)\right|, \frac{1}{2}, x\right) \]
    11. +-commutativeN/A

      \[\leadsto \mathsf{fma}\left(\left|\mathsf{neg}\left(\color{blue}{\left(\left(\mathsf{neg}\left(x\right)\right) + y\right)}\right)\right|, \frac{1}{2}, x\right) \]
    12. distribute-neg-inN/A

      \[\leadsto \mathsf{fma}\left(\left|\color{blue}{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(x\right)\right)\right)\right) + \left(\mathsf{neg}\left(y\right)\right)}\right|, \frac{1}{2}, x\right) \]
    13. remove-double-negN/A

      \[\leadsto \mathsf{fma}\left(\left|\color{blue}{x} + \left(\mathsf{neg}\left(y\right)\right)\right|, \frac{1}{2}, x\right) \]
    14. sub-negN/A

      \[\leadsto \mathsf{fma}\left(\left|\color{blue}{x - y}\right|, \frac{1}{2}, x\right) \]
    15. lower--.f64N/A

      \[\leadsto \mathsf{fma}\left(\left|\color{blue}{x - y}\right|, \frac{1}{2}, x\right) \]
    16. metadata-eval99.9

      \[\leadsto \mathsf{fma}\left(\left|x - y\right|, \color{blue}{0.5}, x\right) \]
  4. Applied rewrites99.9%

    \[\leadsto \color{blue}{\mathsf{fma}\left(\left|x - y\right|, 0.5, x\right)} \]
  5. Step-by-step derivation
    1. lift-fabs.f64N/A

      \[\leadsto \mathsf{fma}\left(\color{blue}{\left|x - y\right|}, \frac{1}{2}, x\right) \]
    2. unpow1N/A

      \[\leadsto \mathsf{fma}\left(\left|\color{blue}{{\left(x - y\right)}^{1}}\right|, \frac{1}{2}, x\right) \]
    3. sqr-powN/A

      \[\leadsto \mathsf{fma}\left(\left|\color{blue}{{\left(x - y\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(x - y\right)}^{\left(\frac{1}{2}\right)}}\right|, \frac{1}{2}, x\right) \]
    4. fabs-sqrN/A

      \[\leadsto \mathsf{fma}\left(\color{blue}{{\left(x - y\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(x - y\right)}^{\left(\frac{1}{2}\right)}}, \frac{1}{2}, x\right) \]
    5. sqr-powN/A

      \[\leadsto \mathsf{fma}\left(\color{blue}{{\left(x - y\right)}^{1}}, \frac{1}{2}, x\right) \]
    6. unpow154.3

      \[\leadsto \mathsf{fma}\left(\color{blue}{x - y}, 0.5, x\right) \]
  6. Applied rewrites54.3%

    \[\leadsto \color{blue}{\mathsf{fma}\left(x - y, 0.5, x\right)} \]
  7. Add Preprocessing

Alternative 6: 26.3% accurate, 3.3× speedup?

\[\begin{array}{l} \\ -0.5 \cdot y \end{array} \]
(FPCore (x y) :precision binary64 (* -0.5 y))
double code(double x, double y) {
	return -0.5 * y;
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    code = (-0.5d0) * y
end function
public static double code(double x, double y) {
	return -0.5 * y;
}
def code(x, y):
	return -0.5 * y
function code(x, y)
	return Float64(-0.5 * y)
end
function tmp = code(x, y)
	tmp = -0.5 * y;
end
code[x_, y_] := N[(-0.5 * y), $MachinePrecision]
\begin{array}{l}

\\
-0.5 \cdot y
\end{array}
Derivation
  1. Initial program 99.9%

    \[x + \frac{\left|y - x\right|}{2} \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. lift-+.f64N/A

      \[\leadsto \color{blue}{x + \frac{\left|y - x\right|}{2}} \]
    2. +-commutativeN/A

      \[\leadsto \color{blue}{\frac{\left|y - x\right|}{2} + x} \]
    3. lift-/.f64N/A

      \[\leadsto \color{blue}{\frac{\left|y - x\right|}{2}} + x \]
    4. div-invN/A

      \[\leadsto \color{blue}{\left|y - x\right| \cdot \frac{1}{2}} + x \]
    5. lower-fma.f64N/A

      \[\leadsto \color{blue}{\mathsf{fma}\left(\left|y - x\right|, \frac{1}{2}, x\right)} \]
    6. lift-fabs.f64N/A

      \[\leadsto \mathsf{fma}\left(\color{blue}{\left|y - x\right|}, \frac{1}{2}, x\right) \]
    7. neg-fabsN/A

      \[\leadsto \mathsf{fma}\left(\color{blue}{\left|\mathsf{neg}\left(\left(y - x\right)\right)\right|}, \frac{1}{2}, x\right) \]
    8. lower-fabs.f64N/A

      \[\leadsto \mathsf{fma}\left(\color{blue}{\left|\mathsf{neg}\left(\left(y - x\right)\right)\right|}, \frac{1}{2}, x\right) \]
    9. lift--.f64N/A

      \[\leadsto \mathsf{fma}\left(\left|\mathsf{neg}\left(\color{blue}{\left(y - x\right)}\right)\right|, \frac{1}{2}, x\right) \]
    10. sub-negN/A

      \[\leadsto \mathsf{fma}\left(\left|\mathsf{neg}\left(\color{blue}{\left(y + \left(\mathsf{neg}\left(x\right)\right)\right)}\right)\right|, \frac{1}{2}, x\right) \]
    11. +-commutativeN/A

      \[\leadsto \mathsf{fma}\left(\left|\mathsf{neg}\left(\color{blue}{\left(\left(\mathsf{neg}\left(x\right)\right) + y\right)}\right)\right|, \frac{1}{2}, x\right) \]
    12. distribute-neg-inN/A

      \[\leadsto \mathsf{fma}\left(\left|\color{blue}{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(x\right)\right)\right)\right) + \left(\mathsf{neg}\left(y\right)\right)}\right|, \frac{1}{2}, x\right) \]
    13. remove-double-negN/A

      \[\leadsto \mathsf{fma}\left(\left|\color{blue}{x} + \left(\mathsf{neg}\left(y\right)\right)\right|, \frac{1}{2}, x\right) \]
    14. sub-negN/A

      \[\leadsto \mathsf{fma}\left(\left|\color{blue}{x - y}\right|, \frac{1}{2}, x\right) \]
    15. lower--.f64N/A

      \[\leadsto \mathsf{fma}\left(\left|\color{blue}{x - y}\right|, \frac{1}{2}, x\right) \]
    16. metadata-eval99.9

      \[\leadsto \mathsf{fma}\left(\left|x - y\right|, \color{blue}{0.5}, x\right) \]
  4. Applied rewrites99.9%

    \[\leadsto \color{blue}{\mathsf{fma}\left(\left|x - y\right|, 0.5, x\right)} \]
  5. Step-by-step derivation
    1. lift-fma.f64N/A

      \[\leadsto \color{blue}{\left|x - y\right| \cdot \frac{1}{2} + x} \]
    2. *-commutativeN/A

      \[\leadsto \color{blue}{\frac{1}{2} \cdot \left|x - y\right|} + x \]
    3. lift-*.f64N/A

      \[\leadsto \color{blue}{\frac{1}{2} \cdot \left|x - y\right|} + x \]
    4. rem-square-sqrtN/A

      \[\leadsto \color{blue}{\sqrt{\frac{1}{2} \cdot \left|x - y\right|} \cdot \sqrt{\frac{1}{2} \cdot \left|x - y\right|}} + x \]
    5. sqrt-unprodN/A

      \[\leadsto \color{blue}{\sqrt{\left(\frac{1}{2} \cdot \left|x - y\right|\right) \cdot \left(\frac{1}{2} \cdot \left|x - y\right|\right)}} + x \]
    6. lift-*.f64N/A

      \[\leadsto \sqrt{\color{blue}{\left(\frac{1}{2} \cdot \left|x - y\right|\right)} \cdot \left(\frac{1}{2} \cdot \left|x - y\right|\right)} + x \]
    7. *-commutativeN/A

      \[\leadsto \sqrt{\color{blue}{\left(\left|x - y\right| \cdot \frac{1}{2}\right)} \cdot \left(\frac{1}{2} \cdot \left|x - y\right|\right)} + x \]
    8. associate-*l*N/A

      \[\leadsto \sqrt{\color{blue}{\left|x - y\right| \cdot \left(\frac{1}{2} \cdot \left(\frac{1}{2} \cdot \left|x - y\right|\right)\right)}} + x \]
    9. sqrt-prodN/A

      \[\leadsto \color{blue}{\sqrt{\left|x - y\right|} \cdot \sqrt{\frac{1}{2} \cdot \left(\frac{1}{2} \cdot \left|x - y\right|\right)}} + x \]
    10. unpow1/2N/A

      \[\leadsto \color{blue}{{\left(\left|x - y\right|\right)}^{\frac{1}{2}}} \cdot \sqrt{\frac{1}{2} \cdot \left(\frac{1}{2} \cdot \left|x - y\right|\right)} + x \]
    11. lower-fma.f64N/A

      \[\leadsto \color{blue}{\mathsf{fma}\left({\left(\left|x - y\right|\right)}^{\frac{1}{2}}, \sqrt{\frac{1}{2} \cdot \left(\frac{1}{2} \cdot \left|x - y\right|\right)}, x\right)} \]
  6. Applied rewrites49.7%

    \[\leadsto \color{blue}{\mathsf{fma}\left(\sqrt{x - y}, \sqrt{0.5 \cdot \left(0.5 \cdot \left(x - y\right)\right)}, x\right)} \]
  7. Taylor expanded in x around 0

    \[\leadsto \color{blue}{\frac{-1}{2} \cdot y} \]
  8. Step-by-step derivation
    1. lower-*.f6426.7

      \[\leadsto \color{blue}{-0.5 \cdot y} \]
  9. Applied rewrites26.7%

    \[\leadsto \color{blue}{-0.5 \cdot y} \]
  10. Add Preprocessing

Reproduce

?
herbie shell --seed 2024296 
(FPCore (x y)
  :name "Graphics.Rendering.Chart.Plot.AreaSpots:renderSpotLegend from Chart-1.5.3"
  :precision binary64
  (+ x (/ (fabs (- y x)) 2.0)))