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

Percentage Accurate: 99.9% → 99.9%
Time: 2.3s
Alternatives: 11
Speedup: 1.1×

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}

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.1× speedup?

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

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

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

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

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

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

      \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - y\right|, x\right) \]
    4. *-lft-identityN/A

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

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

      \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|y - \left(\mathsf{neg}\left(-1\right)\right) \cdot x\right|, x\right) \]
    7. fp-cancel-sign-sub-invN/A

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

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

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

      \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|\left(\mathsf{neg}\left(-1 \cdot y\right)\right) + \left(\mathsf{neg}\left(x\right)\right)\right|, x\right) \]
    11. distribute-neg-inN/A

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

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

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

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

      \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x + y \cdot -1\right|, x\right) \]
    16. fp-cancel-sign-sub-invN/A

      \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - \left(\mathsf{neg}\left(y\right)\right) \cdot -1\right|, x\right) \]
    17. distribute-lft-neg-inN/A

      \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - \left(\mathsf{neg}\left(y \cdot -1\right)\right)\right|, x\right) \]
    18. distribute-rgt-neg-outN/A

      \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - y \cdot \left(\mathsf{neg}\left(-1\right)\right)\right|, x\right) \]
    19. metadata-evalN/A

      \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - y \cdot 1\right|, x\right) \]
    20. *-rgt-identityN/A

      \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - y\right|, x\right) \]
    21. lower--.f6499.9

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

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

Alternative 2: 81.3% accurate, 0.6× speedup?

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

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

\mathbf{elif}\;y \leq 9 \cdot 10^{-5}:\\
\;\;\;\;x + \frac{\left|-x\right|}{2}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if y < -2.05000000000000017e-120

    1. Initial program 99.9%

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

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

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

        \[\leadsto \left(1 + \frac{1}{2} \cdot \frac{\left|y - x\right|}{x}\right) \cdot \color{blue}{x} \]
    4. Applied rewrites87.7%

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

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

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

        \[\leadsto \left(\left|x - y\right| \cdot \frac{\frac{1}{2}}{x} + 1\right) \cdot x \]
      4. lift-fabs.f64N/A

        \[\leadsto \left(\left|x - y\right| \cdot \frac{\frac{1}{2}}{x} + 1\right) \cdot x \]
      5. lift--.f64N/A

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

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

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

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

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

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

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

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

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

        \[\leadsto \left(\frac{1}{2} \cdot \frac{\left|x - y\right|}{x}\right) \cdot x + x \]
    6. Applied rewrites65.1%

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

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

        \[\leadsto \frac{1}{2} \cdot \left|x - y\right| \]
      2. rem-sqrt-square-revN/A

        \[\leadsto \frac{1}{2} \cdot \sqrt{\left(x - y\right) \cdot \left(x - y\right)} \]
      3. sqrt-unprodN/A

        \[\leadsto \frac{1}{2} \cdot \left(\sqrt{x - y} \cdot \color{blue}{\sqrt{x - y}}\right) \]
      4. *-commutativeN/A

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

        \[\leadsto \left(\sqrt{x - y} \cdot \sqrt{x - y}\right) \cdot \color{blue}{\frac{1}{2}} \]
      6. rem-square-sqrtN/A

        \[\leadsto \left(x - y\right) \cdot \frac{1}{2} \]
      7. lift--.f6453.5

        \[\leadsto \left(x - y\right) \cdot 0.5 \]
    9. Applied rewrites53.5%

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

    if -2.05000000000000017e-120 < y < 9.00000000000000057e-5

    1. Initial program 99.9%

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

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

        \[\leadsto x + \frac{\left|\mathsf{neg}\left(x\right)\right|}{2} \]
      2. lower-neg.f6450.6

        \[\leadsto x + \frac{\left|-x\right|}{2} \]
    4. Applied rewrites50.6%

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

    if 9.00000000000000057e-5 < y

    1. Initial program 99.9%

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - y\right|, x\right) \]
      4. *-lft-identityN/A

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

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

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|y - \left(\mathsf{neg}\left(-1\right)\right) \cdot x\right|, x\right) \]
      7. fp-cancel-sign-sub-invN/A

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

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

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

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|\left(\mathsf{neg}\left(-1 \cdot y\right)\right) + \left(\mathsf{neg}\left(x\right)\right)\right|, x\right) \]
      11. distribute-neg-inN/A

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x + y \cdot -1\right|, x\right) \]
      16. fp-cancel-sign-sub-invN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - \left(\mathsf{neg}\left(y\right)\right) \cdot -1\right|, x\right) \]
      17. distribute-lft-neg-inN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - \left(\mathsf{neg}\left(y \cdot -1\right)\right)\right|, x\right) \]
      18. distribute-rgt-neg-outN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - y \cdot \left(\mathsf{neg}\left(-1\right)\right)\right|, x\right) \]
      19. metadata-evalN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - y \cdot 1\right|, x\right) \]
      20. *-rgt-identityN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - y\right|, x\right) \]
      21. lower--.f6499.9

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

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

      \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|-1 \cdot y\right|, x\right) \]
    6. Step-by-step derivation
      1. mul-1-negN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|\mathsf{neg}\left(y\right)\right|, x\right) \]
      2. lower-neg.f6458.7

        \[\leadsto \mathsf{fma}\left(0.5, \left|-y\right|, x\right) \]
    7. Applied rewrites58.7%

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

Alternative 3: 81.0% accurate, 0.7× speedup?

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

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

\mathbf{elif}\;x \leq 2.05 \cdot 10^{-228}:\\
\;\;\;\;\mathsf{fma}\left(0.5, \left|-y\right|, x\right)\\

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


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

    1. Initial program 99.9%

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

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

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

        \[\leadsto \left(1 + \frac{1}{2} \cdot \frac{\left|y - x\right|}{x}\right) \cdot \color{blue}{x} \]
    4. Applied rewrites87.7%

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

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

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

        \[\leadsto \left(\left|x - y\right| \cdot \frac{\frac{1}{2}}{x} + 1\right) \cdot x \]
      4. lift-fabs.f64N/A

        \[\leadsto \left(\left|x - y\right| \cdot \frac{\frac{1}{2}}{x} + 1\right) \cdot x \]
      5. lift--.f64N/A

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

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

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

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

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

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

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

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

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

        \[\leadsto \left(\frac{1}{2} \cdot \frac{\left|x - y\right|}{x}\right) \cdot x + x \]
    6. Applied rewrites65.1%

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

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

        \[\leadsto \frac{1}{2} \cdot \left|x - y\right| \]
      2. rem-sqrt-square-revN/A

        \[\leadsto \frac{1}{2} \cdot \sqrt{\left(x - y\right) \cdot \left(x - y\right)} \]
      3. sqrt-unprodN/A

        \[\leadsto \frac{1}{2} \cdot \left(\sqrt{x - y} \cdot \color{blue}{\sqrt{x - y}}\right) \]
      4. *-commutativeN/A

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

        \[\leadsto \left(\sqrt{x - y} \cdot \sqrt{x - y}\right) \cdot \color{blue}{\frac{1}{2}} \]
      6. rem-square-sqrtN/A

        \[\leadsto \left(x - y\right) \cdot \frac{1}{2} \]
      7. lift--.f6453.5

        \[\leadsto \left(x - y\right) \cdot 0.5 \]
    9. Applied rewrites53.5%

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

    if -2.29999999999999989e-12 < x < 2.04999999999999999e-228

    1. Initial program 99.9%

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - y\right|, x\right) \]
      4. *-lft-identityN/A

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

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

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|y - \left(\mathsf{neg}\left(-1\right)\right) \cdot x\right|, x\right) \]
      7. fp-cancel-sign-sub-invN/A

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

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

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

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|\left(\mathsf{neg}\left(-1 \cdot y\right)\right) + \left(\mathsf{neg}\left(x\right)\right)\right|, x\right) \]
      11. distribute-neg-inN/A

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x + y \cdot -1\right|, x\right) \]
      16. fp-cancel-sign-sub-invN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - \left(\mathsf{neg}\left(y\right)\right) \cdot -1\right|, x\right) \]
      17. distribute-lft-neg-inN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - \left(\mathsf{neg}\left(y \cdot -1\right)\right)\right|, x\right) \]
      18. distribute-rgt-neg-outN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - y \cdot \left(\mathsf{neg}\left(-1\right)\right)\right|, x\right) \]
      19. metadata-evalN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - y \cdot 1\right|, x\right) \]
      20. *-rgt-identityN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - y\right|, x\right) \]
      21. lower--.f6499.9

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

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

      \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|-1 \cdot y\right|, x\right) \]
    6. Step-by-step derivation
      1. mul-1-negN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|\mathsf{neg}\left(y\right)\right|, x\right) \]
      2. lower-neg.f6458.7

        \[\leadsto \mathsf{fma}\left(0.5, \left|-y\right|, x\right) \]
    7. Applied rewrites58.7%

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

    if 2.04999999999999999e-228 < x

    1. Initial program 99.9%

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - y\right|, x\right) \]
      4. *-lft-identityN/A

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

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

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|y - \left(\mathsf{neg}\left(-1\right)\right) \cdot x\right|, x\right) \]
      7. fp-cancel-sign-sub-invN/A

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

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

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

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|\left(\mathsf{neg}\left(-1 \cdot y\right)\right) + \left(\mathsf{neg}\left(x\right)\right)\right|, x\right) \]
      11. distribute-neg-inN/A

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x + y \cdot -1\right|, x\right) \]
      16. fp-cancel-sign-sub-invN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - \left(\mathsf{neg}\left(y\right)\right) \cdot -1\right|, x\right) \]
      17. distribute-lft-neg-inN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - \left(\mathsf{neg}\left(y \cdot -1\right)\right)\right|, x\right) \]
      18. distribute-rgt-neg-outN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - y \cdot \left(\mathsf{neg}\left(-1\right)\right)\right|, x\right) \]
      19. metadata-evalN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - y \cdot 1\right|, x\right) \]
      20. *-rgt-identityN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - y\right|, x\right) \]
      21. lower--.f6499.9

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

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

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - y\right|, x\right) \]
      2. *-lft-identityN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - 1 \cdot y\right|, x\right) \]
      3. metadata-evalN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - \left(\mathsf{neg}\left(-1\right)\right) \cdot y\right|, x\right) \]
      4. fp-cancel-sign-sub-invN/A

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

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x + -1 \cdot y\right|, x\right) \]
      6. rem-sqrt-square-revN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{\left(x + -1 \cdot y\right) \cdot \left(x + -1 \cdot y\right)}, x\right) \]
      7. sqrt-prodN/A

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

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{x + -1 \cdot y} \cdot \color{blue}{\sqrt{x + -1 \cdot y}}, x\right) \]
      9. lower-sqrt.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{x + -1 \cdot y} \cdot \sqrt{\color{blue}{x + -1 \cdot y}}, x\right) \]
      10. fp-cancel-sign-sub-invN/A

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

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{x - 1 \cdot y} \cdot \sqrt{x + -1 \cdot y}, x\right) \]
      12. *-lft-identityN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{x - y} \cdot \sqrt{x + -1 \cdot y}, x\right) \]
      13. lift--.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{x - y} \cdot \sqrt{\color{blue}{x} + -1 \cdot y}, x\right) \]
      14. lower-sqrt.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{x - y} \cdot \sqrt{x + -1 \cdot y}, x\right) \]
      15. fp-cancel-sign-sub-invN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{x - y} \cdot \sqrt{x - \left(\mathsf{neg}\left(-1\right)\right) \cdot y}, x\right) \]
      16. metadata-evalN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{x - y} \cdot \sqrt{x - 1 \cdot y}, x\right) \]
      17. *-lft-identityN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{x - y} \cdot \sqrt{x - y}, x\right) \]
      18. lift--.f6448.1

        \[\leadsto \mathsf{fma}\left(0.5, \sqrt{x - y} \cdot \sqrt{x - y}, x\right) \]
    6. Applied rewrites48.1%

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

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

        \[\leadsto \frac{3}{2} \cdot x + \frac{1}{2} \cdot \color{blue}{{\left(\sqrt{\mathsf{neg}\left(y\right)}\right)}^{2}} \]
      2. lower-fma.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{3}{2}, x, \frac{1}{2} \cdot {\left(\sqrt{\mathsf{neg}\left(y\right)}\right)}^{2}\right) \]
      3. *-commutativeN/A

        \[\leadsto \mathsf{fma}\left(\frac{3}{2}, x, {\left(\sqrt{\mathsf{neg}\left(y\right)}\right)}^{2} \cdot \frac{1}{2}\right) \]
      4. lift-neg.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{3}{2}, x, {\left(\sqrt{-y}\right)}^{2} \cdot \frac{1}{2}\right) \]
      5. sqrt-pow2N/A

        \[\leadsto \mathsf{fma}\left(\frac{3}{2}, x, {\left(-y\right)}^{\left(\frac{2}{2}\right)} \cdot \frac{1}{2}\right) \]
      6. metadata-evalN/A

        \[\leadsto \mathsf{fma}\left(\frac{3}{2}, x, {\left(-y\right)}^{1} \cdot \frac{1}{2}\right) \]
      7. unpow1N/A

        \[\leadsto \mathsf{fma}\left(\frac{3}{2}, x, \left(-y\right) \cdot \frac{1}{2}\right) \]
      8. lower-*.f6453.3

        \[\leadsto \mathsf{fma}\left(1.5, x, \left(-y\right) \cdot 0.5\right) \]
    9. Applied rewrites53.3%

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

      \[\leadsto \frac{-1}{2} \cdot y + \frac{3}{2} \cdot \color{blue}{x} \]
    11. Step-by-step derivation
      1. lower-fma.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{-1}{2}, y, \frac{3}{2} \cdot x\right) \]
      2. lower-*.f6453.2

        \[\leadsto \mathsf{fma}\left(-0.5, y, 1.5 \cdot x\right) \]
    12. Applied rewrites53.2%

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

