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

Percentage Accurate: 100.0% → 100.0%
Time: 2.4s
Alternatives: 7
Speedup: 1.2×

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}

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 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.2× speedup?

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

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

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

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

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

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

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

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

      \[\leadsto y + \left(1 \cdot x - \color{blue}{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. metadata-evalN/A

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

      \[\leadsto y + \left(\mathsf{neg}\left(-1 \cdot x\right)\right) \cdot \color{blue}{\left(1 - 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} \]
  4. Applied rewrites100.0%

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

Alternative 2: 83.7% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \left(x + y\right) - x \cdot y\\ \mathbf{if}\;t\_0 \leq -\infty \lor \neg \left(t\_0 \leq 4 \cdot 10^{+238}\right):\\ \;\;\;\;\left(-x\right) \cdot y\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(1, x, y\right)\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (let* ((t_0 (- (+ x y) (* x y))))
   (if (or (<= t_0 (- INFINITY)) (not (<= t_0 4e+238)))
     (* (- x) y)
     (fma 1.0 x y))))
double code(double x, double y) {
	double t_0 = (x + y) - (x * y);
	double tmp;
	if ((t_0 <= -((double) INFINITY)) || !(t_0 <= 4e+238)) {
		tmp = -x * y;
	} else {
		tmp = fma(1.0, x, y);
	}
	return tmp;
}
function code(x, y)
	t_0 = Float64(Float64(x + y) - Float64(x * y))
	tmp = 0.0
	if ((t_0 <= Float64(-Inf)) || !(t_0 <= 4e+238))
		tmp = Float64(Float64(-x) * y);
	else
		tmp = fma(1.0, x, y);
	end
	return tmp
end
code[x_, y_] := Block[{t$95$0 = N[(N[(x + y), $MachinePrecision] - N[(x * y), $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$0, (-Infinity)], N[Not[LessEqual[t$95$0, 4e+238]], $MachinePrecision]], N[((-x) * y), $MachinePrecision], N[(1.0 * x + y), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \left(x + y\right) - x \cdot y\\
\mathbf{if}\;t\_0 \leq -\infty \lor \neg \left(t\_0 \leq 4 \cdot 10^{+238}\right):\\
\;\;\;\;\left(-x\right) \cdot y\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (-.f64 (+.f64 x y) (*.f64 x y)) < -inf.0 or 4.0000000000000002e238 < (-.f64 (+.f64 x y) (*.f64 x y))

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{y \cdot \left(1 - x\right)} \]
    4. Step-by-step derivation
      1. Applied rewrites97.8%

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

        \[\leadsto -1 \cdot \color{blue}{\left(x \cdot y\right)} \]
      3. Step-by-step derivation
        1. Applied rewrites86.2%

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

        if -inf.0 < (-.f64 (+.f64 x y) (*.f64 x y)) < 4.0000000000000002e238

        1. Initial program 100.0%

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

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

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

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

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

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

            \[\leadsto y + \left(1 \cdot x - \color{blue}{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. metadata-evalN/A

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

            \[\leadsto y + \left(\mathsf{neg}\left(-1 \cdot x\right)\right) \cdot \color{blue}{\left(1 - 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} \]
        4. Applied rewrites100.0%

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

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

            \[\leadsto \mathsf{fma}\left(\color{blue}{1}, x, y\right) \]
        7. Recombined 2 regimes into one program.
        8. Final simplification85.0%

          \[\leadsto \begin{array}{l} \mathbf{if}\;\left(x + y\right) - x \cdot y \leq -\infty \lor \neg \left(\left(x + y\right) - x \cdot y \leq 4 \cdot 10^{+238}\right):\\ \;\;\;\;\left(-x\right) \cdot y\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(1, x, y\right)\\ \end{array} \]
        9. Add Preprocessing

        Alternative 3: 62.3% accurate, 0.5× speedup?

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

          1. Initial program 100.0%

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

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

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

            if -2.00000000000000003e-251 < (-.f64 (+.f64 x y) (*.f64 x y))

            1. Initial program 100.0%

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

              \[\leadsto \color{blue}{y \cdot \left(1 - x\right)} \]
            4. Step-by-step derivation
              1. Applied rewrites65.1%

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

            Alternative 4: 86.8% accurate, 0.6× speedup?

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

              1. Initial program 100.0%

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

                \[\leadsto \color{blue}{y \cdot \left(1 - x\right)} \]
              4. Step-by-step derivation
                1. Applied rewrites99.1%

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

                  \[\leadsto -1 \cdot \color{blue}{\left(x \cdot y\right)} \]
                3. Step-by-step derivation
                  1. Applied rewrites47.3%

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

                  if -9200 < y < 9.00000000000000057e-5

                  1. Initial program 100.0%

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

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

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

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

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

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

                      \[\leadsto y + \left(1 \cdot x - \color{blue}{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. metadata-evalN/A

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

                      \[\leadsto y + \left(\mathsf{neg}\left(-1 \cdot x\right)\right) \cdot \color{blue}{\left(1 - 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} \]
                  4. Applied rewrites100.0%

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

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

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

                    if 9.00000000000000057e-5 < y

                    1. Initial program 100.0%

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

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

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

                    Alternative 5: 38.0% accurate, 0.7× speedup?

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

                      1. Initial program 100.0%

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

                        \[\leadsto \color{blue}{x} \]
                      4. Step-by-step derivation
                        1. Applied rewrites36.2%

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

                        if -2.00000000000000003e-251 < (-.f64 (+.f64 x y) (*.f64 x y))

                        1. Initial program 100.0%

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

                          \[\leadsto \color{blue}{y} \]
                        4. Step-by-step derivation
                          1. Applied rewrites40.6%

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

                        Alternative 6: 75.0% accurate, 1.7× speedup?

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

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

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

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

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

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

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

                            \[\leadsto y + \left(1 \cdot x - \color{blue}{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. metadata-evalN/A

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

                            \[\leadsto y + \left(\mathsf{neg}\left(-1 \cdot x\right)\right) \cdot \color{blue}{\left(1 - 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} \]
                        4. Applied rewrites100.0%

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

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

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

                          Alternative 7: 38.7% accurate, 12.0× speedup?

                          \[\begin{array}{l} \\ x \end{array} \]
                          (FPCore (x y) :precision binary64 x)
                          double code(double x, double y) {
                          	return x;
                          }
                          
                          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
                          
                          public static double code(double x, double y) {
                          	return x;
                          }
                          
                          def code(x, y):
                          	return x
                          
                          function code(x, y)
                          	return x
                          end
                          
                          function tmp = code(x, y)
                          	tmp = x;
                          end
                          
                          code[x_, y_] := x
                          
                          \begin{array}{l}
                          
                          \\
                          x
                          \end{array}
                          
                          Derivation
                          1. Initial program 100.0%

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

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

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

                            Reproduce

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