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

Percentage Accurate: 99.9% → 99.9%
Time: 5.8s
Alternatives: 11
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);
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(x, y)
use fmin_fmax_functions
    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 11 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);
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

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

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

Alternative 1: 99.9% accurate, 1.7× speedup?

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

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

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

    \[\leadsto \color{blue}{x + \frac{1}{2} \cdot \left|y - x\right|} \]
  4. Applied rewrites99.9%

    \[\leadsto \color{blue}{\mathsf{fma}\left(\left|x - y\right|, 0.5, x\right)} \]
  5. Final simplification99.9%

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

Alternative 2: 83.9% accurate, 0.8× speedup?

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

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

\mathbf{elif}\;x \leq 1950000000000:\\
\;\;\;\;\mathsf{fma}\left(\left|-y\right|, 0.5, x\right)\\

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


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

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{x + \frac{1}{2} \cdot \left|y - x\right|} \]
    4. Applied rewrites100.0%

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

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

        \[\leadsto \frac{1}{2} \cdot x + \color{blue}{\frac{1}{2} \cdot y} \]
      3. Step-by-step derivation
        1. Applied rewrites86.2%

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

        if -2.25000000000000008e-107 < x < 1.95e12

        1. Initial program 100.0%

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

          \[\leadsto \color{blue}{x + \frac{1}{2} \cdot \left|y - x\right|} \]
        4. Applied rewrites100.0%

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

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

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

          if 1.95e12 < x

          1. Initial program 99.8%

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

            \[\leadsto \color{blue}{x + \frac{1}{2} \cdot \left|y - x\right|} \]
          4. Applied rewrites99.8%

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

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

              \[\leadsto \frac{-1}{2} \cdot y + \color{blue}{\frac{3}{2} \cdot x} \]
            3. Step-by-step derivation
              1. Applied rewrites89.8%

                \[\leadsto \mathsf{fma}\left(-0.5, \color{blue}{y}, 1.5 \cdot x\right) \]
              2. Step-by-step derivation
                1. Applied rewrites90.0%

                  \[\leadsto \mathsf{fma}\left(x, 1.5, -0.5 \cdot y\right) \]
              3. Recombined 3 regimes into one program.
              4. Add Preprocessing

              Alternative 3: 83.9% accurate, 0.9× speedup?

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

                1. Initial program 100.0%

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

                  \[\leadsto \color{blue}{x + \frac{1}{2} \cdot \left|y - x\right|} \]
                4. Applied rewrites100.0%

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

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

                    \[\leadsto \frac{1}{2} \cdot x + \color{blue}{\frac{1}{2} \cdot y} \]
                  3. Step-by-step derivation
                    1. Applied rewrites86.2%

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

                    if -2.25000000000000008e-107 < x < 1.95e12

                    1. Initial program 100.0%

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

                      \[\leadsto \color{blue}{x + \frac{1}{2} \cdot \left|y - x\right|} \]
                    4. Applied rewrites100.0%

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

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

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

                      if 1.95e12 < x

                      1. Initial program 99.8%

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

                        \[\leadsto \color{blue}{x + \frac{1}{2} \cdot \left|y - x\right|} \]
                      4. Applied rewrites99.8%

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

                          \[\leadsto \mathsf{fma}\left(\sqrt{x - y} \cdot \sqrt{x - y}, 0.5, x\right) \]
                        2. Step-by-step derivation
                          1. Applied rewrites89.8%

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

                        Alternative 4: 83.4% accurate, 0.9× speedup?

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

                          1. Initial program 100.0%

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

                            \[\leadsto \color{blue}{x + \frac{1}{2} \cdot \left|y - x\right|} \]
                          4. Applied rewrites100.0%

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

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

                              \[\leadsto \frac{1}{2} \cdot x + \color{blue}{\frac{1}{2} \cdot y} \]
                            3. Step-by-step derivation
                              1. Applied rewrites86.2%

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

                              if -2.25000000000000008e-107 < x < 1.95e12

                              1. Initial program 100.0%

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

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

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

                                  \[\leadsto \color{blue}{\left|y - x\right| \cdot \frac{1}{2}} \]
                              5. Applied rewrites77.7%

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

                              if 1.95e12 < x

                              1. Initial program 99.8%

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

                                \[\leadsto \color{blue}{x + \frac{1}{2} \cdot \left|y - x\right|} \]
                              4. Applied rewrites99.8%

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

                                  \[\leadsto \mathsf{fma}\left(\sqrt{x - y} \cdot \sqrt{x - y}, 0.5, x\right) \]
                                2. Step-by-step derivation
                                  1. Applied rewrites89.8%

                                    \[\leadsto \mathsf{fma}\left(x - y, 0.5, x\right) \]
                                3. Recombined 3 regimes into one program.
                                4. Final simplification83.2%

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

                                Alternative 5: 82.7% accurate, 0.9× speedup?

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

                                  1. Initial program 100.0%

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

                                    \[\leadsto \color{blue}{x + \frac{1}{2} \cdot \left|y - x\right|} \]
                                  4. Applied rewrites100.0%

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

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

                                      \[\leadsto \frac{1}{2} \cdot x + \color{blue}{\frac{1}{2} \cdot y} \]
                                    3. Step-by-step derivation
                                      1. Applied rewrites86.2%

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

                                      if -2.25000000000000008e-107 < x < 4.6e10

                                      1. Initial program 100.0%

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

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

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

                                          \[\leadsto \color{blue}{\left|y - x\right| \cdot \frac{1}{2}} \]
                                      5. Applied rewrites77.7%

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

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

                                          \[\leadsto \left|-y\right| \cdot 0.5 \]

                                        if 4.6e10 < x

                                        1. Initial program 99.8%

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

                                          \[\leadsto \color{blue}{x + \frac{1}{2} \cdot \left|y - x\right|} \]
                                        4. Applied rewrites99.8%

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

                                            \[\leadsto \mathsf{fma}\left(\sqrt{x - y} \cdot \sqrt{x - y}, 0.5, x\right) \]
                                          2. Step-by-step derivation
                                            1. Applied rewrites89.8%

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

                                          Alternative 6: 79.5% accurate, 0.9× speedup?

                                          \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -2.25 \cdot 10^{-107}:\\ \;\;\;\;\left(y + x\right) \cdot 0.5\\ \mathbf{elif}\;x \leq 2200000000000:\\ \;\;\;\;\left|-y\right| \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;1.5 \cdot x\\ \end{array} \end{array} \]
                                          (FPCore (x y)
                                           :precision binary64
                                           (if (<= x -2.25e-107)
                                             (* (+ y x) 0.5)
                                             (if (<= x 2200000000000.0) (* (fabs (- y)) 0.5) (* 1.5 x))))
                                          double code(double x, double y) {
                                          	double tmp;
                                          	if (x <= -2.25e-107) {
                                          		tmp = (y + x) * 0.5;
                                          	} else if (x <= 2200000000000.0) {
                                          		tmp = fabs(-y) * 0.5;
                                          	} else {
                                          		tmp = 1.5 * x;
                                          	}
                                          	return tmp;
                                          }
                                          
                                          module fmin_fmax_functions
                                              implicit none
                                              private
                                              public fmax
                                              public fmin
                                          
                                              interface fmax
                                                  module procedure fmax88
                                                  module procedure fmax44
                                                  module procedure fmax84
                                                  module procedure fmax48
                                              end interface
                                              interface fmin
                                                  module procedure fmin88
                                                  module procedure fmin44
                                                  module procedure fmin84
                                                  module procedure fmin48
                                              end interface
                                          contains
                                              real(8) function fmax88(x, y) result (res)
                                                  real(8), intent (in) :: x
                                                  real(8), intent (in) :: y
                                                  res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                                              end function
                                              real(4) function fmax44(x, y) result (res)
                                                  real(4), intent (in) :: x
                                                  real(4), intent (in) :: y
                                                  res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                                              end function
                                              real(8) function fmax84(x, y) result(res)
                                                  real(8), intent (in) :: x
                                                  real(4), intent (in) :: y
                                                  res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
                                              end function
                                              real(8) function fmax48(x, y) result(res)
                                                  real(4), intent (in) :: x
                                                  real(8), intent (in) :: y
                                                  res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
                                              end function
                                              real(8) function fmin88(x, y) result (res)
                                                  real(8), intent (in) :: x
                                                  real(8), intent (in) :: y
                                                  res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                                              end function
                                              real(4) function fmin44(x, y) result (res)
                                                  real(4), intent (in) :: x
                                                  real(4), intent (in) :: y
                                                  res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                                              end function
                                              real(8) function fmin84(x, y) result(res)
                                                  real(8), intent (in) :: x
                                                  real(4), intent (in) :: y
                                                  res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
                                              end function
                                              real(8) function fmin48(x, y) result(res)
                                                  real(4), intent (in) :: x
                                                  real(8), intent (in) :: y
                                                  res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
                                              end function
                                          end module
                                          
                                          real(8) function code(x, y)
                                          use fmin_fmax_functions
                                              real(8), intent (in) :: x
                                              real(8), intent (in) :: y
                                              real(8) :: tmp
                                              if (x <= (-2.25d-107)) then
                                                  tmp = (y + x) * 0.5d0
                                              else if (x <= 2200000000000.0d0) then
                                                  tmp = abs(-y) * 0.5d0
                                              else
                                                  tmp = 1.5d0 * x
                                              end if
                                              code = tmp
                                          end function
                                          
                                          public static double code(double x, double y) {
                                          	double tmp;
                                          	if (x <= -2.25e-107) {
                                          		tmp = (y + x) * 0.5;
                                          	} else if (x <= 2200000000000.0) {
                                          		tmp = Math.abs(-y) * 0.5;
                                          	} else {
                                          		tmp = 1.5 * x;
                                          	}
                                          	return tmp;
                                          }
                                          
                                          def code(x, y):
                                          	tmp = 0
                                          	if x <= -2.25e-107:
                                          		tmp = (y + x) * 0.5
                                          	elif x <= 2200000000000.0:
                                          		tmp = math.fabs(-y) * 0.5
                                          	else:
                                          		tmp = 1.5 * x
                                          	return tmp
                                          
                                          function code(x, y)
                                          	tmp = 0.0
                                          	if (x <= -2.25e-107)
                                          		tmp = Float64(Float64(y + x) * 0.5);
                                          	elseif (x <= 2200000000000.0)
                                          		tmp = Float64(abs(Float64(-y)) * 0.5);
                                          	else
                                          		tmp = Float64(1.5 * x);
                                          	end
                                          	return tmp
                                          end
                                          
                                          function tmp_2 = code(x, y)
                                          	tmp = 0.0;
                                          	if (x <= -2.25e-107)
                                          		tmp = (y + x) * 0.5;
                                          	elseif (x <= 2200000000000.0)
                                          		tmp = abs(-y) * 0.5;
                                          	else
                                          		tmp = 1.5 * x;
                                          	end
                                          	tmp_2 = tmp;
                                          end
                                          
                                          code[x_, y_] := If[LessEqual[x, -2.25e-107], N[(N[(y + x), $MachinePrecision] * 0.5), $MachinePrecision], If[LessEqual[x, 2200000000000.0], N[(N[Abs[(-y)], $MachinePrecision] * 0.5), $MachinePrecision], N[(1.5 * x), $MachinePrecision]]]
                                          
                                          \begin{array}{l}
                                          
                                          \\
                                          \begin{array}{l}
                                          \mathbf{if}\;x \leq -2.25 \cdot 10^{-107}:\\
                                          \;\;\;\;\left(y + x\right) \cdot 0.5\\
                                          
                                          \mathbf{elif}\;x \leq 2200000000000:\\
                                          \;\;\;\;\left|-y\right| \cdot 0.5\\
                                          
                                          \mathbf{else}:\\
                                          \;\;\;\;1.5 \cdot x\\
                                          
                                          
                                          \end{array}
                                          \end{array}
                                          
                                          Derivation
                                          1. Split input into 3 regimes
                                          2. if x < -2.25000000000000008e-107

                                            1. Initial program 100.0%

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

                                              \[\leadsto \color{blue}{x + \frac{1}{2} \cdot \left|y - x\right|} \]
                                            4. Applied rewrites100.0%

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

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

                                                \[\leadsto \frac{1}{2} \cdot x + \color{blue}{\frac{1}{2} \cdot y} \]
                                              3. Step-by-step derivation
                                                1. Applied rewrites86.2%

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

                                                if -2.25000000000000008e-107 < x < 2.2e12

                                                1. Initial program 100.0%

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

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

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

                                                    \[\leadsto \color{blue}{\left|y - x\right| \cdot \frac{1}{2}} \]
                                                5. Applied rewrites77.7%

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

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

                                                    \[\leadsto \left|-y\right| \cdot 0.5 \]

                                                  if 2.2e12 < x

                                                  1. Initial program 99.8%

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

                                                    \[\leadsto \color{blue}{x + \frac{1}{2} \cdot \left|y - x\right|} \]
                                                  4. Applied rewrites99.8%

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

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

                                                      \[\leadsto \frac{3}{2} \cdot \color{blue}{x} \]
                                                    3. Step-by-step derivation
                                                      1. Applied rewrites84.9%

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

                                                    Alternative 7: 72.0% accurate, 1.0× speedup?

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

                                                      1. Initial program 99.9%

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

                                                        \[\leadsto \color{blue}{x + \frac{1}{2} \cdot \left|y - x\right|} \]
                                                      4. Applied rewrites99.9%

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

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

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

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

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

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

                                                            if -1.35e-76 < y < 1.8000000000000001e-268

                                                            1. Initial program 99.8%

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

                                                              \[\leadsto \color{blue}{x + \frac{1}{2} \cdot \left|y - x\right|} \]
                                                            4. Applied rewrites99.8%

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

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

                                                                \[\leadsto \frac{3}{2} \cdot \color{blue}{x} \]
                                                              3. Step-by-step derivation
                                                                1. Applied rewrites61.2%

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

                                                                if 1.8000000000000001e-268 < y

                                                                1. Initial program 100.0%

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

                                                                  \[\leadsto \color{blue}{x + \frac{1}{2} \cdot \left|y - x\right|} \]
                                                                4. Applied rewrites100.0%

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

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

                                                                    \[\leadsto \frac{1}{2} \cdot x + \color{blue}{\frac{1}{2} \cdot y} \]
                                                                  3. Step-by-step derivation
                                                                    1. Applied rewrites78.2%

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

                                                                    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -1.35 \cdot 10^{-76}:\\ \;\;\;\;\mathsf{fma}\left(-y, 0.5, x\right)\\ \mathbf{elif}\;y \leq 1.8 \cdot 10^{-268}:\\ \;\;\;\;1.5 \cdot x\\ \mathbf{else}:\\ \;\;\;\;\left(y + x\right) \cdot 0.5\\ \end{array} \]
                                                                  6. Add Preprocessing

                                                                  Alternative 8: 70.4% accurate, 1.0× speedup?

                                                                  \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -1.02 \cdot 10^{-73}:\\ \;\;\;\;-0.5 \cdot y\\ \mathbf{elif}\;y \leq 1.8 \cdot 10^{-268}:\\ \;\;\;\;1.5 \cdot x\\ \mathbf{else}:\\ \;\;\;\;\left(y + x\right) \cdot 0.5\\ \end{array} \end{array} \]
                                                                  (FPCore (x y)
                                                                   :precision binary64
                                                                   (if (<= y -1.02e-73)
                                                                     (* -0.5 y)
                                                                     (if (<= y 1.8e-268) (* 1.5 x) (* (+ y x) 0.5))))
                                                                  double code(double x, double y) {
                                                                  	double tmp;
                                                                  	if (y <= -1.02e-73) {
                                                                  		tmp = -0.5 * y;
                                                                  	} else if (y <= 1.8e-268) {
                                                                  		tmp = 1.5 * x;
                                                                  	} else {
                                                                  		tmp = (y + x) * 0.5;
                                                                  	}
                                                                  	return tmp;
                                                                  }
                                                                  
                                                                  module fmin_fmax_functions
                                                                      implicit none
                                                                      private
                                                                      public fmax
                                                                      public fmin
                                                                  
                                                                      interface fmax
                                                                          module procedure fmax88
                                                                          module procedure fmax44
                                                                          module procedure fmax84
                                                                          module procedure fmax48
                                                                      end interface
                                                                      interface fmin
                                                                          module procedure fmin88
                                                                          module procedure fmin44
                                                                          module procedure fmin84
                                                                          module procedure fmin48
                                                                      end interface
                                                                  contains
                                                                      real(8) function fmax88(x, y) result (res)
                                                                          real(8), intent (in) :: x
                                                                          real(8), intent (in) :: y
                                                                          res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                                                                      end function
                                                                      real(4) function fmax44(x, y) result (res)
                                                                          real(4), intent (in) :: x
                                                                          real(4), intent (in) :: y
                                                                          res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                                                                      end function
                                                                      real(8) function fmax84(x, y) result(res)
                                                                          real(8), intent (in) :: x
                                                                          real(4), intent (in) :: y
                                                                          res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
                                                                      end function
                                                                      real(8) function fmax48(x, y) result(res)
                                                                          real(4), intent (in) :: x
                                                                          real(8), intent (in) :: y
                                                                          res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
                                                                      end function
                                                                      real(8) function fmin88(x, y) result (res)
                                                                          real(8), intent (in) :: x
                                                                          real(8), intent (in) :: y
                                                                          res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                                                                      end function
                                                                      real(4) function fmin44(x, y) result (res)
                                                                          real(4), intent (in) :: x
                                                                          real(4), intent (in) :: y
                                                                          res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                                                                      end function
                                                                      real(8) function fmin84(x, y) result(res)
                                                                          real(8), intent (in) :: x
                                                                          real(4), intent (in) :: y
                                                                          res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
                                                                      end function
                                                                      real(8) function fmin48(x, y) result(res)
                                                                          real(4), intent (in) :: x
                                                                          real(8), intent (in) :: y
                                                                          res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
                                                                      end function
                                                                  end module
                                                                  
                                                                  real(8) function code(x, y)
                                                                  use fmin_fmax_functions
                                                                      real(8), intent (in) :: x
                                                                      real(8), intent (in) :: y
                                                                      real(8) :: tmp
                                                                      if (y <= (-1.02d-73)) then
                                                                          tmp = (-0.5d0) * y
                                                                      else if (y <= 1.8d-268) then
                                                                          tmp = 1.5d0 * x
                                                                      else
                                                                          tmp = (y + x) * 0.5d0
                                                                      end if
                                                                      code = tmp
                                                                  end function
                                                                  
                                                                  public static double code(double x, double y) {
                                                                  	double tmp;
                                                                  	if (y <= -1.02e-73) {
                                                                  		tmp = -0.5 * y;
                                                                  	} else if (y <= 1.8e-268) {
                                                                  		tmp = 1.5 * x;
                                                                  	} else {
                                                                  		tmp = (y + x) * 0.5;
                                                                  	}
                                                                  	return tmp;
                                                                  }
                                                                  
                                                                  def code(x, y):
                                                                  	tmp = 0
                                                                  	if y <= -1.02e-73:
                                                                  		tmp = -0.5 * y
                                                                  	elif y <= 1.8e-268:
                                                                  		tmp = 1.5 * x
                                                                  	else:
                                                                  		tmp = (y + x) * 0.5
                                                                  	return tmp
                                                                  
                                                                  function code(x, y)
                                                                  	tmp = 0.0
                                                                  	if (y <= -1.02e-73)
                                                                  		tmp = Float64(-0.5 * y);
                                                                  	elseif (y <= 1.8e-268)
                                                                  		tmp = Float64(1.5 * x);
                                                                  	else
                                                                  		tmp = Float64(Float64(y + x) * 0.5);
                                                                  	end
                                                                  	return tmp
                                                                  end
                                                                  
                                                                  function tmp_2 = code(x, y)
                                                                  	tmp = 0.0;
                                                                  	if (y <= -1.02e-73)
                                                                  		tmp = -0.5 * y;
                                                                  	elseif (y <= 1.8e-268)
                                                                  		tmp = 1.5 * x;
                                                                  	else
                                                                  		tmp = (y + x) * 0.5;
                                                                  	end
                                                                  	tmp_2 = tmp;
                                                                  end
                                                                  
                                                                  code[x_, y_] := If[LessEqual[y, -1.02e-73], N[(-0.5 * y), $MachinePrecision], If[LessEqual[y, 1.8e-268], N[(1.5 * x), $MachinePrecision], N[(N[(y + x), $MachinePrecision] * 0.5), $MachinePrecision]]]
                                                                  
                                                                  \begin{array}{l}
                                                                  
                                                                  \\
                                                                  \begin{array}{l}
                                                                  \mathbf{if}\;y \leq -1.02 \cdot 10^{-73}:\\
                                                                  \;\;\;\;-0.5 \cdot y\\
                                                                  
                                                                  \mathbf{elif}\;y \leq 1.8 \cdot 10^{-268}:\\
                                                                  \;\;\;\;1.5 \cdot x\\
                                                                  
                                                                  \mathbf{else}:\\
                                                                  \;\;\;\;\left(y + x\right) \cdot 0.5\\
                                                                  
                                                                  
                                                                  \end{array}
                                                                  \end{array}
                                                                  
                                                                  Derivation
                                                                  1. Split input into 3 regimes
                                                                  2. if y < -1.0199999999999999e-73

                                                                    1. Initial program 99.9%

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

                                                                      \[\leadsto \color{blue}{x + \frac{1}{2} \cdot \left|y - x\right|} \]
                                                                    4. Applied rewrites99.9%

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

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

                                                                        \[\leadsto \frac{-1}{2} \cdot \color{blue}{y} \]
                                                                      3. Step-by-step derivation
                                                                        1. Applied rewrites67.3%

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

                                                                        if -1.0199999999999999e-73 < y < 1.8000000000000001e-268

                                                                        1. Initial program 99.8%

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

                                                                          \[\leadsto \color{blue}{x + \frac{1}{2} \cdot \left|y - x\right|} \]
                                                                        4. Applied rewrites99.8%

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

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

                                                                            \[\leadsto \frac{3}{2} \cdot \color{blue}{x} \]
                                                                          3. Step-by-step derivation
                                                                            1. Applied rewrites61.0%

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

                                                                            if 1.8000000000000001e-268 < y

                                                                            1. Initial program 100.0%

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

                                                                              \[\leadsto \color{blue}{x + \frac{1}{2} \cdot \left|y - x\right|} \]
                                                                            4. Applied rewrites100.0%

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

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

                                                                                \[\leadsto \frac{1}{2} \cdot x + \color{blue}{\frac{1}{2} \cdot y} \]
                                                                              3. Step-by-step derivation
                                                                                1. Applied rewrites78.2%

                                                                                  \[\leadsto \left(y + x\right) \cdot \color{blue}{0.5} \]
                                                                              4. Recombined 3 regimes into one program.
                                                                              5. Add Preprocessing

                                                                              Alternative 9: 60.9% accurate, 1.1× speedup?

                                                                              \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -1.02 \cdot 10^{-73}:\\ \;\;\;\;-0.5 \cdot y\\ \mathbf{elif}\;y \leq 1.2 \cdot 10^{-9}:\\ \;\;\;\;1.5 \cdot x\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot y\\ \end{array} \end{array} \]
                                                                              (FPCore (x y)
                                                                               :precision binary64
                                                                               (if (<= y -1.02e-73) (* -0.5 y) (if (<= y 1.2e-9) (* 1.5 x) (* 0.5 y))))
                                                                              double code(double x, double y) {
                                                                              	double tmp;
                                                                              	if (y <= -1.02e-73) {
                                                                              		tmp = -0.5 * y;
                                                                              	} else if (y <= 1.2e-9) {
                                                                              		tmp = 1.5 * x;
                                                                              	} else {
                                                                              		tmp = 0.5 * y;
                                                                              	}
                                                                              	return tmp;
                                                                              }
                                                                              
                                                                              module fmin_fmax_functions
                                                                                  implicit none
                                                                                  private
                                                                                  public fmax
                                                                                  public fmin
                                                                              
                                                                                  interface fmax
                                                                                      module procedure fmax88
                                                                                      module procedure fmax44
                                                                                      module procedure fmax84
                                                                                      module procedure fmax48
                                                                                  end interface
                                                                                  interface fmin
                                                                                      module procedure fmin88
                                                                                      module procedure fmin44
                                                                                      module procedure fmin84
                                                                                      module procedure fmin48
                                                                                  end interface
                                                                              contains
                                                                                  real(8) function fmax88(x, y) result (res)
                                                                                      real(8), intent (in) :: x
                                                                                      real(8), intent (in) :: y
                                                                                      res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                                                                                  end function
                                                                                  real(4) function fmax44(x, y) result (res)
                                                                                      real(4), intent (in) :: x
                                                                                      real(4), intent (in) :: y
                                                                                      res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                                                                                  end function
                                                                                  real(8) function fmax84(x, y) result(res)
                                                                                      real(8), intent (in) :: x
                                                                                      real(4), intent (in) :: y
                                                                                      res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
                                                                                  end function
                                                                                  real(8) function fmax48(x, y) result(res)
                                                                                      real(4), intent (in) :: x
                                                                                      real(8), intent (in) :: y
                                                                                      res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
                                                                                  end function
                                                                                  real(8) function fmin88(x, y) result (res)
                                                                                      real(8), intent (in) :: x
                                                                                      real(8), intent (in) :: y
                                                                                      res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                                                                                  end function
                                                                                  real(4) function fmin44(x, y) result (res)
                                                                                      real(4), intent (in) :: x
                                                                                      real(4), intent (in) :: y
                                                                                      res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                                                                                  end function
                                                                                  real(8) function fmin84(x, y) result(res)
                                                                                      real(8), intent (in) :: x
                                                                                      real(4), intent (in) :: y
                                                                                      res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
                                                                                  end function
                                                                                  real(8) function fmin48(x, y) result(res)
                                                                                      real(4), intent (in) :: x
                                                                                      real(8), intent (in) :: y
                                                                                      res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
                                                                                  end function
                                                                              end module
                                                                              
                                                                              real(8) function code(x, y)
                                                                              use fmin_fmax_functions
                                                                                  real(8), intent (in) :: x
                                                                                  real(8), intent (in) :: y
                                                                                  real(8) :: tmp
                                                                                  if (y <= (-1.02d-73)) then
                                                                                      tmp = (-0.5d0) * y
                                                                                  else if (y <= 1.2d-9) then
                                                                                      tmp = 1.5d0 * x
                                                                                  else
                                                                                      tmp = 0.5d0 * y
                                                                                  end if
                                                                                  code = tmp
                                                                              end function
                                                                              
                                                                              public static double code(double x, double y) {
                                                                              	double tmp;
                                                                              	if (y <= -1.02e-73) {
                                                                              		tmp = -0.5 * y;
                                                                              	} else if (y <= 1.2e-9) {
                                                                              		tmp = 1.5 * x;
                                                                              	} else {
                                                                              		tmp = 0.5 * y;
                                                                              	}
                                                                              	return tmp;
                                                                              }
                                                                              
                                                                              def code(x, y):
                                                                              	tmp = 0
                                                                              	if y <= -1.02e-73:
                                                                              		tmp = -0.5 * y
                                                                              	elif y <= 1.2e-9:
                                                                              		tmp = 1.5 * x
                                                                              	else:
                                                                              		tmp = 0.5 * y
                                                                              	return tmp
                                                                              
                                                                              function code(x, y)
                                                                              	tmp = 0.0
                                                                              	if (y <= -1.02e-73)
                                                                              		tmp = Float64(-0.5 * y);
                                                                              	elseif (y <= 1.2e-9)
                                                                              		tmp = Float64(1.5 * x);
                                                                              	else
                                                                              		tmp = Float64(0.5 * y);
                                                                              	end
                                                                              	return tmp
                                                                              end
                                                                              
                                                                              function tmp_2 = code(x, y)
                                                                              	tmp = 0.0;
                                                                              	if (y <= -1.02e-73)
                                                                              		tmp = -0.5 * y;
                                                                              	elseif (y <= 1.2e-9)
                                                                              		tmp = 1.5 * x;
                                                                              	else
                                                                              		tmp = 0.5 * y;
                                                                              	end
                                                                              	tmp_2 = tmp;
                                                                              end
                                                                              
                                                                              code[x_, y_] := If[LessEqual[y, -1.02e-73], N[(-0.5 * y), $MachinePrecision], If[LessEqual[y, 1.2e-9], N[(1.5 * x), $MachinePrecision], N[(0.5 * y), $MachinePrecision]]]
                                                                              
                                                                              \begin{array}{l}
                                                                              
                                                                              \\
                                                                              \begin{array}{l}
                                                                              \mathbf{if}\;y \leq -1.02 \cdot 10^{-73}:\\
                                                                              \;\;\;\;-0.5 \cdot y\\
                                                                              
                                                                              \mathbf{elif}\;y \leq 1.2 \cdot 10^{-9}:\\
                                                                              \;\;\;\;1.5 \cdot x\\
                                                                              
                                                                              \mathbf{else}:\\
                                                                              \;\;\;\;0.5 \cdot y\\
                                                                              
                                                                              
                                                                              \end{array}
                                                                              \end{array}
                                                                              
                                                                              Derivation
                                                                              1. Split input into 3 regimes
                                                                              2. if y < -1.0199999999999999e-73

                                                                                1. Initial program 99.9%

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

                                                                                  \[\leadsto \color{blue}{x + \frac{1}{2} \cdot \left|y - x\right|} \]
                                                                                4. Applied rewrites99.9%

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

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

                                                                                    \[\leadsto \frac{-1}{2} \cdot \color{blue}{y} \]
                                                                                  3. Step-by-step derivation
                                                                                    1. Applied rewrites67.3%

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

                                                                                    if -1.0199999999999999e-73 < y < 1.2e-9

                                                                                    1. Initial program 99.9%

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

                                                                                      \[\leadsto \color{blue}{x + \frac{1}{2} \cdot \left|y - x\right|} \]
                                                                                    4. Applied rewrites99.9%

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

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

                                                                                        \[\leadsto \frac{3}{2} \cdot \color{blue}{x} \]
                                                                                      3. Step-by-step derivation
                                                                                        1. Applied rewrites54.1%

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

                                                                                        if 1.2e-9 < y

                                                                                        1. Initial program 100.0%

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

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

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

                                                                                            \[\leadsto \color{blue}{\left|y - x\right| \cdot \frac{1}{2}} \]
                                                                                        5. Applied rewrites75.8%

                                                                                          \[\leadsto \color{blue}{\left|x - y\right| \cdot 0.5} \]
                                                                                        6. Step-by-step derivation
                                                                                          1. Applied rewrites72.7%

                                                                                            \[\leadsto \left(y - x\right) \cdot 0.5 \]
                                                                                          2. Taylor expanded in x around 0

                                                                                            \[\leadsto \frac{1}{2} \cdot \color{blue}{y} \]
                                                                                          3. Step-by-step derivation
                                                                                            1. Applied rewrites73.9%

                                                                                              \[\leadsto 0.5 \cdot \color{blue}{y} \]
                                                                                          4. Recombined 3 regimes into one program.
                                                                                          5. Add Preprocessing

                                                                                          Alternative 10: 50.5% accurate, 1.7× speedup?

                                                                                          \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq 1.05 \cdot 10^{-293}:\\ \;\;\;\;-0.5 \cdot y\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot y\\ \end{array} \end{array} \]
                                                                                          (FPCore (x y) :precision binary64 (if (<= y 1.05e-293) (* -0.5 y) (* 0.5 y)))
                                                                                          double code(double x, double y) {
                                                                                          	double tmp;
                                                                                          	if (y <= 1.05e-293) {
                                                                                          		tmp = -0.5 * y;
                                                                                          	} else {
                                                                                          		tmp = 0.5 * y;
                                                                                          	}
                                                                                          	return tmp;
                                                                                          }
                                                                                          
                                                                                          module fmin_fmax_functions
                                                                                              implicit none
                                                                                              private
                                                                                              public fmax
                                                                                              public fmin
                                                                                          
                                                                                              interface fmax
                                                                                                  module procedure fmax88
                                                                                                  module procedure fmax44
                                                                                                  module procedure fmax84
                                                                                                  module procedure fmax48
                                                                                              end interface
                                                                                              interface fmin
                                                                                                  module procedure fmin88
                                                                                                  module procedure fmin44
                                                                                                  module procedure fmin84
                                                                                                  module procedure fmin48
                                                                                              end interface
                                                                                          contains
                                                                                              real(8) function fmax88(x, y) result (res)
                                                                                                  real(8), intent (in) :: x
                                                                                                  real(8), intent (in) :: y
                                                                                                  res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                                                                                              end function
                                                                                              real(4) function fmax44(x, y) result (res)
                                                                                                  real(4), intent (in) :: x
                                                                                                  real(4), intent (in) :: y
                                                                                                  res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                                                                                              end function
                                                                                              real(8) function fmax84(x, y) result(res)
                                                                                                  real(8), intent (in) :: x
                                                                                                  real(4), intent (in) :: y
                                                                                                  res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
                                                                                              end function
                                                                                              real(8) function fmax48(x, y) result(res)
                                                                                                  real(4), intent (in) :: x
                                                                                                  real(8), intent (in) :: y
                                                                                                  res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
                                                                                              end function
                                                                                              real(8) function fmin88(x, y) result (res)
                                                                                                  real(8), intent (in) :: x
                                                                                                  real(8), intent (in) :: y
                                                                                                  res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                                                                                              end function
                                                                                              real(4) function fmin44(x, y) result (res)
                                                                                                  real(4), intent (in) :: x
                                                                                                  real(4), intent (in) :: y
                                                                                                  res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                                                                                              end function
                                                                                              real(8) function fmin84(x, y) result(res)
                                                                                                  real(8), intent (in) :: x
                                                                                                  real(4), intent (in) :: y
                                                                                                  res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
                                                                                              end function
                                                                                              real(8) function fmin48(x, y) result(res)
                                                                                                  real(4), intent (in) :: x
                                                                                                  real(8), intent (in) :: y
                                                                                                  res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
                                                                                              end function
                                                                                          end module
                                                                                          
                                                                                          real(8) function code(x, y)
                                                                                          use fmin_fmax_functions
                                                                                              real(8), intent (in) :: x
                                                                                              real(8), intent (in) :: y
                                                                                              real(8) :: tmp
                                                                                              if (y <= 1.05d-293) then
                                                                                                  tmp = (-0.5d0) * y
                                                                                              else
                                                                                                  tmp = 0.5d0 * y
                                                                                              end if
                                                                                              code = tmp
                                                                                          end function
                                                                                          
                                                                                          public static double code(double x, double y) {
                                                                                          	double tmp;
                                                                                          	if (y <= 1.05e-293) {
                                                                                          		tmp = -0.5 * y;
                                                                                          	} else {
                                                                                          		tmp = 0.5 * y;
                                                                                          	}
                                                                                          	return tmp;
                                                                                          }
                                                                                          
                                                                                          def code(x, y):
                                                                                          	tmp = 0
                                                                                          	if y <= 1.05e-293:
                                                                                          		tmp = -0.5 * y
                                                                                          	else:
                                                                                          		tmp = 0.5 * y
                                                                                          	return tmp
                                                                                          
                                                                                          function code(x, y)
                                                                                          	tmp = 0.0
                                                                                          	if (y <= 1.05e-293)
                                                                                          		tmp = Float64(-0.5 * y);
                                                                                          	else
                                                                                          		tmp = Float64(0.5 * y);
                                                                                          	end
                                                                                          	return tmp
                                                                                          end
                                                                                          
                                                                                          function tmp_2 = code(x, y)
                                                                                          	tmp = 0.0;
                                                                                          	if (y <= 1.05e-293)
                                                                                          		tmp = -0.5 * y;
                                                                                          	else
                                                                                          		tmp = 0.5 * y;
                                                                                          	end
                                                                                          	tmp_2 = tmp;
                                                                                          end
                                                                                          
                                                                                          code[x_, y_] := If[LessEqual[y, 1.05e-293], N[(-0.5 * y), $MachinePrecision], N[(0.5 * y), $MachinePrecision]]
                                                                                          
                                                                                          \begin{array}{l}
                                                                                          
                                                                                          \\
                                                                                          \begin{array}{l}
                                                                                          \mathbf{if}\;y \leq 1.05 \cdot 10^{-293}:\\
                                                                                          \;\;\;\;-0.5 \cdot y\\
                                                                                          
                                                                                          \mathbf{else}:\\
                                                                                          \;\;\;\;0.5 \cdot y\\
                                                                                          
                                                                                          
                                                                                          \end{array}
                                                                                          \end{array}
                                                                                          
                                                                                          Derivation
                                                                                          1. Split input into 2 regimes
                                                                                          2. if y < 1.05000000000000003e-293

                                                                                            1. Initial program 99.9%

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

                                                                                              \[\leadsto \color{blue}{x + \frac{1}{2} \cdot \left|y - x\right|} \]
                                                                                            4. Applied rewrites99.9%

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

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

                                                                                                \[\leadsto \frac{-1}{2} \cdot \color{blue}{y} \]
                                                                                              3. Step-by-step derivation
                                                                                                1. Applied rewrites45.1%

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

                                                                                                if 1.05000000000000003e-293 < y

                                                                                                1. Initial program 100.0%

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

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

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

                                                                                                    \[\leadsto \color{blue}{\left|y - x\right| \cdot \frac{1}{2}} \]
                                                                                                5. Applied rewrites55.5%

                                                                                                  \[\leadsto \color{blue}{\left|x - y\right| \cdot 0.5} \]
                                                                                                6. Step-by-step derivation
                                                                                                  1. Applied rewrites50.3%

                                                                                                    \[\leadsto \left(y - x\right) \cdot 0.5 \]
                                                                                                  2. Taylor expanded in x around 0

                                                                                                    \[\leadsto \frac{1}{2} \cdot \color{blue}{y} \]
                                                                                                  3. Step-by-step derivation
                                                                                                    1. Applied rewrites51.7%

                                                                                                      \[\leadsto 0.5 \cdot \color{blue}{y} \]
                                                                                                  4. Recombined 2 regimes into one program.
                                                                                                  5. Add Preprocessing

                                                                                                  Alternative 11: 26.4% accurate, 3.3× speedup?

                                                                                                  \[\begin{array}{l} \\ 0.5 \cdot y \end{array} \]
                                                                                                  (FPCore (x y) :precision binary64 (* 0.5 y))
                                                                                                  double code(double x, double y) {
                                                                                                  	return 0.5 * y;
                                                                                                  }
                                                                                                  
                                                                                                  module fmin_fmax_functions
                                                                                                      implicit none
                                                                                                      private
                                                                                                      public fmax
                                                                                                      public fmin
                                                                                                  
                                                                                                      interface fmax
                                                                                                          module procedure fmax88
                                                                                                          module procedure fmax44
                                                                                                          module procedure fmax84
                                                                                                          module procedure fmax48
                                                                                                      end interface
                                                                                                      interface fmin
                                                                                                          module procedure fmin88
                                                                                                          module procedure fmin44
                                                                                                          module procedure fmin84
                                                                                                          module procedure fmin48
                                                                                                      end interface
                                                                                                  contains
                                                                                                      real(8) function fmax88(x, y) result (res)
                                                                                                          real(8), intent (in) :: x
                                                                                                          real(8), intent (in) :: y
                                                                                                          res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                                                                                                      end function
                                                                                                      real(4) function fmax44(x, y) result (res)
                                                                                                          real(4), intent (in) :: x
                                                                                                          real(4), intent (in) :: y
                                                                                                          res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                                                                                                      end function
                                                                                                      real(8) function fmax84(x, y) result(res)
                                                                                                          real(8), intent (in) :: x
                                                                                                          real(4), intent (in) :: y
                                                                                                          res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
                                                                                                      end function
                                                                                                      real(8) function fmax48(x, y) result(res)
                                                                                                          real(4), intent (in) :: x
                                                                                                          real(8), intent (in) :: y
                                                                                                          res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
                                                                                                      end function
                                                                                                      real(8) function fmin88(x, y) result (res)
                                                                                                          real(8), intent (in) :: x
                                                                                                          real(8), intent (in) :: y
                                                                                                          res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                                                                                                      end function
                                                                                                      real(4) function fmin44(x, y) result (res)
                                                                                                          real(4), intent (in) :: x
                                                                                                          real(4), intent (in) :: y
                                                                                                          res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                                                                                                      end function
                                                                                                      real(8) function fmin84(x, y) result(res)
                                                                                                          real(8), intent (in) :: x
                                                                                                          real(4), intent (in) :: y
                                                                                                          res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
                                                                                                      end function
                                                                                                      real(8) function fmin48(x, y) result(res)
                                                                                                          real(4), intent (in) :: x
                                                                                                          real(8), intent (in) :: y
                                                                                                          res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
                                                                                                      end function
                                                                                                  end module
                                                                                                  
                                                                                                  real(8) function code(x, y)
                                                                                                  use fmin_fmax_functions
                                                                                                      real(8), intent (in) :: x
                                                                                                      real(8), intent (in) :: y
                                                                                                      code = 0.5d0 * y
                                                                                                  end function
                                                                                                  
                                                                                                  public static double code(double x, double y) {
                                                                                                  	return 0.5 * y;
                                                                                                  }
                                                                                                  
                                                                                                  def code(x, y):
                                                                                                  	return 0.5 * y
                                                                                                  
                                                                                                  function code(x, y)
                                                                                                  	return Float64(0.5 * y)
                                                                                                  end
                                                                                                  
                                                                                                  function tmp = code(x, y)
                                                                                                  	tmp = 0.5 * y;
                                                                                                  end
                                                                                                  
                                                                                                  code[x_, y_] := N[(0.5 * y), $MachinePrecision]
                                                                                                  
                                                                                                  \begin{array}{l}
                                                                                                  
                                                                                                  \\
                                                                                                  0.5 \cdot y
                                                                                                  \end{array}
                                                                                                  
                                                                                                  Derivation
                                                                                                  1. Initial program 99.9%

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

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

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

                                                                                                      \[\leadsto \color{blue}{\left|y - x\right| \cdot \frac{1}{2}} \]
                                                                                                  5. Applied rewrites52.1%

                                                                                                    \[\leadsto \color{blue}{\left|x - y\right| \cdot 0.5} \]
                                                                                                  6. Step-by-step derivation
                                                                                                    1. Applied rewrites24.7%

                                                                                                      \[\leadsto \left(y - x\right) \cdot 0.5 \]
                                                                                                    2. Taylor expanded in x around 0

                                                                                                      \[\leadsto \frac{1}{2} \cdot \color{blue}{y} \]
                                                                                                    3. Step-by-step derivation
                                                                                                      1. Applied rewrites26.0%

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

                                                                                                      Reproduce

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