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

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

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

Initial Program: 99.9% accurate, 1.0× speedup?

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

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

Alternative 1: 99.9% accurate, 1.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. Add Preprocessing
  3. Add Preprocessing

Alternative 2: 71.3% accurate, 1.0× speedup?

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

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

\mathbf{else}:\\
\;\;\;\;x + \frac{\left|y\right|}{2}\\


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

    1. Initial program 100.0%

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

        \[\leadsto \frac{{x}^{3} + {\left(\frac{\left|y - x\right|}{2}\right)}^{3}}{\color{blue}{x \cdot x + \left(\frac{\left|y - x\right|}{2} \cdot \frac{\left|y - x\right|}{2} - x \cdot \frac{\left|y - x\right|}{2}\right)}} \]
      2. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\left({x}^{3} + {\left(\frac{\left|y - x\right|}{2}\right)}^{3}\right), \color{blue}{\left(x \cdot x + \left(\frac{\left|y - x\right|}{2} \cdot \frac{\left|y - x\right|}{2} - x \cdot \frac{\left|y - x\right|}{2}\right)\right)}\right) \]
    4. Applied egg-rr29.0%

      \[\leadsto \color{blue}{\frac{x \cdot \left(x \cdot x\right) + {\left(\frac{\left(y - x\right) \cdot \left(y - x\right)}{4}\right)}^{1.5}}{\frac{\left(y - x\right) \cdot \left(y - x\right)}{4} + x \cdot \left(x + \frac{\left|y - x\right|}{-2}\right)}} \]
    5. Taylor expanded in y around -inf

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

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

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

        \[\leadsto \mathsf{*.f64}\left(\left(\mathsf{neg}\left(y\right)\right), \left(\color{blue}{\frac{1}{2}} + -1 \cdot \frac{\frac{1}{2} \cdot \left(x + 2 \cdot x\right) - x}{y}\right)\right) \]
      4. neg-sub0N/A

        \[\leadsto \mathsf{*.f64}\left(\left(0 - y\right), \left(\color{blue}{\frac{1}{2}} + -1 \cdot \frac{\frac{1}{2} \cdot \left(x + 2 \cdot x\right) - x}{y}\right)\right) \]
      5. --lowering--.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(0, y\right), \left(\color{blue}{\frac{1}{2}} + -1 \cdot \frac{\frac{1}{2} \cdot \left(x + 2 \cdot x\right) - x}{y}\right)\right) \]
      6. mul-1-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(0, y\right), \left(\frac{1}{2} + \left(\mathsf{neg}\left(\frac{\frac{1}{2} \cdot \left(x + 2 \cdot x\right) - x}{y}\right)\right)\right)\right) \]
      7. unsub-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(0, y\right), \left(\frac{1}{2} - \color{blue}{\frac{\frac{1}{2} \cdot \left(x + 2 \cdot x\right) - x}{y}}\right)\right) \]
      8. --lowering--.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(0, y\right), \mathsf{\_.f64}\left(\frac{1}{2}, \color{blue}{\left(\frac{\frac{1}{2} \cdot \left(x + 2 \cdot x\right) - x}{y}\right)}\right)\right) \]
      9. /-lowering-/.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(0, y\right), \mathsf{\_.f64}\left(\frac{1}{2}, \mathsf{/.f64}\left(\left(\frac{1}{2} \cdot \left(x + 2 \cdot x\right) - x\right), \color{blue}{y}\right)\right)\right) \]
      10. --lowering--.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(0, y\right), \mathsf{\_.f64}\left(\frac{1}{2}, \mathsf{/.f64}\left(\mathsf{\_.f64}\left(\left(\frac{1}{2} \cdot \left(x + 2 \cdot x\right)\right), x\right), y\right)\right)\right) \]
      11. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(0, y\right), \mathsf{\_.f64}\left(\frac{1}{2}, \mathsf{/.f64}\left(\mathsf{\_.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \left(x + 2 \cdot x\right)\right), x\right), y\right)\right)\right) \]
      12. distribute-rgt1-inN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(0, y\right), \mathsf{\_.f64}\left(\frac{1}{2}, \mathsf{/.f64}\left(\mathsf{\_.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \left(\left(2 + 1\right) \cdot x\right)\right), x\right), y\right)\right)\right) \]
      13. metadata-evalN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(0, y\right), \mathsf{\_.f64}\left(\frac{1}{2}, \mathsf{/.f64}\left(\mathsf{\_.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \left(3 \cdot x\right)\right), x\right), y\right)\right)\right) \]
      14. *-lowering-*.f6459.9%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(0, y\right), \mathsf{\_.f64}\left(\frac{1}{2}, \mathsf{/.f64}\left(\mathsf{\_.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(3, x\right)\right), x\right), y\right)\right)\right) \]
    7. Simplified59.9%

      \[\leadsto \color{blue}{\left(0 - y\right) \cdot \left(0.5 - \frac{0.5 \cdot \left(3 \cdot x\right) - x}{y}\right)} \]
    8. Taylor expanded in y around 0

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

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

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

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

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

        \[\leadsto \frac{-1}{2} \cdot y - \left(x + \frac{-3}{2} \cdot x\right) \]
      6. distribute-rgt1-inN/A

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

        \[\leadsto \frac{-1}{2} \cdot y - \frac{-1}{2} \cdot x \]
      8. distribute-lft-out--N/A

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

        \[\leadsto \mathsf{*.f64}\left(\frac{-1}{2}, \color{blue}{\left(y - x\right)}\right) \]
      10. --lowering--.f6480.5%

        \[\leadsto \mathsf{*.f64}\left(\frac{-1}{2}, \mathsf{\_.f64}\left(y, \color{blue}{x}\right)\right) \]
    10. Simplified80.5%

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

    if -3.5e-34 < x

    1. Initial program 99.9%

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

      \[\leadsto \mathsf{+.f64}\left(x, \mathsf{/.f64}\left(\mathsf{fabs.f64}\left(\color{blue}{y}\right), 2\right)\right) \]
    4. Step-by-step derivation
      1. Simplified69.8%

        \[\leadsto x + \frac{\left|\color{blue}{y}\right|}{2} \]
    5. Recombined 2 regimes into one program.
    6. Final simplification73.1%

      \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -3.5 \cdot 10^{-34}:\\ \;\;\;\;\left(y - x\right) \cdot -0.5\\ \mathbf{else}:\\ \;\;\;\;x + \frac{\left|y\right|}{2}\\ \end{array} \]
    7. Add Preprocessing

    Alternative 3: 59.9% accurate, 8.2× speedup?

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

      1. Initial program 100.0%

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

          \[\leadsto \frac{{x}^{3} + {\left(\frac{\left|y - x\right|}{2}\right)}^{3}}{\color{blue}{x \cdot x + \left(\frac{\left|y - x\right|}{2} \cdot \frac{\left|y - x\right|}{2} - x \cdot \frac{\left|y - x\right|}{2}\right)}} \]
        2. /-lowering-/.f64N/A

          \[\leadsto \mathsf{/.f64}\left(\left({x}^{3} + {\left(\frac{\left|y - x\right|}{2}\right)}^{3}\right), \color{blue}{\left(x \cdot x + \left(\frac{\left|y - x\right|}{2} \cdot \frac{\left|y - x\right|}{2} - x \cdot \frac{\left|y - x\right|}{2}\right)\right)}\right) \]
      4. Applied egg-rr35.9%

        \[\leadsto \color{blue}{\frac{x \cdot \left(x \cdot x\right) + {\left(\frac{\left(y - x\right) \cdot \left(y - x\right)}{4}\right)}^{1.5}}{\frac{\left(y - x\right) \cdot \left(y - x\right)}{4} + x \cdot \left(x + \frac{\left|y - x\right|}{-2}\right)}} \]
      5. Taylor expanded in y around -inf

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

          \[\leadsto y \cdot \color{blue}{\frac{-1}{2}} \]
        2. *-lowering-*.f6463.2%

          \[\leadsto \mathsf{*.f64}\left(y, \color{blue}{\frac{-1}{2}}\right) \]
      7. Simplified63.2%

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

      if -1.2e-151 < y < 2.50000000000000012e-5

      1. Initial program 99.9%

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

          \[\leadsto \frac{{x}^{3} + {\left(\frac{\left|y - x\right|}{2}\right)}^{3}}{\color{blue}{x \cdot x + \left(\frac{\left|y - x\right|}{2} \cdot \frac{\left|y - x\right|}{2} - x \cdot \frac{\left|y - x\right|}{2}\right)}} \]
        2. /-lowering-/.f64N/A

          \[\leadsto \mathsf{/.f64}\left(\left({x}^{3} + {\left(\frac{\left|y - x\right|}{2}\right)}^{3}\right), \color{blue}{\left(x \cdot x + \left(\frac{\left|y - x\right|}{2} \cdot \frac{\left|y - x\right|}{2} - x \cdot \frac{\left|y - x\right|}{2}\right)\right)}\right) \]
      4. Applied egg-rr37.8%

        \[\leadsto \color{blue}{\frac{x \cdot \left(x \cdot x\right) + {\left(\frac{\left(y - x\right) \cdot \left(y - x\right)}{4}\right)}^{1.5}}{\frac{\left(y - x\right) \cdot \left(y - x\right)}{4} + x \cdot \left(x + \frac{\left|y - x\right|}{-2}\right)}} \]
      5. Taylor expanded in y around -inf

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

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

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

          \[\leadsto \mathsf{*.f64}\left(\left(\mathsf{neg}\left(y\right)\right), \left(\color{blue}{\frac{1}{2}} + -1 \cdot \frac{\frac{1}{2} \cdot \left(x + 2 \cdot x\right) - x}{y}\right)\right) \]
        4. neg-sub0N/A

          \[\leadsto \mathsf{*.f64}\left(\left(0 - y\right), \left(\color{blue}{\frac{1}{2}} + -1 \cdot \frac{\frac{1}{2} \cdot \left(x + 2 \cdot x\right) - x}{y}\right)\right) \]
        5. --lowering--.f64N/A

          \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(0, y\right), \left(\color{blue}{\frac{1}{2}} + -1 \cdot \frac{\frac{1}{2} \cdot \left(x + 2 \cdot x\right) - x}{y}\right)\right) \]
        6. mul-1-negN/A

          \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(0, y\right), \left(\frac{1}{2} + \left(\mathsf{neg}\left(\frac{\frac{1}{2} \cdot \left(x + 2 \cdot x\right) - x}{y}\right)\right)\right)\right) \]
        7. unsub-negN/A

          \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(0, y\right), \left(\frac{1}{2} - \color{blue}{\frac{\frac{1}{2} \cdot \left(x + 2 \cdot x\right) - x}{y}}\right)\right) \]
        8. --lowering--.f64N/A

          \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(0, y\right), \mathsf{\_.f64}\left(\frac{1}{2}, \color{blue}{\left(\frac{\frac{1}{2} \cdot \left(x + 2 \cdot x\right) - x}{y}\right)}\right)\right) \]
        9. /-lowering-/.f64N/A

          \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(0, y\right), \mathsf{\_.f64}\left(\frac{1}{2}, \mathsf{/.f64}\left(\left(\frac{1}{2} \cdot \left(x + 2 \cdot x\right) - x\right), \color{blue}{y}\right)\right)\right) \]
        10. --lowering--.f64N/A

          \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(0, y\right), \mathsf{\_.f64}\left(\frac{1}{2}, \mathsf{/.f64}\left(\mathsf{\_.f64}\left(\left(\frac{1}{2} \cdot \left(x + 2 \cdot x\right)\right), x\right), y\right)\right)\right) \]
        11. *-lowering-*.f64N/A

          \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(0, y\right), \mathsf{\_.f64}\left(\frac{1}{2}, \mathsf{/.f64}\left(\mathsf{\_.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \left(x + 2 \cdot x\right)\right), x\right), y\right)\right)\right) \]
        12. distribute-rgt1-inN/A

          \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(0, y\right), \mathsf{\_.f64}\left(\frac{1}{2}, \mathsf{/.f64}\left(\mathsf{\_.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \left(\left(2 + 1\right) \cdot x\right)\right), x\right), y\right)\right)\right) \]
        13. metadata-evalN/A

          \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(0, y\right), \mathsf{\_.f64}\left(\frac{1}{2}, \mathsf{/.f64}\left(\mathsf{\_.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \left(3 \cdot x\right)\right), x\right), y\right)\right)\right) \]
        14. *-lowering-*.f6436.5%

          \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(0, y\right), \mathsf{\_.f64}\left(\frac{1}{2}, \mathsf{/.f64}\left(\mathsf{\_.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(3, x\right)\right), x\right), y\right)\right)\right) \]
      7. Simplified36.5%

        \[\leadsto \color{blue}{\left(0 - y\right) \cdot \left(0.5 - \frac{0.5 \cdot \left(3 \cdot x\right) - x}{y}\right)} \]
      8. Taylor expanded in y around 0

        \[\leadsto \color{blue}{-1 \cdot \left(x - \frac{3}{2} \cdot x\right)} \]
      9. Step-by-step derivation
        1. sub-negN/A

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

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

          \[\leadsto -1 \cdot x + \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\frac{3}{2} \cdot x\right)\right)\right)\right) \]
        4. remove-double-negN/A

          \[\leadsto -1 \cdot x + \frac{3}{2} \cdot \color{blue}{x} \]
        5. distribute-rgt-outN/A

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

          \[\leadsto x \cdot \frac{1}{2} \]
        7. *-commutativeN/A

          \[\leadsto \frac{1}{2} \cdot \color{blue}{x} \]
        8. *-lowering-*.f6448.3%

          \[\leadsto \mathsf{*.f64}\left(\frac{1}{2}, \color{blue}{x}\right) \]
      10. Simplified48.3%

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

      if 2.50000000000000012e-5 < y

      1. Initial program 100.0%

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

          \[\leadsto \frac{{x}^{3} + {\left(\frac{\left|y - x\right|}{2}\right)}^{3}}{\color{blue}{x \cdot x + \left(\frac{\left|y - x\right|}{2} \cdot \frac{\left|y - x\right|}{2} - x \cdot \frac{\left|y - x\right|}{2}\right)}} \]
        2. /-lowering-/.f64N/A

          \[\leadsto \mathsf{/.f64}\left(\left({x}^{3} + {\left(\frac{\left|y - x\right|}{2}\right)}^{3}\right), \color{blue}{\left(x \cdot x + \left(\frac{\left|y - x\right|}{2} \cdot \frac{\left|y - x\right|}{2} - x \cdot \frac{\left|y - x\right|}{2}\right)\right)}\right) \]
      4. Applied egg-rr24.0%

        \[\leadsto \color{blue}{\frac{x \cdot \left(x \cdot x\right) + {\left(\frac{\left(y - x\right) \cdot \left(y - x\right)}{4}\right)}^{1.5}}{\frac{\left(y - x\right) \cdot \left(y - x\right)}{4} + x \cdot \left(x + \frac{\left|y - x\right|}{-2}\right)}} \]
      5. Taylor expanded in x around 0

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

          \[\leadsto \mathsf{*.f64}\left(\frac{1}{2}, \color{blue}{y}\right) \]
      7. Simplified79.8%

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

      \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -1.2 \cdot 10^{-151}:\\ \;\;\;\;y \cdot -0.5\\ \mathbf{elif}\;y \leq 2.5 \cdot 10^{-5}:\\ \;\;\;\;x \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;y \cdot 0.5\\ \end{array} \]
    5. Add Preprocessing

    Alternative 4: 68.8% accurate, 10.7× speedup?

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

      1. Initial program 99.9%

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

          \[\leadsto \frac{{x}^{3} + {\left(\frac{\left|y - x\right|}{2}\right)}^{3}}{\color{blue}{x \cdot x + \left(\frac{\left|y - x\right|}{2} \cdot \frac{\left|y - x\right|}{2} - x \cdot \frac{\left|y - x\right|}{2}\right)}} \]
        2. /-lowering-/.f64N/A

          \[\leadsto \mathsf{/.f64}\left(\left({x}^{3} + {\left(\frac{\left|y - x\right|}{2}\right)}^{3}\right), \color{blue}{\left(x \cdot x + \left(\frac{\left|y - x\right|}{2} \cdot \frac{\left|y - x\right|}{2} - x \cdot \frac{\left|y - x\right|}{2}\right)\right)}\right) \]
      4. Applied egg-rr36.9%

        \[\leadsto \color{blue}{\frac{x \cdot \left(x \cdot x\right) + {\left(\frac{\left(y - x\right) \cdot \left(y - x\right)}{4}\right)}^{1.5}}{\frac{\left(y - x\right) \cdot \left(y - x\right)}{4} + x \cdot \left(x + \frac{\left|y - x\right|}{-2}\right)}} \]
      5. Taylor expanded in y around -inf

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

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

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

          \[\leadsto \mathsf{*.f64}\left(\left(\mathsf{neg}\left(y\right)\right), \left(\color{blue}{\frac{1}{2}} + -1 \cdot \frac{\frac{1}{2} \cdot \left(x + 2 \cdot x\right) - x}{y}\right)\right) \]
        4. neg-sub0N/A

          \[\leadsto \mathsf{*.f64}\left(\left(0 - y\right), \left(\color{blue}{\frac{1}{2}} + -1 \cdot \frac{\frac{1}{2} \cdot \left(x + 2 \cdot x\right) - x}{y}\right)\right) \]
        5. --lowering--.f64N/A

          \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(0, y\right), \left(\color{blue}{\frac{1}{2}} + -1 \cdot \frac{\frac{1}{2} \cdot \left(x + 2 \cdot x\right) - x}{y}\right)\right) \]
        6. mul-1-negN/A

          \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(0, y\right), \left(\frac{1}{2} + \left(\mathsf{neg}\left(\frac{\frac{1}{2} \cdot \left(x + 2 \cdot x\right) - x}{y}\right)\right)\right)\right) \]
        7. unsub-negN/A

          \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(0, y\right), \left(\frac{1}{2} - \color{blue}{\frac{\frac{1}{2} \cdot \left(x + 2 \cdot x\right) - x}{y}}\right)\right) \]
        8. --lowering--.f64N/A

          \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(0, y\right), \mathsf{\_.f64}\left(\frac{1}{2}, \color{blue}{\left(\frac{\frac{1}{2} \cdot \left(x + 2 \cdot x\right) - x}{y}\right)}\right)\right) \]
        9. /-lowering-/.f64N/A

          \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(0, y\right), \mathsf{\_.f64}\left(\frac{1}{2}, \mathsf{/.f64}\left(\left(\frac{1}{2} \cdot \left(x + 2 \cdot x\right) - x\right), \color{blue}{y}\right)\right)\right) \]
        10. --lowering--.f64N/A

          \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(0, y\right), \mathsf{\_.f64}\left(\frac{1}{2}, \mathsf{/.f64}\left(\mathsf{\_.f64}\left(\left(\frac{1}{2} \cdot \left(x + 2 \cdot x\right)\right), x\right), y\right)\right)\right) \]
        11. *-lowering-*.f64N/A

          \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(0, y\right), \mathsf{\_.f64}\left(\frac{1}{2}, \mathsf{/.f64}\left(\mathsf{\_.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \left(x + 2 \cdot x\right)\right), x\right), y\right)\right)\right) \]
        12. distribute-rgt1-inN/A

          \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(0, y\right), \mathsf{\_.f64}\left(\frac{1}{2}, \mathsf{/.f64}\left(\mathsf{\_.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \left(\left(2 + 1\right) \cdot x\right)\right), x\right), y\right)\right)\right) \]
        13. metadata-evalN/A

          \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(0, y\right), \mathsf{\_.f64}\left(\frac{1}{2}, \mathsf{/.f64}\left(\mathsf{\_.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \left(3 \cdot x\right)\right), x\right), y\right)\right)\right) \]
        14. *-lowering-*.f6457.4%

          \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(0, y\right), \mathsf{\_.f64}\left(\frac{1}{2}, \mathsf{/.f64}\left(\mathsf{\_.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(3, x\right)\right), x\right), y\right)\right)\right) \]
      7. Simplified57.4%

        \[\leadsto \color{blue}{\left(0 - y\right) \cdot \left(0.5 - \frac{0.5 \cdot \left(3 \cdot x\right) - x}{y}\right)} \]
      8. Taylor expanded in y around 0

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

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

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

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

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

          \[\leadsto \frac{-1}{2} \cdot y - \left(x + \frac{-3}{2} \cdot x\right) \]
        6. distribute-rgt1-inN/A

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

          \[\leadsto \frac{-1}{2} \cdot y - \frac{-1}{2} \cdot x \]
        8. distribute-lft-out--N/A

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

          \[\leadsto \mathsf{*.f64}\left(\frac{-1}{2}, \color{blue}{\left(y - x\right)}\right) \]
        10. --lowering--.f6466.8%

          \[\leadsto \mathsf{*.f64}\left(\frac{-1}{2}, \mathsf{\_.f64}\left(y, \color{blue}{x}\right)\right) \]
      10. Simplified66.8%

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

      if 3.8000000000000002e-5 < y

      1. Initial program 100.0%

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

          \[\leadsto \frac{{x}^{3} + {\left(\frac{\left|y - x\right|}{2}\right)}^{3}}{\color{blue}{x \cdot x + \left(\frac{\left|y - x\right|}{2} \cdot \frac{\left|y - x\right|}{2} - x \cdot \frac{\left|y - x\right|}{2}\right)}} \]
        2. /-lowering-/.f64N/A

          \[\leadsto \mathsf{/.f64}\left(\left({x}^{3} + {\left(\frac{\left|y - x\right|}{2}\right)}^{3}\right), \color{blue}{\left(x \cdot x + \left(\frac{\left|y - x\right|}{2} \cdot \frac{\left|y - x\right|}{2} - x \cdot \frac{\left|y - x\right|}{2}\right)\right)}\right) \]
      4. Applied egg-rr24.0%

        \[\leadsto \color{blue}{\frac{x \cdot \left(x \cdot x\right) + {\left(\frac{\left(y - x\right) \cdot \left(y - x\right)}{4}\right)}^{1.5}}{\frac{\left(y - x\right) \cdot \left(y - x\right)}{4} + x \cdot \left(x + \frac{\left|y - x\right|}{-2}\right)}} \]
      5. Taylor expanded in x around 0

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

          \[\leadsto \mathsf{*.f64}\left(\frac{1}{2}, \color{blue}{y}\right) \]
      7. Simplified79.8%

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

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

    Alternative 5: 45.5% accurate, 13.3× speedup?

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

      1. Initial program 99.9%

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

          \[\leadsto \frac{{x}^{3} + {\left(\frac{\left|y - x\right|}{2}\right)}^{3}}{\color{blue}{x \cdot x + \left(\frac{\left|y - x\right|}{2} \cdot \frac{\left|y - x\right|}{2} - x \cdot \frac{\left|y - x\right|}{2}\right)}} \]
        2. /-lowering-/.f64N/A

          \[\leadsto \mathsf{/.f64}\left(\left({x}^{3} + {\left(\frac{\left|y - x\right|}{2}\right)}^{3}\right), \color{blue}{\left(x \cdot x + \left(\frac{\left|y - x\right|}{2} \cdot \frac{\left|y - x\right|}{2} - x \cdot \frac{\left|y - x\right|}{2}\right)\right)}\right) \]
      4. Applied egg-rr36.9%

        \[\leadsto \color{blue}{\frac{x \cdot \left(x \cdot x\right) + {\left(\frac{\left(y - x\right) \cdot \left(y - x\right)}{4}\right)}^{1.5}}{\frac{\left(y - x\right) \cdot \left(y - x\right)}{4} + x \cdot \left(x + \frac{\left|y - x\right|}{-2}\right)}} \]
      5. Taylor expanded in y around -inf

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

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

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

          \[\leadsto \mathsf{*.f64}\left(\left(\mathsf{neg}\left(y\right)\right), \left(\color{blue}{\frac{1}{2}} + -1 \cdot \frac{\frac{1}{2} \cdot \left(x + 2 \cdot x\right) - x}{y}\right)\right) \]
        4. neg-sub0N/A

          \[\leadsto \mathsf{*.f64}\left(\left(0 - y\right), \left(\color{blue}{\frac{1}{2}} + -1 \cdot \frac{\frac{1}{2} \cdot \left(x + 2 \cdot x\right) - x}{y}\right)\right) \]
        5. --lowering--.f64N/A

          \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(0, y\right), \left(\color{blue}{\frac{1}{2}} + -1 \cdot \frac{\frac{1}{2} \cdot \left(x + 2 \cdot x\right) - x}{y}\right)\right) \]
        6. mul-1-negN/A

          \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(0, y\right), \left(\frac{1}{2} + \left(\mathsf{neg}\left(\frac{\frac{1}{2} \cdot \left(x + 2 \cdot x\right) - x}{y}\right)\right)\right)\right) \]
        7. unsub-negN/A

          \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(0, y\right), \left(\frac{1}{2} - \color{blue}{\frac{\frac{1}{2} \cdot \left(x + 2 \cdot x\right) - x}{y}}\right)\right) \]
        8. --lowering--.f64N/A

          \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(0, y\right), \mathsf{\_.f64}\left(\frac{1}{2}, \color{blue}{\left(\frac{\frac{1}{2} \cdot \left(x + 2 \cdot x\right) - x}{y}\right)}\right)\right) \]
        9. /-lowering-/.f64N/A

          \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(0, y\right), \mathsf{\_.f64}\left(\frac{1}{2}, \mathsf{/.f64}\left(\left(\frac{1}{2} \cdot \left(x + 2 \cdot x\right) - x\right), \color{blue}{y}\right)\right)\right) \]
        10. --lowering--.f64N/A

          \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(0, y\right), \mathsf{\_.f64}\left(\frac{1}{2}, \mathsf{/.f64}\left(\mathsf{\_.f64}\left(\left(\frac{1}{2} \cdot \left(x + 2 \cdot x\right)\right), x\right), y\right)\right)\right) \]
        11. *-lowering-*.f64N/A

          \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(0, y\right), \mathsf{\_.f64}\left(\frac{1}{2}, \mathsf{/.f64}\left(\mathsf{\_.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \left(x + 2 \cdot x\right)\right), x\right), y\right)\right)\right) \]
        12. distribute-rgt1-inN/A

          \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(0, y\right), \mathsf{\_.f64}\left(\frac{1}{2}, \mathsf{/.f64}\left(\mathsf{\_.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \left(\left(2 + 1\right) \cdot x\right)\right), x\right), y\right)\right)\right) \]
        13. metadata-evalN/A

          \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(0, y\right), \mathsf{\_.f64}\left(\frac{1}{2}, \mathsf{/.f64}\left(\mathsf{\_.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \left(3 \cdot x\right)\right), x\right), y\right)\right)\right) \]
        14. *-lowering-*.f6457.4%

          \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(0, y\right), \mathsf{\_.f64}\left(\frac{1}{2}, \mathsf{/.f64}\left(\mathsf{\_.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(3, x\right)\right), x\right), y\right)\right)\right) \]
      7. Simplified57.4%

        \[\leadsto \color{blue}{\left(0 - y\right) \cdot \left(0.5 - \frac{0.5 \cdot \left(3 \cdot x\right) - x}{y}\right)} \]
      8. Taylor expanded in y around 0

        \[\leadsto \color{blue}{-1 \cdot \left(x - \frac{3}{2} \cdot x\right)} \]
      9. Step-by-step derivation
        1. sub-negN/A

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

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

          \[\leadsto -1 \cdot x + \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\frac{3}{2} \cdot x\right)\right)\right)\right) \]
        4. remove-double-negN/A

          \[\leadsto -1 \cdot x + \frac{3}{2} \cdot \color{blue}{x} \]
        5. distribute-rgt-outN/A

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

          \[\leadsto x \cdot \frac{1}{2} \]
        7. *-commutativeN/A

          \[\leadsto \frac{1}{2} \cdot \color{blue}{x} \]
        8. *-lowering-*.f6437.0%

          \[\leadsto \mathsf{*.f64}\left(\frac{1}{2}, \color{blue}{x}\right) \]
      10. Simplified37.0%

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

      if 5.59999999999999992e-5 < y

      1. Initial program 100.0%

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

          \[\leadsto \frac{{x}^{3} + {\left(\frac{\left|y - x\right|}{2}\right)}^{3}}{\color{blue}{x \cdot x + \left(\frac{\left|y - x\right|}{2} \cdot \frac{\left|y - x\right|}{2} - x \cdot \frac{\left|y - x\right|}{2}\right)}} \]
        2. /-lowering-/.f64N/A

          \[\leadsto \mathsf{/.f64}\left(\left({x}^{3} + {\left(\frac{\left|y - x\right|}{2}\right)}^{3}\right), \color{blue}{\left(x \cdot x + \left(\frac{\left|y - x\right|}{2} \cdot \frac{\left|y - x\right|}{2} - x \cdot \frac{\left|y - x\right|}{2}\right)\right)}\right) \]
      4. Applied egg-rr24.0%

        \[\leadsto \color{blue}{\frac{x \cdot \left(x \cdot x\right) + {\left(\frac{\left(y - x\right) \cdot \left(y - x\right)}{4}\right)}^{1.5}}{\frac{\left(y - x\right) \cdot \left(y - x\right)}{4} + x \cdot \left(x + \frac{\left|y - x\right|}{-2}\right)}} \]
      5. Taylor expanded in x around 0

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

          \[\leadsto \mathsf{*.f64}\left(\frac{1}{2}, \color{blue}{y}\right) \]
      7. Simplified79.8%

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

      \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq 5.6 \cdot 10^{-5}:\\ \;\;\;\;x \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;y \cdot 0.5\\ \end{array} \]
    5. Add Preprocessing

    Alternative 6: 30.7% 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. Add Preprocessing
    3. Step-by-step derivation
      1. flip3-+N/A

        \[\leadsto \frac{{x}^{3} + {\left(\frac{\left|y - x\right|}{2}\right)}^{3}}{\color{blue}{x \cdot x + \left(\frac{\left|y - x\right|}{2} \cdot \frac{\left|y - x\right|}{2} - x \cdot \frac{\left|y - x\right|}{2}\right)}} \]
      2. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\left({x}^{3} + {\left(\frac{\left|y - x\right|}{2}\right)}^{3}\right), \color{blue}{\left(x \cdot x + \left(\frac{\left|y - x\right|}{2} \cdot \frac{\left|y - x\right|}{2} - x \cdot \frac{\left|y - x\right|}{2}\right)\right)}\right) \]
    4. Applied egg-rr33.3%

      \[\leadsto \color{blue}{\frac{x \cdot \left(x \cdot x\right) + {\left(\frac{\left(y - x\right) \cdot \left(y - x\right)}{4}\right)}^{1.5}}{\frac{\left(y - x\right) \cdot \left(y - x\right)}{4} + x \cdot \left(x + \frac{\left|y - x\right|}{-2}\right)}} \]
    5. Taylor expanded in y around -inf

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

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

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

        \[\leadsto \mathsf{*.f64}\left(\left(\mathsf{neg}\left(y\right)\right), \left(\color{blue}{\frac{1}{2}} + -1 \cdot \frac{\frac{1}{2} \cdot \left(x + 2 \cdot x\right) - x}{y}\right)\right) \]
      4. neg-sub0N/A

        \[\leadsto \mathsf{*.f64}\left(\left(0 - y\right), \left(\color{blue}{\frac{1}{2}} + -1 \cdot \frac{\frac{1}{2} \cdot \left(x + 2 \cdot x\right) - x}{y}\right)\right) \]
      5. --lowering--.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(0, y\right), \left(\color{blue}{\frac{1}{2}} + -1 \cdot \frac{\frac{1}{2} \cdot \left(x + 2 \cdot x\right) - x}{y}\right)\right) \]
      6. mul-1-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(0, y\right), \left(\frac{1}{2} + \left(\mathsf{neg}\left(\frac{\frac{1}{2} \cdot \left(x + 2 \cdot x\right) - x}{y}\right)\right)\right)\right) \]
      7. unsub-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(0, y\right), \left(\frac{1}{2} - \color{blue}{\frac{\frac{1}{2} \cdot \left(x + 2 \cdot x\right) - x}{y}}\right)\right) \]
      8. --lowering--.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(0, y\right), \mathsf{\_.f64}\left(\frac{1}{2}, \color{blue}{\left(\frac{\frac{1}{2} \cdot \left(x + 2 \cdot x\right) - x}{y}\right)}\right)\right) \]
      9. /-lowering-/.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(0, y\right), \mathsf{\_.f64}\left(\frac{1}{2}, \mathsf{/.f64}\left(\left(\frac{1}{2} \cdot \left(x + 2 \cdot x\right) - x\right), \color{blue}{y}\right)\right)\right) \]
      10. --lowering--.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(0, y\right), \mathsf{\_.f64}\left(\frac{1}{2}, \mathsf{/.f64}\left(\mathsf{\_.f64}\left(\left(\frac{1}{2} \cdot \left(x + 2 \cdot x\right)\right), x\right), y\right)\right)\right) \]
      11. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(0, y\right), \mathsf{\_.f64}\left(\frac{1}{2}, \mathsf{/.f64}\left(\mathsf{\_.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \left(x + 2 \cdot x\right)\right), x\right), y\right)\right)\right) \]
      12. distribute-rgt1-inN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(0, y\right), \mathsf{\_.f64}\left(\frac{1}{2}, \mathsf{/.f64}\left(\mathsf{\_.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \left(\left(2 + 1\right) \cdot x\right)\right), x\right), y\right)\right)\right) \]
      13. metadata-evalN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(0, y\right), \mathsf{\_.f64}\left(\frac{1}{2}, \mathsf{/.f64}\left(\mathsf{\_.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \left(3 \cdot x\right)\right), x\right), y\right)\right)\right) \]
      14. *-lowering-*.f6445.3%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{\_.f64}\left(0, y\right), \mathsf{\_.f64}\left(\frac{1}{2}, \mathsf{/.f64}\left(\mathsf{\_.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(3, x\right)\right), x\right), y\right)\right)\right) \]
    7. Simplified45.3%

      \[\leadsto \color{blue}{\left(0 - y\right) \cdot \left(0.5 - \frac{0.5 \cdot \left(3 \cdot x\right) - x}{y}\right)} \]
    8. Taylor expanded in y around 0

      \[\leadsto \color{blue}{-1 \cdot \left(x - \frac{3}{2} \cdot x\right)} \]
    9. Step-by-step derivation
      1. sub-negN/A

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

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

        \[\leadsto -1 \cdot x + \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\frac{3}{2} \cdot x\right)\right)\right)\right) \]
      4. remove-double-negN/A

        \[\leadsto -1 \cdot x + \frac{3}{2} \cdot \color{blue}{x} \]
      5. distribute-rgt-outN/A

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

        \[\leadsto x \cdot \frac{1}{2} \]
      7. *-commutativeN/A

        \[\leadsto \frac{1}{2} \cdot \color{blue}{x} \]
      8. *-lowering-*.f6431.1%

        \[\leadsto \mathsf{*.f64}\left(\frac{1}{2}, \color{blue}{x}\right) \]
    10. Simplified31.1%

      \[\leadsto \color{blue}{0.5 \cdot x} \]
    11. Final simplification31.1%

      \[\leadsto x \cdot 0.5 \]
    12. Add Preprocessing

    Alternative 7: 11.3% 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. Add Preprocessing
    3. Taylor expanded in x around inf

      \[\leadsto \color{blue}{x} \]
    4. Step-by-step derivation
      1. Simplified11.1%

        \[\leadsto \color{blue}{x} \]
      2. Add Preprocessing

      Reproduce

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