Alternative 4: 81.0% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -2.3 \cdot 10^{-12}:\\ \;\;\;\;\left(x - y\right) \cdot 0.5\\ \mathbf{elif}\;x \leq 2.05 \cdot 10^{-228}:\\ \;\;\;\;\mathsf{fma}\left(0.5, \left|-y\right|, 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.3e-12)
   (* (- x y) 0.5)
   (if (<= x 2.05e-228) (fma 0.5 (fabs (- y)) x) (fma (- x y) 0.5 x))))
double code(double x, double y) {
	double tmp;
	if (x <= -2.3e-12) {
		tmp = (x - y) * 0.5;
	} else if (x <= 2.05e-228) {
		tmp = fma(0.5, fabs(-y), x);
	} else {
		tmp = fma((x - y), 0.5, x);
	}
	return tmp;
}
function code(x, y)
	tmp = 0.0
	if (x <= -2.3e-12)
		tmp = Float64(Float64(x - y) * 0.5);
	elseif (x <= 2.05e-228)
		tmp = fma(0.5, abs(Float64(-y)), x);
	else
		tmp = fma(Float64(x - y), 0.5, x);
	end
	return tmp
end
code[x_, y_] := If[LessEqual[x, -2.3e-12], N[(N[(x - y), $MachinePrecision] * 0.5), $MachinePrecision], If[LessEqual[x, 2.05e-228], N[(0.5 * N[Abs[(-y)], $MachinePrecision] + x), $MachinePrecision], N[(N[(x - y), $MachinePrecision] * 0.5 + x), $MachinePrecision]]]
\begin{array}{l}

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

\mathbf{elif}\;x \leq 2.05 \cdot 10^{-228}:\\
\;\;\;\;\mathsf{fma}\left(0.5, \left|-y\right|, 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.29999999999999989e-12

    1. Initial program 99.9%

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

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

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

        \[\leadsto \left(1 + \frac{1}{2} \cdot \frac{\left|y - x\right|}{x}\right) \cdot \color{blue}{x} \]
    4. Applied rewrites87.7%

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

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

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

        \[\leadsto \left(\left|x - y\right| \cdot \frac{\frac{1}{2}}{x} + 1\right) \cdot x \]
      4. lift-fabs.f64N/A

        \[\leadsto \left(\left|x - y\right| \cdot \frac{\frac{1}{2}}{x} + 1\right) \cdot x \]
      5. lift--.f64N/A

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

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

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

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

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

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

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

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

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

        \[\leadsto \left(\frac{1}{2} \cdot \frac{\left|x - y\right|}{x}\right) \cdot x + x \]
    6. Applied rewrites65.1%

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

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

        \[\leadsto \frac{1}{2} \cdot \left|x - y\right| \]
      2. rem-sqrt-square-revN/A

        \[\leadsto \frac{1}{2} \cdot \sqrt{\left(x - y\right) \cdot \left(x - y\right)} \]
      3. sqrt-unprodN/A

        \[\leadsto \frac{1}{2} \cdot \left(\sqrt{x - y} \cdot \color{blue}{\sqrt{x - y}}\right) \]
      4. *-commutativeN/A

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

        \[\leadsto \left(\sqrt{x - y} \cdot \sqrt{x - y}\right) \cdot \color{blue}{\frac{1}{2}} \]
      6. rem-square-sqrtN/A

        \[\leadsto \left(x - y\right) \cdot \frac{1}{2} \]
      7. lift--.f6453.5

        \[\leadsto \left(x - y\right) \cdot 0.5 \]
    9. Applied rewrites53.5%

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

    if -2.29999999999999989e-12 < x < 2.04999999999999999e-228

    1. Initial program 99.9%

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - y\right|, x\right) \]
      4. *-lft-identityN/A

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

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

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|y - \left(\mathsf{neg}\left(-1\right)\right) \cdot x\right|, x\right) \]
      7. fp-cancel-sign-sub-invN/A

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

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

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

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|\left(\mathsf{neg}\left(-1 \cdot y\right)\right) + \left(\mathsf{neg}\left(x\right)\right)\right|, x\right) \]
      11. distribute-neg-inN/A

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x + y \cdot -1\right|, x\right) \]
      16. fp-cancel-sign-sub-invN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - \left(\mathsf{neg}\left(y\right)\right) \cdot -1\right|, x\right) \]
      17. distribute-lft-neg-inN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - \left(\mathsf{neg}\left(y \cdot -1\right)\right)\right|, x\right) \]
      18. distribute-rgt-neg-outN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - y \cdot \left(\mathsf{neg}\left(-1\right)\right)\right|, x\right) \]
      19. metadata-evalN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - y \cdot 1\right|, x\right) \]
      20. *-rgt-identityN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - y\right|, x\right) \]
      21. lower--.f6499.9

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

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

      \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|-1 \cdot y\right|, x\right) \]
    6. Step-by-step derivation
      1. mul-1-negN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|\mathsf{neg}\left(y\right)\right|, x\right) \]
      2. lower-neg.f6458.7

        \[\leadsto \mathsf{fma}\left(0.5, \left|-y\right|, x\right) \]
    7. Applied rewrites58.7%

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

    if 2.04999999999999999e-228 < x

    1. Initial program 99.9%

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - y\right|, x\right) \]
      4. *-lft-identityN/A

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

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

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|y - \left(\mathsf{neg}\left(-1\right)\right) \cdot x\right|, x\right) \]
      7. fp-cancel-sign-sub-invN/A

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

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

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

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|\left(\mathsf{neg}\left(-1 \cdot y\right)\right) + \left(\mathsf{neg}\left(x\right)\right)\right|, x\right) \]
      11. distribute-neg-inN/A

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x + y \cdot -1\right|, x\right) \]
      16. fp-cancel-sign-sub-invN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - \left(\mathsf{neg}\left(y\right)\right) \cdot -1\right|, x\right) \]
      17. distribute-lft-neg-inN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - \left(\mathsf{neg}\left(y \cdot -1\right)\right)\right|, x\right) \]
      18. distribute-rgt-neg-outN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - y \cdot \left(\mathsf{neg}\left(-1\right)\right)\right|, x\right) \]
      19. metadata-evalN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - y \cdot 1\right|, x\right) \]
      20. *-rgt-identityN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - y\right|, x\right) \]
      21. lower--.f6499.9

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

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

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - y\right|, x\right) \]
      2. *-lft-identityN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - 1 \cdot y\right|, x\right) \]
      3. metadata-evalN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - \left(\mathsf{neg}\left(-1\right)\right) \cdot y\right|, x\right) \]
      4. fp-cancel-sign-sub-invN/A

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

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x + -1 \cdot y\right|, x\right) \]
      6. rem-sqrt-square-revN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{\left(x + -1 \cdot y\right) \cdot \left(x + -1 \cdot y\right)}, x\right) \]
      7. sqrt-prodN/A

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

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{x + -1 \cdot y} \cdot \color{blue}{\sqrt{x + -1 \cdot y}}, x\right) \]
      9. lower-sqrt.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{x + -1 \cdot y} \cdot \sqrt{\color{blue}{x + -1 \cdot y}}, x\right) \]
      10. fp-cancel-sign-sub-invN/A

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

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{x - 1 \cdot y} \cdot \sqrt{x + -1 \cdot y}, x\right) \]
      12. *-lft-identityN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{x - y} \cdot \sqrt{x + -1 \cdot y}, x\right) \]
      13. lift--.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{x - y} \cdot \sqrt{\color{blue}{x} + -1 \cdot y}, x\right) \]
      14. lower-sqrt.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{x - y} \cdot \sqrt{x + -1 \cdot y}, x\right) \]
      15. fp-cancel-sign-sub-invN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{x - y} \cdot \sqrt{x - \left(\mathsf{neg}\left(-1\right)\right) \cdot y}, x\right) \]
      16. metadata-evalN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{x - y} \cdot \sqrt{x - 1 \cdot y}, x\right) \]
      17. *-lft-identityN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{x - y} \cdot \sqrt{x - y}, x\right) \]
      18. lift--.f6448.1

        \[\leadsto \mathsf{fma}\left(0.5, \sqrt{x - y} \cdot \sqrt{x - y}, x\right) \]
    6. Applied rewrites48.1%

      \[\leadsto \mathsf{fma}\left(0.5, \sqrt{x - y} \cdot \color{blue}{\sqrt{x - y}}, x\right) \]
    7. Step-by-step derivation
      1. lift-fma.f64N/A

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

        \[\leadsto \frac{1}{2} \cdot \left(\sqrt{x - y} \cdot \sqrt{x - y}\right) + x \]
      3. lift--.f64N/A

        \[\leadsto \frac{1}{2} \cdot \left(\sqrt{x - y} \cdot \sqrt{x - y}\right) + x \]
      4. lift-sqrt.f64N/A

        \[\leadsto \frac{1}{2} \cdot \left(\sqrt{x - y} \cdot \sqrt{x - y}\right) + x \]
      5. lift--.f64N/A

        \[\leadsto \frac{1}{2} \cdot \left(\sqrt{x - y} \cdot \sqrt{x - y}\right) + x \]
      6. lift-sqrt.f64N/A

        \[\leadsto \frac{1}{2} \cdot \left(\sqrt{x - y} \cdot \sqrt{x - y}\right) + x \]
      7. *-commutativeN/A

        \[\leadsto \left(\sqrt{x - y} \cdot \sqrt{x - y}\right) \cdot \frac{1}{2} + x \]
      8. lower-fma.f64N/A

        \[\leadsto \mathsf{fma}\left(\sqrt{x - y} \cdot \sqrt{x - y}, \color{blue}{\frac{1}{2}}, x\right) \]
      9. rem-square-sqrtN/A

        \[\leadsto \mathsf{fma}\left(x - y, \frac{1}{2}, x\right) \]
      10. lift--.f6453.2

        \[\leadsto \mathsf{fma}\left(x - y, 0.5, x\right) \]
    8. Applied rewrites53.2%

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

