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

Percentage Accurate: 100.0% → 100.0%
Time: 6.8s
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);
}
real(8) function code(x, y)
    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);
}
real(8) function code(x, y)
    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(y, 1 - x, x\right) \end{array} \]
(FPCore (x y) :precision binary64 (fma y (- 1.0 x) x))
double code(double x, double y) {
	return fma(y, (1.0 - x), x);
}
function code(x, y)
	return fma(y, Float64(1.0 - x), x)
end
code[x_, y_] := N[(y * N[(1.0 - x), $MachinePrecision] + x), $MachinePrecision]
\begin{array}{l}

\\
\mathsf{fma}\left(y, 1 - x, x\right)
\end{array}
Derivation
  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 + x \cdot \left(1 - y\right)} \]
  4. Step-by-step derivation
    1. distribute-rgt-out--N/A

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \mathsf{fma}\left(y, 1 + \color{blue}{\left(\mathsf{neg}\left(x\right)\right)}, x\right) \]
    13. sub-negN/A

      \[\leadsto \mathsf{fma}\left(y, \color{blue}{1 - x}, x\right) \]
    14. lower--.f64100.0

      \[\leadsto \mathsf{fma}\left(y, \color{blue}{1 - x}, x\right) \]
  5. Applied rewrites100.0%

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

Alternative 2: 86.0% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \left(x + y\right) - x \cdot y\\ t_1 := x \cdot \left(-y\right)\\ \mathbf{if}\;t\_0 \leq -2 \cdot 10^{+295}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;t\_0 \leq 2 \cdot 10^{+291}:\\ \;\;\;\;\mathsf{fma}\left(y, 1, x\right)\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (let* ((t_0 (- (+ x y) (* x y))) (t_1 (* x (- y))))
   (if (<= t_0 -2e+295) t_1 (if (<= t_0 2e+291) (fma y 1.0 x) t_1))))
double code(double x, double y) {
	double t_0 = (x + y) - (x * y);
	double t_1 = x * -y;
	double tmp;
	if (t_0 <= -2e+295) {
		tmp = t_1;
	} else if (t_0 <= 2e+291) {
		tmp = fma(y, 1.0, x);
	} else {
		tmp = t_1;
	}
	return tmp;
}
function code(x, y)
	t_0 = Float64(Float64(x + y) - Float64(x * y))
	t_1 = Float64(x * Float64(-y))
	tmp = 0.0
	if (t_0 <= -2e+295)
		tmp = t_1;
	elseif (t_0 <= 2e+291)
		tmp = fma(y, 1.0, x);
	else
		tmp = t_1;
	end
	return tmp
