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

Percentage Accurate: 100.0% → 100.0%
Time: 6.0s
Alternatives: 6
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 6 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} [x, y] = \mathsf{sort}([x, y])\\ \\ \mathsf{fma}\left(1 - x, y, x\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 x) y x))
assert(x < y);
double code(double x, double y) {
	return fma((1.0 - x), y, x);
}
x, y = sort([x, y])
function code(x, y)
	return fma(Float64(1.0 - x), y, x)
end
NOTE: x and y should be sorted in increasing order before calling this function.
code[x_, y_] := N[(N[(1.0 - x), $MachinePrecision] * y + x), $MachinePrecision]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\mathsf{fma}\left(1 - x, y, 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-lft-out--N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 86.4% 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\\ \mathbf{if}\;t\_0 \leq -\infty \lor \neg \left(t\_0 \leq 5 \cdot 10^{+297}\right):\\ \;\;\;\;\left(-y\right) \cdot x\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(1, y, x\right)\\ \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))))
   (if (or (<= t_0 (- INFINITY)) (not (<= t_0 5e+297)))
     (* (- y) x)
     (fma 1.0 y x))))
assert(x < y);
double code(double x, double y) {
	double t_0 = (x + y) - (x * y);
	double tmp;
	if ((t_0 <= -((double) INFINITY)) || !(t_0 <= 5e+297)) {
		tmp = -y * x;
	} else {
		tmp = fma(1.0, y, x);
	}
	return tmp;
}
x, y = sort([x, y])
function code(x, y)
	t_0 = Float64(Float64(x + y) - Float64(x * y))
	tmp = 0.0
	if ((t_0 <= Float64(-Inf)) || !(t_0 <= 5e+297))
		tmp = Float64(Float64(-y) * x);
	else
		tmp = fma(1.0, y, x);
	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]}, If[Or[LessEqual[t$95$0, (-Infinity)], N[Not[LessEqual[t$95$0, 5e+297]], $MachinePrecision]], N[((-y) * x), $MachinePrecision], N[(1.0 * y + x), $MachinePrecision]]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
