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

Percentage Accurate: 99.9% → 99.9%
Time: 5.6s
Alternatives: 9
Speedup: 1.0×

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 9 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.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}
Derivation
  1. Initial program 99.9%

    \[x + \frac{\left|y - x\right|}{2} \]
  2. Final simplification99.9%

    \[\leadsto x + \frac{\left|y - x\right|}{2} \]

Alternative 2: 72.7% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \left(y - x\right) \cdot 0.5\\ \mathbf{if}\;x \leq -1.15 \cdot 10^{-17}:\\ \;\;\;\;0.5 \cdot \left(x + y\right)\\ \mathbf{elif}\;x \leq 2.8 \cdot 10^{+20} \lor \neg \left(x \leq 10^{+138}\right):\\ \;\;\;\;\left|y - x\right| \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;\frac{t_0 \cdot t_0 - x \cdot x}{y \cdot -0.5 + x \cdot -0.5}\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (let* ((t_0 (* (- y x) 0.5)))
   (if (<= x -1.15e-17)
     (* 0.5 (+ x y))
     (if (or (<= x 2.8e+20) (not (<= x 1e+138)))
       (* (fabs (- y x)) 0.5)
       (/ (- (* t_0 t_0) (* x x)) (+ (* y -0.5) (* x -0.5)))))))
double code(double x, double y) {
	double t_0 = (y - x) * 0.5;
	double tmp;
	if (x <= -1.15e-17) {
		tmp = 0.5 * (x + y);
	} else if ((x <= 2.8e+20) || !(x <= 1e+138)) {
		tmp = fabs((y - x)) * 0.5;
	} else {
		tmp = ((t_0 * t_0) - (x * x)) / ((y * -0.5) + (x * -0.5));
	}
	return tmp;
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8) :: t_0
    real(8) :: tmp
    t_0 = (y - x) * 0.5d0
    if (x <= (-1.15d-17)) then
        tmp = 0.5d0 * (x + y)
    else if ((x <= 2.8d+20) .or. (.not. (x <= 1d+138))) then
        tmp = abs((y - x)) * 0.5d0
    else
        tmp = ((t_0 * t_0) - (x * x)) / ((y * (-0.5d0)) + (x * (-0.5d0)))
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double t_0 = (y - x) * 0.5;
	double tmp;
	if (x <= -1.15e-17) {
		tmp = 0.5 * (x + y);
	} else if ((x <= 2.8e+20) || !(x <= 1e+138)) {
		tmp = Math.abs((y - x)) * 0.5;
	} else {
		tmp = ((t_0 * t_0) - (x * x)) / ((y * -0.5) + (x * -0.5));
	}
	return tmp;
}
def code(x, y):
	t_0 = (y - x) * 0.5
	tmp = 0
	if x <= -1.15e-17:
		tmp = 0.5 * (x + y)
	elif (x <= 2.8e+20) or not (x <= 1e+138):
		tmp = math.fabs((y - x)) * 0.5
	else:
		tmp = ((t_0 * t_0) - (x * x)) / ((y * -0.5) + (x * -0.5))
	return tmp
function code(x, y)
	t_0 = Float64(Float64(y - x) * 0.5)
	tmp = 0.0
	if (x <= -1.15e-17)
		tmp = Float64(0.5 * Float64(x + y));
	elseif ((x <= 2.8e+20) || !(x <= 1e+138))
		tmp = Float64(abs(Float64(y - x)) * 0.5);
	else
		tmp = Float64(Float64(Float64(t_0 * t_0) - Float64(x * x)) / Float64(Float64(y * -0.5) + Float64(x * -0.5)));
	end
	return tmp
end
function tmp_2 = code(x, y)
	t_0 = (y - x) * 0.5;
	tmp = 0.0;
	if (x <= -1.15e-17)
		tmp = 0.5 * (x + y);
	elseif ((x <= 2.8e+20) || ~((x <= 1e+138)))
		tmp = abs((y - x)) * 0.5;
	else
		tmp = ((t_0 * t_0) - (x * x)) / ((y * -0.5) + (x * -0.5));
	end
	tmp_2 = tmp;
