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

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

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

Initial Program: 100.0% accurate, 1.0× speedup?

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

\\
\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 y around 0

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

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

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

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

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

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

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

      \[\leadsto \mathsf{fma}\left(\color{blue}{1 - x}, y, x\right) \]
    8. 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: 85.8% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \left(y + x\right) - y \cdot x\\ t_1 := \left(-y\right) \cdot x\\ \mathbf{if}\;t\_0 \leq -5 \cdot 10^{+301}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;t\_0 \leq 4 \cdot 10^{+282}:\\ \;\;\;\;\mathsf{fma}\left(1, y, x\right)\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (let* ((t_0 (- (+ y x) (* y x))) (t_1 (* (- y) x)))
   (if (<= t_0 -5e+301) t_1 (if (<= t_0 4e+282) (fma 1.0 y x) t_1))))
double code(double x, double y) {
	double t_0 = (y + x) - (y * x);
	double t_1 = -y * x;
	double tmp;
	if (t_0 <= -5e+301) {
		tmp = t_1;
	} else if (t_0 <= 4e+282) {
		tmp = fma(1.0, y, x);
	} else {
		tmp = t_1;
	}
	return tmp;
}
function code(x, y)
	t_0 = Float64(Float64(y + x) - Float64(y * x))
	t_1 = Float64(Float64(-y) * x)
	tmp = 0.0
	if (t_0 <= -5e+301)
		tmp = t_1;
	elseif (t_0 <= 4e+282)
		tmp = fma(1.0, y, x);
	else
		tmp = t_1;
	end
	return tmp
end
code[x_, y_] := Block[{t$95$0 = N[(N[(y + x), $MachinePrecision] - N[(y * x), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[((-y) * x), $MachinePrecision]}, If[LessEqual[t$95$0, -5e+301], t$95$1, If[LessEqual[t$95$0, 4e+282], N[(1.0 * y + x), $MachinePrecision], t$95$1]]]]
\begin{array}{l}

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

\mathbf{elif}\;t\_0 \leq 4 \cdot 10^{+282}:\\
\;\;\;\;\mathsf{fma}\left(1, y, 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)) < -5.0000000000000004e301 or 4.00000000000000013e282 < (-.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--.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 rewrites93.3%

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

      if -5.0000000000000004e301 < (-.f64 (+.f64 x y) (*.f64 x y)) < 4.00000000000000013e282

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

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

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

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

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

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

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

          \[\leadsto \mathsf{fma}\left(\color{blue}{1 - x}, y, x\right) \]
        8. 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 rewrites86.9%

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

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

      Alternative 3: 39.0% accurate, 0.5× speedup?

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

        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--.f6459.7

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

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

          \[\leadsto 1 \cdot x \]
        7. Step-by-step derivation
          1. Applied rewrites39.5%

            \[\leadsto 1 \cdot x \]

          if -2.00000000000000011e-279 < (-.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. *-commutativeN/A

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

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

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

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

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

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

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

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

            \[\leadsto 1 \cdot y \]
          7. Step-by-step derivation
            1. Applied rewrites32.5%

              \[\leadsto 1 \cdot y \]
          8. Recombined 2 regimes into one program.
          9. Final simplification35.9%

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

          Alternative 4: 85.4% accurate, 0.6× speedup?

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

            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--.f6451.1

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

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

            if -1e-8 < y < 2e-14

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

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

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

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

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

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

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

                \[\leadsto \mathsf{fma}\left(\color{blue}{1 - x}, y, x\right) \]
              8. 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.9%

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

              if 2e-14 < 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. *-commutativeN/A

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

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

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

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

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

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

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

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

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

              Alternative 5: 85.4% accurate, 0.6× speedup?

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

                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--.f6451.1

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

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

                if -1e-8 < y < 2e-14

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

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

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

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

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

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

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

                    \[\leadsto \mathsf{fma}\left(\color{blue}{1 - x}, y, x\right) \]
                  8. 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.9%

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

                  if 2e-14 < 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. *-commutativeN/A

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

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

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

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

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

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

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

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

                Alternative 6: 85.7% accurate, 0.6× speedup?

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

                  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--.f6450.3

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

                    \[\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 rewrites50.3%

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

                    if -5.4e11 < y < 2e-14

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

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

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

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

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

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

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

                        \[\leadsto \mathsf{fma}\left(\color{blue}{1 - x}, y, x\right) \]
                      8. 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 rewrites98.8%

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

                      if 2e-14 < 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. *-commutativeN/A

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

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

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

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

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

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

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

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

                    Alternative 7: 76.1% accurate, 1.7× speedup?

                    \[\begin{array}{l} \\ \mathsf{fma}\left(1, y, x\right) \end{array} \]
                    (FPCore (x y) :precision binary64 (fma 1.0 y x))
                    double code(double x, double y) {
                    	return fma(1.0, y, x);
                    }
                    
                    function code(x, y)
                    	return fma(1.0, y, x)
                    end
                    
                    code[x_, y_] := N[(1.0 * y + x), $MachinePrecision]
                    
                    \begin{array}{l}
                    
                    \\
                    \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 y around 0

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

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

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

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

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

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

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

                        \[\leadsto \mathsf{fma}\left(\color{blue}{1 - x}, y, x\right) \]
                      8. 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 rewrites74.1%

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

                      Alternative 8: 39.6% accurate, 2.0× speedup?

                      \[\begin{array}{l} \\ 1 \cdot y \end{array} \]
                      (FPCore (x y) :precision binary64 (* 1.0 y))
                      double code(double x, double y) {
                      	return 1.0 * y;
                      }
                      
                      real(8) function code(x, y)
                          real(8), intent (in) :: x
                          real(8), intent (in) :: y
                          code = 1.0d0 * y
                      end function
                      
                      public static double code(double x, double y) {
                      	return 1.0 * y;
                      }
                      
                      def code(x, y):
                      	return 1.0 * y
                      
                      function code(x, y)
                      	return Float64(1.0 * y)
                      end
                      
                      function tmp = code(x, y)
                      	tmp = 1.0 * y;
                      end
                      
                      code[x_, y_] := N[(1.0 * y), $MachinePrecision]
                      
                      \begin{array}{l}
                      
                      \\
                      1 \cdot y
                      \end{array}
                      
                      Derivation
                      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. *-commutativeN/A

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

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

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

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

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

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

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

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

                        \[\leadsto 1 \cdot y \]
                      7. Step-by-step derivation
                        1. Applied rewrites37.0%

                          \[\leadsto 1 \cdot y \]
                        2. Add Preprocessing

                        Reproduce

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