t_0 := \left(x + y\right) - x \cdot y\\
\mathbf{if}\;t\_0 \leq -\infty \lor \neg \left(t\_0 \leq 5 \cdot 10^{+297}\right):\\
\;\;\;\;\left(-y\right) \cdot x\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(1, y, x\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.9999999999999998e297 < (-.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 inf

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

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

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

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

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

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

        \[\leadsto \color{blue}{\left(1 - y\right)} \cdot x \]
      7. lower--.f6497.0

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

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

      \[\leadsto \left(-1 \cdot y\right) \cdot x \]
    7. Step-by-step derivation
      1. Applied rewrites97.0%

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

      if -inf.0 < (-.f64 (+.f64 x y) (*.f64 x y)) < 4.9999999999999998e297

      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-lft-out--N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\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 5 \cdot 10^{+297}\right):\\ \;\;\;\;\left(-y\right) \cdot x\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(1, y, x\right)\\ \end{array} \]
      10. Add Preprocessing

      Alternative 3: 99.5% accurate, 0.6× speedup?

      \[\begin{array}{l} [x, y] = \mathsf{sort}([x, y])\\ \\ \begin{array}{l} \mathbf{if}\;x \leq -1:\\ \;\;\;\;\mathsf{fma}\left(-y, x, x\right)\\ \mathbf{elif}\;x \leq 1.22 \cdot 10^{-130}:\\ \;\;\;\;\mathsf{fma}\left(1, y, x\right)\\ \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 -1.0)
         (fma (- y) x x)
         (if (<= x 1.22e-130) (fma 1.0 y x) (- y (* y x)))))
      assert(x < y);
      double code(double x, double y) {
      	double tmp;
      	if (x <= -1.0) {
      		tmp = fma(-y, x, x);
      	} else if (x <= 1.22e-130) {
      		tmp = fma(1.0, y, x);
      	} else {
      		tmp = y - (y * x);
      	}
      	return tmp;
      }
      
      x, y = sort([x, y])
      function code(x, y)
      	tmp = 0.0
      	if (x <= -1.0)
      		tmp = fma(Float64(-y), x, x);
      	elseif (x <= 1.22e-130)
      		tmp = fma(1.0, y, x);
      	else
      		tmp = Float64(y - Float64(y * x));
      	end
      	return tmp
      end
      
      NOTE: x and y should be sorted in increasing order before calling this function.
      code[x_, y_] := If[LessEqual[x, -1.0], N[((-y) * x + x), $MachinePrecision], If[LessEqual[x, 1.22e-130], N[(1.0 * y + x), $MachinePrecision], N[(y - N[(y * x), $MachinePrecision]), $MachinePrecision]]]
      
      \begin{array}{l}
      [x, y] = \mathsf{sort}([x, y])\\
      \\
      \begin{array}{l}
      \mathbf{if}\;x \leq -1:\\
      \;\;\;\;\mathsf{fma}\left(-y, x, x\right)\\
      
      \mathbf{elif}\;x \leq 1.22 \cdot 10^{-130}:\\
      \;\;\;\;\mathsf{fma}\left(1, y, x\right)\\
      
      \mathbf{else}:\\
      \;\;\;\;y - y \cdot x\\
      
      
      \end{array}
      \end{array}
      
      Derivation
      1. Split input into 3 regimes
      2. if x < -1

        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. *-commutativeN/A

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

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

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

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

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

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

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

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

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

          if -1 < x < 1.22000000000000003e-130

          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-lft-out--N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            if 1.22000000000000003e-130 < 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-*.f6453.1

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

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

          Alternative 4: 99.5% accurate, 0.6× speedup?

          \[\begin{array}{l} [x, y] = \mathsf{sort}([x, y])\\ \\ \begin{array}{l} \mathbf{if}\;x \leq -1:\\ \;\;\;\;\left(1 - y\right) \cdot x\\ \mathbf{elif}\;x \leq 1.22 \cdot 10^{-130}:\\ \;\;\;\;\mathsf{fma}\left(1, y, x\right)\\ \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 -1.0)
             (* (- 1.0 y) x)
             (if (<= x 1.22e-130) (fma 1.0 y x) (- y (* y x)))))
          assert(x < y);
          double code(double x, double y) {
          	double tmp;
          	if (x <= -1.0) {
          		tmp = (1.0 - y) * x;
          	} else if (x <= 1.22e-130) {
          		tmp = fma(1.0, y, x);
          	} else {
          		tmp = y - (y * x);
          	}
          	return tmp;
          }
          
          x, y = sort([x, y])
          function code(x, y)
          	tmp = 0.0
          	if (x <= -1.0)
          		tmp = Float64(Float64(1.0 - y) * x);
          	elseif (x <= 1.22e-130)
          		tmp = fma(1.0, y, x);
          	else
          		tmp = Float64(y - Float64(y * x));
          	end
          	return tmp
          end
          
          NOTE: x and y should be sorted in increasing order before calling this function.
          code[x_, y_] := If[LessEqual[x, -1.0], N[(N[(1.0 - y), $MachinePrecision] * x), $MachinePrecision], If[LessEqual[x, 1.22e-130], N[(1.0 * y + x), $MachinePrecision], N[(y - N[(y * x), $MachinePrecision]), $MachinePrecision]]]
          
          \begin{array}{l}
          [x, y] = \mathsf{sort}([x, y])\\
          \\
          \begin{array}{l}
          \mathbf{if}\;x \leq -1:\\
          \;\;\;\;\left(1 - y\right) \cdot x\\
          
          \mathbf{elif}\;x \leq 1.22 \cdot 10^{-130}:\\
          \;\;\;\;\mathsf{fma}\left(1, y, x\right)\\
          
          \mathbf{else}:\\
          \;\;\;\;y - y \cdot x\\
          
          
          \end{array}
          \end{array}
          
          Derivation
          1. Split input into 3 regimes
          2. if x < -1

            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. *-commutativeN/A

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

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

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

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

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

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

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

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

            if -1 < x < 1.22000000000000003e-130

            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-lft-out--N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

              if 1.22000000000000003e-130 < 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-*.f6453.1

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

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

            Alternative 5: 98.6% accurate, 0.6× speedup?

            \[\begin{array}{l} [x, y] = \mathsf{sort}([x, y])\\ \\ \begin{array}{l} \mathbf{if}\;x \leq -1:\\ \;\;\;\;\left(1 - y\right) \cdot x\\ \mathbf{elif}\;x \leq 2.5 \cdot 10^{+16}:\\ \;\;\;\;\mathsf{fma}\left(1, y, x\right)\\ \mathbf{else}:\\ \;\;\;\;\left(-y\right) \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 -1.0)
               (* (- 1.0 y) x)
               (if (<= x 2.5e+16) (fma 1.0 y x) (* (- y) x))))
            assert(x < y);
            double code(double x, double y) {
            	double tmp;
            	if (x <= -1.0) {
            		tmp = (1.0 - y) * x;
            	} else if (x <= 2.5e+16) {
            		tmp = fma(1.0, y, x);
            	} else {
            		tmp = -y * x;
            	}
            	return tmp;
            }
            
            x, y = sort([x, y])
            function code(x, y)
            	tmp = 0.0
            	if (x <= -1.0)
            		tmp = Float64(Float64(1.0 - y) * x);
            	elseif (x <= 2.5e+16)
            		tmp = fma(1.0, y, x);
            	else
            		tmp = Float64(Float64(-y) * x);
            	end
            	return tmp
            end
            
            NOTE: x and y should be sorted in increasing order before calling this function.
            code[x_, y_] := If[LessEqual[x, -1.0], N[(N[(1.0 - y), $MachinePrecision] * x), $MachinePrecision], If[LessEqual[x, 2.5e+16], N[(1.0 * y + x), $MachinePrecision], N[((-y) * x), $MachinePrecision]]]
            
            \begin{array}{l}
            [x, y] = \mathsf{sort}([x, y])\\
            \\
            \begin{array}{l}
            \mathbf{if}\;x \leq -1:\\
            \;\;\;\;\left(1 - y\right) \cdot x\\
            
            \mathbf{elif}\;x \leq 2.5 \cdot 10^{+16}:\\
            \;\;\;\;\mathsf{fma}\left(1, y, x\right)\\
            
            \mathbf{else}:\\
            \;\;\;\;\left(-y\right) \cdot x\\
            
            
            \end{array}
            \end{array}
            
            Derivation
            1. Split input into 3 regimes
            2. if x < -1

              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. *-commutativeN/A

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

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

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

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

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

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

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

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

              if -1 < x < 2.5e16

              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-lft-out--N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                if 2.5e16 < x

                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. *-commutativeN/A

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

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

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

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

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

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

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

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

                  \[\leadsto \left(-1 \cdot y\right) \cdot x \]
                7. Step-by-step derivation
                  1. Applied rewrites45.9%

                    \[\leadsto \left(-y\right) \cdot x \]
                8. Recombined 3 regimes into one program.
                9. Add Preprocessing

                Alternative 6: 74.8% accurate, 1.7× speedup?

                \[\begin{array}{l} [x, y] = \mathsf{sort}([x, y])\\ \\ \mathsf{fma}\left(1, y, x\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))
                assert(x < y);
                double code(double x, double y) {
                	return fma(1.0, y, x);
                }
                
                x, y = sort([x, y])
                function code(x, y)
                	return fma(1.0, y, x)
                end
                
                NOTE: x and y should be sorted in increasing order before calling this function.
                code[x_, y_] := N[(1.0 * y + x), $MachinePrecision]
                
                \begin{array}{l}
                [x, y] = \mathsf{sort}([x, y])\\
                \\
                \mathsf{fma}\left(1, y, 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-lft-out--N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                  Reproduce

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