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

Percentage Accurate: 99.9% → 99.9%
Time: 3.7s
Alternatives: 7
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 7 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. Taylor expanded in x around 0

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

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

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

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

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

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

      \[\leadsto \mathsf{fma}\left(\color{blue}{\left|x - \left(\mathsf{neg}\left(-1\right)\right) \cdot y\right|}, \frac{1}{2}, x\right) \]
    7. fp-cancel-sign-sub-invN/A

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

      \[\leadsto \mathsf{fma}\left(\color{blue}{\left|x + -1 \cdot y\right|}, \frac{1}{2}, x\right) \]
    9. fp-cancel-sign-sub-invN/A

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

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

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

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

    \[\leadsto \color{blue}{\mathsf{fma}\left(\left|x - y\right|, 0.5, x\right)} \]
  6. Final simplification100.0%

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

Alternative 2: 61.1% accurate, 0.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -9.8 \cdot 10^{-112}:\\ \;\;\;\;-0.5 \cdot y\\ \mathbf{elif}\;y \leq 3.5 \cdot 10^{-95}:\\ \;\;\;\;1.5 \cdot x\\ \mathbf{else}:\\ \;\;\;\;\left|-y\right| \cdot 0.5\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (if (<= y -9.8e-112)
   (* -0.5 y)
   (if (<= y 3.5e-95) (* 1.5 x) (* (fabs (- y)) 0.5))))
double code(double x, double y) {
	double tmp;
	if (y <= -9.8e-112) {
		tmp = -0.5 * y;
	} else if (y <= 3.5e-95) {
		tmp = 1.5 * x;
	} else {
		tmp = fabs(-y) * 0.5;
	}
	return tmp;
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8) :: tmp
    if (y <= (-9.8d-112)) then
        tmp = (-0.5d0) * y
    else if (y <= 3.5d-95) then
        tmp = 1.5d0 * x
    else
        tmp = abs(-y) * 0.5d0
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double tmp;
	if (y <= -9.8e-112) {
		tmp = -0.5 * y;
	} else if (y <= 3.5e-95) {
		tmp = 1.5 * x;
	} else {
		tmp = Math.abs(-y) * 0.5;
	}
	return tmp;
}
def code(x, y):
	tmp = 0
	if y <= -9.8e-112:
		tmp = -0.5 * y
	elif y <= 3.5e-95:
		tmp = 1.5 * x
	else:
		tmp = math.fabs(-y) * 0.5
	return tmp
function code(x, y)
	tmp = 0.0
	if (y <= -9.8e-112)
		tmp = Float64(-0.5 * y);
	elseif (y <= 3.5e-95)
		tmp = Float64(1.5 * x);
	else
		tmp = Float64(abs(Float64(-y)) * 0.5);
	end
	return tmp
end
function tmp_2 = code(x, y)
	tmp = 0.0;
	if (y <= -9.8e-112)
		tmp = -0.5 * y;
	elseif (y <= 3.5e-95)
		tmp = 1.5 * x;
	else
		tmp = abs(-y) * 0.5;
	end
	tmp_2 = tmp;
end
code[x_, y_] := If[LessEqual[y, -9.8e-112], N[(-0.5 * y), $MachinePrecision], If[LessEqual[y, 3.5e-95], N[(1.5 * x), $MachinePrecision], N[(N[Abs[(-y)], $MachinePrecision] * 0.5), $MachinePrecision]]]
\begin{array}{l}

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

