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

Percentage Accurate: 99.9% → 99.9%
Time: 10.2s
Alternatives: 8
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 8 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 100.0%

    \[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. metadata-eval100.0

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

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

Alternative 2: 79.8% accurate, 0.9× speedup?

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

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

\mathbf{elif}\;y \leq 5.4 \cdot 10^{-105}:\\
\;\;\;\;\mathsf{fma}\left(\left|-x\right|, 0.5, x\right)\\

\mathbf{else}:\\
\;\;\;\;\left|y - x\right| \cdot 0.5\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if y < -2.6e-154

    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. metadata-eval99.9

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

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

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\color{blue}{\sqrt{\left|y - x\right|}} \cdot {\left(\left|y - x\right|\right)}^{\frac{1}{2}}, \frac{1}{2}, x\right) \]
      7. unpow1/2N/A

        \[\leadsto \mathsf{fma}\left(\sqrt{\left|y - x\right|} \cdot \color{blue}{\sqrt{\left|y - x\right|}}, \frac{1}{2}, x\right) \]
      8. lower-sqrt.f6499.3

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\sqrt{\left|y - x\right|} \cdot \color{blue}{\sqrt{\left|y - x\right|}}, \frac{1}{2}, x\right) \]
      4. rem-square-sqrt99.9

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

        \[\leadsto \mathsf{fma}\left(\left|\color{blue}{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. fabs-subN/A

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\color{blue}{\sqrt{x - y}} \cdot \sqrt{x - y}, \frac{1}{2}, x\right) \]
      13. lower-sqrt.f6483.0

        \[\leadsto \mathsf{fma}\left(\sqrt{x - y} \cdot \color{blue}{\sqrt{x - y}}, 0.5, x\right) \]
    8. Applied rewrites83.0%

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

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

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

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

        \[\leadsto \color{blue}{\mathsf{fma}\left(x, \frac{3}{2}, \frac{-1}{2} \cdot y\right)} \]
      4. *-commutativeN/A

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

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

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

    if -2.6e-154 < y < 5.39999999999999985e-105

    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. metadata-eval99.9

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

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

      \[\leadsto \mathsf{fma}\left(\left|\color{blue}{-1 \cdot x}\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(x\right)}\right|, \frac{1}{2}, x\right) \]
      2. lower-neg.f6490.3

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

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

    if 5.39999999999999985e-105 < y

    1. Initial program 100.0%

      \[x + \frac{\left|y - x\right|}{2} \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0

      \[\leadsto \color{blue}{\frac{1}{2} \cdot \left|y - x\right|} \]
    4. Step-by-step derivation
      1. sub-negN/A

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

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

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

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

        \[\leadsto \frac{1}{2} \cdot \left|\color{blue}{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(y\right)\right)\right)\right)} + \left(\mathsf{neg}\left(x\right)\right)\right| \]
      6. mul-1-negN/A

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

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

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

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

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

        \[\leadsto \frac{1}{2} \cdot \left|\color{blue}{\left(\mathsf{neg}\left(-1 \cdot y\right)\right) + \left(\mathsf{neg}\left(x\right)\right)}\right| \]
      12. mul-1-negN/A

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

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

        \[\leadsto \frac{1}{2} \cdot \left|\color{blue}{y - x}\right| \]
      15. lower--.f6471.3

        \[\leadsto 0.5 \cdot \left|\color{blue}{y - x}\right| \]
    5. Applied rewrites71.3%

      \[\leadsto \color{blue}{0.5 \cdot \left|y - x\right|} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification81.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -2.6 \cdot 10^{-154}:\\ \;\;\;\;\mathsf{fma}\left(x, 1.5, y \cdot -0.5\right)\\ \mathbf{elif}\;y \leq 5.4 \cdot 10^{-105}:\\ \;\;\;\;\mathsf{fma}\left(\left|-x\right|, 0.5, x\right)\\ \mathbf{else}:\\ \;\;\;\;\left|y - x\right| \cdot 0.5\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 79.8% accurate, 0.9× speedup?

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

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

\mathbf{elif}\;y \leq 5.4 \cdot 10^{-105}:\\
\;\;\;\;\mathsf{fma}\left(\left|-x\right|, 0.5, x\right)\\

\mathbf{else}:\\
\;\;\;\;\left|y - x\right| \cdot 0.5\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if y < -2.6e-154

    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 x + \color{blue}{\frac{\left|y - x\right|}{2}} \]
      2. clear-numN/A

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

        \[\leadsto x + \color{blue}{\frac{1}{\frac{2}{\left|y - x\right|}}} \]
      4. lower-/.f6499.8

        \[\leadsto x + \frac{1}{\color{blue}{\frac{2}{\left|y - x\right|}}} \]
    4. Applied rewrites99.8%

      \[\leadsto x + \color{blue}{\frac{1}{\frac{2}{\left|y - x\right|}}} \]
    5. Step-by-step derivation
      1. lift-/.f64N/A

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

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{\left|y - x\right|}{2} + x} \]
    6. Applied rewrites98.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left(x - y\right) \cdot \color{blue}{\frac{1}{2}} + x \]
      15. lower-fma.f6486.4

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

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

    if -2.6e-154 < y < 5.39999999999999985e-105

    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. metadata-eval99.9

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

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

      \[\leadsto \mathsf{fma}\left(\left|\color{blue}{-1 \cdot x}\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(x\right)}\right|, \frac{1}{2}, x\right) \]
      2. lower-neg.f6490.3

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

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

    if 5.39999999999999985e-105 < y

    1. Initial program 100.0%

      \[x + \frac{\left|y - x\right|}{2} \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0

      \[\leadsto \color{blue}{\frac{1}{2} \cdot \left|y - x\right|} \]
    4. Step-by-step derivation
      1. sub-negN/A

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

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

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

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

        \[\leadsto \frac{1}{2} \cdot \left|\color{blue}{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(y\right)\right)\right)\right)} + \left(\mathsf{neg}\left(x\right)\right)\right| \]
      6. mul-1-negN/A

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

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

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

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

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

        \[\leadsto \frac{1}{2} \cdot \left|\color{blue}{\left(\mathsf{neg}\left(-1 \cdot y\right)\right) + \left(\mathsf{neg}\left(x\right)\right)}\right| \]
      12. mul-1-negN/A

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

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

        \[\leadsto \frac{1}{2} \cdot \left|\color{blue}{y - x}\right| \]
      15. lower--.f6471.3

        \[\leadsto 0.5 \cdot \left|\color{blue}{y - x}\right| \]
    5. Applied rewrites71.3%

      \[\leadsto \color{blue}{0.5 \cdot \left|y - x\right|} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification81.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -2.6 \cdot 10^{-154}:\\ \;\;\;\;\mathsf{fma}\left(x - y, 0.5, x\right)\\ \mathbf{elif}\;y \leq 5.4 \cdot 10^{-105}:\\ \;\;\;\;\mathsf{fma}\left(\left|-x\right|, 0.5, x\right)\\ \mathbf{else}:\\ \;\;\;\;\left|y - x\right| \cdot 0.5\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 71.3% accurate, 1.2× speedup?

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

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

\mathbf{else}:\\
\;\;\;\;\left|y - x\right| \cdot 0.5\\


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

    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 x + \color{blue}{\frac{\left|y - x\right|}{2}} \]
      2. clear-numN/A

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

        \[\leadsto x + \color{blue}{\frac{1}{\frac{2}{\left|y - x\right|}}} \]
      4. lower-/.f6499.8

        \[\leadsto x + \frac{1}{\color{blue}{\frac{2}{\left|y - x\right|}}} \]
    4. Applied rewrites99.8%

      \[\leadsto x + \color{blue}{\frac{1}{\frac{2}{\left|y - x\right|}}} \]
    5. Step-by-step derivation
      1. lift-/.f64N/A

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

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{\left|y - x\right|}{2} + x} \]
    6. Applied rewrites98.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left(x - y\right) \cdot \color{blue}{\frac{1}{2}} + x \]
      15. lower-fma.f6471.6

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

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

    if 7.5000000000000002e-112 < y

    1. Initial program 100.0%

      \[x + \frac{\left|y - x\right|}{2} \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0

      \[\leadsto \color{blue}{\frac{1}{2} \cdot \left|y - x\right|} \]
    4. Step-by-step derivation
      1. sub-negN/A

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

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

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

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

        \[\leadsto \frac{1}{2} \cdot \left|\color{blue}{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(y\right)\right)\right)\right)} + \left(\mathsf{neg}\left(x\right)\right)\right| \]
      6. mul-1-negN/A

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

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

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

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

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

        \[\leadsto \frac{1}{2} \cdot \left|\color{blue}{\left(\mathsf{neg}\left(-1 \cdot y\right)\right) + \left(\mathsf{neg}\left(x\right)\right)}\right| \]
      12. mul-1-negN/A

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

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

        \[\leadsto \frac{1}{2} \cdot \left|\color{blue}{y - x}\right| \]
      15. lower--.f6471.3

        \[\leadsto 0.5 \cdot \left|\color{blue}{y - x}\right| \]
    5. Applied rewrites71.3%

      \[\leadsto \color{blue}{0.5 \cdot \left|y - x\right|} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification71.5%

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq 7.5 \cdot 10^{-112}:\\ \;\;\;\;\mathsf{fma}\left(x - y, 0.5, x\right)\\ \mathbf{else}:\\ \;\;\;\;\left|y - x\right| \cdot 0.5\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 47.6% accurate, 1.3× speedup?

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

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

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


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

    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. metadata-eval99.9

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

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

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\color{blue}{\sqrt{\left|y - x\right|}} \cdot {\left(\left|y - x\right|\right)}^{\frac{1}{2}}, \frac{1}{2}, x\right) \]
      7. unpow1/2N/A

        \[\leadsto \mathsf{fma}\left(\sqrt{\left|y - x\right|} \cdot \color{blue}{\sqrt{\left|y - x\right|}}, \frac{1}{2}, x\right) \]
      8. lower-sqrt.f6499.3

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\sqrt{\left|y - x\right|} \cdot \color{blue}{\sqrt{\left|y - x\right|}}, \frac{1}{2}, x\right) \]
      4. rem-square-sqrt99.9

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

        \[\leadsto \mathsf{fma}\left(\left|\color{blue}{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. fabs-subN/A

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\color{blue}{\sqrt{x - y}} \cdot \sqrt{x - y}, \frac{1}{2}, x\right) \]
      13. lower-sqrt.f6483.0

        \[\leadsto \mathsf{fma}\left(\sqrt{x - y} \cdot \color{blue}{\sqrt{x - y}}, 0.5, x\right) \]
    8. Applied rewrites83.0%

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

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

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

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

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

    if -3.50000000000000027e-163 < y

    1. Initial program 100.0%

      \[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. metadata-eval100.0

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

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

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\color{blue}{\sqrt{\left|y - x\right|}} \cdot {\left(\left|y - x\right|\right)}^{\frac{1}{2}}, \frac{1}{2}, x\right) \]
      7. unpow1/2N/A

        \[\leadsto \mathsf{fma}\left(\sqrt{\left|y - x\right|} \cdot \color{blue}{\sqrt{\left|y - x\right|}}, \frac{1}{2}, x\right) \]
      8. lower-sqrt.f6499.3

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\sqrt{\left|y - x\right|} \cdot \color{blue}{\sqrt{\left|y - x\right|}}, \frac{1}{2}, x\right) \]
      4. rem-square-sqrt100.0

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

        \[\leadsto \mathsf{fma}\left(\left|\color{blue}{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. fabs-subN/A

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\color{blue}{\sqrt{x - y}} \cdot \sqrt{x - y}, \frac{1}{2}, x\right) \]
      13. lower-sqrt.f6427.6

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

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

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

        \[\leadsto \color{blue}{x \cdot \frac{3}{2}} \]
      2. lower-*.f6433.9

        \[\leadsto \color{blue}{x \cdot 1.5} \]
    11. Applied rewrites33.9%

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

Alternative 6: 45.7% accurate, 1.7× speedup?

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

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

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


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

    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. metadata-eval99.9

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

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

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\color{blue}{\sqrt{\left|y - x\right|}} \cdot {\left(\left|y - x\right|\right)}^{\frac{1}{2}}, \frac{1}{2}, x\right) \]
      7. unpow1/2N/A

        \[\leadsto \mathsf{fma}\left(\sqrt{\left|y - x\right|} \cdot \color{blue}{\sqrt{\left|y - x\right|}}, \frac{1}{2}, x\right) \]
      8. lower-sqrt.f6499.3

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\sqrt{\left|y - x\right|} \cdot \color{blue}{\sqrt{\left|y - x\right|}}, \frac{1}{2}, x\right) \]
      4. rem-square-sqrt99.9

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

        \[\leadsto \mathsf{fma}\left(\left|\color{blue}{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. fabs-subN/A

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\color{blue}{\sqrt{x - y}} \cdot \sqrt{x - y}, \frac{1}{2}, x\right) \]
      13. lower-sqrt.f6486.1

        \[\leadsto \mathsf{fma}\left(\sqrt{x - y} \cdot \color{blue}{\sqrt{x - y}}, 0.5, x\right) \]
    8. Applied rewrites86.1%

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

      \[\leadsto \color{blue}{\frac{-1}{2} \cdot y} \]
    10. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \color{blue}{y \cdot \frac{-1}{2}} \]
      2. lower-*.f6466.7

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

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

    if -2.15e-54 < y

    1. Initial program 100.0%

      \[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. metadata-eval100.0

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

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

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\color{blue}{\sqrt{\left|y - x\right|}} \cdot {\left(\left|y - x\right|\right)}^{\frac{1}{2}}, \frac{1}{2}, x\right) \]
      7. unpow1/2N/A

        \[\leadsto \mathsf{fma}\left(\sqrt{\left|y - x\right|} \cdot \color{blue}{\sqrt{\left|y - x\right|}}, \frac{1}{2}, x\right) \]
      8. lower-sqrt.f6499.3

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\sqrt{\left|y - x\right|} \cdot \color{blue}{\sqrt{\left|y - x\right|}}, \frac{1}{2}, x\right) \]
      4. rem-square-sqrt100.0

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

        \[\leadsto \mathsf{fma}\left(\left|\color{blue}{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. fabs-subN/A

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\color{blue}{\sqrt{x - y}} \cdot \sqrt{x - y}, \frac{1}{2}, x\right) \]
      13. lower-sqrt.f6432.0

        \[\leadsto \mathsf{fma}\left(\sqrt{x - y} \cdot \color{blue}{\sqrt{x - y}}, 0.5, x\right) \]
    8. Applied rewrites32.0%

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

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

        \[\leadsto \color{blue}{x \cdot \frac{3}{2}} \]
      2. lower-*.f6434.8

        \[\leadsto \color{blue}{x \cdot 1.5} \]
    11. Applied rewrites34.8%

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

Alternative 7: 54.9% 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 100.0%

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

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

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

      \[\leadsto x + \color{blue}{\frac{1}{\frac{2}{\left|y - x\right|}}} \]
    4. lower-/.f6499.8

      \[\leadsto x + \frac{1}{\color{blue}{\frac{2}{\left|y - x\right|}}} \]
  4. Applied rewrites99.8%

    \[\leadsto x + \color{blue}{\frac{1}{\frac{2}{\left|y - x\right|}}} \]
  5. Step-by-step derivation
    1. lift-/.f64N/A

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{\left|y - x\right|}{2} + x} \]
  6. Applied rewrites98.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \left(x - y\right) \cdot \color{blue}{\frac{1}{2}} + x \]
    15. lower-fma.f6449.7

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

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