Alternative 5: 80.3% accurate, 0.7× speedup?

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

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

\mathbf{elif}\;x \leq 1.85 \cdot 10^{-7}:\\
\;\;\;\;\mathsf{fma}\left(0.5, \left|-y\right|, x\right)\\

\mathbf{else}:\\
\;\;\;\;1.5 \cdot x\\


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

    1. Initial program 99.9%

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

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

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

        \[\leadsto \left(1 + \frac{1}{2} \cdot \frac{\left|y - x\right|}{x}\right) \cdot \color{blue}{x} \]
    4. Applied rewrites87.7%

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

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

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

        \[\leadsto \left(\left|x - y\right| \cdot \frac{\frac{1}{2}}{x} + 1\right) \cdot x \]
      4. lift-fabs.f64N/A

        \[\leadsto \left(\left|x - y\right| \cdot \frac{\frac{1}{2}}{x} + 1\right) \cdot x \]
      5. lift--.f64N/A

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

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

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

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

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

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

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

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

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

        \[\leadsto \left(\frac{1}{2} \cdot \frac{\left|x - y\right|}{x}\right) \cdot x + x \]
    6. Applied rewrites65.1%

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

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

        \[\leadsto \frac{1}{2} \cdot \left|x - y\right| \]
      2. rem-sqrt-square-revN/A

        \[\leadsto \frac{1}{2} \cdot \sqrt{\left(x - y\right) \cdot \left(x - y\right)} \]
      3. sqrt-unprodN/A

        \[\leadsto \frac{1}{2} \cdot \left(\sqrt{x - y} \cdot \color{blue}{\sqrt{x - y}}\right) \]
      4. *-commutativeN/A

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

        \[\leadsto \left(\sqrt{x - y} \cdot \sqrt{x - y}\right) \cdot \color{blue}{\frac{1}{2}} \]
      6. rem-square-sqrtN/A

        \[\leadsto \left(x - y\right) \cdot \frac{1}{2} \]
      7. lift--.f6453.5

        \[\leadsto \left(x - y\right) \cdot 0.5 \]
    9. Applied rewrites53.5%

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

    if -2.29999999999999989e-12 < x < 1.85000000000000002e-7

    1. Initial program 99.9%

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - y\right|, x\right) \]
      4. *-lft-identityN/A

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

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

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|y - \left(\mathsf{neg}\left(-1\right)\right) \cdot x\right|, x\right) \]
      7. fp-cancel-sign-sub-invN/A

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

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

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

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|\left(\mathsf{neg}\left(-1 \cdot y\right)\right) + \left(\mathsf{neg}\left(x\right)\right)\right|, x\right) \]
      11. distribute-neg-inN/A

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x + y \cdot -1\right|, x\right) \]
      16. fp-cancel-sign-sub-invN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - \left(\mathsf{neg}\left(y\right)\right) \cdot -1\right|, x\right) \]
      17. distribute-lft-neg-inN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - \left(\mathsf{neg}\left(y \cdot -1\right)\right)\right|, x\right) \]
      18. distribute-rgt-neg-outN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - y \cdot \left(\mathsf{neg}\left(-1\right)\right)\right|, x\right) \]
      19. metadata-evalN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - y \cdot 1\right|, x\right) \]
      20. *-rgt-identityN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - y\right|, x\right) \]
      21. lower--.f6499.9

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

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

      \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|-1 \cdot y\right|, x\right) \]
    6. Step-by-step derivation
      1. mul-1-negN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|\mathsf{neg}\left(y\right)\right|, x\right) \]
      2. lower-neg.f6458.7

        \[\leadsto \mathsf{fma}\left(0.5, \left|-y\right|, x\right) \]
    7. Applied rewrites58.7%

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

    if 1.85000000000000002e-7 < x

    1. Initial program 99.9%

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - y\right|, x\right) \]
      4. *-lft-identityN/A

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

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

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|y - \left(\mathsf{neg}\left(-1\right)\right) \cdot x\right|, x\right) \]
      7. fp-cancel-sign-sub-invN/A

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

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

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

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|\left(\mathsf{neg}\left(-1 \cdot y\right)\right) + \left(\mathsf{neg}\left(x\right)\right)\right|, x\right) \]
      11. distribute-neg-inN/A

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x + y \cdot -1\right|, x\right) \]
      16. fp-cancel-sign-sub-invN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - \left(\mathsf{neg}\left(y\right)\right) \cdot -1\right|, x\right) \]
      17. distribute-lft-neg-inN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - \left(\mathsf{neg}\left(y \cdot -1\right)\right)\right|, x\right) \]
      18. distribute-rgt-neg-outN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - y \cdot \left(\mathsf{neg}\left(-1\right)\right)\right|, x\right) \]
      19. metadata-evalN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - y \cdot 1\right|, x\right) \]
      20. *-rgt-identityN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - y\right|, x\right) \]
      21. lower--.f6499.9

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

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

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - y\right|, x\right) \]
      2. *-lft-identityN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - 1 \cdot y\right|, x\right) \]
      3. metadata-evalN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - \left(\mathsf{neg}\left(-1\right)\right) \cdot y\right|, x\right) \]
      4. fp-cancel-sign-sub-invN/A

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

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x + -1 \cdot y\right|, x\right) \]
      6. rem-sqrt-square-revN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{\left(x + -1 \cdot y\right) \cdot \left(x + -1 \cdot y\right)}, x\right) \]
      7. sqrt-prodN/A

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

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{x + -1 \cdot y} \cdot \color{blue}{\sqrt{x + -1 \cdot y}}, x\right) \]
      9. lower-sqrt.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{x + -1 \cdot y} \cdot \sqrt{\color{blue}{x + -1 \cdot y}}, x\right) \]
      10. fp-cancel-sign-sub-invN/A

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

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{x - 1 \cdot y} \cdot \sqrt{x + -1 \cdot y}, x\right) \]
      12. *-lft-identityN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{x - y} \cdot \sqrt{x + -1 \cdot y}, x\right) \]
      13. lift--.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{x - y} \cdot \sqrt{\color{blue}{x} + -1 \cdot y}, x\right) \]
      14. lower-sqrt.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{x - y} \cdot \sqrt{x + -1 \cdot y}, x\right) \]
      15. fp-cancel-sign-sub-invN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{x - y} \cdot \sqrt{x - \left(\mathsf{neg}\left(-1\right)\right) \cdot y}, x\right) \]
      16. metadata-evalN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{x - y} \cdot \sqrt{x - 1 \cdot y}, x\right) \]
      17. *-lft-identityN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{x - y} \cdot \sqrt{x - y}, x\right) \]
      18. lift--.f6448.1

        \[\leadsto \mathsf{fma}\left(0.5, \sqrt{x - y} \cdot \sqrt{x - y}, x\right) \]
    6. Applied rewrites48.1%

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

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

        \[\leadsto \frac{3}{2} \cdot x + \frac{1}{2} \cdot \color{blue}{{\left(\sqrt{\mathsf{neg}\left(y\right)}\right)}^{2}} \]
      2. lower-fma.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{3}{2}, x, \frac{1}{2} \cdot {\left(\sqrt{\mathsf{neg}\left(y\right)}\right)}^{2}\right) \]
      3. *-commutativeN/A

        \[\leadsto \mathsf{fma}\left(\frac{3}{2}, x, {\left(\sqrt{\mathsf{neg}\left(y\right)}\right)}^{2} \cdot \frac{1}{2}\right) \]
      4. lift-neg.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{3}{2}, x, {\left(\sqrt{-y}\right)}^{2} \cdot \frac{1}{2}\right) \]
      5. sqrt-pow2N/A

        \[\leadsto \mathsf{fma}\left(\frac{3}{2}, x, {\left(-y\right)}^{\left(\frac{2}{2}\right)} \cdot \frac{1}{2}\right) \]
      6. metadata-evalN/A

        \[\leadsto \mathsf{fma}\left(\frac{3}{2}, x, {\left(-y\right)}^{1} \cdot \frac{1}{2}\right) \]
      7. unpow1N/A

        \[\leadsto \mathsf{fma}\left(\frac{3}{2}, x, \left(-y\right) \cdot \frac{1}{2}\right) \]
      8. lower-*.f6453.3

        \[\leadsto \mathsf{fma}\left(1.5, x, \left(-y\right) \cdot 0.5\right) \]
    9. Applied rewrites53.3%

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

      \[\leadsto \frac{3}{2} \cdot x \]
    11. Step-by-step derivation
      1. lower-*.f6430.0

        \[\leadsto 1.5 \cdot x \]
    12. Applied rewrites30.0%

      \[\leadsto 1.5 \cdot x \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 6: 78.4% accurate, 0.7× speedup?

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

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

\mathbf{elif}\;x \leq 1.85 \cdot 10^{-7}:\\
\;\;\;\;0.5 \cdot \left|x - y\right|\\

\mathbf{else}:\\
\;\;\;\;1.5 \cdot x\\


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

    1. Initial program 99.9%

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

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

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

        \[\leadsto \left(1 + \frac{1}{2} \cdot \frac{\left|y - x\right|}{x}\right) \cdot \color{blue}{x} \]
    4. Applied rewrites87.7%

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

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

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

        \[\leadsto \left(\left|x - y\right| \cdot \frac{\frac{1}{2}}{x} + 1\right) \cdot x \]
      4. lift-fabs.f64N/A

        \[\leadsto \left(\left|x - y\right| \cdot \frac{\frac{1}{2}}{x} + 1\right) \cdot x \]
      5. lift--.f64N/A

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

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

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

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

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

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

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

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

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

        \[\leadsto \left(\frac{1}{2} \cdot \frac{\left|x - y\right|}{x}\right) \cdot x + x \]
    6. Applied rewrites65.1%

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

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

        \[\leadsto \frac{1}{2} \cdot \left|x - y\right| \]
      2. rem-sqrt-square-revN/A

        \[\leadsto \frac{1}{2} \cdot \sqrt{\left(x - y\right) \cdot \left(x - y\right)} \]
      3. sqrt-unprodN/A

        \[\leadsto \frac{1}{2} \cdot \left(\sqrt{x - y} \cdot \color{blue}{\sqrt{x - y}}\right) \]
      4. *-commutativeN/A

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

        \[\leadsto \left(\sqrt{x - y} \cdot \sqrt{x - y}\right) \cdot \color{blue}{\frac{1}{2}} \]
      6. rem-square-sqrtN/A

        \[\leadsto \left(x - y\right) \cdot \frac{1}{2} \]
      7. lift--.f6453.5

        \[\leadsto \left(x - y\right) \cdot 0.5 \]
    9. Applied rewrites53.5%

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

    if -5.00000000000000043e-212 < x < 1.85000000000000002e-7

    1. Initial program 99.9%

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

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

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

        \[\leadsto \frac{1}{2} \cdot \left|x - y\right| \]
      3. *-lft-identityN/A

        \[\leadsto \frac{1}{2} \cdot \left|1 \cdot x - y\right| \]
      4. metadata-evalN/A

        \[\leadsto \frac{1}{2} \cdot \left|\left(\mathsf{neg}\left(-1\right)\right) \cdot x - y\right| \]
      5. fabs-subN/A

        \[\leadsto \frac{1}{2} \cdot \left|y - \left(\mathsf{neg}\left(-1\right)\right) \cdot x\right| \]
      6. fp-cancel-sign-sub-invN/A

        \[\leadsto \frac{1}{2} \cdot \left|y + -1 \cdot x\right| \]
      7. remove-double-negN/A

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

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

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

        \[\leadsto \frac{1}{2} \cdot \left|\mathsf{neg}\left(\left(-1 \cdot y + x\right)\right)\right| \]
      11. +-commutativeN/A

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

        \[\leadsto \frac{1}{2} \cdot \left|x + -1 \cdot y\right| \]
      13. lower-fabs.f64N/A

        \[\leadsto \frac{1}{2} \cdot \left|x + -1 \cdot y\right| \]
      14. *-commutativeN/A

        \[\leadsto \frac{1}{2} \cdot \left|x + y \cdot -1\right| \]
      15. fp-cancel-sign-sub-invN/A

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

        \[\leadsto \frac{1}{2} \cdot \left|x - \left(\mathsf{neg}\left(y \cdot -1\right)\right)\right| \]
      17. distribute-rgt-neg-outN/A

        \[\leadsto \frac{1}{2} \cdot \left|x - y \cdot \left(\mathsf{neg}\left(-1\right)\right)\right| \]
      18. metadata-evalN/A

        \[\leadsto \frac{1}{2} \cdot \left|x - y \cdot 1\right| \]
      19. *-rgt-identityN/A

        \[\leadsto \frac{1}{2} \cdot \left|x - y\right| \]
      20. lower--.f6453.6

        \[\leadsto 0.5 \cdot \left|x - y\right| \]
    4. Applied rewrites53.6%

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

    if 1.85000000000000002e-7 < x

    1. Initial program 99.9%

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - y\right|, x\right) \]
      4. *-lft-identityN/A

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

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

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|y - \left(\mathsf{neg}\left(-1\right)\right) \cdot x\right|, x\right) \]
      7. fp-cancel-sign-sub-invN/A

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

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

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

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|\left(\mathsf{neg}\left(-1 \cdot y\right)\right) + \left(\mathsf{neg}\left(x\right)\right)\right|, x\right) \]
      11. distribute-neg-inN/A

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x + y \cdot -1\right|, x\right) \]
      16. fp-cancel-sign-sub-invN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - \left(\mathsf{neg}\left(y\right)\right) \cdot -1\right|, x\right) \]
      17. distribute-lft-neg-inN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - \left(\mathsf{neg}\left(y \cdot -1\right)\right)\right|, x\right) \]
      18. distribute-rgt-neg-outN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - y \cdot \left(\mathsf{neg}\left(-1\right)\right)\right|, x\right) \]
      19. metadata-evalN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - y \cdot 1\right|, x\right) \]
      20. *-rgt-identityN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - y\right|, x\right) \]
      21. lower--.f6499.9

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

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

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - y\right|, x\right) \]
      2. *-lft-identityN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - 1 \cdot y\right|, x\right) \]
      3. metadata-evalN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - \left(\mathsf{neg}\left(-1\right)\right) \cdot y\right|, x\right) \]
      4. fp-cancel-sign-sub-invN/A

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

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x + -1 \cdot y\right|, x\right) \]
      6. rem-sqrt-square-revN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{\left(x + -1 \cdot y\right) \cdot \left(x + -1 \cdot y\right)}, x\right) \]
      7. sqrt-prodN/A

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

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{x + -1 \cdot y} \cdot \color{blue}{\sqrt{x + -1 \cdot y}}, x\right) \]
      9. lower-sqrt.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{x + -1 \cdot y} \cdot \sqrt{\color{blue}{x + -1 \cdot y}}, x\right) \]
      10. fp-cancel-sign-sub-invN/A

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

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{x - 1 \cdot y} \cdot \sqrt{x + -1 \cdot y}, x\right) \]
      12. *-lft-identityN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{x - y} \cdot \sqrt{x + -1 \cdot y}, x\right) \]
      13. lift--.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{x - y} \cdot \sqrt{\color{blue}{x} + -1 \cdot y}, x\right) \]
      14. lower-sqrt.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{x - y} \cdot \sqrt{x + -1 \cdot y}, x\right) \]
      15. fp-cancel-sign-sub-invN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{x - y} \cdot \sqrt{x - \left(\mathsf{neg}\left(-1\right)\right) \cdot y}, x\right) \]
      16. metadata-evalN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{x - y} \cdot \sqrt{x - 1 \cdot y}, x\right) \]
      17. *-lft-identityN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{x - y} \cdot \sqrt{x - y}, x\right) \]
      18. lift--.f6448.1

        \[\leadsto \mathsf{fma}\left(0.5, \sqrt{x - y} \cdot \sqrt{x - y}, x\right) \]
    6. Applied rewrites48.1%

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

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

        \[\leadsto \frac{3}{2} \cdot x + \frac{1}{2} \cdot \color{blue}{{\left(\sqrt{\mathsf{neg}\left(y\right)}\right)}^{2}} \]
      2. lower-fma.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{3}{2}, x, \frac{1}{2} \cdot {\left(\sqrt{\mathsf{neg}\left(y\right)}\right)}^{2}\right) \]
      3. *-commutativeN/A

        \[\leadsto \mathsf{fma}\left(\frac{3}{2}, x, {\left(\sqrt{\mathsf{neg}\left(y\right)}\right)}^{2} \cdot \frac{1}{2}\right) \]
      4. lift-neg.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{3}{2}, x, {\left(\sqrt{-y}\right)}^{2} \cdot \frac{1}{2}\right) \]
      5. sqrt-pow2N/A

        \[\leadsto \mathsf{fma}\left(\frac{3}{2}, x, {\left(-y\right)}^{\left(\frac{2}{2}\right)} \cdot \frac{1}{2}\right) \]
      6. metadata-evalN/A

        \[\leadsto \mathsf{fma}\left(\frac{3}{2}, x, {\left(-y\right)}^{1} \cdot \frac{1}{2}\right) \]
      7. unpow1N/A

        \[\leadsto \mathsf{fma}\left(\frac{3}{2}, x, \left(-y\right) \cdot \frac{1}{2}\right) \]
      8. lower-*.f6453.3

        \[\leadsto \mathsf{fma}\left(1.5, x, \left(-y\right) \cdot 0.5\right) \]
    9. Applied rewrites53.3%

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

      \[\leadsto \frac{3}{2} \cdot x \]
    11. Step-by-step derivation
      1. lower-*.f6430.0

        \[\leadsto 1.5 \cdot x \]
    12. Applied rewrites30.0%

      \[\leadsto 1.5 \cdot x \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 7: 77.8% accurate, 0.8× speedup?

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

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

\mathbf{elif}\;x \leq 1.85 \cdot 10^{-7}:\\
\;\;\;\;0.5 \cdot \left|-y\right|\\

\mathbf{else}:\\
\;\;\;\;1.5 \cdot x\\


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

    1. Initial program 99.9%

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

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

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

        \[\leadsto \left(1 + \frac{1}{2} \cdot \frac{\left|y - x\right|}{x}\right) \cdot \color{blue}{x} \]
    4. Applied rewrites87.7%

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

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

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

        \[\leadsto \left(\left|x - y\right| \cdot \frac{\frac{1}{2}}{x} + 1\right) \cdot x \]
      4. lift-fabs.f64N/A

        \[\leadsto \left(\left|x - y\right| \cdot \frac{\frac{1}{2}}{x} + 1\right) \cdot x \]
      5. lift--.f64N/A

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

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

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

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

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

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

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

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

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

        \[\leadsto \left(\frac{1}{2} \cdot \frac{\left|x - y\right|}{x}\right) \cdot x + x \]
    6. Applied rewrites65.1%

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

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

        \[\leadsto \frac{1}{2} \cdot \left|x - y\right| \]
      2. rem-sqrt-square-revN/A

        \[\leadsto \frac{1}{2} \cdot \sqrt{\left(x - y\right) \cdot \left(x - y\right)} \]
      3. sqrt-unprodN/A

        \[\leadsto \frac{1}{2} \cdot \left(\sqrt{x - y} \cdot \color{blue}{\sqrt{x - y}}\right) \]
      4. *-commutativeN/A

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

        \[\leadsto \left(\sqrt{x - y} \cdot \sqrt{x - y}\right) \cdot \color{blue}{\frac{1}{2}} \]
      6. rem-square-sqrtN/A

        \[\leadsto \left(x - y\right) \cdot \frac{1}{2} \]
      7. lift--.f6453.5

        \[\leadsto \left(x - y\right) \cdot 0.5 \]
    9. Applied rewrites53.5%

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

    if -5.00000000000000043e-212 < x < 1.85000000000000002e-7

    1. Initial program 99.9%

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

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

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

        \[\leadsto \frac{1}{2} \cdot \left|x - y\right| \]
      3. *-lft-identityN/A

        \[\leadsto \frac{1}{2} \cdot \left|1 \cdot x - y\right| \]
      4. metadata-evalN/A

        \[\leadsto \frac{1}{2} \cdot \left|\left(\mathsf{neg}\left(-1\right)\right) \cdot x - y\right| \]
      5. fabs-subN/A

        \[\leadsto \frac{1}{2} \cdot \left|y - \left(\mathsf{neg}\left(-1\right)\right) \cdot x\right| \]
      6. fp-cancel-sign-sub-invN/A

        \[\leadsto \frac{1}{2} \cdot \left|y + -1 \cdot x\right| \]
      7. remove-double-negN/A

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

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

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

        \[\leadsto \frac{1}{2} \cdot \left|\mathsf{neg}\left(\left(-1 \cdot y + x\right)\right)\right| \]
      11. +-commutativeN/A

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

        \[\leadsto \frac{1}{2} \cdot \left|x + -1 \cdot y\right| \]
      13. lower-fabs.f64N/A

        \[\leadsto \frac{1}{2} \cdot \left|x + -1 \cdot y\right| \]
      14. *-commutativeN/A

        \[\leadsto \frac{1}{2} \cdot \left|x + y \cdot -1\right| \]
      15. fp-cancel-sign-sub-invN/A

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

        \[\leadsto \frac{1}{2} \cdot \left|x - \left(\mathsf{neg}\left(y \cdot -1\right)\right)\right| \]
      17. distribute-rgt-neg-outN/A

        \[\leadsto \frac{1}{2} \cdot \left|x - y \cdot \left(\mathsf{neg}\left(-1\right)\right)\right| \]
      18. metadata-evalN/A

        \[\leadsto \frac{1}{2} \cdot \left|x - y \cdot 1\right| \]
      19. *-rgt-identityN/A

        \[\leadsto \frac{1}{2} \cdot \left|x - y\right| \]
      20. lower--.f6453.6

        \[\leadsto 0.5 \cdot \left|x - y\right| \]
    4. Applied rewrites53.6%

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

      \[\leadsto \frac{1}{2} \cdot \left|-1 \cdot y\right| \]
    6. Step-by-step derivation
      1. mul-1-negN/A

        \[\leadsto \frac{1}{2} \cdot \left|\mathsf{neg}\left(y\right)\right| \]
      2. lower-neg.f6450.6

        \[\leadsto 0.5 \cdot \left|-y\right| \]
    7. Applied rewrites50.6%

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

    if 1.85000000000000002e-7 < x

    1. Initial program 99.9%

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - y\right|, x\right) \]
      4. *-lft-identityN/A

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

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

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|y - \left(\mathsf{neg}\left(-1\right)\right) \cdot x\right|, x\right) \]
      7. fp-cancel-sign-sub-invN/A

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

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

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

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|\left(\mathsf{neg}\left(-1 \cdot y\right)\right) + \left(\mathsf{neg}\left(x\right)\right)\right|, x\right) \]
      11. distribute-neg-inN/A

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x + y \cdot -1\right|, x\right) \]
      16. fp-cancel-sign-sub-invN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - \left(\mathsf{neg}\left(y\right)\right) \cdot -1\right|, x\right) \]
      17. distribute-lft-neg-inN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - \left(\mathsf{neg}\left(y \cdot -1\right)\right)\right|, x\right) \]
      18. distribute-rgt-neg-outN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - y \cdot \left(\mathsf{neg}\left(-1\right)\right)\right|, x\right) \]
      19. metadata-evalN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - y \cdot 1\right|, x\right) \]
      20. *-rgt-identityN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - y\right|, x\right) \]
      21. lower--.f6499.9

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

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

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - y\right|, x\right) \]
      2. *-lft-identityN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - 1 \cdot y\right|, x\right) \]
      3. metadata-evalN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - \left(\mathsf{neg}\left(-1\right)\right) \cdot y\right|, x\right) \]
      4. fp-cancel-sign-sub-invN/A

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

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x + -1 \cdot y\right|, x\right) \]
      6. rem-sqrt-square-revN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{\left(x + -1 \cdot y\right) \cdot \left(x + -1 \cdot y\right)}, x\right) \]
      7. sqrt-prodN/A

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

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{x + -1 \cdot y} \cdot \color{blue}{\sqrt{x + -1 \cdot y}}, x\right) \]
      9. lower-sqrt.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{x + -1 \cdot y} \cdot \sqrt{\color{blue}{x + -1 \cdot y}}, x\right) \]
      10. fp-cancel-sign-sub-invN/A

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

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{x - 1 \cdot y} \cdot \sqrt{x + -1 \cdot y}, x\right) \]
      12. *-lft-identityN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{x - y} \cdot \sqrt{x + -1 \cdot y}, x\right) \]
      13. lift--.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{x - y} \cdot \sqrt{\color{blue}{x} + -1 \cdot y}, x\right) \]
      14. lower-sqrt.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{x - y} \cdot \sqrt{x + -1 \cdot y}, x\right) \]
      15. fp-cancel-sign-sub-invN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{x - y} \cdot \sqrt{x - \left(\mathsf{neg}\left(-1\right)\right) \cdot y}, x\right) \]
      16. metadata-evalN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{x - y} \cdot \sqrt{x - 1 \cdot y}, x\right) \]
      17. *-lft-identityN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{x - y} \cdot \sqrt{x - y}, x\right) \]
      18. lift--.f6448.1

        \[\leadsto \mathsf{fma}\left(0.5, \sqrt{x - y} \cdot \sqrt{x - y}, x\right) \]
    6. Applied rewrites48.1%

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

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

        \[\leadsto \frac{3}{2} \cdot x + \frac{1}{2} \cdot \color{blue}{{\left(\sqrt{\mathsf{neg}\left(y\right)}\right)}^{2}} \]
      2. lower-fma.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{3}{2}, x, \frac{1}{2} \cdot {\left(\sqrt{\mathsf{neg}\left(y\right)}\right)}^{2}\right) \]
      3. *-commutativeN/A

        \[\leadsto \mathsf{fma}\left(\frac{3}{2}, x, {\left(\sqrt{\mathsf{neg}\left(y\right)}\right)}^{2} \cdot \frac{1}{2}\right) \]
      4. lift-neg.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{3}{2}, x, {\left(\sqrt{-y}\right)}^{2} \cdot \frac{1}{2}\right) \]
      5. sqrt-pow2N/A

        \[\leadsto \mathsf{fma}\left(\frac{3}{2}, x, {\left(-y\right)}^{\left(\frac{2}{2}\right)} \cdot \frac{1}{2}\right) \]
      6. metadata-evalN/A

        \[\leadsto \mathsf{fma}\left(\frac{3}{2}, x, {\left(-y\right)}^{1} \cdot \frac{1}{2}\right) \]
      7. unpow1N/A

        \[\leadsto \mathsf{fma}\left(\frac{3}{2}, x, \left(-y\right) \cdot \frac{1}{2}\right) \]
      8. lower-*.f6453.3

        \[\leadsto \mathsf{fma}\left(1.5, x, \left(-y\right) \cdot 0.5\right) \]
    9. Applied rewrites53.3%

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

      \[\leadsto \frac{3}{2} \cdot x \]
    11. Step-by-step derivation
      1. lower-*.f6430.0

        \[\leadsto 1.5 \cdot x \]
    12. Applied rewrites30.0%

      \[\leadsto 1.5 \cdot x \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 8: 75.5% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -1.04 \cdot 10^{+61}:\\ \;\;\;\;0.5 \cdot x\\ \mathbf{elif}\;x \leq 1.85 \cdot 10^{-7}:\\ \;\;\;\;0.5 \cdot \left|-y\right|\\ \mathbf{else}:\\ \;\;\;\;1.5 \cdot x\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (if (<= x -1.04e+61)
   (* 0.5 x)
   (if (<= x 1.85e-7) (* 0.5 (fabs (- y))) (* 1.5 x))))