\mathbf{elif}\;y \leq 3.5 \cdot 10^{-95}:\\
\;\;\;\;1.5 \cdot x\\

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


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

    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. unpow1N/A

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{y \cdot {\left(\sqrt{\frac{-1}{2}}\right)}^{2}} \]
    6. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \color{blue}{{\left(\sqrt{\frac{-1}{2}}\right)}^{2} \cdot y} \]
      2. unpow2N/A

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

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

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

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

    if -9.7999999999999996e-112 < y < 3.4999999999999997e-95

    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. unpow1N/A

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

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

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

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

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

        \[\leadsto \color{blue}{\mathsf{fma}\left(\sqrt{\frac{\left|y - x\right|}{2}}, \sqrt{\frac{\left|y - x\right|}{2}}, x\right)} \]
    4. Applied rewrites47.2%

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

      \[\leadsto \color{blue}{x \cdot \left(1 + -1 \cdot {\left(\sqrt{\frac{-1}{2}}\right)}^{2}\right)} \]
    6. Step-by-step derivation
      1. *-commutativeN/A

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

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

        \[\leadsto \left(1 + -1 \cdot \color{blue}{\frac{-1}{2}}\right) \cdot x \]
      4. metadata-evalN/A

        \[\leadsto \left(1 + \color{blue}{\frac{1}{2}}\right) \cdot x \]
      5. metadata-evalN/A

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

        \[\leadsto \color{blue}{1.5 \cdot x} \]
    7. Applied rewrites50.6%

      \[\leadsto \color{blue}{1.5 \cdot x} \]

    if 3.4999999999999997e-95 < 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. *-commutativeN/A

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

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

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

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

        \[\leadsto \color{blue}{\left|x - \left(\mathsf{neg}\left(-1\right)\right) \cdot y\right|} \cdot \frac{1}{2} \]
      6. fp-cancel-sign-sub-invN/A

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

        \[\leadsto \color{blue}{\left|x + -1 \cdot y\right|} \cdot \frac{1}{2} \]
      8. fp-cancel-sign-sub-invN/A

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

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

        \[\leadsto \left|x - \color{blue}{y}\right| \cdot \frac{1}{2} \]
      11. lower--.f6472.8

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

      \[\leadsto \color{blue}{\left|x - y\right| \cdot 0.5} \]
    6. Taylor expanded in x around 0

      \[\leadsto \left|-1 \cdot y\right| \cdot \frac{1}{2} \]
    7. Step-by-step derivation
      1. Applied rewrites71.6%

        \[\leadsto \left|-y\right| \cdot 0.5 \]
    8. Recombined 3 regimes into one program.
    9. Add Preprocessing

    Alternative 3: 72.5% accurate, 1.2× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq 1.15 \cdot 10^{-117}:\\ \;\;\;\;\mathsf{fma}\left(y - x, -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.15e-117) (fma (- y x) -0.5 x) (fma (fabs (- y)) 0.5 x)))
    double code(double x, double y) {
    	double tmp;
    	if (y <= 1.15e-117) {
    		tmp = fma((y - x), -0.5, x);
    	} else {
    		tmp = fma(fabs(-y), 0.5, x);
    	}
    	return tmp;
    }
    
    function code(x, y)
    	tmp = 0.0
    	if (y <= 1.15e-117)
    		tmp = fma(Float64(y - x), -0.5, x);
    	else
    		tmp = fma(abs(Float64(-y)), 0.5, x);
    	end
    	return tmp
    end
    
    code[x_, y_] := If[LessEqual[y, 1.15e-117], N[(N[(y - x), $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.15 \cdot 10^{-117}:\\
    \;\;\;\;\mathsf{fma}\left(y - x, -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.14999999999999997e-117

      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. unpow1N/A

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

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

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

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

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

          \[\leadsto \color{blue}{\mathsf{fma}\left(\sqrt{\frac{\left|y - x\right|}{2}}, \sqrt{\frac{\left|y - x\right|}{2}}, x\right)} \]
      4. Applied rewrites62.7%

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

        \[\leadsto \color{blue}{y \cdot {\left(\sqrt{\frac{-1}{2}}\right)}^{2}} \]
      6. Step-by-step derivation
        1. *-commutativeN/A

          \[\leadsto \color{blue}{{\left(\sqrt{\frac{-1}{2}}\right)}^{2} \cdot y} \]
        2. unpow2N/A

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

          \[\leadsto \color{blue}{\frac{-1}{2}} \cdot y \]
        4. lower-*.f6441.0

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

        \[\leadsto \color{blue}{-0.5 \cdot y} \]
      8. Taylor expanded in x around 0

        \[\leadsto \color{blue}{x \cdot \left(1 + -1 \cdot {\left(\sqrt{\frac{-1}{2}}\right)}^{2}\right) + y \cdot {\left(\sqrt{\frac{-1}{2}}\right)}^{2}} \]
      9. Step-by-step derivation
        1. *-commutativeN/A

          \[\leadsto \color{blue}{\left(1 + -1 \cdot {\left(\sqrt{\frac{-1}{2}}\right)}^{2}\right) \cdot x} + y \cdot {\left(\sqrt{\frac{-1}{2}}\right)}^{2} \]
        2. fp-cancel-sign-sub-invN/A

          \[\leadsto \color{blue}{\left(1 - \left(\mathsf{neg}\left(-1\right)\right) \cdot {\left(\sqrt{\frac{-1}{2}}\right)}^{2}\right)} \cdot x + y \cdot {\left(\sqrt{\frac{-1}{2}}\right)}^{2} \]
        3. metadata-evalN/A

          \[\leadsto \left(1 - \color{blue}{1} \cdot {\left(\sqrt{\frac{-1}{2}}\right)}^{2}\right) \cdot x + y \cdot {\left(\sqrt{\frac{-1}{2}}\right)}^{2} \]
        4. *-lft-identityN/A

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

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

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

          \[\leadsto \color{blue}{\frac{3}{2}} \cdot x + y \cdot {\left(\sqrt{\frac{-1}{2}}\right)}^{2} \]
        8. metadata-evalN/A

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

          \[\leadsto \color{blue}{\left(x + \frac{1}{2} \cdot x\right)} + y \cdot {\left(\sqrt{\frac{-1}{2}}\right)}^{2} \]
        10. fp-cancel-sign-sub-invN/A

          \[\leadsto \color{blue}{\left(x - \left(\mathsf{neg}\left(\frac{1}{2}\right)\right) \cdot x\right)} + y \cdot {\left(\sqrt{\frac{-1}{2}}\right)}^{2} \]
        11. metadata-evalN/A

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

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

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

          \[\leadsto \left(x - \color{blue}{x \cdot {\left(\sqrt{\frac{-1}{2}}\right)}^{2}}\right) + y \cdot {\left(\sqrt{\frac{-1}{2}}\right)}^{2} \]
        15. fp-cancel-sub-signN/A

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

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

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

          \[\leadsto \color{blue}{x + \left(-1 \cdot \left(x \cdot {\left(\sqrt{\frac{-1}{2}}\right)}^{2}\right) + y \cdot {\left(\sqrt{\frac{-1}{2}}\right)}^{2}\right)} \]
      10. Applied rewrites69.3%

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

      if 1.14999999999999997e-117 < 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}{x + \frac{1}{2} \cdot \left|y - x\right|} \]
      4. Step-by-step derivation
        1. +-commutativeN/A

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

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

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

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

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

          \[\leadsto \mathsf{fma}\left(\color{blue}{\left|x - \left(\mathsf{neg}\left(-1\right)\right) \cdot y\right|}, \frac{1}{2}, x\right) \]
        7. fp-cancel-sign-sub-invN/A

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

          \[\leadsto \mathsf{fma}\left(\color{blue}{\left|x + -1 \cdot y\right|}, \frac{1}{2}, x\right) \]
        9. fp-cancel-sign-sub-invN/A

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\left|-1 \cdot y\right|, \frac{1}{2}, x\right) \]
      7. Step-by-step derivation
        1. Applied rewrites75.7%

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

      Alternative 4: 71.4% accurate, 1.2× speedup?

      \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq 9.2 \cdot 10^{-105}:\\ \;\;\;\;\mathsf{fma}\left(y - x, -0.5, x\right)\\ \mathbf{else}:\\ \;\;\;\;\left|y - x\right| \cdot 0.5\\ \end{array} \end{array} \]
      (FPCore (x y)
       :precision binary64
       (if (<= y 9.2e-105) (fma (- y x) -0.5 x) (* (fabs (- y x)) 0.5)))
      double code(double x, double y) {
      	double tmp;
      	if (y <= 9.2e-105) {
      		tmp = fma((y - x), -0.5, x);
      	} else {
      		tmp = fabs((y - x)) * 0.5;
      	}
      	return tmp;
      }
      
      function code(x, y)
      	tmp = 0.0
      	if (y <= 9.2e-105)
      		tmp = fma(Float64(y - x), -0.5, x);
      	else
      		tmp = Float64(abs(Float64(y - x)) * 0.5);
      	end
      	return tmp
      end
      
      code[x_, y_] := If[LessEqual[y, 9.2e-105], N[(N[(y - 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 9.2 \cdot 10^{-105}:\\
      \;\;\;\;\mathsf{fma}\left(y - x, -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 < 9.2000000000000004e-105

        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. unpow1N/A

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

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

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

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

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

            \[\leadsto \color{blue}{\mathsf{fma}\left(\sqrt{\frac{\left|y - x\right|}{2}}, \sqrt{\frac{\left|y - x\right|}{2}}, x\right)} \]
        4. Applied rewrites62.3%

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

          \[\leadsto \color{blue}{y \cdot {\left(\sqrt{\frac{-1}{2}}\right)}^{2}} \]
        6. Step-by-step derivation
          1. *-commutativeN/A

            \[\leadsto \color{blue}{{\left(\sqrt{\frac{-1}{2}}\right)}^{2} \cdot y} \]
          2. unpow2N/A

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

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

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

          \[\leadsto \color{blue}{-0.5 \cdot y} \]
        8. Taylor expanded in x around 0

          \[\leadsto \color{blue}{x \cdot \left(1 + -1 \cdot {\left(\sqrt{\frac{-1}{2}}\right)}^{2}\right) + y \cdot {\left(\sqrt{\frac{-1}{2}}\right)}^{2}} \]
        9. Step-by-step derivation
          1. *-commutativeN/A

            \[\leadsto \color{blue}{\left(1 + -1 \cdot {\left(\sqrt{\frac{-1}{2}}\right)}^{2}\right) \cdot x} + y \cdot {\left(\sqrt{\frac{-1}{2}}\right)}^{2} \]
          2. fp-cancel-sign-sub-invN/A

            \[\leadsto \color{blue}{\left(1 - \left(\mathsf{neg}\left(-1\right)\right) \cdot {\left(\sqrt{\frac{-1}{2}}\right)}^{2}\right)} \cdot x + y \cdot {\left(\sqrt{\frac{-1}{2}}\right)}^{2} \]
          3. metadata-evalN/A

            \[\leadsto \left(1 - \color{blue}{1} \cdot {\left(\sqrt{\frac{-1}{2}}\right)}^{2}\right) \cdot x + y \cdot {\left(\sqrt{\frac{-1}{2}}\right)}^{2} \]
          4. *-lft-identityN/A

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

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

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

            \[\leadsto \color{blue}{\frac{3}{2}} \cdot x + y \cdot {\left(\sqrt{\frac{-1}{2}}\right)}^{2} \]
          8. metadata-evalN/A

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

            \[\leadsto \color{blue}{\left(x + \frac{1}{2} \cdot x\right)} + y \cdot {\left(\sqrt{\frac{-1}{2}}\right)}^{2} \]
          10. fp-cancel-sign-sub-invN/A

            \[\leadsto \color{blue}{\left(x - \left(\mathsf{neg}\left(\frac{1}{2}\right)\right) \cdot x\right)} + y \cdot {\left(\sqrt{\frac{-1}{2}}\right)}^{2} \]
          11. metadata-evalN/A

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

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

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

            \[\leadsto \left(x - \color{blue}{x \cdot {\left(\sqrt{\frac{-1}{2}}\right)}^{2}}\right) + y \cdot {\left(\sqrt{\frac{-1}{2}}\right)}^{2} \]
          15. fp-cancel-sub-signN/A

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

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

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

            \[\leadsto \color{blue}{x + \left(-1 \cdot \left(x \cdot {\left(\sqrt{\frac{-1}{2}}\right)}^{2}\right) + y \cdot {\left(\sqrt{\frac{-1}{2}}\right)}^{2}\right)} \]
        10. Applied rewrites69.0%

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

        if 9.2000000000000004e-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. *-commutativeN/A

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

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

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

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

            \[\leadsto \color{blue}{\left|x - \left(\mathsf{neg}\left(-1\right)\right) \cdot y\right|} \cdot \frac{1}{2} \]
          6. fp-cancel-sign-sub-invN/A

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

            \[\leadsto \color{blue}{\left|x + -1 \cdot y\right|} \cdot \frac{1}{2} \]
          8. fp-cancel-sign-sub-invN/A

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

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

            \[\leadsto \left|x - \color{blue}{y}\right| \cdot \frac{1}{2} \]
          11. lower--.f6472.8

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

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

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

      Alternative 5: 70.7% accurate, 1.2× speedup?

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

        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. unpow1N/A

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

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

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

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

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

            \[\leadsto \color{blue}{\mathsf{fma}\left(\sqrt{\frac{\left|y - x\right|}{2}}, \sqrt{\frac{\left|y - x\right|}{2}}, x\right)} \]
        4. Applied rewrites62.3%

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

          \[\leadsto \color{blue}{y \cdot {\left(\sqrt{\frac{-1}{2}}\right)}^{2}} \]
        6. Step-by-step derivation
          1. *-commutativeN/A

            \[\leadsto \color{blue}{{\left(\sqrt{\frac{-1}{2}}\right)}^{2} \cdot y} \]
          2. unpow2N/A

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

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

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

          \[\leadsto \color{blue}{-0.5 \cdot y} \]
        8. Taylor expanded in x around 0

          \[\leadsto \color{blue}{x \cdot \left(1 + -1 \cdot {\left(\sqrt{\frac{-1}{2}}\right)}^{2}\right) + y \cdot {\left(\sqrt{\frac{-1}{2}}\right)}^{2}} \]
        9. Step-by-step derivation
          1. *-commutativeN/A

            \[\leadsto \color{blue}{\left(1 + -1 \cdot {\left(\sqrt{\frac{-1}{2}}\right)}^{2}\right) \cdot x} + y \cdot {\left(\sqrt{\frac{-1}{2}}\right)}^{2} \]
          2. fp-cancel-sign-sub-invN/A

            \[\leadsto \color{blue}{\left(1 - \left(\mathsf{neg}\left(-1\right)\right) \cdot {\left(\sqrt{\frac{-1}{2}}\right)}^{2}\right)} \cdot x + y \cdot {\left(\sqrt{\frac{-1}{2}}\right)}^{2} \]
          3. metadata-evalN/A

            \[\leadsto \left(1 - \color{blue}{1} \cdot {\left(\sqrt{\frac{-1}{2}}\right)}^{2}\right) \cdot x + y \cdot {\left(\sqrt{\frac{-1}{2}}\right)}^{2} \]
          4. *-lft-identityN/A

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

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

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

            \[\leadsto \color{blue}{\frac{3}{2}} \cdot x + y \cdot {\left(\sqrt{\frac{-1}{2}}\right)}^{2} \]
          8. metadata-evalN/A

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

            \[\leadsto \color{blue}{\left(x + \frac{1}{2} \cdot x\right)} + y \cdot {\left(\sqrt{\frac{-1}{2}}\right)}^{2} \]
          10. fp-cancel-sign-sub-invN/A

            \[\leadsto \color{blue}{\left(x - \left(\mathsf{neg}\left(\frac{1}{2}\right)\right) \cdot x\right)} + y \cdot {\left(\sqrt{\frac{-1}{2}}\right)}^{2} \]
          11. metadata-evalN/A

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

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

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

            \[\leadsto \left(x - \color{blue}{x \cdot {\left(\sqrt{\frac{-1}{2}}\right)}^{2}}\right) + y \cdot {\left(\sqrt{\frac{-1}{2}}\right)}^{2} \]
          15. fp-cancel-sub-signN/A

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

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

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

            \[\leadsto \color{blue}{x + \left(-1 \cdot \left(x \cdot {\left(\sqrt{\frac{-1}{2}}\right)}^{2}\right) + y \cdot {\left(\sqrt{\frac{-1}{2}}\right)}^{2}\right)} \]
        10. Applied rewrites69.0%

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

        if 3.6e-95 < 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. *-commutativeN/A

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

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

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

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

            \[\leadsto \color{blue}{\left|x - \left(\mathsf{neg}\left(-1\right)\right) \cdot y\right|} \cdot \frac{1}{2} \]
          6. fp-cancel-sign-sub-invN/A

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

            \[\leadsto \color{blue}{\left|x + -1 \cdot y\right|} \cdot \frac{1}{2} \]
          8. fp-cancel-sign-sub-invN/A

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

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

            \[\leadsto \left|x - \color{blue}{y}\right| \cdot \frac{1}{2} \]
          11. lower--.f6472.8

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

          \[\leadsto \color{blue}{\left|x - y\right| \cdot 0.5} \]
        6. Taylor expanded in x around 0

          \[\leadsto \left|-1 \cdot y\right| \cdot \frac{1}{2} \]
        7. Step-by-step derivation
          1. Applied rewrites71.6%

            \[\leadsto \left|-y\right| \cdot 0.5 \]
        8. Recombined 2 regimes into one program.
        9. Add Preprocessing

        Alternative 6: 45.4% accurate, 1.7× speedup?

        \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -9.8 \cdot 10^{-112}:\\ \;\;\;\;-0.5 \cdot y\\ \mathbf{else}:\\ \;\;\;\;1.5 \cdot x\\ \end{array} \end{array} \]
        (FPCore (x y) :precision binary64 (if (<= y -9.8e-112) (* -0.5 y) (* 1.5 x)))
        double code(double x, double y) {
        	double tmp;
        	if (y <= -9.8e-112) {
        		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 <= (-9.8d-112)) 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 <= -9.8e-112) {
        		tmp = -0.5 * y;
        	} else {
        		tmp = 1.5 * x;
        	}
        	return tmp;
        }
        
        def code(x, y):
        	tmp = 0
        	if y <= -9.8e-112:
        		tmp = -0.5 * y
        	else:
        		tmp = 1.5 * x
        	return tmp
        
        function code(x, y)
        	tmp = 0.0
        	if (y <= -9.8e-112)
        		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 <= -9.8e-112)
        		tmp = -0.5 * y;
        	else
        		tmp = 1.5 * x;
        	end
        	tmp_2 = tmp;
        end
        
        code[x_, y_] := If[LessEqual[y, -9.8e-112], N[(-0.5 * y), $MachinePrecision], N[(1.5 * x), $MachinePrecision]]
        
        \begin{array}{l}
        
        \\
        \begin{array}{l}
        \mathbf{if}\;y \leq -9.8 \cdot 10^{-112}:\\
        \;\;\;\;-0.5 \cdot y\\
        
        \mathbf{else}:\\
        \;\;\;\;1.5 \cdot x\\
        
        
        \end{array}
        \end{array}
        
        Derivation
        1. Split input into 2 regimes
        2. if y < -9.7999999999999996e-112

          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. unpow1N/A

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

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

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

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

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

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

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

            \[\leadsto \color{blue}{y \cdot {\left(\sqrt{\frac{-1}{2}}\right)}^{2}} \]
          6. Step-by-step derivation
            1. *-commutativeN/A

              \[\leadsto \color{blue}{{\left(\sqrt{\frac{-1}{2}}\right)}^{2} \cdot y} \]
            2. unpow2N/A

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

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

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

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

          if -9.7999999999999996e-112 < 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. unpow1N/A

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

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

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

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

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

              \[\leadsto \color{blue}{\mathsf{fma}\left(\sqrt{\frac{\left|y - x\right|}{2}}, \sqrt{\frac{\left|y - x\right|}{2}}, x\right)} \]
          4. Applied rewrites28.4%

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

            \[\leadsto \color{blue}{x \cdot \left(1 + -1 \cdot {\left(\sqrt{\frac{-1}{2}}\right)}^{2}\right)} \]
          6. Step-by-step derivation
            1. *-commutativeN/A

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

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

              \[\leadsto \left(1 + -1 \cdot \color{blue}{\frac{-1}{2}}\right) \cdot x \]
            4. metadata-evalN/A

              \[\leadsto \left(1 + \color{blue}{\frac{1}{2}}\right) \cdot x \]
            5. metadata-evalN/A

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

              \[\leadsto \color{blue}{1.5 \cdot x} \]
          7. Applied rewrites32.6%

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

        Alternative 7: 27.1% 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 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. unpow1N/A

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

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

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

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

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

            \[\leadsto \color{blue}{\mathsf{fma}\left(\sqrt{\frac{\left|y - x\right|}{2}}, \sqrt{\frac{\left|y - x\right|}{2}}, x\right)} \]
        4. Applied rewrites45.8%

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

          \[\leadsto \color{blue}{y \cdot {\left(\sqrt{\frac{-1}{2}}\right)}^{2}} \]
        6. Step-by-step derivation
          1. *-commutativeN/A

            \[\leadsto \color{blue}{{\left(\sqrt{\frac{-1}{2}}\right)}^{2} \cdot y} \]
          2. unpow2N/A

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

            \[\leadsto \color{blue}{\frac{-1}{2}} \cdot y \]
          4. lower-*.f6428.3

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

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

        Reproduce

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