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

Percentage Accurate: 99.9% → 99.9%
Time: 12.2s
Alternatives: 6
Speedup: 1.7×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 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, 0.6× speedup?

\[\begin{array}{l} \\ \mathsf{fma}\left(y + x, \frac{\left|y - x\right|}{y + x} \cdot 0.5, x\right) \end{array} \]
(FPCore (x y)
 :precision binary64
 (fma (+ y x) (* (/ (fabs (- y x)) (+ y x)) 0.5) x))
double code(double x, double y) {
	return fma((y + x), ((fabs((y - x)) / (y + x)) * 0.5), x);
}
function code(x, y)
	return fma(Float64(y + x), Float64(Float64(abs(Float64(y - x)) / Float64(y + x)) * 0.5), x)
end
code[x_, y_] := N[(N[(y + x), $MachinePrecision] * N[(N[(N[Abs[N[(y - x), $MachinePrecision]], $MachinePrecision] / N[(y + x), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision] + x), $MachinePrecision]
\begin{array}{l}

\\
\mathsf{fma}\left(y + x, \frac{\left|y - x\right|}{y + x} \cdot 0.5, x\right)
\end{array}
Derivation
  1. Initial program 99.9%

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \left|\color{blue}{\left(y + x\right) \cdot \frac{y - x}{y + x}}\right| \cdot \frac{1}{2} + x \]
    4. un-div-invN/A

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

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

      \[\leadsto \color{blue}{\frac{\left|\left(y + x\right) \cdot \left(\left(y - x\right) \cdot \frac{1}{y + x}\right)\right|}{2}} + x \]
  6. Applied egg-rr99.9%

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

Alternative 2: 77.5% accurate, 0.6× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;x + \frac{\left|y - x\right|}{2} \leq 1.5 \cdot 10^{-281}:\\
\;\;\;\;\mathsf{fma}\left(0.5, \left|x\right|, x\right)\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\left|y\right|, 0.5, x\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (+.f64 x (/.f64 (fabs.f64 (-.f64 y x)) #s(literal 2 binary64))) < 1.49999999999999987e-281

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(x, \frac{\left|y + \color{blue}{-1 \cdot x}\right| \cdot \frac{1}{2}}{x}, x\right) \]
      9. associate-/l*N/A

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(x, \left|\color{blue}{x - y}\right| \cdot \frac{\frac{1}{2}}{x}, x\right) \]
      20. /-lowering-/.f6499.7

        \[\leadsto \mathsf{fma}\left(x, \left|x - y\right| \cdot \color{blue}{\frac{0.5}{x}}, x\right) \]
    7. Simplified99.7%

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

      \[\leadsto \mathsf{fma}\left(x, \left|\color{blue}{x}\right| \cdot \frac{\frac{1}{2}}{x}, x\right) \]
    9. Step-by-step derivation
      1. Simplified96.1%

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

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

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

          \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{1}{2}, \left|x\right|, x\right)} \]
        3. fabs-lowering-fabs.f6496.3

          \[\leadsto \mathsf{fma}\left(0.5, \color{blue}{\left|x\right|}, x\right) \]
      4. Simplified96.3%

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

      if 1.49999999999999987e-281 < (+.f64 x (/.f64 (fabs.f64 (-.f64 y x)) #s(literal 2 binary64)))

      1. Initial program 99.9%

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

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

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

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\left|\color{blue}{y}\right|, \frac{1}{2}, x\right) \]
      6. Step-by-step derivation
        1. Simplified71.7%

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

      Alternative 3: 53.5% accurate, 0.6× speedup?

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

        1. Initial program 100.0%

          \[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. Simplified18.8%

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

          if 1.49999999999999987e-281 < (+.f64 x (/.f64 (fabs.f64 (-.f64 y x)) #s(literal 2 binary64)))

          1. Initial program 99.9%

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

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

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

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

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

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

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

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

            \[\leadsto \mathsf{fma}\left(\left|\color{blue}{y}\right|, \frac{1}{2}, x\right) \]
          6. Step-by-step derivation
            1. Simplified71.7%

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

              \[\leadsto \color{blue}{\frac{1}{2} \cdot \left|y\right|} \]
            3. Step-by-step derivation
              1. *-lowering-*.f64N/A

                \[\leadsto \color{blue}{\frac{1}{2} \cdot \left|y\right|} \]
              2. fabs-lowering-fabs.f6466.7

                \[\leadsto 0.5 \cdot \color{blue}{\left|y\right|} \]
            4. Simplified66.7%

              \[\leadsto \color{blue}{0.5 \cdot \left|y\right|} \]
          7. Recombined 2 regimes into one program.
          8. Add Preprocessing

          Alternative 4: 75.3% accurate, 1.0× speedup?

          \[\begin{array}{l} \\ \begin{array}{l} t_0 := 0.5 \cdot \left|y\right|\\ \mathbf{if}\;y \leq -790000000:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;y \leq 1.85 \cdot 10^{+47}:\\ \;\;\;\;\mathsf{fma}\left(0.5, \left|x\right|, x\right)\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
          (FPCore (x y)
           :precision binary64
           (let* ((t_0 (* 0.5 (fabs y))))
             (if (<= y -790000000.0) t_0 (if (<= y 1.85e+47) (fma 0.5 (fabs x) x) t_0))))
          double code(double x, double y) {
          	double t_0 = 0.5 * fabs(y);
          	double tmp;
          	if (y <= -790000000.0) {
          		tmp = t_0;
          	} else if (y <= 1.85e+47) {
          		tmp = fma(0.5, fabs(x), x);
          	} else {
          		tmp = t_0;
          	}
          	return tmp;
          }
          
          function code(x, y)
          	t_0 = Float64(0.5 * abs(y))
          	tmp = 0.0
          	if (y <= -790000000.0)
          		tmp = t_0;
          	elseif (y <= 1.85e+47)
          		tmp = fma(0.5, abs(x), x);
          	else
          		tmp = t_0;
          	end
          	return tmp
          end
          
          code[x_, y_] := Block[{t$95$0 = N[(0.5 * N[Abs[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -790000000.0], t$95$0, If[LessEqual[y, 1.85e+47], N[(0.5 * N[Abs[x], $MachinePrecision] + x), $MachinePrecision], t$95$0]]]
          
          \begin{array}{l}
          
          \\
          \begin{array}{l}
          t_0 := 0.5 \cdot \left|y\right|\\
          \mathbf{if}\;y \leq -790000000:\\
          \;\;\;\;t\_0\\
          
          \mathbf{elif}\;y \leq 1.85 \cdot 10^{+47}:\\
          \;\;\;\;\mathsf{fma}\left(0.5, \left|x\right|, x\right)\\
          
          \mathbf{else}:\\
          \;\;\;\;t\_0\\
          
          
          \end{array}
          \end{array}
          
          Derivation
          1. Split input into 2 regimes
          2. if y < -7.9e8 or 1.8500000000000002e47 < y

            1. Initial program 99.9%

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

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

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

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

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

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

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

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

              \[\leadsto \mathsf{fma}\left(\left|\color{blue}{y}\right|, \frac{1}{2}, x\right) \]
            6. Step-by-step derivation
              1. Simplified80.3%

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

                \[\leadsto \color{blue}{\frac{1}{2} \cdot \left|y\right|} \]
              3. Step-by-step derivation
                1. *-lowering-*.f64N/A

                  \[\leadsto \color{blue}{\frac{1}{2} \cdot \left|y\right|} \]
                2. fabs-lowering-fabs.f6476.7

                  \[\leadsto 0.5 \cdot \color{blue}{\left|y\right|} \]
              4. Simplified76.7%

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

              if -7.9e8 < y < 1.8500000000000002e47

              1. Initial program 99.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                  \[\leadsto \mathsf{fma}\left(x, \frac{\left|y + \color{blue}{-1 \cdot x}\right| \cdot \frac{1}{2}}{x}, x\right) \]
                9. associate-/l*N/A

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

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

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

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

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

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

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

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

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

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

                  \[\leadsto \mathsf{fma}\left(x, \left|\color{blue}{x - y}\right| \cdot \frac{\frac{1}{2}}{x}, x\right) \]
                20. /-lowering-/.f6499.7

                  \[\leadsto \mathsf{fma}\left(x, \left|x - y\right| \cdot \color{blue}{\frac{0.5}{x}}, x\right) \]
              7. Simplified99.7%

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

                \[\leadsto \mathsf{fma}\left(x, \left|\color{blue}{x}\right| \cdot \frac{\frac{1}{2}}{x}, x\right) \]
              9. Step-by-step derivation
                1. Simplified76.7%

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

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

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

                    \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{1}{2}, \left|x\right|, x\right)} \]
                  3. fabs-lowering-fabs.f6476.8

                    \[\leadsto \mathsf{fma}\left(0.5, \color{blue}{\left|x\right|}, x\right) \]
                4. Simplified76.8%

                  \[\leadsto \color{blue}{\mathsf{fma}\left(0.5, \left|x\right|, x\right)} \]
              10. Recombined 2 regimes into one program.
              11. Add Preprocessing

              Alternative 5: 99.9% accurate, 1.7× speedup?

              \[\begin{array}{l} \\ \mathsf{fma}\left(\left|y - x\right|, 0.5, x\right) \end{array} \]
              (FPCore (x y) :precision binary64 (fma (fabs (- y x)) 0.5 x))
              double code(double x, double y) {
              	return fma(fabs((y - x)), 0.5, x);
              }
              
              function code(x, y)
              	return fma(abs(Float64(y - x)), 0.5, x)
              end
              
              code[x_, y_] := N[(N[Abs[N[(y - x), $MachinePrecision]], $MachinePrecision] * 0.5 + x), $MachinePrecision]
              
              \begin{array}{l}
              
              \\
              \mathsf{fma}\left(\left|y - x\right|, 0.5, x\right)
              \end{array}
              
              Derivation
              1. Initial program 99.9%

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

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

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

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

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

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

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

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

              Alternative 6: 11.6% accurate, 20.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.5%

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

                Reproduce

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