double code(double x, double y) {
	double tmp;
	if (x <= -1.04e+61) {
		tmp = 0.5 * x;
	} else if (x <= 1.85e-7) {
		tmp = 0.5 * fabs(-y);
	} 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 <= (-1.04d+61)) then
        tmp = 0.5d0 * x
    else if (x <= 1.85d-7) then
        tmp = 0.5d0 * abs(-y)
    else
        tmp = 1.5d0 * x
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double tmp;
	if (x <= -1.04e+61) {
		tmp = 0.5 * x;
	} else if (x <= 1.85e-7) {
		tmp = 0.5 * Math.abs(-y);
	} else {
		tmp = 1.5 * x;
	}
	return tmp;
}
def code(x, y):
	tmp = 0
	if x <= -1.04e+61:
		tmp = 0.5 * x
	elif x <= 1.85e-7:
		tmp = 0.5 * math.fabs(-y)
	else:
		tmp = 1.5 * x
	return tmp
function code(x, y)
	tmp = 0.0
	if (x <= -1.04e+61)
		tmp = Float64(0.5 * x);
	elseif (x <= 1.85e-7)
		tmp = Float64(0.5 * abs(Float64(-y)));
	else
		tmp = Float64(1.5 * x);
	end
	return tmp
end
function tmp_2 = code(x, y)
	tmp = 0.0;
	if (x <= -1.04e+61)
		tmp = 0.5 * x;
	elseif (x <= 1.85e-7)
		tmp = 0.5 * abs(-y);
	else
		tmp = 1.5 * x;
	end
	tmp_2 = tmp;