end
code[x_, y_] := Block[{t$95$0 = N[(N[(y - x), $MachinePrecision] * 0.5), $MachinePrecision]}, If[LessEqual[x, -1.15e-17], N[(0.5 * N[(x + y), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[x, 2.8e+20], N[Not[LessEqual[x, 1e+138]], $MachinePrecision]], N[(N[Abs[N[(y - x), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision], N[(N[(N[(t$95$0 * t$95$0), $MachinePrecision] - N[(x * x), $MachinePrecision]), $MachinePrecision] / N[(N[(y * -0.5), $MachinePrecision] + N[(x * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \left(y - x\right) \cdot 0.5\\
\mathbf{if}\;x \leq -1.15 \cdot 10^{-17}:\\
\;\;\;\;0.5 \cdot \left(x + y\right)\\

\mathbf{elif}\;x \leq 2.8 \cdot 10^{+20} \lor \neg \left(x \leq 10^{+138}\right):\\
\;\;\;\;\left|y - x\right| \cdot 0.5\\

\mathbf{else}:\\
\;\;\;\;\frac{t_0 \cdot t_0 - x \cdot x}{y \cdot -0.5 + x \cdot -0.5}\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < -1.15000000000000004e-17

    1. Initial program 100.0%

      \[x + \frac{\left|y - x\right|}{2} \]
    2. Step-by-step derivation
      1. +-commutative100.0%

        \[\leadsto \color{blue}{\frac{\left|y - x\right|}{2} + x} \]
      2. div-inv100.0%

        \[\leadsto \color{blue}{\left|y - x\right| \cdot \frac{1}{2}} + x \]
      3. fma-def100.0%

        \[\leadsto \color{blue}{\mathsf{fma}\left(\left|y - x\right|, \frac{1}{2}, x\right)} \]
      4. add-sqr-sqrt90.5%

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

        \[\leadsto \mathsf{fma}\left(\color{blue}{\sqrt{y - x} \cdot \sqrt{y - x}}, \frac{1}{2}, x\right) \]
      6. add-sqr-sqrt91.3%

        \[\leadsto \mathsf{fma}\left(\color{blue}{y - x}, \frac{1}{2}, x\right) \]
      7. metadata-eval91.3%

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

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

      \[\leadsto \color{blue}{-0.5 \cdot x + \left(0.5 \cdot y + x\right)} \]
    5. Step-by-step derivation
      1. +-commutative91.3%

        \[\leadsto -0.5 \cdot x + \color{blue}{\left(x + 0.5 \cdot y\right)} \]
      2. associate-+r+91.3%

        \[\leadsto \color{blue}{\left(-0.5 \cdot x + x\right) + 0.5 \cdot y} \]
      3. distribute-lft1-in91.3%

        \[\leadsto \color{blue}{\left(-0.5 + 1\right) \cdot x} + 0.5 \cdot y \]
      4. metadata-eval91.3%

        \[\leadsto \color{blue}{0.5} \cdot x + 0.5 \cdot y \]
      5. distribute-lft-out91.3%

        \[\leadsto \color{blue}{0.5 \cdot \left(x + y\right)} \]
    6. Simplified91.3%

      \[\leadsto \color{blue}{0.5 \cdot \left(x + y\right)} \]

    if -1.15000000000000004e-17 < x < 2.8e20 or 1e138 < x

    1. Initial program 99.9%

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

      \[\leadsto \color{blue}{0.5 \cdot \left|y - x\right|} \]

    if 2.8e20 < x < 1e138

    1. Initial program 99.6%

      \[x + \frac{\left|y - x\right|}{2} \]
    2. Step-by-step derivation
      1. +-commutative99.6%

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

        \[\leadsto \color{blue}{\left|y - x\right| \cdot \frac{1}{2}} + x \]
      3. fma-def99.6%

        \[\leadsto \color{blue}{\mathsf{fma}\left(\left|y - x\right|, \frac{1}{2}, x\right)} \]
      4. add-sqr-sqrt3.8%

        \[\leadsto \mathsf{fma}\left(\left|\color{blue}{\sqrt{y - x} \cdot \sqrt{y - x}}\right|, \frac{1}{2}, x\right) \]
      5. fabs-sqr3.8%

        \[\leadsto \mathsf{fma}\left(\color{blue}{\sqrt{y - x} \cdot \sqrt{y - x}}, \frac{1}{2}, x\right) \]
      6. add-sqr-sqrt16.9%

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(y - x, 0.5, x\right)} \]
    4. Step-by-step derivation
      1. fma-udef16.9%

        \[\leadsto \color{blue}{\left(y - x\right) \cdot 0.5 + x} \]
      2. flip-+13.3%

        \[\leadsto \color{blue}{\frac{\left(\left(y - x\right) \cdot 0.5\right) \cdot \left(\left(y - x\right) \cdot 0.5\right) - x \cdot x}{\left(y - x\right) \cdot 0.5 - x}} \]
    5. Applied egg-rr13.3%

      \[\leadsto \color{blue}{\frac{\left(\left(y - x\right) \cdot 0.5\right) \cdot \left(\left(y - x\right) \cdot 0.5\right) - x \cdot x}{\left(y - x\right) \cdot 0.5 - x}} \]
    6. Step-by-step derivation
      1. add-sqr-sqrt0.2%

        \[\leadsto \frac{\left(\left(y - x\right) \cdot 0.5\right) \cdot \left(\left(y - x\right) \cdot 0.5\right) - x \cdot x}{\color{blue}{\sqrt{\left(y - x\right) \cdot 0.5} \cdot \sqrt{\left(y - x\right) \cdot 0.5}} - x} \]
      2. sqrt-prod87.9%

        \[\leadsto \frac{\left(\left(y - x\right) \cdot 0.5\right) \cdot \left(\left(y - x\right) \cdot 0.5\right) - x \cdot x}{\color{blue}{\sqrt{\left(\left(y - x\right) \cdot 0.5\right) \cdot \left(\left(y - x\right) \cdot 0.5\right)}} - x} \]
      3. associate-*r*87.9%

        \[\leadsto \frac{\left(\left(y - x\right) \cdot 0.5\right) \cdot \left(\left(y - x\right) \cdot 0.5\right) - x \cdot x}{\sqrt{\color{blue}{\left(\left(\left(y - x\right) \cdot 0.5\right) \cdot \left(y - x\right)\right) \cdot 0.5}} - x} \]
      4. sqrt-prod87.5%

        \[\leadsto \frac{\left(\left(y - x\right) \cdot 0.5\right) \cdot \left(\left(y - x\right) \cdot 0.5\right) - x \cdot x}{\color{blue}{\sqrt{\left(\left(y - x\right) \cdot 0.5\right) \cdot \left(y - x\right)} \cdot \sqrt{0.5}} - x} \]
      5. fma-neg87.5%

        \[\leadsto \frac{\left(\left(y - x\right) \cdot 0.5\right) \cdot \left(\left(y - x\right) \cdot 0.5\right) - x \cdot x}{\color{blue}{\mathsf{fma}\left(\sqrt{\left(\left(y - x\right) \cdot 0.5\right) \cdot \left(y - x\right)}, \sqrt{0.5}, -x\right)}} \]
      6. *-commutative87.5%

        \[\leadsto \frac{\left(\left(y - x\right) \cdot 0.5\right) \cdot \left(\left(y - x\right) \cdot 0.5\right) - x \cdot x}{\mathsf{fma}\left(\sqrt{\color{blue}{\left(0.5 \cdot \left(y - x\right)\right)} \cdot \left(y - x\right)}, \sqrt{0.5}, -x\right)} \]
      7. associate-*l*87.5%

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

        \[\leadsto \frac{\left(\left(y - x\right) \cdot 0.5\right) \cdot \left(\left(y - x\right) \cdot 0.5\right) - x \cdot x}{\mathsf{fma}\left(\sqrt{0.5 \cdot \color{blue}{{\left(y - x\right)}^{2}}}, \sqrt{0.5}, -x\right)} \]
    7. Applied egg-rr87.5%

      \[\leadsto \frac{\left(\left(y - x\right) \cdot 0.5\right) \cdot \left(\left(y - x\right) \cdot 0.5\right) - x \cdot x}{\color{blue}{\mathsf{fma}\left(\sqrt{0.5 \cdot {\left(y - x\right)}^{2}}, \sqrt{0.5}, -x\right)}} \]
    8. Taylor expanded in y around -inf 87.4%

      \[\leadsto \frac{\left(\left(y - x\right) \cdot 0.5\right) \cdot \left(\left(y - x\right) \cdot 0.5\right) - x \cdot x}{\color{blue}{\left({\left(\sqrt{0.5}\right)}^{2} \cdot x + -1 \cdot \left({\left(\sqrt{0.5}\right)}^{2} \cdot y\right)\right) - x}} \]
    9. Step-by-step derivation
      1. sub-neg87.4%

        \[\leadsto \frac{\left(\left(y - x\right) \cdot 0.5\right) \cdot \left(\left(y - x\right) \cdot 0.5\right) - x \cdot x}{\color{blue}{\left({\left(\sqrt{0.5}\right)}^{2} \cdot x + -1 \cdot \left({\left(\sqrt{0.5}\right)}^{2} \cdot y\right)\right) + \left(-x\right)}} \]
      2. +-commutative87.4%

        \[\leadsto \frac{\left(\left(y - x\right) \cdot 0.5\right) \cdot \left(\left(y - x\right) \cdot 0.5\right) - x \cdot x}{\color{blue}{\left(-1 \cdot \left({\left(\sqrt{0.5}\right)}^{2} \cdot y\right) + {\left(\sqrt{0.5}\right)}^{2} \cdot x\right)} + \left(-x\right)} \]
      3. associate-+l+87.4%

        \[\leadsto \frac{\left(\left(y - x\right) \cdot 0.5\right) \cdot \left(\left(y - x\right) \cdot 0.5\right) - x \cdot x}{\color{blue}{-1 \cdot \left({\left(\sqrt{0.5}\right)}^{2} \cdot y\right) + \left({\left(\sqrt{0.5}\right)}^{2} \cdot x + \left(-x\right)\right)}} \]
      4. *-commutative87.4%

        \[\leadsto \frac{\left(\left(y - x\right) \cdot 0.5\right) \cdot \left(\left(y - x\right) \cdot 0.5\right) - x \cdot x}{\color{blue}{\left({\left(\sqrt{0.5}\right)}^{2} \cdot y\right) \cdot -1} + \left({\left(\sqrt{0.5}\right)}^{2} \cdot x + \left(-x\right)\right)} \]
      5. *-commutative87.4%

        \[\leadsto \frac{\left(\left(y - x\right) \cdot 0.5\right) \cdot \left(\left(y - x\right) \cdot 0.5\right) - x \cdot x}{\color{blue}{\left(y \cdot {\left(\sqrt{0.5}\right)}^{2}\right)} \cdot -1 + \left({\left(\sqrt{0.5}\right)}^{2} \cdot x + \left(-x\right)\right)} \]
      6. unpow287.4%

        \[\leadsto \frac{\left(\left(y - x\right) \cdot 0.5\right) \cdot \left(\left(y - x\right) \cdot 0.5\right) - x \cdot x}{\left(y \cdot \color{blue}{\left(\sqrt{0.5} \cdot \sqrt{0.5}\right)}\right) \cdot -1 + \left({\left(\sqrt{0.5}\right)}^{2} \cdot x + \left(-x\right)\right)} \]
      7. rem-square-sqrt87.7%

        \[\leadsto \frac{\left(\left(y - x\right) \cdot 0.5\right) \cdot \left(\left(y - x\right) \cdot 0.5\right) - x \cdot x}{\left(y \cdot \color{blue}{0.5}\right) \cdot -1 + \left({\left(\sqrt{0.5}\right)}^{2} \cdot x + \left(-x\right)\right)} \]
      8. associate-*l*87.7%

        \[\leadsto \frac{\left(\left(y - x\right) \cdot 0.5\right) \cdot \left(\left(y - x\right) \cdot 0.5\right) - x \cdot x}{\color{blue}{y \cdot \left(0.5 \cdot -1\right)} + \left({\left(\sqrt{0.5}\right)}^{2} \cdot x + \left(-x\right)\right)} \]
      9. metadata-eval87.7%

        \[\leadsto \frac{\left(\left(y - x\right) \cdot 0.5\right) \cdot \left(\left(y - x\right) \cdot 0.5\right) - x \cdot x}{y \cdot \color{blue}{-0.5} + \left({\left(\sqrt{0.5}\right)}^{2} \cdot x + \left(-x\right)\right)} \]
      10. unpow287.7%

        \[\leadsto \frac{\left(\left(y - x\right) \cdot 0.5\right) \cdot \left(\left(y - x\right) \cdot 0.5\right) - x \cdot x}{y \cdot -0.5 + \left(\color{blue}{\left(\sqrt{0.5} \cdot \sqrt{0.5}\right)} \cdot x + \left(-x\right)\right)} \]
      11. rem-square-sqrt88.5%

        \[\leadsto \frac{\left(\left(y - x\right) \cdot 0.5\right) \cdot \left(\left(y - x\right) \cdot 0.5\right) - x \cdot x}{y \cdot -0.5 + \left(\color{blue}{0.5} \cdot x + \left(-x\right)\right)} \]
      12. neg-mul-188.5%

        \[\leadsto \frac{\left(\left(y - x\right) \cdot 0.5\right) \cdot \left(\left(y - x\right) \cdot 0.5\right) - x \cdot x}{y \cdot -0.5 + \left(0.5 \cdot x + \color{blue}{-1 \cdot x}\right)} \]
      13. distribute-rgt-out88.5%

        \[\leadsto \frac{\left(\left(y - x\right) \cdot 0.5\right) \cdot \left(\left(y - x\right) \cdot 0.5\right) - x \cdot x}{y \cdot -0.5 + \color{blue}{x \cdot \left(0.5 + -1\right)}} \]
      14. metadata-eval88.5%

        \[\leadsto \frac{\left(\left(y - x\right) \cdot 0.5\right) \cdot \left(\left(y - x\right) \cdot 0.5\right) - x \cdot x}{y \cdot -0.5 + x \cdot \color{blue}{-0.5}} \]
    10. Simplified88.5%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -1.15 \cdot 10^{-17}:\\ \;\;\;\;0.5 \cdot \left(x + y\right)\\ \mathbf{elif}\;x \leq 2.8 \cdot 10^{+20} \lor \neg \left(x \leq 10^{+138}\right):\\ \;\;\;\;\left|y - x\right| \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(\left(y - x\right) \cdot 0.5\right) \cdot \left(\left(y - x\right) \cdot 0.5\right) - x \cdot x}{y \cdot -0.5 + x \cdot -0.5}\\ \end{array} \]

Alternative 3: 72.9% accurate, 3.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \left(y - x\right) \cdot 0.5\\ \mathbf{if}\;y \leq -5 \cdot 10^{+131}:\\ \;\;\;\;\frac{y}{0.5} \cdot -0.25\\ \mathbf{elif}\;y \leq -7.7 \cdot 10^{-149} \lor \neg \left(y \leq 1.35 \cdot 10^{-96}\right) \land y \leq 3.1 \cdot 10^{-87}:\\ \;\;\;\;\frac{t_0 \cdot t_0 - x \cdot x}{y \cdot -0.5 + x \cdot -0.5}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(x + y\right)\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (let* ((t_0 (* (- y x) 0.5)))
   (if (<= y -5e+131)
     (* (/ y 0.5) -0.25)
     (if (or (<= y -7.7e-149) (and (not (<= y 1.35e-96)) (<= y 3.1e-87)))
       (/ (- (* t_0 t_0) (* x x)) (+ (* y -0.5) (* x -0.5)))
       (* 0.5 (+ x y))))))
double code(double x, double y) {
	double t_0 = (y - x) * 0.5;
	double tmp;
	if (y <= -5e+131) {
		tmp = (y / 0.5) * -0.25;
	} else if ((y <= -7.7e-149) || (!(y <= 1.35e-96) && (y <= 3.1e-87))) {
		tmp = ((t_0 * t_0) - (x * x)) / ((y * -0.5) + (x * -0.5));
	} else {
		tmp = 0.5 * (x + y);
	}
	return tmp;
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8) :: t_0
    real(8) :: tmp
    t_0 = (y - x) * 0.5d0
    if (y <= (-5d+131)) then
        tmp = (y / 0.5d0) * (-0.25d0)
    else if ((y <= (-7.7d-149)) .or. (.not. (y <= 1.35d-96)) .and. (y <= 3.1d-87)) then
        tmp = ((t_0 * t_0) - (x * x)) / ((y * (-0.5d0)) + (x * (-0.5d0)))
    else
        tmp = 0.5d0 * (x + y)
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double t_0 = (y - x) * 0.5;
	double tmp;
	if (y <= -5e+131) {
		tmp = (y / 0.5) * -0.25;
	} else if ((y <= -7.7e-149) || (!(y <= 1.35e-96) && (y <= 3.1e-87))) {
		tmp = ((t_0 * t_0) - (x * x)) / ((y * -0.5) + (x * -0.5));
	} else {
		tmp = 0.5 * (x + y);
	}
	return tmp;
}
def code(x, y):
	t_0 = (y - x) * 0.5
	tmp = 0
	if y <= -5e+131:
		tmp = (y / 0.5) * -0.25
	elif (y <= -7.7e-149) or (not (y <= 1.35e-96) and (y <= 3.1e-87)):
		tmp = ((t_0 * t_0) - (x * x)) / ((y * -0.5) + (x * -0.5))
	else:
		tmp = 0.5 * (x + y)
	return tmp
function code(x, y)
	t_0 = Float64(Float64(y - x) * 0.5)
	tmp = 0.0
	if (y <= -5e+131)
		tmp = Float64(Float64(y / 0.5) * -0.25);
	elseif ((y <= -7.7e-149) || (!(y <= 1.35e-96) && (y <= 3.1e-87)))
		tmp = Float64(Float64(Float64(t_0 * t_0) - Float64(x * x)) / Float64(Float64(y * -0.5) + Float64(x * -0.5)));
	else
		tmp = Float64(0.5 * Float64(x + y));
	end
	return tmp
end
function tmp_2 = code(x, y)
	t_0 = (y - x) * 0.5;
	tmp = 0.0;
	if (y <= -5e+131)
		tmp = (y / 0.5) * -0.25;
	elseif ((y <= -7.7e-149) || (~((y <= 1.35e-96)) && (y <= 3.1e-87)))
		tmp = ((t_0 * t_0) - (x * x)) / ((y * -0.5) + (x * -0.5));
	else
		tmp = 0.5 * (x + y);
	end
	tmp_2 = tmp;
end
code[x_, y_] := Block[{t$95$0 = N[(N[(y - x), $MachinePrecision] * 0.5), $MachinePrecision]}, If[LessEqual[y, -5e+131], N[(N[(y / 0.5), $MachinePrecision] * -0.25), $MachinePrecision], If[Or[LessEqual[y, -7.7e-149], And[N[Not[LessEqual[y, 1.35e-96]], $MachinePrecision], LessEqual[y, 3.1e-87]]], N[(N[(N[(t$95$0 * t$95$0), $MachinePrecision] - N[(x * x), $MachinePrecision]), $MachinePrecision] / N[(N[(y * -0.5), $MachinePrecision] + N[(x * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(x + y), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \left(y - x\right) \cdot 0.5\\
\mathbf{if}\;y \leq -5 \cdot 10^{+131}:\\
\;\;\;\;\frac{y}{0.5} \cdot -0.25\\

\mathbf{elif}\;y \leq -7.7 \cdot 10^{-149} \lor \neg \left(y \leq 1.35 \cdot 10^{-96}\right) \land y \leq 3.1 \cdot 10^{-87}:\\
\;\;\;\;\frac{t_0 \cdot t_0 - x \cdot x}{y \cdot -0.5 + x \cdot -0.5}\\

\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(x + y\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if y < -4.99999999999999995e131

    1. Initial program 100.0%

      \[x + \frac{\left|y - x\right|}{2} \]
    2. Step-by-step derivation
      1. +-commutative100.0%

        \[\leadsto \color{blue}{\frac{\left|y - x\right|}{2} + x} \]
      2. div-inv100.0%

        \[\leadsto \color{blue}{\left|y - x\right| \cdot \frac{1}{2}} + x \]
      3. fma-def100.0%

        \[\leadsto \color{blue}{\mathsf{fma}\left(\left|y - x\right|, \frac{1}{2}, x\right)} \]
      4. add-sqr-sqrt7.9%

        \[\leadsto \mathsf{fma}\left(\left|\color{blue}{\sqrt{y - x} \cdot \sqrt{y - x}}\right|, \frac{1}{2}, x\right) \]
      5. fabs-sqr7.9%

        \[\leadsto \mathsf{fma}\left(\color{blue}{\sqrt{y - x} \cdot \sqrt{y - x}}, \frac{1}{2}, x\right) \]
      6. add-sqr-sqrt9.1%

        \[\leadsto \mathsf{fma}\left(\color{blue}{y - x}, \frac{1}{2}, x\right) \]
      7. metadata-eval9.1%

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(y - x, 0.5, x\right)} \]
    4. Step-by-step derivation
      1. fma-udef9.1%

        \[\leadsto \color{blue}{\left(y - x\right) \cdot 0.5 + x} \]
      2. flip-+0.2%

        \[\leadsto \color{blue}{\frac{\left(\left(y - x\right) \cdot 0.5\right) \cdot \left(\left(y - x\right) \cdot 0.5\right) - x \cdot x}{\left(y - x\right) \cdot 0.5 - x}} \]
    5. Applied egg-rr0.2%

      \[\leadsto \color{blue}{\frac{\left(\left(y - x\right) \cdot 0.5\right) \cdot \left(\left(y - x\right) \cdot 0.5\right) - x \cdot x}{\left(y - x\right) \cdot 0.5 - x}} \]
    6. Step-by-step derivation
      1. add-sqr-sqrt0.0%

        \[\leadsto \frac{\left(\left(y - x\right) \cdot 0.5\right) \cdot \left(\left(y - x\right) \cdot 0.5\right) - x \cdot x}{\color{blue}{\sqrt{\left(y - x\right) \cdot 0.5} \cdot \sqrt{\left(y - x\right) \cdot 0.5}} - x} \]
      2. sqrt-prod13.1%

        \[\leadsto \frac{\left(\left(y - x\right) \cdot 0.5\right) \cdot \left(\left(y - x\right) \cdot 0.5\right) - x \cdot x}{\color{blue}{\sqrt{\left(\left(y - x\right) \cdot 0.5\right) \cdot \left(\left(y - x\right) \cdot 0.5\right)}} - x} \]
      3. associate-*r*13.1%

        \[\leadsto \frac{\left(\left(y - x\right) \cdot 0.5\right) \cdot \left(\left(y - x\right) \cdot 0.5\right) - x \cdot x}{\sqrt{\color{blue}{\left(\left(\left(y - x\right) \cdot 0.5\right) \cdot \left(y - x\right)\right) \cdot 0.5}} - x} \]
      4. sqrt-prod13.1%

        \[\leadsto \frac{\left(\left(y - x\right) \cdot 0.5\right) \cdot \left(\left(y - x\right) \cdot 0.5\right) - x \cdot x}{\color{blue}{\sqrt{\left(\left(y - x\right) \cdot 0.5\right) \cdot \left(y - x\right)} \cdot \sqrt{0.5}} - x} \]
      5. fma-neg13.1%

        \[\leadsto \frac{\left(\left(y - x\right) \cdot 0.5\right) \cdot \left(\left(y - x\right) \cdot 0.5\right) - x \cdot x}{\color{blue}{\mathsf{fma}\left(\sqrt{\left(\left(y - x\right) \cdot 0.5\right) \cdot \left(y - x\right)}, \sqrt{0.5}, -x\right)}} \]
      6. *-commutative13.1%

        \[\leadsto \frac{\left(\left(y - x\right) \cdot 0.5\right) \cdot \left(\left(y - x\right) \cdot 0.5\right) - x \cdot x}{\mathsf{fma}\left(\sqrt{\color{blue}{\left(0.5 \cdot \left(y - x\right)\right)} \cdot \left(y - x\right)}, \sqrt{0.5}, -x\right)} \]
      7. associate-*l*13.1%

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

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

      \[\leadsto \frac{\left(\left(y - x\right) \cdot 0.5\right) \cdot \left(\left(y - x\right) \cdot 0.5\right) - x \cdot x}{\color{blue}{\mathsf{fma}\left(\sqrt{0.5 \cdot {\left(y - x\right)}^{2}}, \sqrt{0.5}, -x\right)}} \]
    8. Taylor expanded in y around -inf 85.6%

      \[\leadsto \color{blue}{-0.25 \cdot \frac{y}{{\left(\sqrt{0.5}\right)}^{2}}} \]
    9. Step-by-step derivation
      1. *-commutative85.6%

        \[\leadsto \color{blue}{\frac{y}{{\left(\sqrt{0.5}\right)}^{2}} \cdot -0.25} \]
      2. unpow285.6%

        \[\leadsto \frac{y}{\color{blue}{\sqrt{0.5} \cdot \sqrt{0.5}}} \cdot -0.25 \]
      3. rem-square-sqrt87.3%

        \[\leadsto \frac{y}{\color{blue}{0.5}} \cdot -0.25 \]
    10. Simplified87.3%

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

    if -4.99999999999999995e131 < y < -7.70000000000000025e-149 or 1.35e-96 < y < 3.09999999999999998e-87

    1. Initial program 99.9%

      \[x + \frac{\left|y - x\right|}{2} \]
    2. Step-by-step derivation
      1. +-commutative99.9%

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

        \[\leadsto \color{blue}{\left|y - x\right| \cdot \frac{1}{2}} + x \]
      3. fma-def99.9%

        \[\leadsto \color{blue}{\mathsf{fma}\left(\left|y - x\right|, \frac{1}{2}, x\right)} \]
      4. add-sqr-sqrt20.8%

        \[\leadsto \mathsf{fma}\left(\left|\color{blue}{\sqrt{y - x} \cdot \sqrt{y - x}}\right|, \frac{1}{2}, x\right) \]
      5. fabs-sqr20.8%

        \[\leadsto \mathsf{fma}\left(\color{blue}{\sqrt{y - x} \cdot \sqrt{y - x}}, \frac{1}{2}, x\right) \]
      6. add-sqr-sqrt25.4%

        \[\leadsto \mathsf{fma}\left(\color{blue}{y - x}, \frac{1}{2}, x\right) \]
      7. metadata-eval25.4%

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(y - x, 0.5, x\right)} \]
    4. Step-by-step derivation
      1. fma-udef25.4%

        \[\leadsto \color{blue}{\left(y - x\right) \cdot 0.5 + x} \]
      2. flip-+15.4%

        \[\leadsto \color{blue}{\frac{\left(\left(y - x\right) \cdot 0.5\right) \cdot \left(\left(y - x\right) \cdot 0.5\right) - x \cdot x}{\left(y - x\right) \cdot 0.5 - x}} \]
    5. Applied egg-rr15.4%

      \[\leadsto \color{blue}{\frac{\left(\left(y - x\right) \cdot 0.5\right) \cdot \left(\left(y - x\right) \cdot 0.5\right) - x \cdot x}{\left(y - x\right) \cdot 0.5 - x}} \]
    6. Step-by-step derivation
      1. add-sqr-sqrt11.9%

        \[\leadsto \frac{\left(\left(y - x\right) \cdot 0.5\right) \cdot \left(\left(y - x\right) \cdot 0.5\right) - x \cdot x}{\color{blue}{\sqrt{\left(y - x\right) \cdot 0.5} \cdot \sqrt{\left(y - x\right) \cdot 0.5}} - x} \]
      2. sqrt-prod84.8%

        \[\leadsto \frac{\left(\left(y - x\right) \cdot 0.5\right) \cdot \left(\left(y - x\right) \cdot 0.5\right) - x \cdot x}{\color{blue}{\sqrt{\left(\left(y - x\right) \cdot 0.5\right) \cdot \left(\left(y - x\right) \cdot 0.5\right)}} - x} \]
      3. associate-*r*84.8%

        \[\leadsto \frac{\left(\left(y - x\right) \cdot 0.5\right) \cdot \left(\left(y - x\right) \cdot 0.5\right) - x \cdot x}{\sqrt{\color{blue}{\left(\left(\left(y - x\right) \cdot 0.5\right) \cdot \left(y - x\right)\right) \cdot 0.5}} - x} \]
      4. sqrt-prod84.3%

        \[\leadsto \frac{\left(\left(y - x\right) \cdot 0.5\right) \cdot \left(\left(y - x\right) \cdot 0.5\right) - x \cdot x}{\color{blue}{\sqrt{\left(\left(y - x\right) \cdot 0.5\right) \cdot \left(y - x\right)} \cdot \sqrt{0.5}} - x} \]
      5. fma-neg84.3%

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

        \[\leadsto \frac{\left(\left(y - x\right) \cdot 0.5\right) \cdot \left(\left(y - x\right) \cdot 0.5\right) - x \cdot x}{\mathsf{fma}\left(\sqrt{\color{blue}{\left(0.5 \cdot \left(y - x\right)\right)} \cdot \left(y - x\right)}, \sqrt{0.5}, -x\right)} \]
      7. associate-*l*84.3%

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

        \[\leadsto \frac{\left(\left(y - x\right) \cdot 0.5\right) \cdot \left(\left(y - x\right) \cdot 0.5\right) - x \cdot x}{\mathsf{fma}\left(\sqrt{0.5 \cdot \color{blue}{{\left(y - x\right)}^{2}}}, \sqrt{0.5}, -x\right)} \]
    7. Applied egg-rr84.3%

      \[\leadsto \frac{\left(\left(y - x\right) \cdot 0.5\right) \cdot \left(\left(y - x\right) \cdot 0.5\right) - x \cdot x}{\color{blue}{\mathsf{fma}\left(\sqrt{0.5 \cdot {\left(y - x\right)}^{2}}, \sqrt{0.5}, -x\right)}} \]
    8. Taylor expanded in y around -inf 73.8%

      \[\leadsto \frac{\left(\left(y - x\right) \cdot 0.5\right) \cdot \left(\left(y - x\right) \cdot 0.5\right) - x \cdot x}{\color{blue}{\left({\left(\sqrt{0.5}\right)}^{2} \cdot x + -1 \cdot \left({\left(\sqrt{0.5}\right)}^{2} \cdot y\right)\right) - x}} \]
    9. Step-by-step derivation
      1. sub-neg73.8%

        \[\leadsto \frac{\left(\left(y - x\right) \cdot 0.5\right) \cdot \left(\left(y - x\right) \cdot 0.5\right) - x \cdot x}{\color{blue}{\left({\left(\sqrt{0.5}\right)}^{2} \cdot x + -1 \cdot \left({\left(\sqrt{0.5}\right)}^{2} \cdot y\right)\right) + \left(-x\right)}} \]
      2. +-commutative73.8%

        \[\leadsto \frac{\left(\left(y - x\right) \cdot 0.5\right) \cdot \left(\left(y - x\right) \cdot 0.5\right) - x \cdot x}{\color{blue}{\left(-1 \cdot \left({\left(\sqrt{0.5}\right)}^{2} \cdot y\right) + {\left(\sqrt{0.5}\right)}^{2} \cdot x\right)} + \left(-x\right)} \]
      3. associate-+l+73.8%

        \[\leadsto \frac{\left(\left(y - x\right) \cdot 0.5\right) \cdot \left(\left(y - x\right) \cdot 0.5\right) - x \cdot x}{\color{blue}{-1 \cdot \left({\left(\sqrt{0.5}\right)}^{2} \cdot y\right) + \left({\left(\sqrt{0.5}\right)}^{2} \cdot x + \left(-x\right)\right)}} \]
      4. *-commutative73.8%

        \[\leadsto \frac{\left(\left(y - x\right) \cdot 0.5\right) \cdot \left(\left(y - x\right) \cdot 0.5\right) - x \cdot x}{\color{blue}{\left({\left(\sqrt{0.5}\right)}^{2} \cdot y\right) \cdot -1} + \left({\left(\sqrt{0.5}\right)}^{2} \cdot x + \left(-x\right)\right)} \]
      5. *-commutative73.8%

        \[\leadsto \frac{\left(\left(y - x\right) \cdot 0.5\right) \cdot \left(\left(y - x\right) \cdot 0.5\right) - x \cdot x}{\color{blue}{\left(y \cdot {\left(\sqrt{0.5}\right)}^{2}\right)} \cdot -1 + \left({\left(\sqrt{0.5}\right)}^{2} \cdot x + \left(-x\right)\right)} \]
      6. unpow273.8%

        \[\leadsto \frac{\left(\left(y - x\right) \cdot 0.5\right) \cdot \left(\left(y - x\right) \cdot 0.5\right) - x \cdot x}{\left(y \cdot \color{blue}{\left(\sqrt{0.5} \cdot \sqrt{0.5}\right)}\right) \cdot -1 + \left({\left(\sqrt{0.5}\right)}^{2} \cdot x + \left(-x\right)\right)} \]
      7. rem-square-sqrt74.9%

        \[\leadsto \frac{\left(\left(y - x\right) \cdot 0.5\right) \cdot \left(\left(y - x\right) \cdot 0.5\right) - x \cdot x}{\left(y \cdot \color{blue}{0.5}\right) \cdot -1 + \left({\left(\sqrt{0.5}\right)}^{2} \cdot x + \left(-x\right)\right)} \]
      8. associate-*l*74.9%

        \[\leadsto \frac{\left(\left(y - x\right) \cdot 0.5\right) \cdot \left(\left(y - x\right) \cdot 0.5\right) - x \cdot x}{\color{blue}{y \cdot \left(0.5 \cdot -1\right)} + \left({\left(\sqrt{0.5}\right)}^{2} \cdot x + \left(-x\right)\right)} \]
      9. metadata-eval74.9%

        \[\leadsto \frac{\left(\left(y - x\right) \cdot 0.5\right) \cdot \left(\left(y - x\right) \cdot 0.5\right) - x \cdot x}{y \cdot \color{blue}{-0.5} + \left({\left(\sqrt{0.5}\right)}^{2} \cdot x + \left(-x\right)\right)} \]
      10. unpow274.9%

        \[\leadsto \frac{\left(\left(y - x\right) \cdot 0.5\right) \cdot \left(\left(y - x\right) \cdot 0.5\right) - x \cdot x}{y \cdot -0.5 + \left(\color{blue}{\left(\sqrt{0.5} \cdot \sqrt{0.5}\right)} \cdot x + \left(-x\right)\right)} \]
      11. rem-square-sqrt74.9%

        \[\leadsto \frac{\left(\left(y - x\right) \cdot 0.5\right) \cdot \left(\left(y - x\right) \cdot 0.5\right) - x \cdot x}{y \cdot -0.5 + \left(\color{blue}{0.5} \cdot x + \left(-x\right)\right)} \]
      12. neg-mul-174.9%

        \[\leadsto \frac{\left(\left(y - x\right) \cdot 0.5\right) \cdot \left(\left(y - x\right) \cdot 0.5\right) - x \cdot x}{y \cdot -0.5 + \left(0.5 \cdot x + \color{blue}{-1 \cdot x}\right)} \]
      13. distribute-rgt-out74.9%

        \[\leadsto \frac{\left(\left(y - x\right) \cdot 0.5\right) \cdot \left(\left(y - x\right) \cdot 0.5\right) - x \cdot x}{y \cdot -0.5 + \color{blue}{x \cdot \left(0.5 + -1\right)}} \]
      14. metadata-eval74.9%

        \[\leadsto \frac{\left(\left(y - x\right) \cdot 0.5\right) \cdot \left(\left(y - x\right) \cdot 0.5\right) - x \cdot x}{y \cdot -0.5 + x \cdot \color{blue}{-0.5}} \]
    10. Simplified74.9%

      \[\leadsto \frac{\left(\left(y - x\right) \cdot 0.5\right) \cdot \left(\left(y - x\right) \cdot 0.5\right) - x \cdot x}{\color{blue}{y \cdot -0.5 + x \cdot -0.5}} \]

    if -7.70000000000000025e-149 < y < 1.35e-96 or 3.09999999999999998e-87 < y

    1. Initial program 99.9%

      \[x + \frac{\left|y - x\right|}{2} \]
    2. Step-by-step derivation
      1. +-commutative99.9%

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

        \[\leadsto \color{blue}{\left|y - x\right| \cdot \frac{1}{2}} + x \]
      3. fma-def99.9%

        \[\leadsto \color{blue}{\mathsf{fma}\left(\left|y - x\right|, \frac{1}{2}, x\right)} \]
      4. add-sqr-sqrt72.1%

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

        \[\leadsto \mathsf{fma}\left(\color{blue}{\sqrt{y - x} \cdot \sqrt{y - x}}, \frac{1}{2}, x\right) \]
      6. add-sqr-sqrt77.4%

        \[\leadsto \mathsf{fma}\left(\color{blue}{y - x}, \frac{1}{2}, x\right) \]
      7. metadata-eval77.4%

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

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

      \[\leadsto \color{blue}{-0.5 \cdot x + \left(0.5 \cdot y + x\right)} \]
    5. Step-by-step derivation
      1. +-commutative77.4%

        \[\leadsto -0.5 \cdot x + \color{blue}{\left(x + 0.5 \cdot y\right)} \]
      2. associate-+r+77.4%

        \[\leadsto \color{blue}{\left(-0.5 \cdot x + x\right) + 0.5 \cdot y} \]
      3. distribute-lft1-in77.4%

        \[\leadsto \color{blue}{\left(-0.5 + 1\right) \cdot x} + 0.5 \cdot y \]
      4. metadata-eval77.4%

        \[\leadsto \color{blue}{0.5} \cdot x + 0.5 \cdot y \]
      5. distribute-lft-out77.4%

        \[\leadsto \color{blue}{0.5 \cdot \left(x + y\right)} \]
    6. Simplified77.4%

      \[\leadsto \color{blue}{0.5 \cdot \left(x + y\right)} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification78.2%

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -5 \cdot 10^{+131}:\\ \;\;\;\;\frac{y}{0.5} \cdot -0.25\\ \mathbf{elif}\;y \leq -7.7 \cdot 10^{-149} \lor \neg \left(y \leq 1.35 \cdot 10^{-96}\right) \land y \leq 3.1 \cdot 10^{-87}:\\ \;\;\;\;\frac{\left(\left(y - x\right) \cdot 0.5\right) \cdot \left(\left(y - x\right) \cdot 0.5\right) - x \cdot x}{y \cdot -0.5 + x \cdot -0.5}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(x + y\right)\\ \end{array} \]

Alternative 4: 69.5% accurate, 4.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \left(y - x\right) \cdot 0.5\\ \mathbf{if}\;y \leq -3.9 \cdot 10^{+21}:\\ \;\;\;\;\frac{y}{0.5} \cdot -0.25\\ \mathbf{elif}\;y \leq -1.9 \cdot 10^{-28}:\\ \;\;\;\;x \cdot 0.5\\ \mathbf{elif}\;y \leq -5 \cdot 10^{-93}:\\ \;\;\;\;\frac{t_0 \cdot t_0 - x \cdot x}{y \cdot -0.5}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(x + y\right)\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (let* ((t_0 (* (- y x) 0.5)))
   (if (<= y -3.9e+21)
     (* (/ y 0.5) -0.25)
     (if (<= y -1.9e-28)
       (* x 0.5)
       (if (<= y -5e-93)
         (/ (- (* t_0 t_0) (* x x)) (* y -0.5))
         (* 0.5 (+ x y)))))))
double code(double x, double y) {
	double t_0 = (y - x) * 0.5;
	double tmp;
	if (y <= -3.9e+21) {
		tmp = (y / 0.5) * -0.25;
	} else if (y <= -1.9e-28) {
		tmp = x * 0.5;
	} else if (y <= -5e-93) {
		tmp = ((t_0 * t_0) - (x * x)) / (y * -0.5);
	} else {
		tmp = 0.5 * (x + y);
	}
	return tmp;
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8) :: t_0
    real(8) :: tmp
    t_0 = (y - x) * 0.5d0
    if (y <= (-3.9d+21)) then
        tmp = (y / 0.5d0) * (-0.25d0)
    else if (y <= (-1.9d-28)) then
        tmp = x * 0.5d0
    else if (y <= (-5d-93)) then
        tmp = ((t_0 * t_0) - (x * x)) / (y * (-0.5d0))
    else
        tmp = 0.5d0 * (x + y)
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double t_0 = (y - x) * 0.5;
	double tmp;
	if (y <= -3.9e+21) {
		tmp = (y / 0.5) * -0.25;
	} else if (y <= -1.9e-28) {
		tmp = x * 0.5;
	} else if (y <= -5e-93) {
		tmp = ((t_0 * t_0) - (x * x)) / (y * -0.5);
	} else {
		tmp = 0.5 * (x + y);
	}
	return tmp;
}
def code(x, y):
	t_0 = (y - x) * 0.5
	tmp = 0
	if y <= -3.9e+21:
		tmp = (y / 0.5) * -0.25
	elif y <= -1.9e-28:
		tmp = x * 0.5
	elif y <= -5e-93:
		tmp = ((t_0 * t_0) - (x * x)) / (y * -0.5)
	else:
		tmp = 0.5 * (x + y)
	return tmp
function code(x, y)
	t_0 = Float64(Float64(y - x) * 0.5)
	tmp = 0.0
	if (y <= -3.9e+21)
		tmp = Float64(Float64(y / 0.5) * -0.25);
	elseif (y <= -1.9e-28)
		tmp = Float64(x * 0.5);
	elseif (y <= -5e-93)
		tmp = Float64(Float64(Float64(t_0 * t_0) - Float64(x * x)) / Float64(y * -0.5));
	else
		tmp = Float64(0.5 * Float64(x + y));
	end
	return tmp
end
function tmp_2 = code(x, y)
	t_0 = (y - x) * 0.5;
	tmp = 0.0;
	if (y <= -3.9e+21)
		tmp = (y / 0.5) * -0.25;
	elseif (y <= -1.9e-28)
		tmp = x * 0.5;
	elseif (y <= -5e-93)
		tmp = ((t_0 * t_0) - (x * x)) / (y * -0.5);
	else
		tmp = 0.5 * (x + y);
	end
	tmp_2 = tmp;
end
code[x_, y_] := Block[{t$95$0 = N[(N[(y - x), $MachinePrecision] * 0.5), $MachinePrecision]}, If[LessEqual[y, -3.9e+21], N[(N[(y / 0.5), $MachinePrecision] * -0.25), $MachinePrecision], If[LessEqual[y, -1.9e-28], N[(x * 0.5), $MachinePrecision], If[LessEqual[y, -5e-93], N[(N[(N[(t$95$0 * t$95$0), $MachinePrecision] - N[(x * x), $MachinePrecision]), $MachinePrecision] / N[(y * -0.5), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(x + y), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \left(y - x\right) \cdot 0.5\\
\mathbf{if}\;y \leq -3.9 \cdot 10^{+21}:\\
\;\;\;\;\frac{y}{0.5} \cdot -0.25\\

\mathbf{elif}\;y \leq -1.9 \cdot 10^{-28}:\\
\;\;\;\;x \cdot 0.5\\

\mathbf{elif}\;y \leq -5 \cdot 10^{-93}:\\
\;\;\;\;\frac{t_0 \cdot t_0 - x \cdot x}{y \cdot -0.5}\\

\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(x + y\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if y < -3.9e21

    1. Initial program 100.0%

      \[x + \frac{\left|y - x\right|}{2} \]
    2. Step-by-step derivation
      1. +-commutative100.0%

        \[\leadsto \color{blue}{\frac{\left|y - x\right|}{2} + x} \]
      2. div-inv100.0%

        \[\leadsto \color{blue}{\left|y - x\right| \cdot \frac{1}{2}} + x \]
      3. fma-def100.0%

        \[\leadsto \color{blue}{\mathsf{fma}\left(\left|y - x\right|, \frac{1}{2}, x\right)} \]
      4. add-sqr-sqrt6.1%

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

        \[\leadsto \mathsf{fma}\left(\color{blue}{\sqrt{y - x} \cdot \sqrt{y - x}}, \frac{1}{2}, x\right) \]
      6. add-sqr-sqrt7.5%

        \[\leadsto \mathsf{fma}\left(\color{blue}{y - x}, \frac{1}{2}, x\right) \]
      7. metadata-eval7.5%

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(y - x, 0.5, x\right)} \]
    4. Step-by-step derivation
      1. fma-udef7.5%

        \[\leadsto \color{blue}{\left(y - x\right) \cdot 0.5 + x} \]
      2. flip-+2.0%

        \[\leadsto \color{blue}{\frac{\left(\left(y - x\right) \cdot 0.5\right) \cdot \left(\left(y - x\right) \cdot 0.5\right) - x \cdot x}{\left(y - x\right) \cdot 0.5 - x}} \]
    5. Applied egg-rr2.0%

      \[\leadsto \color{blue}{\frac{\left(\left(y - x\right) \cdot 0.5\right) \cdot \left(\left(y - x\right) \cdot 0.5\right) - x \cdot x}{\left(y - x\right) \cdot 0.5 - x}} \]
    6. Step-by-step derivation
      1. add-sqr-sqrt1.5%

        \[\leadsto \frac{\left(\left(y - x\right) \cdot 0.5\right) \cdot \left(\left(y - x\right) \cdot 0.5\right) - x \cdot x}{\color{blue}{\sqrt{\left(y - x\right) \cdot 0.5} \cdot \sqrt{\left(y - x\right) \cdot 0.5}} - x} \]
      2. sqrt-prod47.6%

        \[\leadsto \frac{\left(\left(y - x\right) \cdot 0.5\right) \cdot \left(\left(y - x\right) \cdot 0.5\right) - x \cdot x}{\color{blue}{\sqrt{\left(\left(y - x\right) \cdot 0.5\right) \cdot \left(\left(y - x\right) \cdot 0.5\right)}} - x} \]
      3. associate-*r*47.6%

        \[\leadsto \frac{\left(\left(y - x\right) \cdot 0.5\right) \cdot \left(\left(y - x\right) \cdot 0.5\right) - x \cdot x}{\sqrt{\color{blue}{\left(\left(\left(y - x\right) \cdot 0.5\right) \cdot \left(y - x\right)\right) \cdot 0.5}} - x} \]
      4. sqrt-prod47.3%

        \[\leadsto \frac{\left(\left(y - x\right) \cdot 0.5\right) \cdot \left(\left(y - x\right) \cdot 0.5\right) - x \cdot x}{\color{blue}{\sqrt{\left(\left(y - x\right) \cdot 0.5\right) \cdot \left(y - x\right)} \cdot \sqrt{0.5}} - x} \]
      5. fma-neg47.3%

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

        \[\leadsto \frac{\left(\left(y - x\right) \cdot 0.5\right) \cdot \left(\left(y - x\right) \cdot 0.5\right) - x \cdot x}{\mathsf{fma}\left(\sqrt{\color{blue}{\left(0.5 \cdot \left(y - x\right)\right)} \cdot \left(y - x\right)}, \sqrt{0.5}, -x\right)} \]
      7. associate-*l*47.3%

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

        \[\leadsto \frac{\left(\left(y - x\right) \cdot 0.5\right) \cdot \left(\left(y - x\right) \cdot 0.5\right) - x \cdot x}{\mathsf{fma}\left(\sqrt{0.5 \cdot \color{blue}{{\left(y - x\right)}^{2}}}, \sqrt{0.5}, -x\right)} \]
    7. Applied egg-rr47.3%

      \[\leadsto \frac{\left(\left(y - x\right) \cdot 0.5\right) \cdot \left(\left(y - x\right) \cdot 0.5\right) - x \cdot x}{\color{blue}{\mathsf{fma}\left(\sqrt{0.5 \cdot {\left(y - x\right)}^{2}}, \sqrt{0.5}, -x\right)}} \]
    8. Taylor expanded in y around -inf 85.6%

      \[\leadsto \color{blue}{-0.25 \cdot \frac{y}{{\left(\sqrt{0.5}\right)}^{2}}} \]
    9. Step-by-step derivation
      1. *-commutative85.6%

        \[\leadsto \color{blue}{\frac{y}{{\left(\sqrt{0.5}\right)}^{2}} \cdot -0.25} \]
      2. unpow285.6%

        \[\leadsto \frac{y}{\color{blue}{\sqrt{0.5} \cdot \sqrt{0.5}}} \cdot -0.25 \]
      3. rem-square-sqrt87.4%

        \[\leadsto \frac{y}{\color{blue}{0.5}} \cdot -0.25 \]
    10. Simplified87.4%

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

    if -3.9e21 < y < -1.90000000000000005e-28

    1. Initial program 99.7%

      \[x + \frac{\left|y - x\right|}{2} \]
    2. Step-by-step derivation
      1. +-commutative99.7%

        \[\leadsto \color{blue}{\frac{\left|y - x\right|}{2} + x} \]
      2. div-inv99.7%

        \[\leadsto \color{blue}{\left|y - x\right| \cdot \frac{1}{2}} + x \]
      3. fma-def99.7%

        \[\leadsto \color{blue}{\mathsf{fma}\left(\left|y - x\right|, \frac{1}{2}, x\right)} \]
      4. add-sqr-sqrt49.8%

        \[\leadsto \mathsf{fma}\left(\left|\color{blue}{\sqrt{y - x} \cdot \sqrt{y - x}}\right|, \frac{1}{2}, x\right) \]
      5. fabs-sqr49.8%

        \[\leadsto \mathsf{fma}\left(\color{blue}{\sqrt{y - x} \cdot \sqrt{y - x}}, \frac{1}{2}, x\right) \]
      6. add-sqr-sqrt55.4%

        \[\leadsto \mathsf{fma}\left(\color{blue}{y - x}, \frac{1}{2}, x\right) \]
      7. metadata-eval55.4%

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

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

      \[\leadsto \color{blue}{-0.5 \cdot x + x} \]
    5. Step-by-step derivation
      1. distribute-lft1-in56.1%

        \[\leadsto \color{blue}{\left(-0.5 + 1\right) \cdot x} \]
      2. metadata-eval56.1%

        \[\leadsto \color{blue}{0.5} \cdot x \]
      3. *-commutative56.1%

        \[\leadsto \color{blue}{x \cdot 0.5} \]
    6. Simplified56.1%

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

    if -1.90000000000000005e-28 < y < -4.99999999999999994e-93

    1. Initial program 100.0%

      \[x + \frac{\left|y - x\right|}{2} \]
    2. Step-by-step derivation
      1. +-commutative100.0%

        \[\leadsto \color{blue}{\frac{\left|y - x\right|}{2} + x} \]
      2. div-inv100.0%

        \[\leadsto \color{blue}{\left|y - x\right| \cdot \frac{1}{2}} + x \]
      3. fma-def100.0%

        \[\leadsto \color{blue}{\mathsf{fma}\left(\left|y - x\right|, \frac{1}{2}, x\right)} \]
      4. add-sqr-sqrt18.0%

        \[\leadsto \mathsf{fma}\left(\left|\color{blue}{\sqrt{y - x} \cdot \sqrt{y - x}}\right|, \frac{1}{2}, x\right) \]
      5. fabs-sqr18.0%

        \[\leadsto \mathsf{fma}\left(\color{blue}{\sqrt{y - x} \cdot \sqrt{y - x}}, \frac{1}{2}, x\right) \]
      6. add-sqr-sqrt22.7%

        \[\leadsto \mathsf{fma}\left(\color{blue}{y - x}, \frac{1}{2}, x\right) \]
      7. metadata-eval22.7%

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(y - x, 0.5, x\right)} \]
    4. Step-by-step derivation
      1. fma-udef22.7%

        \[\leadsto \color{blue}{\left(y - x\right) \cdot 0.5 + x} \]
      2. flip-+20.9%

        \[\leadsto \color{blue}{\frac{\left(\left(y - x\right) \cdot 0.5\right) \cdot \left(\left(y - x\right) \cdot 0.5\right) - x \cdot x}{\left(y - x\right) \cdot 0.5 - x}} \]
    5. Applied egg-rr20.9%

      \[\leadsto \color{blue}{\frac{\left(\left(y - x\right) \cdot 0.5\right) \cdot \left(\left(y - x\right) \cdot 0.5\right) - x \cdot x}{\left(y - x\right) \cdot 0.5 - x}} \]
    6. Step-by-step derivation
      1. add-sqr-sqrt18.0%

        \[\leadsto \frac{\left(\left(y - x\right) \cdot 0.5\right) \cdot \left(\left(y - x\right) \cdot 0.5\right) - x \cdot x}{\color{blue}{\sqrt{\left(y - x\right) \cdot 0.5} \cdot \sqrt{\left(y - x\right) \cdot 0.5}} - x} \]
      2. sqrt-prod90.5%

        \[\leadsto \frac{\left(\left(y - x\right) \cdot 0.5\right) \cdot \left(\left(y - x\right) \cdot 0.5\right) - x \cdot x}{\color{blue}{\sqrt{\left(\left(y - x\right) \cdot 0.5\right) \cdot \left(\left(y - x\right) \cdot 0.5\right)}} - x} \]
      3. associate-*r*90.5%

        \[\leadsto \frac{\left(\left(y - x\right) \cdot 0.5\right) \cdot \left(\left(y - x\right) \cdot 0.5\right) - x \cdot x}{\sqrt{\color{blue}{\left(\left(\left(y - x\right) \cdot 0.5\right) \cdot \left(y - x\right)\right) \cdot 0.5}} - x} \]
      4. sqrt-prod90.1%

        \[\leadsto \frac{\left(\left(y - x\right) \cdot 0.5\right) \cdot \left(\left(y - x\right) \cdot 0.5\right) - x \cdot x}{\color{blue}{\sqrt{\left(\left(y - x\right) \cdot 0.5\right) \cdot \left(y - x\right)} \cdot \sqrt{0.5}} - x} \]
      5. fma-neg90.1%

        \[\leadsto \frac{\left(\left(y - x\right) \cdot 0.5\right) \cdot \left(\left(y - x\right) \cdot 0.5\right) - x \cdot x}{\color{blue}{\mathsf{fma}\left(\sqrt{\left(\left(y - x\right) \cdot 0.5\right) \cdot \left(y - x\right)}, \sqrt{0.5}, -x\right)}} \]
      6. *-commutative90.1%

        \[\leadsto \frac{\left(\left(y - x\right) \cdot 0.5\right) \cdot \left(\left(y - x\right) \cdot 0.5\right) - x \cdot x}{\mathsf{fma}\left(\sqrt{\color{blue}{\left(0.5 \cdot \left(y - x\right)\right)} \cdot \left(y - x\right)}, \sqrt{0.5}, -x\right)} \]
      7. associate-*l*90.1%

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

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

      \[\leadsto \frac{\left(\left(y - x\right) \cdot 0.5\right) \cdot \left(\left(y - x\right) \cdot 0.5\right) - x \cdot x}{\color{blue}{\mathsf{fma}\left(\sqrt{0.5 \cdot {\left(y - x\right)}^{2}}, \sqrt{0.5}, -x\right)}} \]
    8. Taylor expanded in y around -inf 63.6%

      \[\leadsto \frac{\left(\left(y - x\right) \cdot 0.5\right) \cdot \left(\left(y - x\right) \cdot 0.5\right) - x \cdot x}{\color{blue}{-1 \cdot \left({\left(\sqrt{0.5}\right)}^{2} \cdot y\right)}} \]
    9. Step-by-step derivation
      1. *-commutative63.6%

        \[\leadsto \frac{\left(\left(y - x\right) \cdot 0.5\right) \cdot \left(\left(y - x\right) \cdot 0.5\right) - x \cdot x}{\color{blue}{\left({\left(\sqrt{0.5}\right)}^{2} \cdot y\right) \cdot -1}} \]
      2. *-commutative63.6%

        \[\leadsto \frac{\left(\left(y - x\right) \cdot 0.5\right) \cdot \left(\left(y - x\right) \cdot 0.5\right) - x \cdot x}{\color{blue}{\left(y \cdot {\left(\sqrt{0.5}\right)}^{2}\right)} \cdot -1} \]
      3. unpow263.6%

        \[\leadsto \frac{\left(\left(y - x\right) \cdot 0.5\right) \cdot \left(\left(y - x\right) \cdot 0.5\right) - x \cdot x}{\left(y \cdot \color{blue}{\left(\sqrt{0.5} \cdot \sqrt{0.5}\right)}\right) \cdot -1} \]
      4. rem-square-sqrt64.9%

        \[\leadsto \frac{\left(\left(y - x\right) \cdot 0.5\right) \cdot \left(\left(y - x\right) \cdot 0.5\right) - x \cdot x}{\left(y \cdot \color{blue}{0.5}\right) \cdot -1} \]
      5. associate-*l*64.9%

        \[\leadsto \frac{\left(\left(y - x\right) \cdot 0.5\right) \cdot \left(\left(y - x\right) \cdot 0.5\right) - x \cdot x}{\color{blue}{y \cdot \left(0.5 \cdot -1\right)}} \]
      6. metadata-eval64.9%

        \[\leadsto \frac{\left(\left(y - x\right) \cdot 0.5\right) \cdot \left(\left(y - x\right) \cdot 0.5\right) - x \cdot x}{y \cdot \color{blue}{-0.5}} \]
    10. Simplified64.9%

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

    if -4.99999999999999994e-93 < y

    1. Initial program 99.9%

      \[x + \frac{\left|y - x\right|}{2} \]
    2. Step-by-step derivation
      1. +-commutative99.9%

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

        \[\leadsto \color{blue}{\left|y - x\right| \cdot \frac{1}{2}} + x \]
      3. fma-def99.9%

        \[\leadsto \color{blue}{\mathsf{fma}\left(\left|y - x\right|, \frac{1}{2}, x\right)} \]
      4. add-sqr-sqrt68.0%

        \[\leadsto \mathsf{fma}\left(\left|\color{blue}{\sqrt{y - x} \cdot \sqrt{y - x}}\right|, \frac{1}{2}, x\right) \]
      5. fabs-sqr68.0%

        \[\leadsto \mathsf{fma}\left(\color{blue}{\sqrt{y - x} \cdot \sqrt{y - x}}, \frac{1}{2}, x\right) \]
      6. add-sqr-sqrt73.6%

        \[\leadsto \mathsf{fma}\left(\color{blue}{y - x}, \frac{1}{2}, x\right) \]
      7. metadata-eval73.6%

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

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

      \[\leadsto \color{blue}{-0.5 \cdot x + \left(0.5 \cdot y + x\right)} \]
    5. Step-by-step derivation
      1. +-commutative73.6%

        \[\leadsto -0.5 \cdot x + \color{blue}{\left(x + 0.5 \cdot y\right)} \]
      2. associate-+r+73.6%

        \[\leadsto \color{blue}{\left(-0.5 \cdot x + x\right) + 0.5 \cdot y} \]
      3. distribute-lft1-in73.6%

        \[\leadsto \color{blue}{\left(-0.5 + 1\right) \cdot x} + 0.5 \cdot y \]
      4. metadata-eval73.6%

        \[\leadsto \color{blue}{0.5} \cdot x + 0.5 \cdot y \]
      5. distribute-lft-out73.6%

        \[\leadsto \color{blue}{0.5 \cdot \left(x + y\right)} \]
    6. Simplified73.6%

      \[\leadsto \color{blue}{0.5 \cdot \left(x + y\right)} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification75.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -3.9 \cdot 10^{+21}:\\ \;\;\;\;\frac{y}{0.5} \cdot -0.25\\ \mathbf{elif}\;y \leq -1.9 \cdot 10^{-28}:\\ \;\;\;\;x \cdot 0.5\\ \mathbf{elif}\;y \leq -5 \cdot 10^{-93}:\\ \;\;\;\;\frac{\left(\left(y - x\right) \cdot 0.5\right) \cdot \left(\left(y - x\right) \cdot 0.5\right) - x \cdot x}{y \cdot -0.5}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(x + y\right)\\ \end{array} \]

Alternative 5: 69.6% accurate, 9.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{y}{0.5} \cdot -0.25\\ \mathbf{if}\;y \leq -1.25 \cdot 10^{+20}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq -1.85 \cdot 10^{-28}:\\ \;\;\;\;x \cdot 0.5\\ \mathbf{elif}\;y \leq -4.3 \cdot 10^{-96}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(x + y\right)\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (let* ((t_0 (* (/ y 0.5) -0.25)))
   (if (<= y -1.25e+20)
     t_0
     (if (<= y -1.85e-28)
       (* x 0.5)
       (if (<= y -4.3e-96) t_0 (* 0.5 (+ x y)))))))
double code(double x, double y) {
	double t_0 = (y / 0.5) * -0.25;
	double tmp;
	if (y <= -1.25e+20) {
		tmp = t_0;
	} else if (y <= -1.85e-28) {
		tmp = x * 0.5;
	} else if (y <= -4.3e-96) {
		tmp = t_0;
	} else {
		tmp = 0.5 * (x + y);
	}
	return tmp;
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8) :: t_0
    real(8) :: tmp
    t_0 = (y / 0.5d0) * (-0.25d0)
    if (y <= (-1.25d+20)) then
        tmp = t_0
    else if (y <= (-1.85d-28)) then
        tmp = x * 0.5d0
    else if (y <= (-4.3d-96)) then
        tmp = t_0
    else
        tmp = 0.5d0 * (x + y)
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double t_0 = (y / 0.5) * -0.25;
	double tmp;
	if (y <= -1.25e+20) {
		tmp = t_0;
	} else if (y <= -1.85e-28) {
		tmp = x * 0.5;
	} else if (y <= -4.3e-96) {
		tmp = t_0;
	} else {
		tmp = 0.5 * (x + y);
	}
	return tmp;
}
def code(x, y):
	t_0 = (y / 0.5) * -0.25
	tmp = 0
	if y <= -1.25e+20:
		tmp = t_0
	elif y <= -1.85e-28:
		tmp = x * 0.5
	elif y <= -4.3e-96:
		tmp = t_0
	else:
		tmp = 0.5 * (x + y)
	return tmp
function code(x, y)
	t_0 = Float64(Float64(y / 0.5) * -0.25)
	tmp = 0.0
	if (y <= -1.25e+20)
		tmp = t_0;
	elseif (y <= -1.85e-28)
		tmp = Float64(x * 0.5);
	elseif (y <= -4.3e-96)
		tmp = t_0;
	else
		tmp = Float64(0.5 * Float64(x + y));
	end
	return tmp
end
function tmp_2 = code(x, y)
	t_0 = (y / 0.5) * -0.25;
	tmp = 0.0;
	if (y <= -1.25e+20)
		tmp = t_0;
	elseif (y <= -1.85e-28)
		tmp = x * 0.5;
	elseif (y <= -4.3e-96)
		tmp = t_0;
	else
		tmp = 0.5 * (x + y);
	end
	tmp_2 = tmp;
end
code[x_, y_] := Block[{t$95$0 = N[(N[(y / 0.5), $MachinePrecision] * -0.25), $MachinePrecision]}, If[LessEqual[y, -1.25e+20], t$95$0, If[LessEqual[y, -1.85e-28], N[(x * 0.5), $MachinePrecision], If[LessEqual[y, -4.3e-96], t$95$0, N[(0.5 * N[(x + y), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{y}{0.5} \cdot -0.25\\
\mathbf{if}\;y \leq -1.25 \cdot 10^{+20}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;y \leq -1.85 \cdot 10^{-28}:\\
\;\;\;\;x \cdot 0.5\\

\mathbf{elif}\;y \leq -4.3 \cdot 10^{-96}:\\
\;\;\;\;t_0\\

\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(x + y\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if y < -1.25e20 or -1.8500000000000001e-28 < y < -4.2999999999999998e-96

    1. Initial program 100.0%

      \[x + \frac{\left|y - x\right|}{2} \]
    2. Step-by-step derivation
      1. +-commutative100.0%

        \[\leadsto \color{blue}{\frac{\left|y - x\right|}{2} + x} \]
      2. div-inv100.0%

        \[\leadsto \color{blue}{\left|y - x\right| \cdot \frac{1}{2}} + x \]
      3. fma-def100.0%

        \[\leadsto \color{blue}{\mathsf{fma}\left(\left|y - x\right|, \frac{1}{2}, x\right)} \]
      4. add-sqr-sqrt7.8%

        \[\leadsto \mathsf{fma}\left(\left|\color{blue}{\sqrt{y - x} \cdot \sqrt{y - x}}\right|, \frac{1}{2}, x\right) \]
      5. fabs-sqr7.8%

        \[\leadsto \mathsf{fma}\left(\color{blue}{\sqrt{y - x} \cdot \sqrt{y - x}}, \frac{1}{2}, x\right) \]
      6. add-sqr-sqrt9.7%

        \[\leadsto \mathsf{fma}\left(\color{blue}{y - x}, \frac{1}{2}, x\right) \]
      7. metadata-eval9.7%

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(y - x, 0.5, x\right)} \]
    4. Step-by-step derivation
      1. fma-udef9.7%

        \[\leadsto \color{blue}{\left(y - x\right) \cdot 0.5 + x} \]
      2. flip-+4.8%

        \[\leadsto \color{blue}{\frac{\left(\left(y - x\right) \cdot 0.5\right) \cdot \left(\left(y - x\right) \cdot 0.5\right) - x \cdot x}{\left(y - x\right) \cdot 0.5 - x}} \]
    5. Applied egg-rr4.8%

      \[\leadsto \color{blue}{\frac{\left(\left(y - x\right) \cdot 0.5\right) \cdot \left(\left(y - x\right) \cdot 0.5\right) - x \cdot x}{\left(y - x\right) \cdot 0.5 - x}} \]
    6. Step-by-step derivation
      1. add-sqr-sqrt3.9%

        \[\leadsto \frac{\left(\left(y - x\right) \cdot 0.5\right) \cdot \left(\left(y - x\right) \cdot 0.5\right) - x \cdot x}{\color{blue}{\sqrt{\left(y - x\right) \cdot 0.5} \cdot \sqrt{\left(y - x\right) \cdot 0.5}} - x} \]
      2. sqrt-prod53.8%

        \[\leadsto \frac{\left(\left(y - x\right) \cdot 0.5\right) \cdot \left(\left(y - x\right) \cdot 0.5\right) - x \cdot x}{\color{blue}{\sqrt{\left(\left(y - x\right) \cdot 0.5\right) \cdot \left(\left(y - x\right) \cdot 0.5\right)}} - x} \]
      3. associate-*r*53.8%

        \[\leadsto \frac{\left(\left(y - x\right) \cdot 0.5\right) \cdot \left(\left(y - x\right) \cdot 0.5\right) - x \cdot x}{\sqrt{\color{blue}{\left(\left(\left(y - x\right) \cdot 0.5\right) \cdot \left(y - x\right)\right) \cdot 0.5}} - x} \]
      4. sqrt-prod53.5%

        \[\leadsto \frac{\left(\left(y - x\right) \cdot 0.5\right) \cdot \left(\left(y - x\right) \cdot 0.5\right) - x \cdot x}{\color{blue}{\sqrt{\left(\left(y - x\right) \cdot 0.5\right) \cdot \left(y - x\right)} \cdot \sqrt{0.5}} - x} \]
      5. fma-neg53.5%

        \[\leadsto \frac{\left(\left(y - x\right) \cdot 0.5\right) \cdot \left(\left(y - x\right) \cdot 0.5\right) - x \cdot x}{\color{blue}{\mathsf{fma}\left(\sqrt{\left(\left(y - x\right) \cdot 0.5\right) \cdot \left(y - x\right)}, \sqrt{0.5}, -x\right)}} \]
      6. *-commutative53.5%

        \[\leadsto \frac{\left(\left(y - x\right) \cdot 0.5\right) \cdot \left(\left(y - x\right) \cdot 0.5\right) - x \cdot x}{\mathsf{fma}\left(\sqrt{\color{blue}{\left(0.5 \cdot \left(y - x\right)\right)} \cdot \left(y - x\right)}, \sqrt{0.5}, -x\right)} \]
      7. associate-*l*53.5%

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

        \[\leadsto \frac{\left(\left(y - x\right) \cdot 0.5\right) \cdot \left(\left(y - x\right) \cdot 0.5\right) - x \cdot x}{\mathsf{fma}\left(\sqrt{0.5 \cdot \color{blue}{{\left(y - x\right)}^{2}}}, \sqrt{0.5}, -x\right)} \]
    7. Applied egg-rr53.5%

      \[\leadsto \frac{\left(\left(y - x\right) \cdot 0.5\right) \cdot \left(\left(y - x\right) \cdot 0.5\right) - x \cdot x}{\color{blue}{\mathsf{fma}\left(\sqrt{0.5 \cdot {\left(y - x\right)}^{2}}, \sqrt{0.5}, -x\right)}} \]
    8. Taylor expanded in y around -inf 82.4%

      \[\leadsto \color{blue}{-0.25 \cdot \frac{y}{{\left(\sqrt{0.5}\right)}^{2}}} \]
    9. Step-by-step derivation
      1. *-commutative82.4%

        \[\leadsto \color{blue}{\frac{y}{{\left(\sqrt{0.5}\right)}^{2}} \cdot -0.25} \]
      2. unpow282.4%

        \[\leadsto \frac{y}{\color{blue}{\sqrt{0.5} \cdot \sqrt{0.5}}} \cdot -0.25 \]
      3. rem-square-sqrt84.1%

        \[\leadsto \frac{y}{\color{blue}{0.5}} \cdot -0.25 \]
    10. Simplified84.1%

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

    if -1.25e20 < y < -1.8500000000000001e-28

    1. Initial program 99.7%

      \[x + \frac{\left|y - x\right|}{2} \]
    2. Step-by-step derivation
      1. +-commutative99.7%

        \[\leadsto \color{blue}{\frac{\left|y - x\right|}{2} + x} \]
      2. div-inv99.7%

        \[\leadsto \color{blue}{\left|y - x\right| \cdot \frac{1}{2}} + x \]
      3. fma-def99.7%

        \[\leadsto \color{blue}{\mathsf{fma}\left(\left|y - x\right|, \frac{1}{2}, x\right)} \]
      4. add-sqr-sqrt49.8%

        \[\leadsto \mathsf{fma}\left(\left|\color{blue}{\sqrt{y - x} \cdot \sqrt{y - x}}\right|, \frac{1}{2}, x\right) \]
      5. fabs-sqr49.8%

        \[\leadsto \mathsf{fma}\left(\color{blue}{\sqrt{y - x} \cdot \sqrt{y - x}}, \frac{1}{2}, x\right) \]
      6. add-sqr-sqrt55.4%

        \[\leadsto \mathsf{fma}\left(\color{blue}{y - x}, \frac{1}{2}, x\right) \]
      7. metadata-eval55.4%

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

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

      \[\leadsto \color{blue}{-0.5 \cdot x + x} \]
    5. Step-by-step derivation
      1. distribute-lft1-in56.1%

        \[\leadsto \color{blue}{\left(-0.5 + 1\right) \cdot x} \]
      2. metadata-eval56.1%

        \[\leadsto \color{blue}{0.5} \cdot x \]
      3. *-commutative56.1%

        \[\leadsto \color{blue}{x \cdot 0.5} \]
    6. Simplified56.1%

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

    if -4.2999999999999998e-96 < y

    1. Initial program 99.9%

      \[x + \frac{\left|y - x\right|}{2} \]
    2. Step-by-step derivation
      1. +-commutative99.9%

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

        \[\leadsto \color{blue}{\left|y - x\right| \cdot \frac{1}{2}} + x \]
      3. fma-def99.9%

        \[\leadsto \color{blue}{\mathsf{fma}\left(\left|y - x\right|, \frac{1}{2}, x\right)} \]
      4. add-sqr-sqrt68.0%

        \[\leadsto \mathsf{fma}\left(\left|\color{blue}{\sqrt{y - x} \cdot \sqrt{y - x}}\right|, \frac{1}{2}, x\right) \]
      5. fabs-sqr68.0%

        \[\leadsto \mathsf{fma}\left(\color{blue}{\sqrt{y - x} \cdot \sqrt{y - x}}, \frac{1}{2}, x\right) \]
      6. add-sqr-sqrt73.6%

        \[\leadsto \mathsf{fma}\left(\color{blue}{y - x}, \frac{1}{2}, x\right) \]
      7. metadata-eval73.6%

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

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

      \[\leadsto \color{blue}{-0.5 \cdot x + \left(0.5 \cdot y + x\right)} \]
    5. Step-by-step derivation
      1. +-commutative73.6%

        \[\leadsto -0.5 \cdot x + \color{blue}{\left(x + 0.5 \cdot y\right)} \]
      2. associate-+r+73.6%

        \[\leadsto \color{blue}{\left(-0.5 \cdot x + x\right) + 0.5 \cdot y} \]
      3. distribute-lft1-in73.6%

        \[\leadsto \color{blue}{\left(-0.5 + 1\right) \cdot x} + 0.5 \cdot y \]
      4. metadata-eval73.6%

        \[\leadsto \color{blue}{0.5} \cdot x + 0.5 \cdot y \]
      5. distribute-lft-out73.6%

        \[\leadsto \color{blue}{0.5 \cdot \left(x + y\right)} \]
    6. Simplified73.6%

      \[\leadsto \color{blue}{0.5 \cdot \left(x + y\right)} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification75.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -1.25 \cdot 10^{+20}:\\ \;\;\;\;\frac{y}{0.5} \cdot -0.25\\ \mathbf{elif}\;y \leq -1.85 \cdot 10^{-28}:\\ \;\;\;\;x \cdot 0.5\\ \mathbf{elif}\;y \leq -4.3 \cdot 10^{-96}:\\ \;\;\;\;\frac{y}{0.5} \cdot -0.25\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(x + y\right)\\ \end{array} \]

Alternative 6: 31.2% accurate, 21.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq 2 \cdot 10^{-211}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y \cdot 0.5\\ \end{array} \end{array} \]
(FPCore (x y) :precision binary64 (if (<= y 2e-211) x (* y 0.5)))
double code(double x, double y) {
	double tmp;
	if (y <= 2e-211) {
		tmp = x;
	} else {
		tmp = 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 <= 2d-211) then
        tmp = x
    else
        tmp = y * 0.5d0
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double tmp;
	if (y <= 2e-211) {
		tmp = x;
	} else {
		tmp = y * 0.5;
	}
	return tmp;
}
def code(x, y):
	tmp = 0
	if y <= 2e-211:
		tmp = x
	else:
		tmp = y * 0.5
	return tmp
function code(x, y)
	tmp = 0.0
	if (y <= 2e-211)
		tmp = x;
	else
		tmp = Float64(y * 0.5);
	end
	return tmp
end
function tmp_2 = code(x, y)
	tmp = 0.0;
	if (y <= 2e-211)
		tmp = x;
	else
		tmp = y * 0.5;
	end
	tmp_2 = tmp;
end
code[x_, y_] := If[LessEqual[y, 2e-211], x, N[(y * 0.5), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq 2 \cdot 10^{-211}:\\
\;\;\;\;x\\

\mathbf{else}:\\
\;\;\;\;y \cdot 0.5\\


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

    1. Initial program 99.9%

      \[x + \frac{\left|y - x\right|}{2} \]
    2. Taylor expanded in x around inf 11.6%

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

    if 2.00000000000000017e-211 < y

    1. Initial program 100.0%

      \[x + \frac{\left|y - x\right|}{2} \]
    2. Step-by-step derivation
      1. +-commutative100.0%

        \[\leadsto \color{blue}{\frac{\left|y - x\right|}{2} + x} \]
      2. div-inv100.0%

        \[\leadsto \color{blue}{\left|y - x\right| \cdot \frac{1}{2}} + x \]
      3. fma-def100.0%

        \[\leadsto \color{blue}{\mathsf{fma}\left(\left|y - x\right|, \frac{1}{2}, x\right)} \]
      4. add-sqr-sqrt78.3%

        \[\leadsto \mathsf{fma}\left(\left|\color{blue}{\sqrt{y - x} \cdot \sqrt{y - x}}\right|, \frac{1}{2}, x\right) \]
      5. fabs-sqr78.3%

        \[\leadsto \mathsf{fma}\left(\color{blue}{\sqrt{y - x} \cdot \sqrt{y - x}}, \frac{1}{2}, x\right) \]
      6. add-sqr-sqrt82.7%

        \[\leadsto \mathsf{fma}\left(\color{blue}{y - x}, \frac{1}{2}, x\right) \]
      7. metadata-eval82.7%

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

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

      \[\leadsto \color{blue}{0.5 \cdot y} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification31.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq 2 \cdot 10^{-211}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y \cdot 0.5\\ \end{array} \]

Alternative 7: 44.6% accurate, 21.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq 9.5 \cdot 10^{-190}:\\ \;\;\;\;x \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;y \cdot 0.5\\ \end{array} \end{array} \]
(FPCore (x y) :precision binary64 (if (<= y 9.5e-190) (* x 0.5) (* y 0.5)))
double code(double x, double y) {
	double tmp;
	if (y <= 9.5e-190) {
		tmp = x * 0.5;
	} else {
		tmp = 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.5d-190) then
        tmp = x * 0.5d0
    else
        tmp = y * 0.5d0
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double tmp;
	if (y <= 9.5e-190) {
		tmp = x * 0.5;
	} else {
		tmp = y * 0.5;
	}
	return tmp;
}
def code(x, y):
	tmp = 0
	if y <= 9.5e-190:
		tmp = x * 0.5
	else:
		tmp = y * 0.5
	return tmp
function code(x, y)
	tmp = 0.0
	if (y <= 9.5e-190)
		tmp = Float64(x * 0.5);
	else
		tmp = Float64(y * 0.5);
	end
	return tmp
end
function tmp_2 = code(x, y)
	tmp = 0.0;
	if (y <= 9.5e-190)
		tmp = x * 0.5;
	else
		tmp = y * 0.5;
	end
	tmp_2 = tmp;
end
code[x_, y_] := If[LessEqual[y, 9.5e-190], N[(x * 0.5), $MachinePrecision], N[(y * 0.5), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq 9.5 \cdot 10^{-190}:\\
\;\;\;\;x \cdot 0.5\\

\mathbf{else}:\\
\;\;\;\;y \cdot 0.5\\


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

    1. Initial program 99.9%

      \[x + \frac{\left|y - x\right|}{2} \]
    2. Step-by-step derivation
      1. +-commutative99.9%

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

        \[\leadsto \color{blue}{\left|y - x\right| \cdot \frac{1}{2}} + x \]
      3. fma-def99.9%

        \[\leadsto \color{blue}{\mathsf{fma}\left(\left|y - x\right|, \frac{1}{2}, x\right)} \]
      4. add-sqr-sqrt30.5%

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

        \[\leadsto \mathsf{fma}\left(\color{blue}{\sqrt{y - x} \cdot \sqrt{y - x}}, \frac{1}{2}, x\right) \]
      6. add-sqr-sqrt35.0%

        \[\leadsto \mathsf{fma}\left(\color{blue}{y - x}, \frac{1}{2}, x\right) \]
      7. metadata-eval35.0%

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

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

      \[\leadsto \color{blue}{-0.5 \cdot x + x} \]
    5. Step-by-step derivation
      1. distribute-lft1-in35.1%

        \[\leadsto \color{blue}{\left(-0.5 + 1\right) \cdot x} \]
      2. metadata-eval35.1%

        \[\leadsto \color{blue}{0.5} \cdot x \]
      3. *-commutative35.1%

        \[\leadsto \color{blue}{x \cdot 0.5} \]
    6. Simplified35.1%

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

    if 9.50000000000000055e-190 < y

    1. Initial program 100.0%

      \[x + \frac{\left|y - x\right|}{2} \]
    2. Step-by-step derivation
      1. +-commutative100.0%

        \[\leadsto \color{blue}{\frac{\left|y - x\right|}{2} + x} \]
      2. div-inv100.0%

        \[\leadsto \color{blue}{\left|y - x\right| \cdot \frac{1}{2}} + x \]
      3. fma-def100.0%

        \[\leadsto \color{blue}{\mathsf{fma}\left(\left|y - x\right|, \frac{1}{2}, x\right)} \]
      4. add-sqr-sqrt78.3%

        \[\leadsto \mathsf{fma}\left(\left|\color{blue}{\sqrt{y - x} \cdot \sqrt{y - x}}\right|, \frac{1}{2}, x\right) \]
      5. fabs-sqr78.3%

        \[\leadsto \mathsf{fma}\left(\color{blue}{\sqrt{y - x} \cdot \sqrt{y - x}}, \frac{1}{2}, x\right) \]
      6. add-sqr-sqrt82.7%

        \[\leadsto \mathsf{fma}\left(\color{blue}{y - x}, \frac{1}{2}, x\right) \]
      7. metadata-eval82.7%

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

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

      \[\leadsto \color{blue}{0.5 \cdot y} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification46.3%

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq 9.5 \cdot 10^{-190}:\\ \;\;\;\;x \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;y \cdot 0.5\\ \end{array} \]

Alternative 8: 54.7% accurate, 21.4× speedup?

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

\\
0.5 \cdot \left(x + y\right)
\end{array}
Derivation
  1. Initial program 99.9%

    \[x + \frac{\left|y - x\right|}{2} \]
  2. Step-by-step derivation
    1. +-commutative99.9%

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

      \[\leadsto \color{blue}{\left|y - x\right| \cdot \frac{1}{2}} + x \]
    3. fma-def99.9%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\left|y - x\right|, \frac{1}{2}, x\right)} \]
    4. add-sqr-sqrt49.2%

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

      \[\leadsto \mathsf{fma}\left(\color{blue}{\sqrt{y - x} \cdot \sqrt{y - x}}, \frac{1}{2}, x\right) \]
    6. add-sqr-sqrt53.7%

      \[\leadsto \mathsf{fma}\left(\color{blue}{y - x}, \frac{1}{2}, x\right) \]
    7. metadata-eval53.7%

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

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

    \[\leadsto \color{blue}{-0.5 \cdot x + \left(0.5 \cdot y + x\right)} \]
  5. Step-by-step derivation
    1. +-commutative53.6%

      \[\leadsto -0.5 \cdot x + \color{blue}{\left(x + 0.5 \cdot y\right)} \]
    2. associate-+r+53.7%

      \[\leadsto \color{blue}{\left(-0.5 \cdot x + x\right) + 0.5 \cdot y} \]
    3. distribute-lft1-in53.7%

      \[\leadsto \color{blue}{\left(-0.5 + 1\right) \cdot x} + 0.5 \cdot y \]
    4. metadata-eval53.7%

      \[\leadsto \color{blue}{0.5} \cdot x + 0.5 \cdot y \]
    5. distribute-lft-out53.7%

      \[\leadsto \color{blue}{0.5 \cdot \left(x + y\right)} \]
  6. Simplified53.7%

    \[\leadsto \color{blue}{0.5 \cdot \left(x + y\right)} \]
  7. Final simplification53.7%

    \[\leadsto 0.5 \cdot \left(x + y\right) \]

Alternative 9: 11.4% accurate, 107.0× speedup?

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

\\
x
\end{array}
Derivation
  1. Initial program 99.9%

    \[x + \frac{\left|y - x\right|}{2} \]
  2. Taylor expanded in x around inf 10.7%

    \[\leadsto \color{blue}{x} \]
  3. Final simplification10.7%

    \[\leadsto x \]

Reproduce

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