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

Percentage Accurate: 99.9% → 99.9%
Time: 2.2s
Alternatives: 6
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 6 alternatives:

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

Initial Program: 99.9% accurate, 1.0× speedup?

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

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

Alternative 1: 99.9% accurate, 1.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: 70.2% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;x \leq -9 \cdot 10^{-88}:\\
\;\;\;\;0.5 \cdot \left(x + y\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -8.99999999999999982e-88

    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. add-sqr-sqrt99.1%

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

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\sqrt{\left(y - x\right) \cdot \color{blue}{0.5}}, \sqrt{\frac{\left|y - x\right|}{2}}, x\right) \]
      9. div-inv87.0%

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

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

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

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

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

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

      \[\leadsto \color{blue}{{\left(\sqrt{0.5}\right)}^{2} \cdot y + \left({\left(\sqrt{0.5}\right)}^{2} \cdot \left({\left(\sqrt{-1}\right)}^{2} \cdot x\right) + x\right)} \]
    5. Step-by-step derivation
      1. +-commutative0.0%

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto y \cdot 0.5 + \left(x \cdot 1 + x \cdot \color{blue}{-0.5}\right) \]
      14. distribute-lft-out87.8%

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

        \[\leadsto y \cdot 0.5 + x \cdot \color{blue}{0.5} \]
      16. distribute-rgt-out87.8%

        \[\leadsto \color{blue}{0.5 \cdot \left(y + x\right)} \]
      17. +-commutative87.8%

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

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

    if -8.99999999999999982e-88 < x

    1. Initial program 99.9%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -9 \cdot 10^{-88}:\\ \;\;\;\;0.5 \cdot \left(x + y\right)\\ \mathbf{else}:\\ \;\;\;\;\left|y - x\right| \cdot 0.5\\ \end{array} \]

Alternative 3: 45.4% accurate, 21.1× speedup?

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

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

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


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

    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. add-sqr-sqrt99.3%

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

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\sqrt{\left(y - x\right) \cdot \color{blue}{0.5}}, \sqrt{\frac{\left|y - x\right|}{2}}, x\right) \]
      9. div-inv34.2%

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

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

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

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

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

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

      \[\leadsto \color{blue}{{\left(\sqrt{0.5}\right)}^{2} \cdot \left({\left(\sqrt{-1}\right)}^{2} \cdot x\right) + x} \]
    5. Step-by-step derivation
      1. *-commutative0.0%

        \[\leadsto \color{blue}{\left({\left(\sqrt{-1}\right)}^{2} \cdot x\right) \cdot {\left(\sqrt{0.5}\right)}^{2}} + x \]
      2. unpow20.0%

        \[\leadsto \left({\left(\sqrt{-1}\right)}^{2} \cdot x\right) \cdot \color{blue}{\left(\sqrt{0.5} \cdot \sqrt{0.5}\right)} + x \]
      3. rem-square-sqrt0.0%

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

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

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

        \[\leadsto x \cdot \left(\color{blue}{\left(\sqrt{-1} \cdot \sqrt{-1}\right)} \cdot 0.5\right) + x \]
      7. rem-square-sqrt35.0%

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

        \[\leadsto x \cdot \color{blue}{-0.5} + x \]
      9. *-commutative35.0%

        \[\leadsto \color{blue}{-0.5 \cdot x} + x \]
      10. distribute-lft1-in35.0%

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

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

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

    if 1.00000000000000004e-42 < 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. add-sqr-sqrt99.3%

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

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\sqrt{\left(y - x\right) \cdot \color{blue}{0.5}}, \sqrt{\frac{\left|y - x\right|}{2}}, x\right) \]
      9. div-inv87.4%

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

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

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

        \[\leadsto \mathsf{fma}\left(\sqrt{\left(y - x\right) \cdot 0.5}, \sqrt{\color{blue}{\left(y - x\right)} \cdot \frac{1}{2}}, x\right) \]
      13. metadata-eval87.4%

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

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

      \[\leadsto \color{blue}{{\left(\sqrt{0.5}\right)}^{2} \cdot y} \]
    5. Step-by-step derivation
      1. unpow276.9%

        \[\leadsto \color{blue}{\left(\sqrt{0.5} \cdot \sqrt{0.5}\right)} \cdot y \]
      2. rem-square-sqrt78.4%

        \[\leadsto \color{blue}{0.5} \cdot y \]
    6. Simplified78.4%

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

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

Alternative 4: 54.5% 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. add-sqr-sqrt99.3%

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \mathsf{fma}\left(\sqrt{\left(y - x\right) \cdot 0.5}, \sqrt{\color{blue}{\left(y - x\right)} \cdot \frac{1}{2}}, x\right) \]
    13. metadata-eval46.5%

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

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

    \[\leadsto \color{blue}{{\left(\sqrt{0.5}\right)}^{2} \cdot y + \left({\left(\sqrt{0.5}\right)}^{2} \cdot \left({\left(\sqrt{-1}\right)}^{2} \cdot x\right) + x\right)} \]
  5. Step-by-step derivation
    1. +-commutative0.0%

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto y \cdot 0.5 + \left(x \cdot 1 + x \cdot \color{blue}{-0.5}\right) \]
    14. distribute-lft-out51.7%

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

      \[\leadsto y \cdot 0.5 + x \cdot \color{blue}{0.5} \]
    16. distribute-rgt-out51.7%

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

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

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

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

Alternative 5: 30.8% accurate, 35.7× speedup?

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

\\
x \cdot 0.5
\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. add-sqr-sqrt99.3%

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \mathsf{fma}\left(\sqrt{\left(y - x\right) \cdot 0.5}, \sqrt{\color{blue}{\left(y - x\right)} \cdot \frac{1}{2}}, x\right) \]
    13. metadata-eval46.5%

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

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

    \[\leadsto \color{blue}{{\left(\sqrt{0.5}\right)}^{2} \cdot \left({\left(\sqrt{-1}\right)}^{2} \cdot x\right) + x} \]
  5. Step-by-step derivation
    1. *-commutative0.0%

      \[\leadsto \color{blue}{\left({\left(\sqrt{-1}\right)}^{2} \cdot x\right) \cdot {\left(\sqrt{0.5}\right)}^{2}} + x \]
    2. unpow20.0%

      \[\leadsto \left({\left(\sqrt{-1}\right)}^{2} \cdot x\right) \cdot \color{blue}{\left(\sqrt{0.5} \cdot \sqrt{0.5}\right)} + x \]
    3. rem-square-sqrt0.0%

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

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

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

      \[\leadsto x \cdot \left(\color{blue}{\left(\sqrt{-1} \cdot \sqrt{-1}\right)} \cdot 0.5\right) + x \]
    7. rem-square-sqrt29.6%

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

      \[\leadsto x \cdot \color{blue}{-0.5} + x \]
    9. *-commutative29.6%

      \[\leadsto \color{blue}{-0.5 \cdot x} + x \]
    10. distribute-lft1-in29.6%

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

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

    \[\leadsto \color{blue}{0.5 \cdot x} \]
  7. Final simplification29.6%

    \[\leadsto x \cdot 0.5 \]

Alternative 6: 11.5% 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 11.4%

    \[\leadsto \color{blue}{x} \]
  3. Final simplification11.4%

    \[\leadsto x \]

Reproduce

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