end
code[x_, y_] := If[LessEqual[x, -1.04e+61], N[(0.5 * x), $MachinePrecision], If[LessEqual[x, 1.85e-7], N[(0.5 * N[Abs[(-y)], $MachinePrecision]), $MachinePrecision], N[(1.5 * x), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.04 \cdot 10^{+61}:\\
\;\;\;\;0.5 \cdot x\\

\mathbf{elif}\;x \leq 1.85 \cdot 10^{-7}:\\
\;\;\;\;0.5 \cdot \left|-y\right|\\

\mathbf{else}:\\
\;\;\;\;1.5 \cdot x\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < -1.04000000000000003e61

    1. Initial program 99.9%

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - y\right|, x\right) \]
      4. *-lft-identityN/A

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

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

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|y - \left(\mathsf{neg}\left(-1\right)\right) \cdot x\right|, x\right) \]
      7. fp-cancel-sign-sub-invN/A

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

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

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

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|\left(\mathsf{neg}\left(-1 \cdot y\right)\right) + \left(\mathsf{neg}\left(x\right)\right)\right|, x\right) \]
      11. distribute-neg-inN/A

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x + y \cdot -1\right|, x\right) \]
      16. fp-cancel-sign-sub-invN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - \left(\mathsf{neg}\left(y\right)\right) \cdot -1\right|, x\right) \]
      17. distribute-lft-neg-inN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - \left(\mathsf{neg}\left(y \cdot -1\right)\right)\right|, x\right) \]
      18. distribute-rgt-neg-outN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - y \cdot \left(\mathsf{neg}\left(-1\right)\right)\right|, x\right) \]
      19. metadata-evalN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - y \cdot 1\right|, x\right) \]
      20. *-rgt-identityN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - y\right|, x\right) \]
      21. lower--.f6499.9

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

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

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - y\right|, x\right) \]
      2. *-lft-identityN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - 1 \cdot y\right|, x\right) \]
      3. metadata-evalN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - \left(\mathsf{neg}\left(-1\right)\right) \cdot y\right|, x\right) \]
      4. fp-cancel-sign-sub-invN/A

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

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x + -1 \cdot y\right|, x\right) \]
      6. rem-sqrt-square-revN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{\left(x + -1 \cdot y\right) \cdot \left(x + -1 \cdot y\right)}, x\right) \]
      7. sqrt-prodN/A

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

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{x + -1 \cdot y} \cdot \color{blue}{\sqrt{x + -1 \cdot y}}, x\right) \]
      9. lower-sqrt.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{x + -1 \cdot y} \cdot \sqrt{\color{blue}{x + -1 \cdot y}}, x\right) \]
      10. fp-cancel-sign-sub-invN/A

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

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{x - 1 \cdot y} \cdot \sqrt{x + -1 \cdot y}, x\right) \]
      12. *-lft-identityN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{x - y} \cdot \sqrt{x + -1 \cdot y}, x\right) \]
      13. lift--.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{x - y} \cdot \sqrt{\color{blue}{x} + -1 \cdot y}, x\right) \]
      14. lower-sqrt.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{x - y} \cdot \sqrt{x + -1 \cdot y}, x\right) \]
      15. fp-cancel-sign-sub-invN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{x - y} \cdot \sqrt{x - \left(\mathsf{neg}\left(-1\right)\right) \cdot y}, x\right) \]
      16. metadata-evalN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{x - y} \cdot \sqrt{x - 1 \cdot y}, x\right) \]
      17. *-lft-identityN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{x - y} \cdot \sqrt{x - y}, x\right) \]
      18. lift--.f6448.1

        \[\leadsto \mathsf{fma}\left(0.5, \sqrt{x - y} \cdot \sqrt{x - y}, x\right) \]
    6. Applied rewrites48.1%

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

      \[\leadsto \frac{1}{2} \cdot \color{blue}{\left({x}^{2} \cdot {\left(\sqrt{\frac{1}{x}}\right)}^{2}\right)} \]
    8. Step-by-step derivation
      1. sqrt-pow2N/A

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

        \[\leadsto \frac{1}{2} \cdot \left({x}^{2} \cdot {\left(\frac{1}{x}\right)}^{1}\right) \]
      3. unpow1N/A

        \[\leadsto \frac{1}{2} \cdot \left({x}^{2} \cdot \frac{1}{x}\right) \]
      4. inv-powN/A

        \[\leadsto \frac{1}{2} \cdot \left({x}^{2} \cdot {x}^{-1}\right) \]
      5. pow-prod-upN/A

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

        \[\leadsto \frac{1}{2} \cdot {x}^{1} \]
      7. unpow1N/A

        \[\leadsto \frac{1}{2} \cdot x \]
      8. lower-*.f6431.2

        \[\leadsto 0.5 \cdot x \]
    9. Applied rewrites31.2%

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

    if -1.04000000000000003e61 < x < 1.85000000000000002e-7

    1. Initial program 99.9%

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

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

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

        \[\leadsto \frac{1}{2} \cdot \left|x - y\right| \]
      3. *-lft-identityN/A

        \[\leadsto \frac{1}{2} \cdot \left|1 \cdot x - y\right| \]
      4. metadata-evalN/A

        \[\leadsto \frac{1}{2} \cdot \left|\left(\mathsf{neg}\left(-1\right)\right) \cdot x - y\right| \]
      5. fabs-subN/A

        \[\leadsto \frac{1}{2} \cdot \left|y - \left(\mathsf{neg}\left(-1\right)\right) \cdot x\right| \]
      6. fp-cancel-sign-sub-invN/A

        \[\leadsto \frac{1}{2} \cdot \left|y + -1 \cdot x\right| \]
      7. remove-double-negN/A

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

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

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

        \[\leadsto \frac{1}{2} \cdot \left|\mathsf{neg}\left(\left(-1 \cdot y + x\right)\right)\right| \]
      11. +-commutativeN/A

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

        \[\leadsto \frac{1}{2} \cdot \left|x + -1 \cdot y\right| \]
      13. lower-fabs.f64N/A

        \[\leadsto \frac{1}{2} \cdot \left|x + -1 \cdot y\right| \]
      14. *-commutativeN/A

        \[\leadsto \frac{1}{2} \cdot \left|x + y \cdot -1\right| \]
      15. fp-cancel-sign-sub-invN/A

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

        \[\leadsto \frac{1}{2} \cdot \left|x - \left(\mathsf{neg}\left(y \cdot -1\right)\right)\right| \]
      17. distribute-rgt-neg-outN/A

        \[\leadsto \frac{1}{2} \cdot \left|x - y \cdot \left(\mathsf{neg}\left(-1\right)\right)\right| \]
      18. metadata-evalN/A

        \[\leadsto \frac{1}{2} \cdot \left|x - y \cdot 1\right| \]
      19. *-rgt-identityN/A

        \[\leadsto \frac{1}{2} \cdot \left|x - y\right| \]
      20. lower--.f6453.6

        \[\leadsto 0.5 \cdot \left|x - y\right| \]
    4. Applied rewrites53.6%

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

      \[\leadsto \frac{1}{2} \cdot \left|-1 \cdot y\right| \]
    6. Step-by-step derivation
      1. mul-1-negN/A

        \[\leadsto \frac{1}{2} \cdot \left|\mathsf{neg}\left(y\right)\right| \]
      2. lower-neg.f6450.6

        \[\leadsto 0.5 \cdot \left|-y\right| \]
    7. Applied rewrites50.6%

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

    if 1.85000000000000002e-7 < x

    1. Initial program 99.9%

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - y\right|, x\right) \]
      4. *-lft-identityN/A

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

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

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|y - \left(\mathsf{neg}\left(-1\right)\right) \cdot x\right|, x\right) \]
      7. fp-cancel-sign-sub-invN/A

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

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

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

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|\left(\mathsf{neg}\left(-1 \cdot y\right)\right) + \left(\mathsf{neg}\left(x\right)\right)\right|, x\right) \]
      11. distribute-neg-inN/A

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x + y \cdot -1\right|, x\right) \]
      16. fp-cancel-sign-sub-invN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - \left(\mathsf{neg}\left(y\right)\right) \cdot -1\right|, x\right) \]
      17. distribute-lft-neg-inN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - \left(\mathsf{neg}\left(y \cdot -1\right)\right)\right|, x\right) \]
      18. distribute-rgt-neg-outN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - y \cdot \left(\mathsf{neg}\left(-1\right)\right)\right|, x\right) \]
      19. metadata-evalN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - y \cdot 1\right|, x\right) \]
      20. *-rgt-identityN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - y\right|, x\right) \]
      21. lower--.f6499.9

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

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

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - y\right|, x\right) \]
      2. *-lft-identityN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - 1 \cdot y\right|, x\right) \]
      3. metadata-evalN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - \left(\mathsf{neg}\left(-1\right)\right) \cdot y\right|, x\right) \]
      4. fp-cancel-sign-sub-invN/A

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

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x + -1 \cdot y\right|, x\right) \]
      6. rem-sqrt-square-revN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{\left(x + -1 \cdot y\right) \cdot \left(x + -1 \cdot y\right)}, x\right) \]
      7. sqrt-prodN/A

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

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{x + -1 \cdot y} \cdot \color{blue}{\sqrt{x + -1 \cdot y}}, x\right) \]
      9. lower-sqrt.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{x + -1 \cdot y} \cdot \sqrt{\color{blue}{x + -1 \cdot y}}, x\right) \]
      10. fp-cancel-sign-sub-invN/A

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

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{x - 1 \cdot y} \cdot \sqrt{x + -1 \cdot y}, x\right) \]
      12. *-lft-identityN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{x - y} \cdot \sqrt{x + -1 \cdot y}, x\right) \]
      13. lift--.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{x - y} \cdot \sqrt{\color{blue}{x} + -1 \cdot y}, x\right) \]
      14. lower-sqrt.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{x - y} \cdot \sqrt{x + -1 \cdot y}, x\right) \]
      15. fp-cancel-sign-sub-invN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{x - y} \cdot \sqrt{x - \left(\mathsf{neg}\left(-1\right)\right) \cdot y}, x\right) \]
      16. metadata-evalN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{x - y} \cdot \sqrt{x - 1 \cdot y}, x\right) \]
      17. *-lft-identityN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{x - y} \cdot \sqrt{x - y}, x\right) \]
      18. lift--.f6448.1

        \[\leadsto \mathsf{fma}\left(0.5, \sqrt{x - y} \cdot \sqrt{x - y}, x\right) \]
    6. Applied rewrites48.1%

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

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

        \[\leadsto \frac{3}{2} \cdot x + \frac{1}{2} \cdot \color{blue}{{\left(\sqrt{\mathsf{neg}\left(y\right)}\right)}^{2}} \]
      2. lower-fma.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{3}{2}, x, \frac{1}{2} \cdot {\left(\sqrt{\mathsf{neg}\left(y\right)}\right)}^{2}\right) \]
      3. *-commutativeN/A

        \[\leadsto \mathsf{fma}\left(\frac{3}{2}, x, {\left(\sqrt{\mathsf{neg}\left(y\right)}\right)}^{2} \cdot \frac{1}{2}\right) \]
      4. lift-neg.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{3}{2}, x, {\left(\sqrt{-y}\right)}^{2} \cdot \frac{1}{2}\right) \]
      5. sqrt-pow2N/A

        \[\leadsto \mathsf{fma}\left(\frac{3}{2}, x, {\left(-y\right)}^{\left(\frac{2}{2}\right)} \cdot \frac{1}{2}\right) \]
      6. metadata-evalN/A

        \[\leadsto \mathsf{fma}\left(\frac{3}{2}, x, {\left(-y\right)}^{1} \cdot \frac{1}{2}\right) \]
      7. unpow1N/A

        \[\leadsto \mathsf{fma}\left(\frac{3}{2}, x, \left(-y\right) \cdot \frac{1}{2}\right) \]
      8. lower-*.f6453.3

        \[\leadsto \mathsf{fma}\left(1.5, x, \left(-y\right) \cdot 0.5\right) \]
    9. Applied rewrites53.3%

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

      \[\leadsto \frac{3}{2} \cdot x \]
    11. Step-by-step derivation
      1. lower-*.f6430.0

        \[\leadsto 1.5 \cdot x \]
    12. Applied rewrites30.0%

      \[\leadsto 1.5 \cdot x \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 9: 56.6% accurate, 0.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;x \leq -7.5 \cdot 10^{+28}:\\
\;\;\;\;0.5 \cdot x\\

\mathbf{elif}\;x \leq 8.2 \cdot 10^{-163}:\\
\;\;\;\;-0.5 \cdot y\\

\mathbf{else}:\\
\;\;\;\;1.5 \cdot x\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < -7.4999999999999998e28

    1. Initial program 99.9%

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - y\right|, x\right) \]
      4. *-lft-identityN/A

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

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

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|y - \left(\mathsf{neg}\left(-1\right)\right) \cdot x\right|, x\right) \]
      7. fp-cancel-sign-sub-invN/A

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

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

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

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|\left(\mathsf{neg}\left(-1 \cdot y\right)\right) + \left(\mathsf{neg}\left(x\right)\right)\right|, x\right) \]
      11. distribute-neg-inN/A

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x + y \cdot -1\right|, x\right) \]
      16. fp-cancel-sign-sub-invN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - \left(\mathsf{neg}\left(y\right)\right) \cdot -1\right|, x\right) \]
      17. distribute-lft-neg-inN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - \left(\mathsf{neg}\left(y \cdot -1\right)\right)\right|, x\right) \]
      18. distribute-rgt-neg-outN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - y \cdot \left(\mathsf{neg}\left(-1\right)\right)\right|, x\right) \]
      19. metadata-evalN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - y \cdot 1\right|, x\right) \]
      20. *-rgt-identityN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - y\right|, x\right) \]
      21. lower--.f6499.9

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

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

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - y\right|, x\right) \]
      2. *-lft-identityN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - 1 \cdot y\right|, x\right) \]
      3. metadata-evalN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - \left(\mathsf{neg}\left(-1\right)\right) \cdot y\right|, x\right) \]
      4. fp-cancel-sign-sub-invN/A

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

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x + -1 \cdot y\right|, x\right) \]
      6. rem-sqrt-square-revN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{\left(x + -1 \cdot y\right) \cdot \left(x + -1 \cdot y\right)}, x\right) \]
      7. sqrt-prodN/A

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

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{x + -1 \cdot y} \cdot \color{blue}{\sqrt{x + -1 \cdot y}}, x\right) \]
      9. lower-sqrt.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{x + -1 \cdot y} \cdot \sqrt{\color{blue}{x + -1 \cdot y}}, x\right) \]
      10. fp-cancel-sign-sub-invN/A

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

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{x - 1 \cdot y} \cdot \sqrt{x + -1 \cdot y}, x\right) \]
      12. *-lft-identityN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{x - y} \cdot \sqrt{x + -1 \cdot y}, x\right) \]
      13. lift--.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{x - y} \cdot \sqrt{\color{blue}{x} + -1 \cdot y}, x\right) \]
      14. lower-sqrt.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{x - y} \cdot \sqrt{x + -1 \cdot y}, x\right) \]
      15. fp-cancel-sign-sub-invN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{x - y} \cdot \sqrt{x - \left(\mathsf{neg}\left(-1\right)\right) \cdot y}, x\right) \]
      16. metadata-evalN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{x - y} \cdot \sqrt{x - 1 \cdot y}, x\right) \]
      17. *-lft-identityN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{x - y} \cdot \sqrt{x - y}, x\right) \]
      18. lift--.f6448.1

        \[\leadsto \mathsf{fma}\left(0.5, \sqrt{x - y} \cdot \sqrt{x - y}, x\right) \]
    6. Applied rewrites48.1%

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

      \[\leadsto \frac{1}{2} \cdot \color{blue}{\left({x}^{2} \cdot {\left(\sqrt{\frac{1}{x}}\right)}^{2}\right)} \]
    8. Step-by-step derivation
      1. sqrt-pow2N/A

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

        \[\leadsto \frac{1}{2} \cdot \left({x}^{2} \cdot {\left(\frac{1}{x}\right)}^{1}\right) \]
      3. unpow1N/A

        \[\leadsto \frac{1}{2} \cdot \left({x}^{2} \cdot \frac{1}{x}\right) \]
      4. inv-powN/A

        \[\leadsto \frac{1}{2} \cdot \left({x}^{2} \cdot {x}^{-1}\right) \]
      5. pow-prod-upN/A

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

        \[\leadsto \frac{1}{2} \cdot {x}^{1} \]
      7. unpow1N/A

        \[\leadsto \frac{1}{2} \cdot x \]
      8. lower-*.f6431.2

        \[\leadsto 0.5 \cdot x \]
    9. Applied rewrites31.2%

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

    if -7.4999999999999998e28 < x < 8.19999999999999965e-163

    1. Initial program 99.9%

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - y\right|, x\right) \]
      4. *-lft-identityN/A

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

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

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|y - \left(\mathsf{neg}\left(-1\right)\right) \cdot x\right|, x\right) \]
      7. fp-cancel-sign-sub-invN/A

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

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

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

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|\left(\mathsf{neg}\left(-1 \cdot y\right)\right) + \left(\mathsf{neg}\left(x\right)\right)\right|, x\right) \]
      11. distribute-neg-inN/A

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x + y \cdot -1\right|, x\right) \]
      16. fp-cancel-sign-sub-invN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - \left(\mathsf{neg}\left(y\right)\right) \cdot -1\right|, x\right) \]
      17. distribute-lft-neg-inN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - \left(\mathsf{neg}\left(y \cdot -1\right)\right)\right|, x\right) \]
      18. distribute-rgt-neg-outN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - y \cdot \left(\mathsf{neg}\left(-1\right)\right)\right|, x\right) \]
      19. metadata-evalN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - y \cdot 1\right|, x\right) \]
      20. *-rgt-identityN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - y\right|, x\right) \]
      21. lower--.f6499.9

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

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

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - y\right|, x\right) \]
      2. *-lft-identityN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - 1 \cdot y\right|, x\right) \]
      3. metadata-evalN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - \left(\mathsf{neg}\left(-1\right)\right) \cdot y\right|, x\right) \]
      4. fp-cancel-sign-sub-invN/A

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

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x + -1 \cdot y\right|, x\right) \]
      6. rem-sqrt-square-revN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{\left(x + -1 \cdot y\right) \cdot \left(x + -1 \cdot y\right)}, x\right) \]
      7. sqrt-prodN/A

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

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{x + -1 \cdot y} \cdot \color{blue}{\sqrt{x + -1 \cdot y}}, x\right) \]
      9. lower-sqrt.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{x + -1 \cdot y} \cdot \sqrt{\color{blue}{x + -1 \cdot y}}, x\right) \]
      10. fp-cancel-sign-sub-invN/A

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

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{x - 1 \cdot y} \cdot \sqrt{x + -1 \cdot y}, x\right) \]
      12. *-lft-identityN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{x - y} \cdot \sqrt{x + -1 \cdot y}, x\right) \]
      13. lift--.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{x - y} \cdot \sqrt{\color{blue}{x} + -1 \cdot y}, x\right) \]
      14. lower-sqrt.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{x - y} \cdot \sqrt{x + -1 \cdot y}, x\right) \]
      15. fp-cancel-sign-sub-invN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{x - y} \cdot \sqrt{x - \left(\mathsf{neg}\left(-1\right)\right) \cdot y}, x\right) \]
      16. metadata-evalN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{x - y} \cdot \sqrt{x - 1 \cdot y}, x\right) \]
      17. *-lft-identityN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{x - y} \cdot \sqrt{x - y}, x\right) \]
      18. lift--.f6448.1

        \[\leadsto \mathsf{fma}\left(0.5, \sqrt{x - y} \cdot \sqrt{x - y}, x\right) \]
    6. Applied rewrites48.1%

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

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

        \[\leadsto \frac{3}{2} \cdot x + \frac{1}{2} \cdot \color{blue}{{\left(\sqrt{\mathsf{neg}\left(y\right)}\right)}^{2}} \]
      2. lower-fma.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{3}{2}, x, \frac{1}{2} \cdot {\left(\sqrt{\mathsf{neg}\left(y\right)}\right)}^{2}\right) \]
      3. *-commutativeN/A

        \[\leadsto \mathsf{fma}\left(\frac{3}{2}, x, {\left(\sqrt{\mathsf{neg}\left(y\right)}\right)}^{2} \cdot \frac{1}{2}\right) \]
      4. lift-neg.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{3}{2}, x, {\left(\sqrt{-y}\right)}^{2} \cdot \frac{1}{2}\right) \]
      5. sqrt-pow2N/A

        \[\leadsto \mathsf{fma}\left(\frac{3}{2}, x, {\left(-y\right)}^{\left(\frac{2}{2}\right)} \cdot \frac{1}{2}\right) \]
      6. metadata-evalN/A

        \[\leadsto \mathsf{fma}\left(\frac{3}{2}, x, {\left(-y\right)}^{1} \cdot \frac{1}{2}\right) \]
      7. unpow1N/A

        \[\leadsto \mathsf{fma}\left(\frac{3}{2}, x, \left(-y\right) \cdot \frac{1}{2}\right) \]
      8. lower-*.f6453.3

        \[\leadsto \mathsf{fma}\left(1.5, x, \left(-y\right) \cdot 0.5\right) \]
    9. Applied rewrites53.3%

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

      \[\leadsto \frac{-1}{2} \cdot y \]
    11. Step-by-step derivation
      1. lower-*.f6425.7

        \[\leadsto -0.5 \cdot y \]
    12. Applied rewrites25.7%

      \[\leadsto -0.5 \cdot y \]

    if 8.19999999999999965e-163 < x

    1. Initial program 99.9%

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - y\right|, x\right) \]
      4. *-lft-identityN/A

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

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

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|y - \left(\mathsf{neg}\left(-1\right)\right) \cdot x\right|, x\right) \]
      7. fp-cancel-sign-sub-invN/A

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

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

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

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|\left(\mathsf{neg}\left(-1 \cdot y\right)\right) + \left(\mathsf{neg}\left(x\right)\right)\right|, x\right) \]
      11. distribute-neg-inN/A

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x + y \cdot -1\right|, x\right) \]
      16. fp-cancel-sign-sub-invN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - \left(\mathsf{neg}\left(y\right)\right) \cdot -1\right|, x\right) \]
      17. distribute-lft-neg-inN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - \left(\mathsf{neg}\left(y \cdot -1\right)\right)\right|, x\right) \]
      18. distribute-rgt-neg-outN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - y \cdot \left(\mathsf{neg}\left(-1\right)\right)\right|, x\right) \]
      19. metadata-evalN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - y \cdot 1\right|, x\right) \]
      20. *-rgt-identityN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - y\right|, x\right) \]
      21. lower--.f6499.9

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

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

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - y\right|, x\right) \]
      2. *-lft-identityN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - 1 \cdot y\right|, x\right) \]
      3. metadata-evalN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - \left(\mathsf{neg}\left(-1\right)\right) \cdot y\right|, x\right) \]
      4. fp-cancel-sign-sub-invN/A

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

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x + -1 \cdot y\right|, x\right) \]
      6. rem-sqrt-square-revN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{\left(x + -1 \cdot y\right) \cdot \left(x + -1 \cdot y\right)}, x\right) \]
      7. sqrt-prodN/A

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

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{x + -1 \cdot y} \cdot \color{blue}{\sqrt{x + -1 \cdot y}}, x\right) \]
      9. lower-sqrt.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{x + -1 \cdot y} \cdot \sqrt{\color{blue}{x + -1 \cdot y}}, x\right) \]
      10. fp-cancel-sign-sub-invN/A

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

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{x - 1 \cdot y} \cdot \sqrt{x + -1 \cdot y}, x\right) \]
      12. *-lft-identityN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{x - y} \cdot \sqrt{x + -1 \cdot y}, x\right) \]
      13. lift--.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{x - y} \cdot \sqrt{\color{blue}{x} + -1 \cdot y}, x\right) \]
      14. lower-sqrt.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{x - y} \cdot \sqrt{x + -1 \cdot y}, x\right) \]
      15. fp-cancel-sign-sub-invN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{x - y} \cdot \sqrt{x - \left(\mathsf{neg}\left(-1\right)\right) \cdot y}, x\right) \]
      16. metadata-evalN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{x - y} \cdot \sqrt{x - 1 \cdot y}, x\right) \]
      17. *-lft-identityN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{x - y} \cdot \sqrt{x - y}, x\right) \]
      18. lift--.f6448.1

        \[\leadsto \mathsf{fma}\left(0.5, \sqrt{x - y} \cdot \sqrt{x - y}, x\right) \]
    6. Applied rewrites48.1%

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

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

        \[\leadsto \frac{3}{2} \cdot x + \frac{1}{2} \cdot \color{blue}{{\left(\sqrt{\mathsf{neg}\left(y\right)}\right)}^{2}} \]
      2. lower-fma.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{3}{2}, x, \frac{1}{2} \cdot {\left(\sqrt{\mathsf{neg}\left(y\right)}\right)}^{2}\right) \]
      3. *-commutativeN/A

        \[\leadsto \mathsf{fma}\left(\frac{3}{2}, x, {\left(\sqrt{\mathsf{neg}\left(y\right)}\right)}^{2} \cdot \frac{1}{2}\right) \]
      4. lift-neg.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{3}{2}, x, {\left(\sqrt{-y}\right)}^{2} \cdot \frac{1}{2}\right) \]
      5. sqrt-pow2N/A

        \[\leadsto \mathsf{fma}\left(\frac{3}{2}, x, {\left(-y\right)}^{\left(\frac{2}{2}\right)} \cdot \frac{1}{2}\right) \]
      6. metadata-evalN/A

        \[\leadsto \mathsf{fma}\left(\frac{3}{2}, x, {\left(-y\right)}^{1} \cdot \frac{1}{2}\right) \]
      7. unpow1N/A

        \[\leadsto \mathsf{fma}\left(\frac{3}{2}, x, \left(-y\right) \cdot \frac{1}{2}\right) \]
      8. lower-*.f6453.3

        \[\leadsto \mathsf{fma}\left(1.5, x, \left(-y\right) \cdot 0.5\right) \]
    9. Applied rewrites53.3%

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

      \[\leadsto \frac{3}{2} \cdot x \]
    11. Step-by-step derivation
      1. lower-*.f6430.0

        \[\leadsto 1.5 \cdot x \]
    12. Applied rewrites30.0%

      \[\leadsto 1.5 \cdot x \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 10: 45.3% accurate, 1.4× speedup?

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

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

\mathbf{else}:\\
\;\;\;\;1.5 \cdot x\\


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

    1. Initial program 99.9%

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - y\right|, x\right) \]
      4. *-lft-identityN/A

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

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

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|y - \left(\mathsf{neg}\left(-1\right)\right) \cdot x\right|, x\right) \]
      7. fp-cancel-sign-sub-invN/A

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

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

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

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|\left(\mathsf{neg}\left(-1 \cdot y\right)\right) + \left(\mathsf{neg}\left(x\right)\right)\right|, x\right) \]
      11. distribute-neg-inN/A

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x + y \cdot -1\right|, x\right) \]
      16. fp-cancel-sign-sub-invN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - \left(\mathsf{neg}\left(y\right)\right) \cdot -1\right|, x\right) \]
      17. distribute-lft-neg-inN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - \left(\mathsf{neg}\left(y \cdot -1\right)\right)\right|, x\right) \]
      18. distribute-rgt-neg-outN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - y \cdot \left(\mathsf{neg}\left(-1\right)\right)\right|, x\right) \]
      19. metadata-evalN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - y \cdot 1\right|, x\right) \]
      20. *-rgt-identityN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - y\right|, x\right) \]
      21. lower--.f6499.9

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

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

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - y\right|, x\right) \]
      2. *-lft-identityN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - 1 \cdot y\right|, x\right) \]
      3. metadata-evalN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - \left(\mathsf{neg}\left(-1\right)\right) \cdot y\right|, x\right) \]
      4. fp-cancel-sign-sub-invN/A

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

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x + -1 \cdot y\right|, x\right) \]
      6. rem-sqrt-square-revN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{\left(x + -1 \cdot y\right) \cdot \left(x + -1 \cdot y\right)}, x\right) \]
      7. sqrt-prodN/A

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

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{x + -1 \cdot y} \cdot \color{blue}{\sqrt{x + -1 \cdot y}}, x\right) \]
      9. lower-sqrt.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{x + -1 \cdot y} \cdot \sqrt{\color{blue}{x + -1 \cdot y}}, x\right) \]
      10. fp-cancel-sign-sub-invN/A

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

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{x - 1 \cdot y} \cdot \sqrt{x + -1 \cdot y}, x\right) \]
      12. *-lft-identityN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{x - y} \cdot \sqrt{x + -1 \cdot y}, x\right) \]
      13. lift--.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{x - y} \cdot \sqrt{\color{blue}{x} + -1 \cdot y}, x\right) \]
      14. lower-sqrt.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{x - y} \cdot \sqrt{x + -1 \cdot y}, x\right) \]
      15. fp-cancel-sign-sub-invN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{x - y} \cdot \sqrt{x - \left(\mathsf{neg}\left(-1\right)\right) \cdot y}, x\right) \]
      16. metadata-evalN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{x - y} \cdot \sqrt{x - 1 \cdot y}, x\right) \]
      17. *-lft-identityN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{x - y} \cdot \sqrt{x - y}, x\right) \]
      18. lift--.f6448.1

        \[\leadsto \mathsf{fma}\left(0.5, \sqrt{x - y} \cdot \sqrt{x - y}, x\right) \]
    6. Applied rewrites48.1%

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

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

        \[\leadsto \frac{3}{2} \cdot x + \frac{1}{2} \cdot \color{blue}{{\left(\sqrt{\mathsf{neg}\left(y\right)}\right)}^{2}} \]
      2. lower-fma.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{3}{2}, x, \frac{1}{2} \cdot {\left(\sqrt{\mathsf{neg}\left(y\right)}\right)}^{2}\right) \]
      3. *-commutativeN/A

        \[\leadsto \mathsf{fma}\left(\frac{3}{2}, x, {\left(\sqrt{\mathsf{neg}\left(y\right)}\right)}^{2} \cdot \frac{1}{2}\right) \]
      4. lift-neg.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{3}{2}, x, {\left(\sqrt{-y}\right)}^{2} \cdot \frac{1}{2}\right) \]
      5. sqrt-pow2N/A

        \[\leadsto \mathsf{fma}\left(\frac{3}{2}, x, {\left(-y\right)}^{\left(\frac{2}{2}\right)} \cdot \frac{1}{2}\right) \]
      6. metadata-evalN/A

        \[\leadsto \mathsf{fma}\left(\frac{3}{2}, x, {\left(-y\right)}^{1} \cdot \frac{1}{2}\right) \]
      7. unpow1N/A

        \[\leadsto \mathsf{fma}\left(\frac{3}{2}, x, \left(-y\right) \cdot \frac{1}{2}\right) \]
      8. lower-*.f6453.3

        \[\leadsto \mathsf{fma}\left(1.5, x, \left(-y\right) \cdot 0.5\right) \]
    9. Applied rewrites53.3%

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

      \[\leadsto \frac{-1}{2} \cdot y \]
    11. Step-by-step derivation
      1. lower-*.f6425.7

        \[\leadsto -0.5 \cdot y \]
    12. Applied rewrites25.7%

      \[\leadsto -0.5 \cdot y \]

    if -5.0000000000000002e-85 < y

    1. Initial program 99.9%

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - y\right|, x\right) \]
      4. *-lft-identityN/A

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

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

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|y - \left(\mathsf{neg}\left(-1\right)\right) \cdot x\right|, x\right) \]
      7. fp-cancel-sign-sub-invN/A

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

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

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

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|\left(\mathsf{neg}\left(-1 \cdot y\right)\right) + \left(\mathsf{neg}\left(x\right)\right)\right|, x\right) \]
      11. distribute-neg-inN/A

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x + y \cdot -1\right|, x\right) \]
      16. fp-cancel-sign-sub-invN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - \left(\mathsf{neg}\left(y\right)\right) \cdot -1\right|, x\right) \]
      17. distribute-lft-neg-inN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - \left(\mathsf{neg}\left(y \cdot -1\right)\right)\right|, x\right) \]
      18. distribute-rgt-neg-outN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - y \cdot \left(\mathsf{neg}\left(-1\right)\right)\right|, x\right) \]
      19. metadata-evalN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - y \cdot 1\right|, x\right) \]
      20. *-rgt-identityN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - y\right|, x\right) \]
      21. lower--.f6499.9

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

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

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - y\right|, x\right) \]
      2. *-lft-identityN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - 1 \cdot y\right|, x\right) \]
      3. metadata-evalN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - \left(\mathsf{neg}\left(-1\right)\right) \cdot y\right|, x\right) \]
      4. fp-cancel-sign-sub-invN/A

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

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x + -1 \cdot y\right|, x\right) \]
      6. rem-sqrt-square-revN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{\left(x + -1 \cdot y\right) \cdot \left(x + -1 \cdot y\right)}, x\right) \]
      7. sqrt-prodN/A

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

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{x + -1 \cdot y} \cdot \color{blue}{\sqrt{x + -1 \cdot y}}, x\right) \]
      9. lower-sqrt.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{x + -1 \cdot y} \cdot \sqrt{\color{blue}{x + -1 \cdot y}}, x\right) \]
      10. fp-cancel-sign-sub-invN/A

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

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{x - 1 \cdot y} \cdot \sqrt{x + -1 \cdot y}, x\right) \]
      12. *-lft-identityN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{x - y} \cdot \sqrt{x + -1 \cdot y}, x\right) \]
      13. lift--.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{x - y} \cdot \sqrt{\color{blue}{x} + -1 \cdot y}, x\right) \]
      14. lower-sqrt.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{x - y} \cdot \sqrt{x + -1 \cdot y}, x\right) \]
      15. fp-cancel-sign-sub-invN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{x - y} \cdot \sqrt{x - \left(\mathsf{neg}\left(-1\right)\right) \cdot y}, x\right) \]
      16. metadata-evalN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{x - y} \cdot \sqrt{x - 1 \cdot y}, x\right) \]
      17. *-lft-identityN/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{x - y} \cdot \sqrt{x - y}, x\right) \]
      18. lift--.f6448.1

        \[\leadsto \mathsf{fma}\left(0.5, \sqrt{x - y} \cdot \sqrt{x - y}, x\right) \]
    6. Applied rewrites48.1%

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

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

        \[\leadsto \frac{3}{2} \cdot x + \frac{1}{2} \cdot \color{blue}{{\left(\sqrt{\mathsf{neg}\left(y\right)}\right)}^{2}} \]
      2. lower-fma.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{3}{2}, x, \frac{1}{2} \cdot {\left(\sqrt{\mathsf{neg}\left(y\right)}\right)}^{2}\right) \]
      3. *-commutativeN/A

        \[\leadsto \mathsf{fma}\left(\frac{3}{2}, x, {\left(\sqrt{\mathsf{neg}\left(y\right)}\right)}^{2} \cdot \frac{1}{2}\right) \]
      4. lift-neg.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{3}{2}, x, {\left(\sqrt{-y}\right)}^{2} \cdot \frac{1}{2}\right) \]
      5. sqrt-pow2N/A

        \[\leadsto \mathsf{fma}\left(\frac{3}{2}, x, {\left(-y\right)}^{\left(\frac{2}{2}\right)} \cdot \frac{1}{2}\right) \]
      6. metadata-evalN/A

        \[\leadsto \mathsf{fma}\left(\frac{3}{2}, x, {\left(-y\right)}^{1} \cdot \frac{1}{2}\right) \]
      7. unpow1N/A

        \[\leadsto \mathsf{fma}\left(\frac{3}{2}, x, \left(-y\right) \cdot \frac{1}{2}\right) \]
      8. lower-*.f6453.3

        \[\leadsto \mathsf{fma}\left(1.5, x, \left(-y\right) \cdot 0.5\right) \]
    9. Applied rewrites53.3%

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

      \[\leadsto \frac{3}{2} \cdot x \]
    11. Step-by-step derivation
      1. lower-*.f6430.0

        \[\leadsto 1.5 \cdot x \]
    12. Applied rewrites30.0%

      \[\leadsto 1.5 \cdot x \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 11: 25.7% accurate, 2.8× 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. Taylor expanded in x around 0

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

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

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

      \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - y\right|, x\right) \]
    4. *-lft-identityN/A

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

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

      \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|y - \left(\mathsf{neg}\left(-1\right)\right) \cdot x\right|, x\right) \]
    7. fp-cancel-sign-sub-invN/A

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

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

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

      \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|\left(\mathsf{neg}\left(-1 \cdot y\right)\right) + \left(\mathsf{neg}\left(x\right)\right)\right|, x\right) \]
    11. distribute-neg-inN/A

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

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

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

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

      \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x + y \cdot -1\right|, x\right) \]
    16. fp-cancel-sign-sub-invN/A

      \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - \left(\mathsf{neg}\left(y\right)\right) \cdot -1\right|, x\right) \]
    17. distribute-lft-neg-inN/A

      \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - \left(\mathsf{neg}\left(y \cdot -1\right)\right)\right|, x\right) \]
    18. distribute-rgt-neg-outN/A

      \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - y \cdot \left(\mathsf{neg}\left(-1\right)\right)\right|, x\right) \]
    19. metadata-evalN/A

      \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - y \cdot 1\right|, x\right) \]
    20. *-rgt-identityN/A

      \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - y\right|, x\right) \]
    21. lower--.f6499.9

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

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

      \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - y\right|, x\right) \]
    2. *-lft-identityN/A

      \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - 1 \cdot y\right|, x\right) \]
    3. metadata-evalN/A

      \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x - \left(\mathsf{neg}\left(-1\right)\right) \cdot y\right|, x\right) \]
    4. fp-cancel-sign-sub-invN/A

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

      \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \left|x + -1 \cdot y\right|, x\right) \]
    6. rem-sqrt-square-revN/A

      \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{\left(x + -1 \cdot y\right) \cdot \left(x + -1 \cdot y\right)}, x\right) \]
    7. sqrt-prodN/A

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

      \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{x + -1 \cdot y} \cdot \color{blue}{\sqrt{x + -1 \cdot y}}, x\right) \]
    9. lower-sqrt.f64N/A

      \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{x + -1 \cdot y} \cdot \sqrt{\color{blue}{x + -1 \cdot y}}, x\right) \]
    10. fp-cancel-sign-sub-invN/A

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

      \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{x - 1 \cdot y} \cdot \sqrt{x + -1 \cdot y}, x\right) \]
    12. *-lft-identityN/A

      \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{x - y} \cdot \sqrt{x + -1 \cdot y}, x\right) \]
    13. lift--.f64N/A

      \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{x - y} \cdot \sqrt{\color{blue}{x} + -1 \cdot y}, x\right) \]
    14. lower-sqrt.f64N/A

      \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{x - y} \cdot \sqrt{x + -1 \cdot y}, x\right) \]
    15. fp-cancel-sign-sub-invN/A

      \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{x - y} \cdot \sqrt{x - \left(\mathsf{neg}\left(-1\right)\right) \cdot y}, x\right) \]
    16. metadata-evalN/A

      \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{x - y} \cdot \sqrt{x - 1 \cdot y}, x\right) \]
    17. *-lft-identityN/A

      \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \sqrt{x - y} \cdot \sqrt{x - y}, x\right) \]
    18. lift--.f6448.1

      \[\leadsto \mathsf{fma}\left(0.5, \sqrt{x - y} \cdot \sqrt{x - y}, x\right) \]
  6. Applied rewrites48.1%

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

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

      \[\leadsto \frac{3}{2} \cdot x + \frac{1}{2} \cdot \color{blue}{{\left(\sqrt{\mathsf{neg}\left(y\right)}\right)}^{2}} \]
    2. lower-fma.f64N/A

      \[\leadsto \mathsf{fma}\left(\frac{3}{2}, x, \frac{1}{2} \cdot {\left(\sqrt{\mathsf{neg}\left(y\right)}\right)}^{2}\right) \]
    3. *-commutativeN/A

      \[\leadsto \mathsf{fma}\left(\frac{3}{2}, x, {\left(\sqrt{\mathsf{neg}\left(y\right)}\right)}^{2} \cdot \frac{1}{2}\right) \]
    4. lift-neg.f64N/A

      \[\leadsto \mathsf{fma}\left(\frac{3}{2}, x, {\left(\sqrt{-y}\right)}^{2} \cdot \frac{1}{2}\right) \]
    5. sqrt-pow2N/A

      \[\leadsto \mathsf{fma}\left(\frac{3}{2}, x, {\left(-y\right)}^{\left(\frac{2}{2}\right)} \cdot \frac{1}{2}\right) \]
    6. metadata-evalN/A

      \[\leadsto \mathsf{fma}\left(\frac{3}{2}, x, {\left(-y\right)}^{1} \cdot \frac{1}{2}\right) \]
    7. unpow1N/A

      \[\leadsto \mathsf{fma}\left(\frac{3}{2}, x, \left(-y\right) \cdot \frac{1}{2}\right) \]
    8. lower-*.f6453.3

      \[\leadsto \mathsf{fma}\left(1.5, x, \left(-y\right) \cdot 0.5\right) \]
  9. Applied rewrites53.3%

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

    \[\leadsto \frac{-1}{2} \cdot y \]
  11. Step-by-step derivation
    1. lower-*.f6425.7

      \[\leadsto -0.5 \cdot y \]
  12. Applied rewrites25.7%

    \[\leadsto -0.5 \cdot y \]
  13. Add Preprocessing

Reproduce

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