end
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, -2e+295], t$95$1, If[LessEqual[t$95$0, 2e+291], N[(y * 1.0 + x), $MachinePrecision], t$95$1]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \left(x + y\right) - x \cdot y\\
t_1 := x \cdot \left(-y\right)\\
\mathbf{if}\;t\_0 \leq -2 \cdot 10^{+295}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;t\_0 \leq 2 \cdot 10^{+291}:\\
\;\;\;\;\mathsf{fma}\left(y, 1, x\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)) < -2e295 or 1.9999999999999999e291 < (-.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. distribute-rgt-out--N/A

        \[\leadsto \color{blue}{1 \cdot y - x \cdot y} \]
      2. *-lft-identityN/A

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

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

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

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

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

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

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

      if -2e295 < (-.f64 (+.f64 x y) (*.f64 x y)) < 1.9999999999999999e291

      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 + x \cdot \left(1 - y\right)} \]
      4. Step-by-step derivation
        1. distribute-rgt-out--N/A

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

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

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

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

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

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

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

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

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

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

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

          \[\leadsto \mathsf{fma}\left(y, 1 + \color{blue}{\left(\mathsf{neg}\left(x\right)\right)}, x\right) \]
        13. sub-negN/A

          \[\leadsto \mathsf{fma}\left(y, \color{blue}{1 - x}, x\right) \]
        14. lower--.f64100.0

          \[\leadsto \mathsf{fma}\left(y, \color{blue}{1 - x}, x\right) \]
      5. Applied rewrites100.0%

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

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

          \[\leadsto \mathsf{fma}\left(y, 1, x\right) \]
      8. Recombined 2 regimes into one program.
      9. Final simplification90.1%

        \[\leadsto \begin{array}{l} \mathbf{if}\;\left(x + y\right) - x \cdot y \leq -2 \cdot 10^{+295}:\\ \;\;\;\;x \cdot \left(-y\right)\\ \mathbf{elif}\;\left(x + y\right) - x \cdot y \leq 2 \cdot 10^{+291}:\\ \;\;\;\;\mathsf{fma}\left(y, 1, x\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(-y\right)\\ \end{array} \]
      10. Add Preprocessing

      Alternative 3: 61.7% accurate, 0.5× speedup?

      \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\left(x + y\right) - x \cdot y \leq -4 \cdot 10^{-278}:\\ \;\;\;\;\mathsf{fma}\left(-y, x, x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(-y, x, y\right)\\ \end{array} \end{array} \]
      (FPCore (x y)
       :precision binary64
       (if (<= (- (+ x y) (* x y)) -4e-278) (fma (- y) x x) (fma (- y) x y)))
      double code(double x, double y) {
      	double tmp;
      	if (((x + y) - (x * y)) <= -4e-278) {
      		tmp = fma(-y, x, x);
      	} else {
      		tmp = fma(-y, x, y);
      	}
      	return tmp;
      }
      
      function code(x, y)
      	tmp = 0.0
      	if (Float64(Float64(x + y) - Float64(x * y)) <= -4e-278)
      		tmp = fma(Float64(-y), x, x);
      	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], -4e-278], N[((-y) * x + x), $MachinePrecision], N[((-y) * x + y), $MachinePrecision]]
      
      \begin{array}{l}
      
      \\
      \begin{array}{l}
      \mathbf{if}\;\left(x + y\right) - x \cdot y \leq -4 \cdot 10^{-278}:\\
      \;\;\;\;\mathsf{fma}\left(-y, x, x\right)\\
      
      \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)) < -3.99999999999999975e-278

        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 \cdot \left(1 - y\right)} \]
        4. Step-by-step derivation
          1. distribute-lft-out--N/A

            \[\leadsto \color{blue}{x \cdot 1 - x \cdot y} \]
          2. *-rgt-identityN/A

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

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

            \[\leadsto x - \color{blue}{y \cdot x} \]
          5. lower-*.f6471.1

            \[\leadsto x - \color{blue}{y \cdot x} \]
        5. Applied rewrites71.1%

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

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

          if -3.99999999999999975e-278 < (-.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. distribute-rgt-out--N/A

              \[\leadsto \color{blue}{1 \cdot y - x \cdot y} \]
            2. *-lft-identityN/A

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

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

              \[\leadsto y - \color{blue}{y \cdot x} \]
            5. lower-*.f6465.3

              \[\leadsto y - \color{blue}{y \cdot x} \]
          5. Applied rewrites65.3%

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

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

          Alternative 4: 61.7% accurate, 0.5× speedup?

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

            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 \cdot \left(1 - y\right)} \]
            4. Step-by-step derivation
              1. distribute-lft-out--N/A

                \[\leadsto \color{blue}{x \cdot 1 - x \cdot y} \]
              2. *-rgt-identityN/A

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

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

                \[\leadsto x - \color{blue}{y \cdot x} \]
              5. lower-*.f6471.1

                \[\leadsto x - \color{blue}{y \cdot x} \]
            5. Applied rewrites71.1%

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

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

              if -3.99999999999999975e-278 < (-.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. distribute-rgt-out--N/A

                  \[\leadsto \color{blue}{1 \cdot y - x \cdot y} \]
                2. *-lft-identityN/A

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

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

                  \[\leadsto y - \color{blue}{y \cdot x} \]
                5. lower-*.f6465.3

                  \[\leadsto y - \color{blue}{y \cdot x} \]
              5. Applied rewrites65.3%

                \[\leadsto \color{blue}{y - y \cdot x} \]
            7. Recombined 2 regimes into one program.
            8. Final simplification68.2%

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

            Alternative 5: 61.7% accurate, 0.5× speedup?

            \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\left(x + y\right) - x \cdot y \leq -4 \cdot 10^{-278}:\\ \;\;\;\;x - x \cdot y\\ \mathbf{else}:\\ \;\;\;\;y - x \cdot y\\ \end{array} \end{array} \]
            (FPCore (x y)
             :precision binary64
             (if (<= (- (+ x y) (* x y)) -4e-278) (- x (* x y)) (- y (* x y))))
            double code(double x, double y) {
            	double tmp;
            	if (((x + y) - (x * y)) <= -4e-278) {
            		tmp = x - (x * y);
            	} else {
            		tmp = y - (x * y);
            	}
            	return tmp;
            }
            
            real(8) function code(x, y)
                real(8), intent (in) :: x
                real(8), intent (in) :: y
                real(8) :: tmp
                if (((x + y) - (x * y)) <= (-4d-278)) then
                    tmp = x - (x * y)
                else
                    tmp = y - (x * y)
                end if
                code = tmp
            end function
            
            public static double code(double x, double y) {
            	double tmp;
            	if (((x + y) - (x * y)) <= -4e-278) {
            		tmp = x - (x * y);
            	} else {
            		tmp = y - (x * y);
            	}
            	return tmp;
            }
            
            def code(x, y):
            	tmp = 0
            	if ((x + y) - (x * y)) <= -4e-278:
            		tmp = x - (x * y)
            	else:
            		tmp = y - (x * y)
            	return tmp
            
            function code(x, y)
            	tmp = 0.0
            	if (Float64(Float64(x + y) - Float64(x * y)) <= -4e-278)
            		tmp = Float64(x - Float64(x * y));
            	else
            		tmp = Float64(y - Float64(x * y));
            	end
            	return tmp
            end
            
            function tmp_2 = code(x, y)
            	tmp = 0.0;
            	if (((x + y) - (x * y)) <= -4e-278)
            		tmp = x - (x * y);
            	else
            		tmp = y - (x * y);
            	end
            	tmp_2 = tmp;
            end
            
            code[x_, y_] := If[LessEqual[N[(N[(x + y), $MachinePrecision] - N[(x * y), $MachinePrecision]), $MachinePrecision], -4e-278], N[(x - N[(x * y), $MachinePrecision]), $MachinePrecision], N[(y - N[(x * y), $MachinePrecision]), $MachinePrecision]]
            
            \begin{array}{l}
            
            \\
            \begin{array}{l}
            \mathbf{if}\;\left(x + y\right) - x \cdot y \leq -4 \cdot 10^{-278}:\\
            \;\;\;\;x - x \cdot y\\
            
            \mathbf{else}:\\
            \;\;\;\;y - x \cdot y\\
            
            
            \end{array}
            \end{array}
            
            Derivation
            1. Split input into 2 regimes
            2. if (-.f64 (+.f64 x y) (*.f64 x y)) < -3.99999999999999975e-278

              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 \cdot \left(1 - y\right)} \]
              4. Step-by-step derivation
                1. distribute-lft-out--N/A

                  \[\leadsto \color{blue}{x \cdot 1 - x \cdot y} \]
                2. *-rgt-identityN/A

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

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

                  \[\leadsto x - \color{blue}{y \cdot x} \]
                5. lower-*.f6471.1

                  \[\leadsto x - \color{blue}{y \cdot x} \]
              5. Applied rewrites71.1%

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

              if -3.99999999999999975e-278 < (-.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. distribute-rgt-out--N/A

                  \[\leadsto \color{blue}{1 \cdot y - x \cdot y} \]
                2. *-lft-identityN/A

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

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

                  \[\leadsto y - \color{blue}{y \cdot x} \]
                5. lower-*.f6465.3

                  \[\leadsto y - \color{blue}{y \cdot x} \]
              5. Applied rewrites65.3%

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

              \[\leadsto \begin{array}{l} \mathbf{if}\;\left(x + y\right) - x \cdot y \leq -4 \cdot 10^{-278}:\\ \;\;\;\;x - x \cdot y\\ \mathbf{else}:\\ \;\;\;\;y - x \cdot y\\ \end{array} \]
            5. Add Preprocessing

            Alternative 6: 86.2% accurate, 0.6× speedup?

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

              1. Initial program 99.9%

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

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

                  \[\leadsto \color{blue}{x \cdot 1 - x \cdot y} \]
                2. *-rgt-identityN/A

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

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

                  \[\leadsto x - \color{blue}{y \cdot x} \]
                5. lower-*.f6498.5

                  \[\leadsto x - \color{blue}{y \cdot x} \]
              5. Applied rewrites98.5%

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

              if -1 < x < 1.65e6

              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 + x \cdot \left(1 - y\right)} \]
              4. Step-by-step derivation
                1. distribute-rgt-out--N/A

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

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

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

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

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

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

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

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

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

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

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

                  \[\leadsto \mathsf{fma}\left(y, 1 + \color{blue}{\left(\mathsf{neg}\left(x\right)\right)}, x\right) \]
                13. sub-negN/A

                  \[\leadsto \mathsf{fma}\left(y, \color{blue}{1 - x}, x\right) \]
                14. lower--.f64100.0

                  \[\leadsto \mathsf{fma}\left(y, \color{blue}{1 - x}, x\right) \]
              5. Applied rewrites100.0%

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

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

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

                if 1.65e6 < x

                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. distribute-rgt-out--N/A

                    \[\leadsto \color{blue}{1 \cdot y - x \cdot y} \]
                  2. *-lft-identityN/A

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

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

                    \[\leadsto y - \color{blue}{y \cdot x} \]
                  5. lower-*.f6454.1

                    \[\leadsto y - \color{blue}{y \cdot x} \]
                5. Applied rewrites54.1%

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

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

                    \[\leadsto y \cdot \color{blue}{\left(-x\right)} \]
                8. Recombined 3 regimes into one program.
                9. Final simplification88.7%

                  \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -1:\\ \;\;\;\;x - x \cdot y\\ \mathbf{elif}\;x \leq 1650000:\\ \;\;\;\;\mathsf{fma}\left(y, 1, x\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(-y\right)\\ \end{array} \]
                10. Add Preprocessing

                Alternative 7: 75.4% accurate, 1.7× speedup?

                \[\begin{array}{l} \\ \mathsf{fma}\left(y, 1, x\right) \end{array} \]
                (FPCore (x y) :precision binary64 (fma y 1.0 x))
                double code(double x, double y) {
                	return fma(y, 1.0, x);
                }
                
                function code(x, y)
                	return fma(y, 1.0, x)
                end
                
                code[x_, y_] := N[(y * 1.0 + x), $MachinePrecision]
                
                \begin{array}{l}
                
                \\
                \mathsf{fma}\left(y, 1, x\right)
                \end{array}
                
                Derivation
                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 + x \cdot \left(1 - y\right)} \]
                4. Step-by-step derivation
                  1. distribute-rgt-out--N/A

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

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

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

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

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

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

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

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

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

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

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

                    \[\leadsto \mathsf{fma}\left(y, 1 + \color{blue}{\left(\mathsf{neg}\left(x\right)\right)}, x\right) \]
                  13. sub-negN/A

                    \[\leadsto \mathsf{fma}\left(y, \color{blue}{1 - x}, x\right) \]
                  14. lower--.f64100.0

                    \[\leadsto \mathsf{fma}\left(y, \color{blue}{1 - x}, x\right) \]
                5. Applied rewrites100.0%

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

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

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

                  Reproduce

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