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

Percentage Accurate: 100.0% → 100.0%
Time: 7.4s
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} \\ \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. sub-negN/A

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

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

      \[\leadsto y + \left(\color{blue}{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. cancel-sign-sub-invN/A

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

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

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

      \[\leadsto y \cdot \color{blue}{\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. Simplified100.0%

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

Alternative 2: 86.9% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \left(y + x\right) - y \cdot x\\ t_1 := x \cdot \left(-y\right)\\ \mathbf{if}\;t\_0 \leq -\infty:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;t\_0 \leq 10^{+300}:\\ \;\;\;\;y + x\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (let* ((t_0 (- (+ y x) (* y x))) (t_1 (* x (- y))))
   (if (<= t_0 (- INFINITY)) t_1 (if (<= t_0 1e+300) (+ y x) t_1))))
double code(double x, double y) {
	double t_0 = (y + x) - (y * x);
	double t_1 = x * -y;
	double tmp;
	if (t_0 <= -((double) INFINITY)) {
		tmp = t_1;
	} else if (t_0 <= 1e+300) {
		tmp = y + x;
	} else {
		tmp = t_1;
	}
	return tmp;
}
public static double code(double x, double y) {
	double t_0 = (y + x) - (y * x);
	double t_1 = x * -y;
	double tmp;
	if (t_0 <= -Double.POSITIVE_INFINITY) {
		tmp = t_1;
	} else if (t_0 <= 1e+300) {
		tmp = y + x;
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(x, y):
	t_0 = (y + x) - (y * x)
	t_1 = x * -y
	tmp = 0
	if t_0 <= -math.inf:
		tmp = t_1
	elif t_0 <= 1e+300:
		tmp = y + x
	else:
		tmp = t_1
	return tmp
function code(x, y)
	t_0 = Float64(Float64(y + x) - Float64(y * x))
	t_1 = Float64(x * Float64(-y))
	tmp = 0.0
	if (t_0 <= Float64(-Inf))
		tmp = t_1;
	elseif (t_0 <= 1e+300)
		tmp = Float64(y + x);
	else
		tmp = t_1;
	end
	return tmp
end
function tmp_2 = code(x, y)
	t_0 = (y + x) - (y * x);
	t_1 = x * -y;
	tmp = 0.0;
	if (t_0 <= -Inf)
		tmp = t_1;
	elseif (t_0 <= 1e+300)
		tmp = y + x;
	else
		tmp = t_1;
	end
	tmp_2 = tmp;
end
code[x_, y_] := Block[{t$95$0 = N[(N[(y + x), $MachinePrecision] - N[(y * x), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(x * (-y)), $MachinePrecision]}, If[LessEqual[t$95$0, (-Infinity)], t$95$1, If[LessEqual[t$95$0, 1e+300], N[(y + x), $MachinePrecision], t$95$1]]]]
\begin{array}{l}

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

\mathbf{elif}\;t\_0 \leq 10^{+300}:\\
\;\;\;\;y + x\\

\mathbf{else}:\\
\;\;\;\;t\_1\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (-.f64 (+.f64 x y) (*.f64 x y)) < -inf.0 or 1.0000000000000001e300 < (-.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. 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-*.f64100.0

        \[\leadsto x - \color{blue}{y \cdot x} \]
    5. Simplified100.0%

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

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

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

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

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

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

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

        \[\leadsto x \cdot \color{blue}{\left(-y\right)} \]
    8. Simplified100.0%

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

    if -inf.0 < (-.f64 (+.f64 x y) (*.f64 x y)) < 1.0000000000000001e300

    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. sub-negN/A

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

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

        \[\leadsto y + \left(\color{blue}{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. cancel-sign-sub-invN/A

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

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

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

        \[\leadsto y \cdot \color{blue}{\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. Simplified100.0%

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

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

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

        \[\leadsto \color{blue}{x + y} \]
      3. Step-by-step derivation
        1. +-commutativeN/A

          \[\leadsto \color{blue}{y + x} \]
        2. lower-+.f6484.9

          \[\leadsto \color{blue}{y + x} \]
      4. Simplified84.9%

        \[\leadsto \color{blue}{y + x} \]
    8. Recombined 2 regimes into one program.
    9. Final simplification86.6%

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

    Alternative 3: 62.7% accurate, 0.5× speedup?

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

      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. sub-negN/A

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

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

          \[\leadsto y + \left(\color{blue}{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. cancel-sign-sub-invN/A

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

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

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

          \[\leadsto y \cdot \color{blue}{\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. Simplified100.0%

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

        \[\leadsto \mathsf{fma}\left(y, \color{blue}{-1 \cdot x}, x\right) \]
      7. Step-by-step derivation
        1. mul-1-negN/A

          \[\leadsto \mathsf{fma}\left(y, \color{blue}{\mathsf{neg}\left(x\right)}, x\right) \]
        2. lower-neg.f6459.9

          \[\leadsto \mathsf{fma}\left(y, \color{blue}{-x}, x\right) \]
      8. Simplified59.9%

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

      if -1.99999999999999986e-272 < (-.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-*.f6459.0

          \[\leadsto y - \color{blue}{y \cdot x} \]
      5. Simplified59.0%

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

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

    Alternative 4: 62.7% accurate, 0.5× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\left(y + x\right) - y \cdot x \leq -2 \cdot 10^{-272}:\\ \;\;\;\;x - y \cdot x\\ \mathbf{else}:\\ \;\;\;\;y - y \cdot x\\ \end{array} \end{array} \]
    (FPCore (x y)
     :precision binary64
     (if (<= (- (+ y x) (* y x)) -2e-272) (- x (* y x)) (- y (* y x))))
    double code(double x, double y) {
    	double tmp;
    	if (((y + x) - (y * x)) <= -2e-272) {
    		tmp = x - (y * x);
    	} else {
    		tmp = y - (y * x);
    	}
    	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-272)) then
            tmp = x - (y * x)
        else
            tmp = y - (y * x)
        end if
        code = tmp
    end function
    
    public static double code(double x, double y) {
    	double tmp;
    	if (((y + x) - (y * x)) <= -2e-272) {
    		tmp = x - (y * x);
    	} else {
    		tmp = y - (y * x);
    	}
    	return tmp;
    }
    
    def code(x, y):
    	tmp = 0
    	if ((y + x) - (y * x)) <= -2e-272:
    		tmp = x - (y * x)
    	else:
    		tmp = y - (y * x)
    	return tmp
    
    function code(x, y)
    	tmp = 0.0
    	if (Float64(Float64(y + x) - Float64(y * x)) <= -2e-272)
    		tmp = Float64(x - Float64(y * x));
    	else
    		tmp = Float64(y - Float64(y * x));
    	end
    	return tmp
    end
    
    function tmp_2 = code(x, y)
    	tmp = 0.0;
    	if (((y + x) - (y * x)) <= -2e-272)
    		tmp = x - (y * x);
    	else
    		tmp = y - (y * x);
    	end
    	tmp_2 = tmp;
    end
    
    code[x_, y_] := If[LessEqual[N[(N[(y + x), $MachinePrecision] - N[(y * x), $MachinePrecision]), $MachinePrecision], -2e-272], N[(x - N[(y * x), $MachinePrecision]), $MachinePrecision], N[(y - N[(y * x), $MachinePrecision]), $MachinePrecision]]
    
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    \mathbf{if}\;\left(y + x\right) - y \cdot x \leq -2 \cdot 10^{-272}:\\
    \;\;\;\;x - y \cdot x\\
    
    \mathbf{else}:\\
    \;\;\;\;y - y \cdot x\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if (-.f64 (+.f64 x y) (*.f64 x y)) < -1.99999999999999986e-272

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

          \[\leadsto x - \color{blue}{y \cdot x} \]
      5. Simplified59.9%

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

      if -1.99999999999999986e-272 < (-.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-*.f6459.0

          \[\leadsto y - \color{blue}{y \cdot x} \]
      5. Simplified59.0%

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

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

    Alternative 5: 98.9% accurate, 0.6× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} t_0 := x - y \cdot x\\ \mathbf{if}\;x \leq -1:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;x \leq 1:\\ \;\;\;\;y + x\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
    (FPCore (x y)
     :precision binary64
     (let* ((t_0 (- x (* y x)))) (if (<= x -1.0) t_0 (if (<= x 1.0) (+ y x) t_0))))
    double code(double x, double y) {
    	double t_0 = x - (y * x);
    	double tmp;
    	if (x <= -1.0) {
    		tmp = t_0;
    	} else if (x <= 1.0) {
    		tmp = y + x;
    	} else {
    		tmp = t_0;
    	}
    	return tmp;
    }
    
    real(8) function code(x, y)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        real(8) :: t_0
        real(8) :: tmp
        t_0 = x - (y * x)
        if (x <= (-1.0d0)) then
            tmp = t_0
        else if (x <= 1.0d0) then
            tmp = y + x
        else
            tmp = t_0
        end if
        code = tmp
    end function
    
    public static double code(double x, double y) {
    	double t_0 = x - (y * x);
    	double tmp;
    	if (x <= -1.0) {
    		tmp = t_0;
    	} else if (x <= 1.0) {
    		tmp = y + x;
    	} else {
    		tmp = t_0;
    	}
    	return tmp;
    }
    
    def code(x, y):
    	t_0 = x - (y * x)
    	tmp = 0
    	if x <= -1.0:
    		tmp = t_0
    	elif x <= 1.0:
    		tmp = y + x
    	else:
    		tmp = t_0
    	return tmp
    
    function code(x, y)
    	t_0 = Float64(x - Float64(y * x))
    	tmp = 0.0
    	if (x <= -1.0)
    		tmp = t_0;
    	elseif (x <= 1.0)
    		tmp = Float64(y + x);
    	else
    		tmp = t_0;
    	end
    	return tmp
    end
    
    function tmp_2 = code(x, y)
    	t_0 = x - (y * x);
    	tmp = 0.0;
    	if (x <= -1.0)
    		tmp = t_0;
    	elseif (x <= 1.0)
    		tmp = y + x;
    	else
    		tmp = t_0;
    	end
    	tmp_2 = tmp;
    end
    
    code[x_, y_] := Block[{t$95$0 = N[(x - N[(y * x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -1.0], t$95$0, If[LessEqual[x, 1.0], N[(y + x), $MachinePrecision], t$95$0]]]
    
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    t_0 := x - y \cdot x\\
    \mathbf{if}\;x \leq -1:\\
    \;\;\;\;t\_0\\
    
    \mathbf{elif}\;x \leq 1:\\
    \;\;\;\;y + x\\
    
    \mathbf{else}:\\
    \;\;\;\;t\_0\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if x < -1 or 1 < x

      1. Initial program 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.7

          \[\leadsto x - \color{blue}{y \cdot x} \]
      5. Simplified98.7%

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

      if -1 < x < 1

      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. sub-negN/A

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

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

          \[\leadsto y + \left(\color{blue}{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. cancel-sign-sub-invN/A

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

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

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

          \[\leadsto y \cdot \color{blue}{\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. Simplified100.0%

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

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

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

          \[\leadsto \color{blue}{x + y} \]
        3. Step-by-step derivation
          1. +-commutativeN/A

            \[\leadsto \color{blue}{y + x} \]
          2. lower-+.f6498.9

            \[\leadsto \color{blue}{y + x} \]
        4. Simplified98.9%

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

      Alternative 6: 75.5% accurate, 3.0× speedup?

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

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

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

          \[\leadsto y + \left(\color{blue}{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. cancel-sign-sub-invN/A

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

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

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

          \[\leadsto y \cdot \color{blue}{\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. Simplified100.0%

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

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

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

          \[\leadsto \color{blue}{x + y} \]
        3. Step-by-step derivation
          1. +-commutativeN/A

            \[\leadsto \color{blue}{y + x} \]
          2. lower-+.f6475.9

            \[\leadsto \color{blue}{y + x} \]
        4. Simplified75.9%

          \[\leadsto \color{blue}{y + x} \]
        5. Add Preprocessing

        Reproduce

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