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

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

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

Initial Program: 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. Applied rewrites100.0%

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

Alternative 2: 98.5% accurate, 0.7× speedup?

\[\begin{array}{l} [x, y] = \mathsf{sort}([x, y])\\ \\ \begin{array}{l} \mathbf{if}\;y \leq -430000000000:\\ \;\;\;\;\left(-x\right) \cdot y\\ \mathbf{elif}\;y \leq 5.5 \cdot 10^{-5}:\\ \;\;\;\;\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 -430000000000.0)
   (* (- x) y)
   (if (<= y 5.5e-5) (fma 1.0 x y) (* (- 1.0 x) y))))
assert(x < y);
double code(double x, double y) {
	double tmp;
	if (y <= -430000000000.0) {
		tmp = -x * y;
	} else if (y <= 5.5e-5) {
		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 <= -430000000000.0)
		tmp = Float64(Float64(-x) * y);
	elseif (y <= 5.5e-5)
		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, -430000000000.0], N[((-x) * y), $MachinePrecision], If[LessEqual[y, 5.5e-5], 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 -430000000000:\\
\;\;\;\;\left(-x\right) \cdot y\\

\mathbf{elif}\;y \leq 5.5 \cdot 10^{-5}:\\
\;\;\;\;\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 < -4.3e11

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{y \cdot \left(1 - x\right)} \]
    3. Step-by-step derivation
      1. *-lft-identityN/A

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

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

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

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

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

        \[\leadsto y + y \cdot \left(\mathsf{neg}\left(x\right)\right) \]
      7. distribute-rgt-neg-outN/A

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

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

        \[\leadsto y - \color{blue}{y \cdot x} \]
      10. *-commutativeN/A

        \[\leadsto y - x \cdot \color{blue}{y} \]
      11. lower--.f64N/A

        \[\leadsto y - \color{blue}{x \cdot y} \]
      12. *-commutativeN/A

        \[\leadsto y - y \cdot \color{blue}{x} \]
      13. lower-*.f6462.4

        \[\leadsto y - y \cdot \color{blue}{x} \]
    4. Applied rewrites62.4%

      \[\leadsto \color{blue}{y - y \cdot x} \]
    5. Taylor expanded in x around inf

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

        \[\leadsto \left(-1 \cdot x\right) \cdot y \]
      2. lower-*.f64N/A

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

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

        \[\leadsto \left(-x\right) \cdot y \]
    7. Applied rewrites26.5%

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

    if -4.3e11 < y < 5.5000000000000002e-5

    1. Initial program 100.0%

      \[\left(x + y\right) - x \cdot y \]
    2. Applied rewrites100.0%

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

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

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

      if 5.5000000000000002e-5 < y

      1. Initial program 100.0%

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

        \[\leadsto \color{blue}{y \cdot \left(1 - x\right)} \]
      3. Step-by-step derivation
        1. *-lft-identityN/A

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

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

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

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

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

          \[\leadsto y + y \cdot \left(\mathsf{neg}\left(x\right)\right) \]
        7. distribute-rgt-neg-outN/A

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

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

          \[\leadsto y - \color{blue}{y \cdot x} \]
        10. *-commutativeN/A

          \[\leadsto y - x \cdot \color{blue}{y} \]
        11. lower--.f64N/A

          \[\leadsto y - \color{blue}{x \cdot y} \]
        12. *-commutativeN/A

          \[\leadsto y - y \cdot \color{blue}{x} \]
        13. lower-*.f6462.4

          \[\leadsto y - y \cdot \color{blue}{x} \]
      4. Applied rewrites62.4%

        \[\leadsto \color{blue}{y - y \cdot x} \]
      5. Step-by-step derivation
        1. lift-*.f64N/A

          \[\leadsto y - y \cdot \color{blue}{x} \]
        2. lift--.f64N/A

          \[\leadsto y - \color{blue}{y \cdot x} \]
        3. *-commutativeN/A

          \[\leadsto y - x \cdot \color{blue}{y} \]
        4. fp-cancel-sub-sign-invN/A

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

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

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

          \[\leadsto \left(1 + -1 \cdot x\right) \cdot y \]
        8. lower-*.f64N/A

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

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

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

          \[\leadsto \left(1 - x\right) \cdot y \]
        12. lower--.f6462.4

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

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

    Alternative 3: 98.3% 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 -2 \cdot 10^{-295}:\\ \;\;\;\;\left(1 - y\right) \cdot x\\ \mathbf{else}:\\ \;\;\;\;y - y \cdot x\\ \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)) -2e-295) (* (- 1.0 y) x) (- y (* y x))))
    assert(x < y);
    double code(double x, double y) {
    	double tmp;
    	if (((x + y) - (x * y)) <= -2e-295) {
    		tmp = (1.0 - y) * x;
    	} else {
    		tmp = y - (y * x);
    	}
    	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)) <= (-2d-295)) then
            tmp = (1.0d0 - y) * x
        else
            tmp = y - (y * x)
        end if
        code = tmp
    end function
    
    assert x < y;
    public static double code(double x, double y) {
    	double tmp;
    	if (((x + y) - (x * y)) <= -2e-295) {
    		tmp = (1.0 - y) * x;
    	} else {
    		tmp = y - (y * x);
    	}
    	return tmp;
    }
    
    [x, y] = sort([x, y])
    def code(x, y):
    	tmp = 0
    	if ((x + y) - (x * y)) <= -2e-295:
    		tmp = (1.0 - y) * x
    	else:
    		tmp = y - (y * x)
    	return tmp
    
    x, y = sort([x, y])
    function code(x, y)
    	tmp = 0.0
    	if (Float64(Float64(x + y) - Float64(x * y)) <= -2e-295)
    		tmp = Float64(Float64(1.0 - y) * x);
    	else
    		tmp = Float64(y - Float64(y * x));
    	end
    	return tmp
    end
    
    x, y = num2cell(sort([x, y])){:}
    function tmp_2 = code(x, y)
    	tmp = 0.0;
    	if (((x + y) - (x * y)) <= -2e-295)
    		tmp = (1.0 - y) * x;
    	else
    		tmp = y - (y * x);
    	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], -2e-295], N[(N[(1.0 - y), $MachinePrecision] * x), $MachinePrecision], N[(y - N[(y * x), $MachinePrecision]), $MachinePrecision]]
    
    \begin{array}{l}
    [x, y] = \mathsf{sort}([x, y])\\
    \\
    \begin{array}{l}
    \mathbf{if}\;\left(x + y\right) - x \cdot y \leq -2 \cdot 10^{-295}:\\
    \;\;\;\;\left(1 - y\right) \cdot x\\
    
    \mathbf{else}:\\
    \;\;\;\;y - y \cdot x\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if (-.f64 (+.f64 x y) (*.f64 x y)) < -2.00000000000000012e-295

      1. Initial program 100.0%

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

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

          \[\leadsto x \cdot \frac{1 \cdot 1 - y \cdot y}{\color{blue}{1 + y}} \]
        2. sqr-neg-revN/A

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

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

          \[\leadsto x \cdot \frac{1 \cdot 1 - \left(-1 \cdot y\right) \cdot \left(-1 \cdot y\right)}{1 + y} \]
        5. sqr-neg-revN/A

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

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

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

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

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

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

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

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

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

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

          \[\leadsto 1 \cdot x + \left(\mathsf{neg}\left(y\right)\right) \cdot x \]
        16. fp-cancel-sub-signN/A

          \[\leadsto 1 \cdot x - \color{blue}{y \cdot x} \]
      4. Applied rewrites63.0%

        \[\leadsto \color{blue}{x - y \cdot x} \]
      5. Step-by-step derivation
        1. lift-*.f64N/A

          \[\leadsto x - y \cdot \color{blue}{x} \]
        2. lift--.f64N/A

          \[\leadsto x - \color{blue}{y \cdot x} \]
        3. fp-cancel-sub-sign-invN/A

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

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

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

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

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

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

          \[\leadsto \left(1 - y\right) \cdot x \]
        10. lower-*.f64N/A

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

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

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

      if -2.00000000000000012e-295 < (-.f64 (+.f64 x y) (*.f64 x y))

      1. Initial program 100.0%

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

        \[\leadsto \color{blue}{y \cdot \left(1 - x\right)} \]
      3. Step-by-step derivation
        1. *-lft-identityN/A

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

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

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

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

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

          \[\leadsto y + y \cdot \left(\mathsf{neg}\left(x\right)\right) \]
        7. distribute-rgt-neg-outN/A

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

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

          \[\leadsto y - \color{blue}{y \cdot x} \]
        10. *-commutativeN/A

          \[\leadsto y - x \cdot \color{blue}{y} \]
        11. lower--.f64N/A

          \[\leadsto y - \color{blue}{x \cdot y} \]
        12. *-commutativeN/A

          \[\leadsto y - y \cdot \color{blue}{x} \]
        13. lower-*.f6462.4

          \[\leadsto y - y \cdot \color{blue}{x} \]
      4. Applied rewrites62.4%

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

    Alternative 4: 98.3% 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 -2 \cdot 10^{-295}:\\ \;\;\;\;\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)) -2e-295) (* (- 1.0 y) x) (* (- 1.0 x) y)))
    assert(x < y);
    double code(double x, double y) {
    	double tmp;
    	if (((x + y) - (x * y)) <= -2e-295) {
    		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)) <= (-2d-295)) 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)) <= -2e-295) {
    		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)) <= -2e-295:
    		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)) <= -2e-295)
    		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)) <= -2e-295)
    		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], -2e-295], 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 -2 \cdot 10^{-295}:\\
    \;\;\;\;\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)) < -2.00000000000000012e-295

      1. Initial program 100.0%

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

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

          \[\leadsto x \cdot \frac{1 \cdot 1 - y \cdot y}{\color{blue}{1 + y}} \]
        2. sqr-neg-revN/A

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

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

          \[\leadsto x \cdot \frac{1 \cdot 1 - \left(-1 \cdot y\right) \cdot \left(-1 \cdot y\right)}{1 + y} \]
        5. sqr-neg-revN/A

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

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

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

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

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

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

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

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

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

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

          \[\leadsto 1 \cdot x + \left(\mathsf{neg}\left(y\right)\right) \cdot x \]
        16. fp-cancel-sub-signN/A

          \[\leadsto 1 \cdot x - \color{blue}{y \cdot x} \]
      4. Applied rewrites63.0%

        \[\leadsto \color{blue}{x - y \cdot x} \]
      5. Step-by-step derivation
        1. lift-*.f64N/A

          \[\leadsto x - y \cdot \color{blue}{x} \]
        2. lift--.f64N/A

          \[\leadsto x - \color{blue}{y \cdot x} \]
        3. fp-cancel-sub-sign-invN/A

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

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

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

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

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

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

          \[\leadsto \left(1 - y\right) \cdot x \]
        10. lower-*.f64N/A

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

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

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

      if -2.00000000000000012e-295 < (-.f64 (+.f64 x y) (*.f64 x y))

      1. Initial program 100.0%

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

        \[\leadsto \color{blue}{y \cdot \left(1 - x\right)} \]
      3. Step-by-step derivation
        1. *-lft-identityN/A

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

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

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

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

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

          \[\leadsto y + y \cdot \left(\mathsf{neg}\left(x\right)\right) \]
        7. distribute-rgt-neg-outN/A

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

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

          \[\leadsto y - \color{blue}{y \cdot x} \]
        10. *-commutativeN/A

          \[\leadsto y - x \cdot \color{blue}{y} \]
        11. lower--.f64N/A

          \[\leadsto y - \color{blue}{x \cdot y} \]
        12. *-commutativeN/A

          \[\leadsto y - y \cdot \color{blue}{x} \]
        13. lower-*.f6462.4

          \[\leadsto y - y \cdot \color{blue}{x} \]
      4. Applied rewrites62.4%

        \[\leadsto \color{blue}{y - y \cdot x} \]
      5. Step-by-step derivation
        1. lift-*.f64N/A

          \[\leadsto y - y \cdot \color{blue}{x} \]
        2. lift--.f64N/A

          \[\leadsto y - \color{blue}{y \cdot x} \]
        3. *-commutativeN/A

          \[\leadsto y - x \cdot \color{blue}{y} \]
        4. fp-cancel-sub-sign-invN/A

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

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

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

          \[\leadsto \left(1 + -1 \cdot x\right) \cdot y \]
        8. lower-*.f64N/A

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

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

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

          \[\leadsto \left(1 - x\right) \cdot y \]
        12. lower--.f6462.4

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

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

    Alternative 5: 86.7% 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(-x\right) \cdot y\\ \mathbf{if}\;t\_0 \leq -5 \cdot 10^{+303}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;t\_0 \leq 10^{+299}:\\ \;\;\;\;\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 (* (- x) y)))
       (if (<= t_0 -5e+303) t_1 (if (<= t_0 1e+299) (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 = -x * y;
    	double tmp;
    	if (t_0 <= -5e+303) {
    		tmp = t_1;
    	} else if (t_0 <= 1e+299) {
    		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(-x) * y)
    	tmp = 0.0
    	if (t_0 <= -5e+303)
    		tmp = t_1;
    	elseif (t_0 <= 1e+299)
    		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[((-x) * y), $MachinePrecision]}, If[LessEqual[t$95$0, -5e+303], t$95$1, If[LessEqual[t$95$0, 1e+299], 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(-x\right) \cdot y\\
    \mathbf{if}\;t\_0 \leq -5 \cdot 10^{+303}:\\
    \;\;\;\;t\_1\\
    
    \mathbf{elif}\;t\_0 \leq 10^{+299}:\\
    \;\;\;\;\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)) < -4.9999999999999997e303 or 1.0000000000000001e299 < (-.f64 (+.f64 x y) (*.f64 x y))

      1. Initial program 100.0%

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

        \[\leadsto \color{blue}{y \cdot \left(1 - x\right)} \]
      3. Step-by-step derivation
        1. *-lft-identityN/A

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

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

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

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

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

          \[\leadsto y + y \cdot \left(\mathsf{neg}\left(x\right)\right) \]
        7. distribute-rgt-neg-outN/A

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

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

          \[\leadsto y - \color{blue}{y \cdot x} \]
        10. *-commutativeN/A

          \[\leadsto y - x \cdot \color{blue}{y} \]
        11. lower--.f64N/A

          \[\leadsto y - \color{blue}{x \cdot y} \]
        12. *-commutativeN/A

          \[\leadsto y - y \cdot \color{blue}{x} \]
        13. lower-*.f6462.4

          \[\leadsto y - y \cdot \color{blue}{x} \]
      4. Applied rewrites62.4%

        \[\leadsto \color{blue}{y - y \cdot x} \]
      5. Taylor expanded in x around inf

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

          \[\leadsto \left(-1 \cdot x\right) \cdot y \]
        2. lower-*.f64N/A

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

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

          \[\leadsto \left(-x\right) \cdot y \]
      7. Applied rewrites26.5%

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

      if -4.9999999999999997e303 < (-.f64 (+.f64 x y) (*.f64 x y)) < 1.0000000000000001e299

      1. Initial program 100.0%

        \[\left(x + y\right) - x \cdot y \]
      2. Applied rewrites100.0%

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

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

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

      Alternative 6: 61.4% accurate, 0.7× speedup?

      \[\begin{array}{l} [x, y] = \mathsf{sort}([x, y])\\ \\ \begin{array}{l} t_0 := \left(-x\right) \cdot y\\ \mathbf{if}\;x \leq -1:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;x \leq 1:\\ \;\;\;\;y\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \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))) (if (<= x -1.0) t_0 (if (<= x 1.0) y t_0))))
      assert(x < y);
      double code(double x, double y) {
      	double t_0 = -x * y;
      	double tmp;
      	if (x <= -1.0) {
      		tmp = t_0;
      	} else if (x <= 1.0) {
      		tmp = y;
      	} else {
      		tmp = t_0;
      	}
      	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) :: tmp
          t_0 = -x * y
          if (x <= (-1.0d0)) then
              tmp = t_0
          else if (x <= 1.0d0) then
              tmp = y
          else
              tmp = t_0
          end if
          code = tmp
      end function
      
      assert x < y;
      public static double code(double x, double y) {
      	double t_0 = -x * y;
      	double tmp;
      	if (x <= -1.0) {
      		tmp = t_0;
      	} else if (x <= 1.0) {
      		tmp = y;
      	} else {
      		tmp = t_0;
      	}
      	return tmp;
      }
      
      [x, y] = sort([x, y])
      def code(x, y):
      	t_0 = -x * y
      	tmp = 0
      	if x <= -1.0:
      		tmp = t_0
      	elif x <= 1.0:
      		tmp = y
      	else:
      		tmp = t_0
      	return tmp
      
      x, y = sort([x, y])
      function code(x, y)
      	t_0 = Float64(Float64(-x) * y)
      	tmp = 0.0
      	if (x <= -1.0)
      		tmp = t_0;
      	elseif (x <= 1.0)
      		tmp = y;
      	else
      		tmp = t_0;
      	end
      	return tmp
      end
      
      x, y = num2cell(sort([x, y])){:}
      function tmp_2 = code(x, y)
      	t_0 = -x * y;
      	tmp = 0.0;
      	if (x <= -1.0)
      		tmp = t_0;
      	elseif (x <= 1.0)
      		tmp = y;
      	else
      		tmp = t_0;
      	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[((-x) * y), $MachinePrecision]}, If[LessEqual[x, -1.0], t$95$0, If[LessEqual[x, 1.0], y, t$95$0]]]
      
      \begin{array}{l}
      [x, y] = \mathsf{sort}([x, y])\\
      \\
      \begin{array}{l}
      t_0 := \left(-x\right) \cdot y\\
      \mathbf{if}\;x \leq -1:\\
      \;\;\;\;t\_0\\
      
      \mathbf{elif}\;x \leq 1:\\
      \;\;\;\;y\\
      
      \mathbf{else}:\\
      \;\;\;\;t\_0\\
      
      
      \end{array}
      \end{array}
      
      Derivation
      1. Split input into 2 regimes
      2. if x < -1 or 1 < x

        1. Initial program 100.0%

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

          \[\leadsto \color{blue}{y \cdot \left(1 - x\right)} \]
        3. Step-by-step derivation
          1. *-lft-identityN/A

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

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

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

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

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

            \[\leadsto y + y \cdot \left(\mathsf{neg}\left(x\right)\right) \]
          7. distribute-rgt-neg-outN/A

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

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

            \[\leadsto y - \color{blue}{y \cdot x} \]
          10. *-commutativeN/A

            \[\leadsto y - x \cdot \color{blue}{y} \]
          11. lower--.f64N/A

            \[\leadsto y - \color{blue}{x \cdot y} \]
          12. *-commutativeN/A

            \[\leadsto y - y \cdot \color{blue}{x} \]
          13. lower-*.f6462.4

            \[\leadsto y - y \cdot \color{blue}{x} \]
        4. Applied rewrites62.4%

          \[\leadsto \color{blue}{y - y \cdot x} \]
        5. Taylor expanded in x around inf

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

            \[\leadsto \left(-1 \cdot x\right) \cdot y \]
          2. lower-*.f64N/A

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

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

            \[\leadsto \left(-x\right) \cdot y \]
        7. Applied rewrites26.5%

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

        if -1 < x < 1

        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 rewrites38.6%

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

        Alternative 7: 38.6% accurate, 9.3× speedup?

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

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

          Reproduce

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