Data.Colour.RGBSpace.HSL:hsl from colour-2.3.3, A

Percentage Accurate: 100.0% → 100.0%
Time: 7.1s
Alternatives: 8
Speedup: 1.1×

Specification

?
\[\begin{array}{l} \\ \left(x + y\right) - x \cdot y \end{array} \]
(FPCore (x y) :precision binary64 (- (+ x y) (* x y)))
double code(double x, double y) {
	return (x + y) - (x * 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 = (x + y) - (x * y)
end function
public static double code(double x, double y) {
	return (x + y) - (x * y);
}
def code(x, y):
	return (x + y) - (x * y)
function code(x, y)
	return Float64(Float64(x + y) - Float64(x * y))
end
function tmp = code(x, y)
	tmp = (x + y) - (x * y);
end
code[x_, y_] := N[(N[(x + y), $MachinePrecision] - N[(x * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\left(x + y\right) - x \cdot y
\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 8 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: 100.0% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \left(x + y\right) - x \cdot y \end{array} \]
(FPCore (x y) :precision binary64 (- (+ x y) (* x y)))
double code(double x, double y) {
	return (x + y) - (x * 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 = (x + y) - (x * y)
end function
public static double code(double x, double y) {
	return (x + y) - (x * y);
}
def code(x, y):
	return (x + y) - (x * y)
function code(x, y)
	return Float64(Float64(x + y) - Float64(x * y))
end
function tmp = code(x, y)
	tmp = (x + y) - (x * y);
end
code[x_, y_] := N[(N[(x + y), $MachinePrecision] - N[(x * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\left(x + y\right) - x \cdot y
\end{array}

Alternative 1: 100.0% accurate, 1.1× speedup?

\[\begin{array}{l} [x, y] = \mathsf{sort}([x, y])\\ \\ \mathsf{fma}\left(1 - y, x, y\right) \end{array} \]
NOTE: x and y should be sorted in increasing order before calling this function.
(FPCore (x y) :precision binary64 (fma (- 1.0 y) x y))
assert(x < y);
double code(double x, double y) {
	return fma((1.0 - y), x, y);
}
x, y = sort([x, y])
function code(x, y)
	return fma(Float64(1.0 - y), x, y)
end
NOTE: x and y should be sorted in increasing order before calling this function.
code[x_, y_] := N[(N[(1.0 - y), $MachinePrecision] * x + y), $MachinePrecision]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\mathsf{fma}\left(1 - y, x, y\right)
\end{array}
Derivation
  1. Initial program 100.0%

    \[\left(x + y\right) - x \cdot y \]
  2. Step-by-step derivation
    1. lift-+.f64N/A

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

      \[\leadsto \left(x + y\right) - \color{blue}{x \cdot y} \]
    3. lift--.f64N/A

      \[\leadsto \color{blue}{\left(x + y\right) - x \cdot y} \]
    4. +-commutativeN/A

      \[\leadsto \color{blue}{\left(y + x\right)} - x \cdot y \]
    5. associate--l+N/A

      \[\leadsto \color{blue}{y + \left(x - x \cdot y\right)} \]
    6. *-lft-identityN/A

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

      \[\leadsto y + \left(1 \cdot x - \color{blue}{y \cdot x}\right) \]
    8. fp-cancel-sub-signN/A

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

      \[\leadsto y + \left(1 \cdot x + \color{blue}{\left(-1 \cdot y\right)} \cdot x\right) \]
    10. distribute-rgt-inN/A

      \[\leadsto y + \color{blue}{x \cdot \left(1 + -1 \cdot y\right)} \]
    11. *-lft-identityN/A

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

      \[\leadsto y + \left(\color{blue}{\left(\mathsf{neg}\left(-1\right)\right)} \cdot x\right) \cdot \left(1 + -1 \cdot y\right) \]
    13. distribute-lft-neg-outN/A

      \[\leadsto y + \color{blue}{\left(\mathsf{neg}\left(-1 \cdot x\right)\right)} \cdot \left(1 + -1 \cdot y\right) \]
    14. fp-cancel-sign-sub-invN/A

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

      \[\leadsto y + \left(\mathsf{neg}\left(-1 \cdot x\right)\right) \cdot \left(1 - \color{blue}{1} \cdot y\right) \]
    16. *-lft-identityN/A

      \[\leadsto y + \left(\mathsf{neg}\left(-1 \cdot x\right)\right) \cdot \left(1 - \color{blue}{y}\right) \]
    17. fp-cancel-sub-sign-invN/A

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

      \[\leadsto y - \color{blue}{\left(\mathsf{neg}\left(x\right)\right)} \cdot \left(1 - y\right) \]
    19. fp-cancel-sign-sub-invN/A

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

      \[\leadsto \color{blue}{x \cdot \left(1 - y\right) + y} \]
  3. Applied rewrites100.0%

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

Alternative 2: 98.9% accurate, 0.5× speedup?

\[\begin{array}{l} [x, y] = \mathsf{sort}([x, y])\\ \\ \begin{array}{l} \mathbf{if}\;\left(x + y\right) - x \cdot y \leq -1 \cdot 10^{-279}:\\ \;\;\;\;\left(1 - y\right) \cdot x\\ \mathbf{else}:\\ \;\;\;\;y - x \cdot y\\ \end{array} \end{array} \]
NOTE: x and y should be sorted in increasing order before calling this function.
(FPCore (x y)
 :precision binary64
 (if (<= (- (+ x y) (* x y)) -1e-279) (* (- 1.0 y) x) (- y (* x y))))
assert(x < y);
double code(double x, double y) {
	double tmp;
	if (((x + y) - (x * y)) <= -1e-279) {
		tmp = (1.0 - y) * x;
	} else {
		tmp = y - (x * y);
	}
	return tmp;
}
NOTE: x and y should be sorted in increasing order before calling this function.
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 + y) - (x * y)) <= (-1d-279)) then
        tmp = (1.0d0 - y) * x
    else
        tmp = y - (x * y)
    end if
    code = tmp
end function
assert x < y;
public static double code(double x, double y) {
	double tmp;
	if (((x + y) - (x * y)) <= -1e-279) {
		tmp = (1.0 - y) * x;
	} else {
		tmp = y - (x * y);
	}
	return tmp;
}
[x, y] = sort([x, y])
def code(x, y):
	tmp = 0
	if ((x + y) - (x * y)) <= -1e-279:
		tmp = (1.0 - y) * x
	else:
		tmp = y - (x * y)
	return tmp
x, y = sort([x, y])
function code(x, y)
	tmp = 0.0
	if (Float64(Float64(x + y) - Float64(x * y)) <= -1e-279)
		tmp = Float64(Float64(1.0 - y) * x);
	else
		tmp = Float64(y - Float64(x * y));
	end
	return tmp
end
x, y = num2cell(sort([x, y])){:}
function tmp_2 = code(x, y)
	tmp = 0.0;
	if (((x + y) - (x * y)) <= -1e-279)
		tmp = (1.0 - y) * x;
	else
		tmp = y - (x * y);
	end
	tmp_2 = tmp;
end
NOTE: x and y should be sorted in increasing order before calling this function.
code[x_, y_] := If[LessEqual[N[(N[(x + y), $MachinePrecision] - N[(x * y), $MachinePrecision]), $MachinePrecision], -1e-279], N[(N[(1.0 - y), $MachinePrecision] * x), $MachinePrecision], N[(y - N[(x * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;\left(x + y\right) - x \cdot y \leq -1 \cdot 10^{-279}:\\
\;\;\;\;\left(1 - y\right) \cdot x\\

\mathbf{else}:\\
\;\;\;\;y - x \cdot y\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (-.f64 (+.f64 x y) (*.f64 x y)) < -1.00000000000000006e-279

    1. Initial program 100.0%

      \[\left(x + y\right) - x \cdot y \]
    2. Step-by-step derivation
      1. lift-+.f64N/A

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

        \[\leadsto \left(x + y\right) - \color{blue}{x \cdot y} \]
      3. lift--.f64N/A

        \[\leadsto \color{blue}{\left(x + y\right) - x \cdot y} \]
      4. +-commutativeN/A

        \[\leadsto \color{blue}{\left(y + x\right)} - x \cdot y \]
      5. associate--l+N/A

        \[\leadsto \color{blue}{y + \left(x - x \cdot y\right)} \]
      6. *-lft-identityN/A

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

        \[\leadsto y + \left(1 \cdot x - \color{blue}{y \cdot x}\right) \]
      8. fp-cancel-sub-signN/A

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

        \[\leadsto y + \left(1 \cdot x + \color{blue}{\left(-1 \cdot y\right)} \cdot x\right) \]
      10. distribute-rgt-inN/A

        \[\leadsto y + \color{blue}{x \cdot \left(1 + -1 \cdot y\right)} \]
      11. *-lft-identityN/A

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

        \[\leadsto y + \left(\color{blue}{\left(\mathsf{neg}\left(-1\right)\right)} \cdot x\right) \cdot \left(1 + -1 \cdot y\right) \]
      13. distribute-lft-neg-outN/A

        \[\leadsto y + \color{blue}{\left(\mathsf{neg}\left(-1 \cdot x\right)\right)} \cdot \left(1 + -1 \cdot y\right) \]
      14. fp-cancel-sign-sub-invN/A

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

        \[\leadsto y + \left(\mathsf{neg}\left(-1 \cdot x\right)\right) \cdot \left(1 - \color{blue}{1} \cdot y\right) \]
      16. *-lft-identityN/A

        \[\leadsto y + \left(\mathsf{neg}\left(-1 \cdot x\right)\right) \cdot \left(1 - \color{blue}{y}\right) \]
      17. fp-cancel-sub-sign-invN/A

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

        \[\leadsto y - \color{blue}{\left(\mathsf{neg}\left(x\right)\right)} \cdot \left(1 - y\right) \]
      19. fp-cancel-sign-sub-invN/A

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

        \[\leadsto \color{blue}{x \cdot \left(1 - y\right) + y} \]
    3. Applied rewrites100.0%

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

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

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

        \[\leadsto x \cdot \left(1 - y\right) \]
      3. flip--N/A

        \[\leadsto x \cdot \left(1 - y\right) \]
      4. *-lft-identityN/A

        \[\leadsto x \cdot \left(1 - y\right) \]
      5. *-lft-identityN/A

        \[\leadsto x \cdot \left(1 - y\right) \]
      6. *-lft-identityN/A

        \[\leadsto x \cdot \left(1 - y\right) \]
      7. flip--N/A

        \[\leadsto x \cdot \left(1 - y\right) \]
      8. metadata-evalN/A

        \[\leadsto x \cdot \left(1 - y\right) \]
      9. fp-cancel-sign-sub-invN/A

        \[\leadsto x \cdot \left(1 - y\right) \]
      10. distribute-rgt-inN/A

        \[\leadsto x \cdot \left(1 - y\right) \]
      11. mul-1-negN/A

        \[\leadsto x \cdot \left(1 - y\right) \]
      12. fp-cancel-sub-signN/A

        \[\leadsto x \cdot \left(1 - y\right) \]
      13. *-lft-identityN/A

        \[\leadsto x \cdot \left(1 - y\right) \]
      14. *-commutativeN/A

        \[\leadsto x \cdot \left(1 - y\right) \]
      15. associate--l+N/A

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

        \[\leadsto x \cdot \left(1 - y\right) \]
      17. *-commutativeN/A

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

        \[\leadsto \left(1 - y\right) \cdot \color{blue}{x} \]
      19. lift--.f6498.7

        \[\leadsto \left(1 - y\right) \cdot x \]
    6. Applied rewrites98.7%

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

    if -1.00000000000000006e-279 < (-.f64 (+.f64 x y) (*.f64 x y))

    1. Initial program 100.0%

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

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

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

    Alternative 3: 98.5% accurate, 0.5× speedup?

    \[\begin{array}{l} [x, y] = \mathsf{sort}([x, y])\\ \\ \begin{array}{l} \mathbf{if}\;\left(x + y\right) - x \cdot y \leq -1 \cdot 10^{-279}:\\ \;\;\;\;\left(1 - y\right) \cdot x\\ \mathbf{else}:\\ \;\;\;\;\left(1 - x\right) \cdot y\\ \end{array} \end{array} \]
    NOTE: x and y should be sorted in increasing order before calling this function.
    (FPCore (x y)
     :precision binary64
     (if (<= (- (+ x y) (* x y)) -1e-279) (* (- 1.0 y) x) (* (- 1.0 x) y)))
    assert(x < y);
    double code(double x, double y) {
    	double tmp;
    	if (((x + y) - (x * y)) <= -1e-279) {
    		tmp = (1.0 - y) * x;
    	} else {
    		tmp = (1.0 - x) * y;
    	}
    	return tmp;
    }
    
    NOTE: x and y should be sorted in increasing order before calling this function.
    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 + y) - (x * y)) <= (-1d-279)) then
            tmp = (1.0d0 - y) * x
        else
            tmp = (1.0d0 - x) * y
        end if
        code = tmp
    end function
    
    assert x < y;
    public static double code(double x, double y) {
    	double tmp;
    	if (((x + y) - (x * y)) <= -1e-279) {
    		tmp = (1.0 - y) * x;
    	} else {
    		tmp = (1.0 - x) * y;
    	}
    	return tmp;
    }
    
    [x, y] = sort([x, y])
    def code(x, y):
    	tmp = 0
    	if ((x + y) - (x * y)) <= -1e-279:
    		tmp = (1.0 - y) * x
    	else:
    		tmp = (1.0 - x) * y
    	return tmp
    
    x, y = sort([x, y])
    function code(x, y)
    	tmp = 0.0
    	if (Float64(Float64(x + y) - Float64(x * y)) <= -1e-279)
    		tmp = Float64(Float64(1.0 - y) * x);
    	else
    		tmp = Float64(Float64(1.0 - x) * y);
    	end
    	return tmp
    end
    
    x, y = num2cell(sort([x, y])){:}
    function tmp_2 = code(x, y)
    	tmp = 0.0;
    	if (((x + y) - (x * y)) <= -1e-279)
    		tmp = (1.0 - y) * x;
    	else
    		tmp = (1.0 - x) * y;
    	end
    	tmp_2 = tmp;
    end
    
    NOTE: x and y should be sorted in increasing order before calling this function.
    code[x_, y_] := If[LessEqual[N[(N[(x + y), $MachinePrecision] - N[(x * y), $MachinePrecision]), $MachinePrecision], -1e-279], N[(N[(1.0 - y), $MachinePrecision] * x), $MachinePrecision], N[(N[(1.0 - x), $MachinePrecision] * y), $MachinePrecision]]
    
    \begin{array}{l}
    [x, y] = \mathsf{sort}([x, y])\\
    \\
    \begin{array}{l}
    \mathbf{if}\;\left(x + y\right) - x \cdot y \leq -1 \cdot 10^{-279}:\\
    \;\;\;\;\left(1 - y\right) \cdot x\\
    
    \mathbf{else}:\\
    \;\;\;\;\left(1 - x\right) \cdot y\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if (-.f64 (+.f64 x y) (*.f64 x y)) < -1.00000000000000006e-279

      1. Initial program 100.0%

        \[\left(x + y\right) - x \cdot y \]
      2. Step-by-step derivation
        1. lift-+.f64N/A

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

          \[\leadsto \left(x + y\right) - \color{blue}{x \cdot y} \]
        3. lift--.f64N/A

          \[\leadsto \color{blue}{\left(x + y\right) - x \cdot y} \]
        4. +-commutativeN/A

          \[\leadsto \color{blue}{\left(y + x\right)} - x \cdot y \]
        5. associate--l+N/A

          \[\leadsto \color{blue}{y + \left(x - x \cdot y\right)} \]
        6. *-lft-identityN/A

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

          \[\leadsto y + \left(1 \cdot x - \color{blue}{y \cdot x}\right) \]
        8. fp-cancel-sub-signN/A

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

          \[\leadsto y + \left(1 \cdot x + \color{blue}{\left(-1 \cdot y\right)} \cdot x\right) \]
        10. distribute-rgt-inN/A

          \[\leadsto y + \color{blue}{x \cdot \left(1 + -1 \cdot y\right)} \]
        11. *-lft-identityN/A

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

          \[\leadsto y + \left(\color{blue}{\left(\mathsf{neg}\left(-1\right)\right)} \cdot x\right) \cdot \left(1 + -1 \cdot y\right) \]
        13. distribute-lft-neg-outN/A

          \[\leadsto y + \color{blue}{\left(\mathsf{neg}\left(-1 \cdot x\right)\right)} \cdot \left(1 + -1 \cdot y\right) \]
        14. fp-cancel-sign-sub-invN/A

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

          \[\leadsto y + \left(\mathsf{neg}\left(-1 \cdot x\right)\right) \cdot \left(1 - \color{blue}{1} \cdot y\right) \]
        16. *-lft-identityN/A

          \[\leadsto y + \left(\mathsf{neg}\left(-1 \cdot x\right)\right) \cdot \left(1 - \color{blue}{y}\right) \]
        17. fp-cancel-sub-sign-invN/A

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

          \[\leadsto y - \color{blue}{\left(\mathsf{neg}\left(x\right)\right)} \cdot \left(1 - y\right) \]
        19. fp-cancel-sign-sub-invN/A

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

          \[\leadsto \color{blue}{x \cdot \left(1 - y\right) + y} \]
      3. Applied rewrites100.0%

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

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

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

          \[\leadsto x \cdot \left(1 - y\right) \]
        3. flip--N/A

          \[\leadsto x \cdot \left(1 - y\right) \]
        4. *-lft-identityN/A

          \[\leadsto x \cdot \left(1 - y\right) \]
        5. *-lft-identityN/A

          \[\leadsto x \cdot \left(1 - y\right) \]
        6. *-lft-identityN/A

          \[\leadsto x \cdot \left(1 - y\right) \]
        7. flip--N/A

          \[\leadsto x \cdot \left(1 - y\right) \]
        8. metadata-evalN/A

          \[\leadsto x \cdot \left(1 - y\right) \]
        9. fp-cancel-sign-sub-invN/A

          \[\leadsto x \cdot \left(1 - y\right) \]
        10. distribute-rgt-inN/A

          \[\leadsto x \cdot \left(1 - y\right) \]
        11. mul-1-negN/A

          \[\leadsto x \cdot \left(1 - y\right) \]
        12. fp-cancel-sub-signN/A

          \[\leadsto x \cdot \left(1 - y\right) \]
        13. *-lft-identityN/A

          \[\leadsto x \cdot \left(1 - y\right) \]
        14. *-commutativeN/A

          \[\leadsto x \cdot \left(1 - y\right) \]
        15. associate--l+N/A

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

          \[\leadsto x \cdot \left(1 - y\right) \]
        17. *-commutativeN/A

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

          \[\leadsto \left(1 - y\right) \cdot \color{blue}{x} \]
        19. lift--.f6498.7

          \[\leadsto \left(1 - y\right) \cdot x \]
      6. Applied rewrites98.7%

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

      if -1.00000000000000006e-279 < (-.f64 (+.f64 x y) (*.f64 x y))

      1. Initial program 100.0%

        \[\left(x + y\right) - x \cdot y \]
      2. Step-by-step derivation
        1. lift-+.f64N/A

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

          \[\leadsto \left(x + y\right) - \color{blue}{x \cdot y} \]
        3. lift--.f64N/A

          \[\leadsto \color{blue}{\left(x + y\right) - x \cdot y} \]
        4. +-commutativeN/A

          \[\leadsto \color{blue}{\left(y + x\right)} - x \cdot y \]
        5. associate--l+N/A

          \[\leadsto \color{blue}{y + \left(x - x \cdot y\right)} \]
        6. *-lft-identityN/A

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

          \[\leadsto y + \left(1 \cdot x - \color{blue}{y \cdot x}\right) \]
        8. fp-cancel-sub-signN/A

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

          \[\leadsto y + \left(1 \cdot x + \color{blue}{\left(-1 \cdot y\right)} \cdot x\right) \]
        10. distribute-rgt-inN/A

          \[\leadsto y + \color{blue}{x \cdot \left(1 + -1 \cdot y\right)} \]
        11. *-lft-identityN/A

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

          \[\leadsto y + \left(\color{blue}{\left(\mathsf{neg}\left(-1\right)\right)} \cdot x\right) \cdot \left(1 + -1 \cdot y\right) \]
        13. distribute-lft-neg-outN/A

          \[\leadsto y + \color{blue}{\left(\mathsf{neg}\left(-1 \cdot x\right)\right)} \cdot \left(1 + -1 \cdot y\right) \]
        14. fp-cancel-sign-sub-invN/A

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

          \[\leadsto y + \left(\mathsf{neg}\left(-1 \cdot x\right)\right) \cdot \left(1 - \color{blue}{1} \cdot y\right) \]
        16. *-lft-identityN/A

          \[\leadsto y + \left(\mathsf{neg}\left(-1 \cdot x\right)\right) \cdot \left(1 - \color{blue}{y}\right) \]
        17. fp-cancel-sub-sign-invN/A

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

          \[\leadsto y - \color{blue}{\left(\mathsf{neg}\left(x\right)\right)} \cdot \left(1 - y\right) \]
        19. fp-cancel-sign-sub-invN/A

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

          \[\leadsto \color{blue}{x \cdot \left(1 - y\right) + y} \]
      3. Applied rewrites100.0%

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

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

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

          \[\leadsto y \cdot \left(1 + -1 \cdot x\right) \]
        3. flip--N/A

          \[\leadsto y \cdot \left(1 + -1 \cdot x\right) \]
        4. *-lft-identityN/A

          \[\leadsto y \cdot \left(1 + -1 \cdot x\right) \]
        5. *-lft-identityN/A

          \[\leadsto y \cdot \left(1 + -1 \cdot x\right) \]
        6. *-lft-identityN/A

          \[\leadsto y \cdot \left(1 + -1 \cdot x\right) \]
        7. flip--N/A

          \[\leadsto y \cdot \left(1 + -1 \cdot x\right) \]
        8. metadata-evalN/A

          \[\leadsto y \cdot \left(1 + -1 \cdot x\right) \]
        9. fp-cancel-sign-sub-invN/A

          \[\leadsto y \cdot \left(1 + -1 \cdot x\right) \]
        10. distribute-rgt-inN/A

          \[\leadsto y \cdot \left(1 + -1 \cdot x\right) \]
        11. mul-1-negN/A

          \[\leadsto y \cdot \left(1 + -1 \cdot x\right) \]
        12. fp-cancel-sub-signN/A

          \[\leadsto y \cdot \left(1 + -1 \cdot x\right) \]
        13. *-lft-identityN/A

          \[\leadsto y \cdot \left(1 + -1 \cdot x\right) \]
        14. *-commutativeN/A

          \[\leadsto y \cdot \left(1 + -1 \cdot x\right) \]
        15. associate--l+N/A

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

          \[\leadsto y \cdot \left(1 + -1 \cdot x\right) \]
      6. Applied rewrites98.3%

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

    Alternative 4: 98.5% accurate, 0.7× speedup?

    \[\begin{array}{l} [x, y] = \mathsf{sort}([x, y])\\ \\ \begin{array}{l} \mathbf{if}\;y \leq -160000000:\\ \;\;\;\;\left(-y\right) \cdot x\\ \mathbf{elif}\;y \leq 1:\\ \;\;\;\;\mathsf{fma}\left(1, x, y\right)\\ \mathbf{else}:\\ \;\;\;\;\left(1 - x\right) \cdot y\\ \end{array} \end{array} \]
    NOTE: x and y should be sorted in increasing order before calling this function.
    (FPCore (x y)
     :precision binary64
     (if (<= y -160000000.0)
       (* (- y) x)
       (if (<= y 1.0) (fma 1.0 x y) (* (- 1.0 x) y))))
    assert(x < y);
    double code(double x, double y) {
    	double tmp;
    	if (y <= -160000000.0) {
    		tmp = -y * x;
    	} else if (y <= 1.0) {
    		tmp = fma(1.0, x, y);
    	} else {
    		tmp = (1.0 - x) * y;
    	}
    	return tmp;
    }
    
    x, y = sort([x, y])
    function code(x, y)
    	tmp = 0.0
    	if (y <= -160000000.0)
    		tmp = Float64(Float64(-y) * x);
    	elseif (y <= 1.0)
    		tmp = fma(1.0, x, y);
    	else
    		tmp = Float64(Float64(1.0 - x) * y);
    	end
    	return tmp
    end
    
    NOTE: x and y should be sorted in increasing order before calling this function.
    code[x_, y_] := If[LessEqual[y, -160000000.0], N[((-y) * x), $MachinePrecision], If[LessEqual[y, 1.0], N[(1.0 * x + y), $MachinePrecision], N[(N[(1.0 - x), $MachinePrecision] * y), $MachinePrecision]]]
    
    \begin{array}{l}
    [x, y] = \mathsf{sort}([x, y])\\
    \\
    \begin{array}{l}
    \mathbf{if}\;y \leq -160000000:\\
    \;\;\;\;\left(-y\right) \cdot x\\
    
    \mathbf{elif}\;y \leq 1:\\
    \;\;\;\;\mathsf{fma}\left(1, x, y\right)\\
    
    \mathbf{else}:\\
    \;\;\;\;\left(1 - x\right) \cdot y\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 3 regimes
    2. if y < -1.6e8

      1. Initial program 100.0%

        \[\left(x + y\right) - x \cdot y \]
      2. Step-by-step derivation
        1. lift-+.f64N/A

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

          \[\leadsto \left(x + y\right) - \color{blue}{x \cdot y} \]
        3. lift--.f64N/A

          \[\leadsto \color{blue}{\left(x + y\right) - x \cdot y} \]
        4. +-commutativeN/A

          \[\leadsto \color{blue}{\left(y + x\right)} - x \cdot y \]
        5. associate--l+N/A

          \[\leadsto \color{blue}{y + \left(x - x \cdot y\right)} \]
        6. *-lft-identityN/A

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

          \[\leadsto y + \left(1 \cdot x - \color{blue}{y \cdot x}\right) \]
        8. fp-cancel-sub-signN/A

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

          \[\leadsto y + \left(1 \cdot x + \color{blue}{\left(-1 \cdot y\right)} \cdot x\right) \]
        10. distribute-rgt-inN/A

          \[\leadsto y + \color{blue}{x \cdot \left(1 + -1 \cdot y\right)} \]
        11. *-lft-identityN/A

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

          \[\leadsto y + \left(\color{blue}{\left(\mathsf{neg}\left(-1\right)\right)} \cdot x\right) \cdot \left(1 + -1 \cdot y\right) \]
        13. distribute-lft-neg-outN/A

          \[\leadsto y + \color{blue}{\left(\mathsf{neg}\left(-1 \cdot x\right)\right)} \cdot \left(1 + -1 \cdot y\right) \]
        14. fp-cancel-sign-sub-invN/A

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

          \[\leadsto y + \left(\mathsf{neg}\left(-1 \cdot x\right)\right) \cdot \left(1 - \color{blue}{1} \cdot y\right) \]
        16. *-lft-identityN/A

          \[\leadsto y + \left(\mathsf{neg}\left(-1 \cdot x\right)\right) \cdot \left(1 - \color{blue}{y}\right) \]
        17. fp-cancel-sub-sign-invN/A

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

          \[\leadsto y - \color{blue}{\left(\mathsf{neg}\left(x\right)\right)} \cdot \left(1 - y\right) \]
        19. fp-cancel-sign-sub-invN/A

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

          \[\leadsto \color{blue}{x \cdot \left(1 - y\right) + y} \]
      3. Applied rewrites100.0%

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

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

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

          \[\leadsto x \cdot \left(1 - y\right) \]
        3. flip--N/A

          \[\leadsto x \cdot \left(1 - y\right) \]
        4. *-lft-identityN/A

          \[\leadsto x \cdot \left(1 - y\right) \]
        5. *-lft-identityN/A

          \[\leadsto x \cdot \left(1 - y\right) \]
        6. *-lft-identityN/A

          \[\leadsto x \cdot \left(1 - y\right) \]
        7. flip--N/A

          \[\leadsto x \cdot \left(1 - y\right) \]
        8. metadata-evalN/A

          \[\leadsto x \cdot \left(1 - y\right) \]
        9. fp-cancel-sign-sub-invN/A

          \[\leadsto x \cdot \left(1 - y\right) \]
        10. distribute-rgt-inN/A

          \[\leadsto x \cdot \left(1 - y\right) \]
        11. mul-1-negN/A

          \[\leadsto x \cdot \left(1 - y\right) \]
        12. fp-cancel-sub-signN/A

          \[\leadsto x \cdot \left(1 - y\right) \]
        13. *-lft-identityN/A

          \[\leadsto x \cdot \left(1 - y\right) \]
        14. *-commutativeN/A

          \[\leadsto x \cdot \left(1 - y\right) \]
        15. associate--l+N/A

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

          \[\leadsto x \cdot \left(1 - y\right) \]
        17. *-commutativeN/A

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

          \[\leadsto \left(1 - y\right) \cdot \color{blue}{x} \]
        19. lift--.f64100.0

          \[\leadsto \left(1 - y\right) \cdot x \]
      6. Applied rewrites100.0%

        \[\leadsto \color{blue}{\left(1 - y\right) \cdot x} \]
      7. Taylor expanded in y around inf

        \[\leadsto \left(-1 \cdot y\right) \cdot x \]
      8. Step-by-step derivation
        1. mul-1-negN/A

          \[\leadsto \left(\mathsf{neg}\left(y\right)\right) \cdot x \]
        2. lower-neg.f6498.6

          \[\leadsto \left(-y\right) \cdot x \]
      9. Applied rewrites98.6%

        \[\leadsto \left(-y\right) \cdot x \]

      if -1.6e8 < y < 1

      1. Initial program 100.0%

        \[\left(x + y\right) - x \cdot y \]
      2. Step-by-step derivation
        1. lift-+.f64N/A

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

          \[\leadsto \left(x + y\right) - \color{blue}{x \cdot y} \]
        3. lift--.f64N/A

          \[\leadsto \color{blue}{\left(x + y\right) - x \cdot y} \]
        4. +-commutativeN/A

          \[\leadsto \color{blue}{\left(y + x\right)} - x \cdot y \]
        5. associate--l+N/A

          \[\leadsto \color{blue}{y + \left(x - x \cdot y\right)} \]
        6. *-lft-identityN/A

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

          \[\leadsto y + \left(1 \cdot x - \color{blue}{y \cdot x}\right) \]
        8. fp-cancel-sub-signN/A

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

          \[\leadsto y + \left(1 \cdot x + \color{blue}{\left(-1 \cdot y\right)} \cdot x\right) \]
        10. distribute-rgt-inN/A

          \[\leadsto y + \color{blue}{x \cdot \left(1 + -1 \cdot y\right)} \]
        11. *-lft-identityN/A

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

          \[\leadsto y + \left(\color{blue}{\left(\mathsf{neg}\left(-1\right)\right)} \cdot x\right) \cdot \left(1 + -1 \cdot y\right) \]
        13. distribute-lft-neg-outN/A

          \[\leadsto y + \color{blue}{\left(\mathsf{neg}\left(-1 \cdot x\right)\right)} \cdot \left(1 + -1 \cdot y\right) \]
        14. fp-cancel-sign-sub-invN/A

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

          \[\leadsto y + \left(\mathsf{neg}\left(-1 \cdot x\right)\right) \cdot \left(1 - \color{blue}{1} \cdot y\right) \]
        16. *-lft-identityN/A

          \[\leadsto y + \left(\mathsf{neg}\left(-1 \cdot x\right)\right) \cdot \left(1 - \color{blue}{y}\right) \]
        17. fp-cancel-sub-sign-invN/A

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

          \[\leadsto y - \color{blue}{\left(\mathsf{neg}\left(x\right)\right)} \cdot \left(1 - y\right) \]
        19. fp-cancel-sign-sub-invN/A

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

          \[\leadsto \color{blue}{x \cdot \left(1 - y\right) + y} \]
      3. Applied rewrites100.0%

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

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

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

        if 1 < y

        1. Initial program 100.0%

          \[\left(x + y\right) - x \cdot y \]
        2. Step-by-step derivation
          1. lift-+.f64N/A

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

            \[\leadsto \left(x + y\right) - \color{blue}{x \cdot y} \]
          3. lift--.f64N/A

            \[\leadsto \color{blue}{\left(x + y\right) - x \cdot y} \]
          4. +-commutativeN/A

            \[\leadsto \color{blue}{\left(y + x\right)} - x \cdot y \]
          5. associate--l+N/A

            \[\leadsto \color{blue}{y + \left(x - x \cdot y\right)} \]
          6. *-lft-identityN/A

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

            \[\leadsto y + \left(1 \cdot x - \color{blue}{y \cdot x}\right) \]
          8. fp-cancel-sub-signN/A

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

            \[\leadsto y + \left(1 \cdot x + \color{blue}{\left(-1 \cdot y\right)} \cdot x\right) \]
          10. distribute-rgt-inN/A

            \[\leadsto y + \color{blue}{x \cdot \left(1 + -1 \cdot y\right)} \]
          11. *-lft-identityN/A

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

            \[\leadsto y + \left(\color{blue}{\left(\mathsf{neg}\left(-1\right)\right)} \cdot x\right) \cdot \left(1 + -1 \cdot y\right) \]
          13. distribute-lft-neg-outN/A

            \[\leadsto y + \color{blue}{\left(\mathsf{neg}\left(-1 \cdot x\right)\right)} \cdot \left(1 + -1 \cdot y\right) \]
          14. fp-cancel-sign-sub-invN/A

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

            \[\leadsto y + \left(\mathsf{neg}\left(-1 \cdot x\right)\right) \cdot \left(1 - \color{blue}{1} \cdot y\right) \]
          16. *-lft-identityN/A

            \[\leadsto y + \left(\mathsf{neg}\left(-1 \cdot x\right)\right) \cdot \left(1 - \color{blue}{y}\right) \]
          17. fp-cancel-sub-sign-invN/A

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

            \[\leadsto y - \color{blue}{\left(\mathsf{neg}\left(x\right)\right)} \cdot \left(1 - y\right) \]
          19. fp-cancel-sign-sub-invN/A

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

            \[\leadsto \color{blue}{x \cdot \left(1 - y\right) + y} \]
        3. Applied rewrites100.0%

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

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

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

            \[\leadsto y \cdot \left(1 + -1 \cdot x\right) \]
          3. flip--N/A

            \[\leadsto y \cdot \left(1 + -1 \cdot x\right) \]
          4. *-lft-identityN/A

            \[\leadsto y \cdot \left(1 + -1 \cdot x\right) \]
          5. *-lft-identityN/A

            \[\leadsto y \cdot \left(1 + -1 \cdot x\right) \]
          6. *-lft-identityN/A

            \[\leadsto y \cdot \left(1 + -1 \cdot x\right) \]
          7. flip--N/A

            \[\leadsto y \cdot \left(1 + -1 \cdot x\right) \]
          8. metadata-evalN/A

            \[\leadsto y \cdot \left(1 + -1 \cdot x\right) \]
          9. fp-cancel-sign-sub-invN/A

            \[\leadsto y \cdot \left(1 + -1 \cdot x\right) \]
          10. distribute-rgt-inN/A

            \[\leadsto y \cdot \left(1 + -1 \cdot x\right) \]
          11. mul-1-negN/A

            \[\leadsto y \cdot \left(1 + -1 \cdot x\right) \]
          12. fp-cancel-sub-signN/A

            \[\leadsto y \cdot \left(1 + -1 \cdot x\right) \]
          13. *-lft-identityN/A

            \[\leadsto y \cdot \left(1 + -1 \cdot x\right) \]
          14. *-commutativeN/A

            \[\leadsto y \cdot \left(1 + -1 \cdot x\right) \]
          15. associate--l+N/A

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

            \[\leadsto y \cdot \left(1 + -1 \cdot x\right) \]
        6. Applied rewrites99.5%

          \[\leadsto \color{blue}{\left(1 - x\right) \cdot y} \]
      6. Recombined 3 regimes into one program.
      7. Add Preprocessing

      Alternative 5: 86.9% accurate, 0.3× speedup?

      \[\begin{array}{l} [x, y] = \mathsf{sort}([x, y])\\ \\ \begin{array}{l} t_0 := \left(x + y\right) - x \cdot y\\ t_1 := \left(-y\right) \cdot x\\ \mathbf{if}\;t\_0 \leq -1 \cdot 10^{+304}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;t\_0 \leq 10^{+308}:\\ \;\;\;\;\mathsf{fma}\left(1, x, y\right)\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
      NOTE: x and y should be sorted in increasing order before calling this function.
      (FPCore (x y)
       :precision binary64
       (let* ((t_0 (- (+ x y) (* x y))) (t_1 (* (- y) x)))
         (if (<= t_0 -1e+304) t_1 (if (<= t_0 1e+308) (fma 1.0 x y) t_1))))
      assert(x < y);
      double code(double x, double y) {
      	double t_0 = (x + y) - (x * y);
      	double t_1 = -y * x;
      	double tmp;
      	if (t_0 <= -1e+304) {
      		tmp = t_1;
      	} else if (t_0 <= 1e+308) {
      		tmp = fma(1.0, x, y);
      	} else {
      		tmp = t_1;
      	}
      	return tmp;
      }
      
      x, y = sort([x, y])
      function code(x, y)
      	t_0 = Float64(Float64(x + y) - Float64(x * y))
      	t_1 = Float64(Float64(-y) * x)
      	tmp = 0.0
      	if (t_0 <= -1e+304)
      		tmp = t_1;
      	elseif (t_0 <= 1e+308)
      		tmp = fma(1.0, x, y);
      	else
      		tmp = t_1;
      	end
      	return tmp
      end
      
      NOTE: x and y should be sorted in increasing order before calling this function.
      code[x_, y_] := Block[{t$95$0 = N[(N[(x + y), $MachinePrecision] - N[(x * y), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[((-y) * x), $MachinePrecision]}, If[LessEqual[t$95$0, -1e+304], t$95$1, If[LessEqual[t$95$0, 1e+308], N[(1.0 * x + y), $MachinePrecision], t$95$1]]]]
      
      \begin{array}{l}
      [x, y] = \mathsf{sort}([x, y])\\
      \\
      \begin{array}{l}
      t_0 := \left(x + y\right) - x \cdot y\\
      t_1 := \left(-y\right) \cdot x\\
      \mathbf{if}\;t\_0 \leq -1 \cdot 10^{+304}:\\
      \;\;\;\;t\_1\\
      
      \mathbf{elif}\;t\_0 \leq 10^{+308}:\\
      \;\;\;\;\mathsf{fma}\left(1, x, y\right)\\
      
      \mathbf{else}:\\
      \;\;\;\;t\_1\\
      
      
      \end{array}
      \end{array}
      
      Derivation
      1. Split input into 2 regimes
      2. if (-.f64 (+.f64 x y) (*.f64 x y)) < -9.9999999999999994e303 or 1e308 < (-.f64 (+.f64 x y) (*.f64 x y))

        1. Initial program 100.0%

          \[\left(x + y\right) - x \cdot y \]
        2. Step-by-step derivation
          1. lift-+.f64N/A

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

            \[\leadsto \left(x + y\right) - \color{blue}{x \cdot y} \]
          3. lift--.f64N/A

            \[\leadsto \color{blue}{\left(x + y\right) - x \cdot y} \]
          4. +-commutativeN/A

            \[\leadsto \color{blue}{\left(y + x\right)} - x \cdot y \]
          5. associate--l+N/A

            \[\leadsto \color{blue}{y + \left(x - x \cdot y\right)} \]
          6. *-lft-identityN/A

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

            \[\leadsto y + \left(1 \cdot x - \color{blue}{y \cdot x}\right) \]
          8. fp-cancel-sub-signN/A

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

            \[\leadsto y + \left(1 \cdot x + \color{blue}{\left(-1 \cdot y\right)} \cdot x\right) \]
          10. distribute-rgt-inN/A

            \[\leadsto y + \color{blue}{x \cdot \left(1 + -1 \cdot y\right)} \]
          11. *-lft-identityN/A

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

            \[\leadsto y + \left(\color{blue}{\left(\mathsf{neg}\left(-1\right)\right)} \cdot x\right) \cdot \left(1 + -1 \cdot y\right) \]
          13. distribute-lft-neg-outN/A

            \[\leadsto y + \color{blue}{\left(\mathsf{neg}\left(-1 \cdot x\right)\right)} \cdot \left(1 + -1 \cdot y\right) \]
          14. fp-cancel-sign-sub-invN/A

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

            \[\leadsto y + \left(\mathsf{neg}\left(-1 \cdot x\right)\right) \cdot \left(1 - \color{blue}{1} \cdot y\right) \]
          16. *-lft-identityN/A

            \[\leadsto y + \left(\mathsf{neg}\left(-1 \cdot x\right)\right) \cdot \left(1 - \color{blue}{y}\right) \]
          17. fp-cancel-sub-sign-invN/A

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

            \[\leadsto y - \color{blue}{\left(\mathsf{neg}\left(x\right)\right)} \cdot \left(1 - y\right) \]
          19. fp-cancel-sign-sub-invN/A

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

            \[\leadsto \color{blue}{x \cdot \left(1 - y\right) + y} \]
        3. Applied rewrites100.0%

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

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

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

            \[\leadsto x \cdot \left(1 - y\right) \]
          3. flip--N/A

            \[\leadsto x \cdot \left(1 - y\right) \]
          4. *-lft-identityN/A

            \[\leadsto x \cdot \left(1 - y\right) \]
          5. *-lft-identityN/A

            \[\leadsto x \cdot \left(1 - y\right) \]
          6. *-lft-identityN/A

            \[\leadsto x \cdot \left(1 - y\right) \]
          7. flip--N/A

            \[\leadsto x \cdot \left(1 - y\right) \]
          8. metadata-evalN/A

            \[\leadsto x \cdot \left(1 - y\right) \]
          9. fp-cancel-sign-sub-invN/A

            \[\leadsto x \cdot \left(1 - y\right) \]
          10. distribute-rgt-inN/A

            \[\leadsto x \cdot \left(1 - y\right) \]
          11. mul-1-negN/A

            \[\leadsto x \cdot \left(1 - y\right) \]
          12. fp-cancel-sub-signN/A

            \[\leadsto x \cdot \left(1 - y\right) \]
          13. *-lft-identityN/A

            \[\leadsto x \cdot \left(1 - y\right) \]
          14. *-commutativeN/A

            \[\leadsto x \cdot \left(1 - y\right) \]
          15. associate--l+N/A

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

            \[\leadsto x \cdot \left(1 - y\right) \]
          17. *-commutativeN/A

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

            \[\leadsto \left(1 - y\right) \cdot \color{blue}{x} \]
          19. lift--.f6499.9

            \[\leadsto \left(1 - y\right) \cdot x \]
        6. Applied rewrites99.9%

          \[\leadsto \color{blue}{\left(1 - y\right) \cdot x} \]
        7. Taylor expanded in y around inf

          \[\leadsto \left(-1 \cdot y\right) \cdot x \]
        8. Step-by-step derivation
          1. mul-1-negN/A

            \[\leadsto \left(\mathsf{neg}\left(y\right)\right) \cdot x \]
          2. lower-neg.f6497.4

            \[\leadsto \left(-y\right) \cdot x \]
        9. Applied rewrites97.4%

          \[\leadsto \left(-y\right) \cdot x \]

        if -9.9999999999999994e303 < (-.f64 (+.f64 x y) (*.f64 x y)) < 1e308

        1. Initial program 100.0%

          \[\left(x + y\right) - x \cdot y \]
        2. Step-by-step derivation
          1. lift-+.f64N/A

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

            \[\leadsto \left(x + y\right) - \color{blue}{x \cdot y} \]
          3. lift--.f64N/A

            \[\leadsto \color{blue}{\left(x + y\right) - x \cdot y} \]
          4. +-commutativeN/A

            \[\leadsto \color{blue}{\left(y + x\right)} - x \cdot y \]
          5. associate--l+N/A

            \[\leadsto \color{blue}{y + \left(x - x \cdot y\right)} \]
          6. *-lft-identityN/A

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

            \[\leadsto y + \left(1 \cdot x - \color{blue}{y \cdot x}\right) \]
          8. fp-cancel-sub-signN/A

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

            \[\leadsto y + \left(1 \cdot x + \color{blue}{\left(-1 \cdot y\right)} \cdot x\right) \]
          10. distribute-rgt-inN/A

            \[\leadsto y + \color{blue}{x \cdot \left(1 + -1 \cdot y\right)} \]
          11. *-lft-identityN/A

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

            \[\leadsto y + \left(\color{blue}{\left(\mathsf{neg}\left(-1\right)\right)} \cdot x\right) \cdot \left(1 + -1 \cdot y\right) \]
          13. distribute-lft-neg-outN/A

            \[\leadsto y + \color{blue}{\left(\mathsf{neg}\left(-1 \cdot x\right)\right)} \cdot \left(1 + -1 \cdot y\right) \]
          14. fp-cancel-sign-sub-invN/A

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

            \[\leadsto y + \left(\mathsf{neg}\left(-1 \cdot x\right)\right) \cdot \left(1 - \color{blue}{1} \cdot y\right) \]
          16. *-lft-identityN/A

            \[\leadsto y + \left(\mathsf{neg}\left(-1 \cdot x\right)\right) \cdot \left(1 - \color{blue}{y}\right) \]
          17. fp-cancel-sub-sign-invN/A

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

            \[\leadsto y - \color{blue}{\left(\mathsf{neg}\left(x\right)\right)} \cdot \left(1 - y\right) \]
          19. fp-cancel-sign-sub-invN/A

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

            \[\leadsto \color{blue}{x \cdot \left(1 - y\right) + y} \]
        3. Applied rewrites100.0%

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

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

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

        Alternative 6: 86.0% accurate, 0.2× speedup?

        \[\begin{array}{l} [x, y] = \mathsf{sort}([x, y])\\ \\ \begin{array}{l} t_0 := \left(x + y\right) - x \cdot y\\ t_1 := \left(-y\right) \cdot x\\ \mathbf{if}\;t\_0 \leq -1 \cdot 10^{+304}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;t\_0 \leq -1 \cdot 10^{-279}:\\ \;\;\;\;x\\ \mathbf{elif}\;t\_0 \leq 10^{+308}:\\ \;\;\;\;y\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
        NOTE: x and y should be sorted in increasing order before calling this function.
        (FPCore (x y)
         :precision binary64
         (let* ((t_0 (- (+ x y) (* x y))) (t_1 (* (- y) x)))
           (if (<= t_0 -1e+304)
             t_1
             (if (<= t_0 -1e-279) x (if (<= t_0 1e+308) y t_1)))))
        assert(x < y);
        double code(double x, double y) {
        	double t_0 = (x + y) - (x * y);
        	double t_1 = -y * x;
        	double tmp;
        	if (t_0 <= -1e+304) {
        		tmp = t_1;
        	} else if (t_0 <= -1e-279) {
        		tmp = x;
        	} else if (t_0 <= 1e+308) {
        		tmp = y;
        	} else {
        		tmp = t_1;
        	}
        	return tmp;
        }
        
        NOTE: x and y should be sorted in increasing order before calling this function.
        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) :: t_0
            real(8) :: t_1
            real(8) :: tmp
            t_0 = (x + y) - (x * y)
            t_1 = -y * x
            if (t_0 <= (-1d+304)) then
                tmp = t_1
            else if (t_0 <= (-1d-279)) then
                tmp = x
            else if (t_0 <= 1d+308) then
                tmp = y
            else
                tmp = t_1
            end if
            code = tmp
        end function
        
        assert x < y;
        public static double code(double x, double y) {
        	double t_0 = (x + y) - (x * y);
        	double t_1 = -y * x;
        	double tmp;
        	if (t_0 <= -1e+304) {
        		tmp = t_1;
        	} else if (t_0 <= -1e-279) {
        		tmp = x;
        	} else if (t_0 <= 1e+308) {
        		tmp = y;
        	} else {
        		tmp = t_1;
        	}
        	return tmp;
        }
        
        [x, y] = sort([x, y])
        def code(x, y):
        	t_0 = (x + y) - (x * y)
        	t_1 = -y * x
        	tmp = 0
        	if t_0 <= -1e+304:
        		tmp = t_1
        	elif t_0 <= -1e-279:
        		tmp = x
        	elif t_0 <= 1e+308:
        		tmp = y
        	else:
        		tmp = t_1
        	return tmp
        
        x, y = sort([x, y])
        function code(x, y)
        	t_0 = Float64(Float64(x + y) - Float64(x * y))
        	t_1 = Float64(Float64(-y) * x)
        	tmp = 0.0
        	if (t_0 <= -1e+304)
        		tmp = t_1;
        	elseif (t_0 <= -1e-279)
        		tmp = x;
        	elseif (t_0 <= 1e+308)
        		tmp = y;
        	else
        		tmp = t_1;
        	end
        	return tmp
        end
        
        x, y = num2cell(sort([x, y])){:}
        function tmp_2 = code(x, y)
        	t_0 = (x + y) - (x * y);
        	t_1 = -y * x;
        	tmp = 0.0;
        	if (t_0 <= -1e+304)
        		tmp = t_1;
        	elseif (t_0 <= -1e-279)
        		tmp = x;
        	elseif (t_0 <= 1e+308)
        		tmp = y;
        	else
        		tmp = t_1;
        	end
        	tmp_2 = tmp;
        end
        
        NOTE: x and y should be sorted in increasing order before calling this function.
        code[x_, y_] := Block[{t$95$0 = N[(N[(x + y), $MachinePrecision] - N[(x * y), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[((-y) * x), $MachinePrecision]}, If[LessEqual[t$95$0, -1e+304], t$95$1, If[LessEqual[t$95$0, -1e-279], x, If[LessEqual[t$95$0, 1e+308], y, t$95$1]]]]]
        
        \begin{array}{l}
        [x, y] = \mathsf{sort}([x, y])\\
        \\
        \begin{array}{l}
        t_0 := \left(x + y\right) - x \cdot y\\
        t_1 := \left(-y\right) \cdot x\\
        \mathbf{if}\;t\_0 \leq -1 \cdot 10^{+304}:\\
        \;\;\;\;t\_1\\
        
        \mathbf{elif}\;t\_0 \leq -1 \cdot 10^{-279}:\\
        \;\;\;\;x\\
        
        \mathbf{elif}\;t\_0 \leq 10^{+308}:\\
        \;\;\;\;y\\
        
        \mathbf{else}:\\
        \;\;\;\;t\_1\\
        
        
        \end{array}
        \end{array}
        
        Derivation
        1. Split input into 3 regimes
        2. if (-.f64 (+.f64 x y) (*.f64 x y)) < -9.9999999999999994e303 or 1e308 < (-.f64 (+.f64 x y) (*.f64 x y))

          1. Initial program 100.0%

            \[\left(x + y\right) - x \cdot y \]
          2. Step-by-step derivation
            1. lift-+.f64N/A

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

              \[\leadsto \left(x + y\right) - \color{blue}{x \cdot y} \]
            3. lift--.f64N/A

              \[\leadsto \color{blue}{\left(x + y\right) - x \cdot y} \]
            4. +-commutativeN/A

              \[\leadsto \color{blue}{\left(y + x\right)} - x \cdot y \]
            5. associate--l+N/A

              \[\leadsto \color{blue}{y + \left(x - x \cdot y\right)} \]
            6. *-lft-identityN/A

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

              \[\leadsto y + \left(1 \cdot x - \color{blue}{y \cdot x}\right) \]
            8. fp-cancel-sub-signN/A

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

              \[\leadsto y + \left(1 \cdot x + \color{blue}{\left(-1 \cdot y\right)} \cdot x\right) \]
            10. distribute-rgt-inN/A

              \[\leadsto y + \color{blue}{x \cdot \left(1 + -1 \cdot y\right)} \]
            11. *-lft-identityN/A

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

              \[\leadsto y + \left(\color{blue}{\left(\mathsf{neg}\left(-1\right)\right)} \cdot x\right) \cdot \left(1 + -1 \cdot y\right) \]
            13. distribute-lft-neg-outN/A

              \[\leadsto y + \color{blue}{\left(\mathsf{neg}\left(-1 \cdot x\right)\right)} \cdot \left(1 + -1 \cdot y\right) \]
            14. fp-cancel-sign-sub-invN/A

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

              \[\leadsto y + \left(\mathsf{neg}\left(-1 \cdot x\right)\right) \cdot \left(1 - \color{blue}{1} \cdot y\right) \]
            16. *-lft-identityN/A

              \[\leadsto y + \left(\mathsf{neg}\left(-1 \cdot x\right)\right) \cdot \left(1 - \color{blue}{y}\right) \]
            17. fp-cancel-sub-sign-invN/A

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

              \[\leadsto y - \color{blue}{\left(\mathsf{neg}\left(x\right)\right)} \cdot \left(1 - y\right) \]
            19. fp-cancel-sign-sub-invN/A

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

              \[\leadsto \color{blue}{x \cdot \left(1 - y\right) + y} \]
          3. Applied rewrites100.0%

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

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

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

              \[\leadsto x \cdot \left(1 - y\right) \]
            3. flip--N/A

              \[\leadsto x \cdot \left(1 - y\right) \]
            4. *-lft-identityN/A

              \[\leadsto x \cdot \left(1 - y\right) \]
            5. *-lft-identityN/A

              \[\leadsto x \cdot \left(1 - y\right) \]
            6. *-lft-identityN/A

              \[\leadsto x \cdot \left(1 - y\right) \]
            7. flip--N/A

              \[\leadsto x \cdot \left(1 - y\right) \]
            8. metadata-evalN/A

              \[\leadsto x \cdot \left(1 - y\right) \]
            9. fp-cancel-sign-sub-invN/A

              \[\leadsto x \cdot \left(1 - y\right) \]
            10. distribute-rgt-inN/A

              \[\leadsto x \cdot \left(1 - y\right) \]
            11. mul-1-negN/A

              \[\leadsto x \cdot \left(1 - y\right) \]
            12. fp-cancel-sub-signN/A

              \[\leadsto x \cdot \left(1 - y\right) \]
            13. *-lft-identityN/A

              \[\leadsto x \cdot \left(1 - y\right) \]
            14. *-commutativeN/A

              \[\leadsto x \cdot \left(1 - y\right) \]
            15. associate--l+N/A

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

              \[\leadsto x \cdot \left(1 - y\right) \]
            17. *-commutativeN/A

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

              \[\leadsto \left(1 - y\right) \cdot \color{blue}{x} \]
            19. lift--.f6499.9

              \[\leadsto \left(1 - y\right) \cdot x \]
          6. Applied rewrites99.9%

            \[\leadsto \color{blue}{\left(1 - y\right) \cdot x} \]
          7. Taylor expanded in y around inf

            \[\leadsto \left(-1 \cdot y\right) \cdot x \]
          8. Step-by-step derivation
            1. mul-1-negN/A

              \[\leadsto \left(\mathsf{neg}\left(y\right)\right) \cdot x \]
            2. lower-neg.f6497.4

              \[\leadsto \left(-y\right) \cdot x \]
          9. Applied rewrites97.4%

            \[\leadsto \left(-y\right) \cdot x \]

          if -9.9999999999999994e303 < (-.f64 (+.f64 x y) (*.f64 x y)) < -1.00000000000000006e-279

          1. Initial program 100.0%

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

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

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

            if -1.00000000000000006e-279 < (-.f64 (+.f64 x y) (*.f64 x y)) < 1e308

            1. Initial program 100.0%

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

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

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

            Alternative 7: 74.4% accurate, 0.7× speedup?

            \[\begin{array}{l} [x, y] = \mathsf{sort}([x, y])\\ \\ \begin{array}{l} \mathbf{if}\;\left(x + y\right) - x \cdot y \leq -1 \cdot 10^{-279}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y\\ \end{array} \end{array} \]
            NOTE: x and y should be sorted in increasing order before calling this function.
            (FPCore (x y) :precision binary64 (if (<= (- (+ x y) (* x y)) -1e-279) x y))
            assert(x < y);
            double code(double x, double y) {
            	double tmp;
            	if (((x + y) - (x * y)) <= -1e-279) {
            		tmp = x;
            	} else {
            		tmp = y;
            	}
            	return tmp;
            }
            
            NOTE: x and y should be sorted in increasing order before calling this function.
            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 + y) - (x * y)) <= (-1d-279)) then
                    tmp = x
                else
                    tmp = y
                end if
                code = tmp
            end function
            
            assert x < y;
            public static double code(double x, double y) {
            	double tmp;
            	if (((x + y) - (x * y)) <= -1e-279) {
            		tmp = x;
            	} else {
            		tmp = y;
            	}
            	return tmp;
            }
            
            [x, y] = sort([x, y])
            def code(x, y):
            	tmp = 0
            	if ((x + y) - (x * y)) <= -1e-279:
            		tmp = x
            	else:
            		tmp = y
            	return tmp
            
            x, y = sort([x, y])
            function code(x, y)
            	tmp = 0.0
            	if (Float64(Float64(x + y) - Float64(x * y)) <= -1e-279)
            		tmp = x;
            	else
            		tmp = y;
            	end
            	return tmp
            end
            
            x, y = num2cell(sort([x, y])){:}
            function tmp_2 = code(x, y)
            	tmp = 0.0;
            	if (((x + y) - (x * y)) <= -1e-279)
            		tmp = x;
            	else
            		tmp = y;
            	end
            	tmp_2 = tmp;
            end
            
            NOTE: x and y should be sorted in increasing order before calling this function.
            code[x_, y_] := If[LessEqual[N[(N[(x + y), $MachinePrecision] - N[(x * y), $MachinePrecision]), $MachinePrecision], -1e-279], x, y]
            
            \begin{array}{l}
            [x, y] = \mathsf{sort}([x, y])\\
            \\
            \begin{array}{l}
            \mathbf{if}\;\left(x + y\right) - x \cdot y \leq -1 \cdot 10^{-279}:\\
            \;\;\;\;x\\
            
            \mathbf{else}:\\
            \;\;\;\;y\\
            
            
            \end{array}
            \end{array}
            
            Derivation
            1. Split input into 2 regimes
            2. if (-.f64 (+.f64 x y) (*.f64 x y)) < -1.00000000000000006e-279

              1. Initial program 100.0%

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

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

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

                if -1.00000000000000006e-279 < (-.f64 (+.f64 x y) (*.f64 x y))

                1. Initial program 100.0%

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

                  \[\leadsto \color{blue}{y} \]
                3. Step-by-step derivation
                  1. Applied rewrites74.8%

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

                Alternative 8: 37.3% accurate, 9.3× speedup?

                \[\begin{array}{l} [x, y] = \mathsf{sort}([x, y])\\ \\ x \end{array} \]
                NOTE: x and y should be sorted in increasing order before calling this function.
                (FPCore (x y) :precision binary64 x)
                assert(x < y);
                double code(double x, double y) {
                	return x;
                }
                
                NOTE: x and y should be sorted in increasing order before calling this function.
                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
                end function
                
                assert x < y;
                public static double code(double x, double y) {
                	return x;
                }
                
                [x, y] = sort([x, y])
                def code(x, y):
                	return x
                
                x, y = sort([x, y])
                function code(x, y)
                	return x
                end
                
                x, y = num2cell(sort([x, y])){:}
                function tmp = code(x, y)
                	tmp = x;
                end
                
                NOTE: x and y should be sorted in increasing order before calling this function.
                code[x_, y_] := x
                
                \begin{array}{l}
                [x, y] = \mathsf{sort}([x, y])\\
                \\
                x
                \end{array}
                
                Derivation
                1. Initial program 100.0%

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

                  \[\leadsto \color{blue}{x} \]
                3. Step-by-step derivation
                  1. Applied rewrites37.3%

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

                  Reproduce

                  ?
                  herbie shell --seed 2025112 
                  (FPCore (x y)
                    :name "Data.Colour.RGBSpace.HSL:hsl from colour-2.3.3, A"
                    :precision binary64
                    (- (+ x y) (* x y)))