Alternative 8: 29.9% accurate, 3.3× speedup?

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

\\
x \cdot 1.5
\end{array}
Derivation
  1. Initial program 100.0%

    \[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. metadata-eval100.0

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

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

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

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

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

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

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

      \[\leadsto \mathsf{fma}\left(\color{blue}{\sqrt{\left|y - x\right|}} \cdot {\left(\left|y - x\right|\right)}^{\frac{1}{2}}, \frac{1}{2}, x\right) \]
    7. unpow1/2N/A

      \[\leadsto \mathsf{fma}\left(\sqrt{\left|y - x\right|} \cdot \color{blue}{\sqrt{\left|y - x\right|}}, \frac{1}{2}, x\right) \]
    8. lower-sqrt.f6499.3

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

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

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

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

      \[\leadsto \mathsf{fma}\left(\sqrt{\left|y - x\right|} \cdot \color{blue}{\sqrt{\left|y - x\right|}}, \frac{1}{2}, x\right) \]
    4. rem-square-sqrt100.0

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

      \[\leadsto \mathsf{fma}\left(\left|\color{blue}{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. fabs-subN/A

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{x \cdot \frac{3}{2}} \]
    2. lower-*.f6431.6

      \[\leadsto \color{blue}{x \cdot 1.5} \]
  11. Applied rewrites31.6%

    \[\leadsto \color{blue}{x \cdot 1.5} \]
  12. Add Preprocessing

Reproduce

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