Data.Colour.RGBSpace.HSV:hsv from colour-2.3.3, I

Percentage Accurate: 96.1% → 99.4%
Time: 10.1s
Alternatives: 5
Speedup: 0.4×

Specification

?
\[\begin{array}{l} \\ x \cdot \left(1 - y \cdot z\right) \end{array} \]
(FPCore (x y z) :precision binary64 (* x (- 1.0 (* y z))))
double code(double x, double y, double z) {
	return x * (1.0 - (y * z));
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = x * (1.0d0 - (y * z))
end function
public static double code(double x, double y, double z) {
	return x * (1.0 - (y * z));
}
def code(x, y, z):
	return x * (1.0 - (y * z))
function code(x, y, z)
	return Float64(x * Float64(1.0 - Float64(y * z)))
end
function tmp = code(x, y, z)
	tmp = x * (1.0 - (y * z));
end
code[x_, y_, z_] := N[(x * N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
x \cdot \left(1 - y \cdot z\right)
\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 5 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: 96.1% accurate, 1.0× speedup?

\[\begin{array}{l} \\ x \cdot \left(1 - y \cdot z\right) \end{array} \]
(FPCore (x y z) :precision binary64 (* x (- 1.0 (* y z))))
double code(double x, double y, double z) {
	return x * (1.0 - (y * z));
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = x * (1.0d0 - (y * z))
end function
public static double code(double x, double y, double z) {
	return x * (1.0 - (y * z));
}
def code(x, y, z):
	return x * (1.0 - (y * z))
function code(x, y, z)
	return Float64(x * Float64(1.0 - Float64(y * z)))
end
function tmp = code(x, y, z)
	tmp = x * (1.0 - (y * z));
end
code[x_, y_, z_] := N[(x * N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
x \cdot \left(1 - y \cdot z\right)
\end{array}

Alternative 1: 99.4% accurate, 0.4× speedup?

\[\begin{array}{l} [x, y, z] = \mathsf{sort}([x, y, z])\\ \\ \begin{array}{l} \mathbf{if}\;z \cdot y \leq -\infty:\\ \;\;\;\;z \cdot \left(x \cdot \left(-y\right)\right)\\ \mathbf{elif}\;z \cdot y \leq 5 \cdot 10^{+119}:\\ \;\;\;\;x \cdot \left(1 - z \cdot y\right)\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(x \cdot \left(-z\right)\right)\\ \end{array} \end{array} \]
NOTE: x, y, and z should be sorted in increasing order before calling this function.
(FPCore (x y z)
 :precision binary64
 (if (<= (* z y) (- INFINITY))
   (* z (* x (- y)))
   (if (<= (* z y) 5e+119) (* x (- 1.0 (* z y))) (* y (* x (- z))))))
assert(x < y && y < z);
double code(double x, double y, double z) {
	double tmp;
	if ((z * y) <= -((double) INFINITY)) {
		tmp = z * (x * -y);
	} else if ((z * y) <= 5e+119) {
		tmp = x * (1.0 - (z * y));
	} else {
		tmp = y * (x * -z);
	}
	return tmp;
}
assert x < y && y < z;
public static double code(double x, double y, double z) {
	double tmp;
	if ((z * y) <= -Double.POSITIVE_INFINITY) {
		tmp = z * (x * -y);
	} else if ((z * y) <= 5e+119) {
		tmp = x * (1.0 - (z * y));
	} else {
		tmp = y * (x * -z);
	}
	return tmp;
}
[x, y, z] = sort([x, y, z])
def code(x, y, z):
	tmp = 0
	if (z * y) <= -math.inf:
		tmp = z * (x * -y)
	elif (z * y) <= 5e+119:
		tmp = x * (1.0 - (z * y))
	else:
		tmp = y * (x * -z)
	return tmp
x, y, z = sort([x, y, z])
function code(x, y, z)
	tmp = 0.0
	if (Float64(z * y) <= Float64(-Inf))
		tmp = Float64(z * Float64(x * Float64(-y)));
	elseif (Float64(z * y) <= 5e+119)
		tmp = Float64(x * Float64(1.0 - Float64(z * y)));
	else
		tmp = Float64(y * Float64(x * Float64(-z)));
	end
	return tmp
end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if ((z * y) <= -Inf)
		tmp = z * (x * -y);
	elseif ((z * y) <= 5e+119)
		tmp = x * (1.0 - (z * y));
	else
		tmp = y * (x * -z);
	end
	tmp_2 = tmp;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function.
code[x_, y_, z_] := If[LessEqual[N[(z * y), $MachinePrecision], (-Infinity)], N[(z * N[(x * (-y)), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(z * y), $MachinePrecision], 5e+119], N[(x * N[(1.0 - N[(z * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(y * N[(x * (-z)), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;z \cdot y \leq -\infty:\\
\;\;\;\;z \cdot \left(x \cdot \left(-y\right)\right)\\

\mathbf{elif}\;z \cdot y \leq 5 \cdot 10^{+119}:\\
\;\;\;\;x \cdot \left(1 - z \cdot y\right)\\

\mathbf{else}:\\
\;\;\;\;y \cdot \left(x \cdot \left(-z\right)\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (*.f64 y z) < -inf.0

    1. Initial program 63.6%

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

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

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

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

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

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

        \[\leadsto x \cdot \left(y \cdot \color{blue}{\left(\mathsf{neg}\left(z\right)\right)}\right) \]
      6. neg-lowering-neg.f6463.6

        \[\leadsto x \cdot \left(y \cdot \color{blue}{\left(-z\right)}\right) \]
    5. Simplified63.6%

      \[\leadsto x \cdot \color{blue}{\left(y \cdot \left(-z\right)\right)} \]
    6. Step-by-step derivation
      1. distribute-rgt-neg-outN/A

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

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

        \[\leadsto \color{blue}{\left(x \cdot \left(\mathsf{neg}\left(y\right)\right)\right) \cdot z} \]
      4. *-lowering-*.f64N/A

        \[\leadsto \color{blue}{\left(x \cdot \left(\mathsf{neg}\left(y\right)\right)\right) \cdot z} \]
      5. *-lowering-*.f64N/A

        \[\leadsto \color{blue}{\left(x \cdot \left(\mathsf{neg}\left(y\right)\right)\right)} \cdot z \]
      6. neg-lowering-neg.f6499.9

        \[\leadsto \left(x \cdot \color{blue}{\left(-y\right)}\right) \cdot z \]
    7. Applied egg-rr99.9%

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

    if -inf.0 < (*.f64 y z) < 4.9999999999999999e119

    1. Initial program 99.9%

      \[x \cdot \left(1 - y \cdot z\right) \]
    2. Add Preprocessing

    if 4.9999999999999999e119 < (*.f64 y z)

    1. Initial program 89.1%

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

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

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

        \[\leadsto \left(-1 \cdot x\right) \cdot \color{blue}{\left(z \cdot y\right)} \]
      3. associate-*r*N/A

        \[\leadsto \color{blue}{\left(\left(-1 \cdot x\right) \cdot z\right) \cdot y} \]
      4. associate-*r*N/A

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

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

        \[\leadsto \color{blue}{y \cdot \left(-1 \cdot \left(x \cdot z\right)\right)} \]
      7. associate-*r*N/A

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

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

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

        \[\leadsto y \cdot \left(z \cdot \color{blue}{\left(\mathsf{neg}\left(x\right)\right)}\right) \]
      11. neg-lowering-neg.f6495.5

        \[\leadsto y \cdot \left(z \cdot \color{blue}{\left(-x\right)}\right) \]
    5. Simplified95.5%

      \[\leadsto \color{blue}{y \cdot \left(z \cdot \left(-x\right)\right)} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification99.2%

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

Alternative 2: 94.3% accurate, 0.4× speedup?

\[\begin{array}{l} [x, y, z] = \mathsf{sort}([x, y, z])\\ \\ \begin{array}{l} t_0 := y \cdot \left(x \cdot \left(-z\right)\right)\\ \mathbf{if}\;z \cdot y \leq -4000:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;z \cdot y \leq 10^{-9}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
NOTE: x, y, and z should be sorted in increasing order before calling this function.
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (* y (* x (- z)))))
   (if (<= (* z y) -4000.0) t_0 (if (<= (* z y) 1e-9) x t_0))))
assert(x < y && y < z);
double code(double x, double y, double z) {
	double t_0 = y * (x * -z);
	double tmp;
	if ((z * y) <= -4000.0) {
		tmp = t_0;
	} else if ((z * y) <= 1e-9) {
		tmp = x;
	} else {
		tmp = t_0;
	}
	return tmp;
}
NOTE: x, y, and z should be sorted in increasing order before calling this function.
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: t_0
    real(8) :: tmp
    t_0 = y * (x * -z)
    if ((z * y) <= (-4000.0d0)) then
        tmp = t_0
    else if ((z * y) <= 1d-9) then
        tmp = x
    else
        tmp = t_0
    end if
    code = tmp
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
	double t_0 = y * (x * -z);
	double tmp;
	if ((z * y) <= -4000.0) {
		tmp = t_0;
	} else if ((z * y) <= 1e-9) {
		tmp = x;
	} else {
		tmp = t_0;
	}
	return tmp;
}
[x, y, z] = sort([x, y, z])
def code(x, y, z):
	t_0 = y * (x * -z)
	tmp = 0
	if (z * y) <= -4000.0:
		tmp = t_0
	elif (z * y) <= 1e-9:
		tmp = x
	else:
		tmp = t_0
	return tmp
x, y, z = sort([x, y, z])
function code(x, y, z)
	t_0 = Float64(y * Float64(x * Float64(-z)))
	tmp = 0.0
	if (Float64(z * y) <= -4000.0)
		tmp = t_0;
	elseif (Float64(z * y) <= 1e-9)
		tmp = x;
	else
		tmp = t_0;
	end
	return tmp
end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
	t_0 = y * (x * -z);
	tmp = 0.0;
	if ((z * y) <= -4000.0)
		tmp = t_0;
	elseif ((z * y) <= 1e-9)
		tmp = x;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function.
code[x_, y_, z_] := Block[{t$95$0 = N[(y * N[(x * (-z)), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(z * y), $MachinePrecision], -4000.0], t$95$0, If[LessEqual[N[(z * y), $MachinePrecision], 1e-9], x, t$95$0]]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
t_0 := y \cdot \left(x \cdot \left(-z\right)\right)\\
\mathbf{if}\;z \cdot y \leq -4000:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;z \cdot y \leq 10^{-9}:\\
\;\;\;\;x\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 y z) < -4e3 or 1.00000000000000006e-9 < (*.f64 y z)

    1. Initial program 90.6%

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

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

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

        \[\leadsto \left(-1 \cdot x\right) \cdot \color{blue}{\left(z \cdot y\right)} \]
      3. associate-*r*N/A

        \[\leadsto \color{blue}{\left(\left(-1 \cdot x\right) \cdot z\right) \cdot y} \]
      4. associate-*r*N/A

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

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

        \[\leadsto \color{blue}{y \cdot \left(-1 \cdot \left(x \cdot z\right)\right)} \]
      7. associate-*r*N/A

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

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

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

        \[\leadsto y \cdot \left(z \cdot \color{blue}{\left(\mathsf{neg}\left(x\right)\right)}\right) \]
      11. neg-lowering-neg.f6491.7

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

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

    if -4e3 < (*.f64 y z) < 1.00000000000000006e-9

    1. Initial program 100.0%

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

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

        \[\leadsto \color{blue}{x} \]
    5. Recombined 2 regimes into one program.
    6. Final simplification94.3%

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

    Alternative 3: 93.7% accurate, 0.4× speedup?

    \[\begin{array}{l} [x, y, z] = \mathsf{sort}([x, y, z])\\ \\ \begin{array}{l} t_0 := -x \cdot \left(z \cdot y\right)\\ \mathbf{if}\;z \cdot y \leq -4000:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;z \cdot y \leq 10^{-9}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
    NOTE: x, y, and z should be sorted in increasing order before calling this function.
    (FPCore (x y z)
     :precision binary64
     (let* ((t_0 (- (* x (* z y)))))
       (if (<= (* z y) -4000.0) t_0 (if (<= (* z y) 1e-9) x t_0))))
    assert(x < y && y < z);
    double code(double x, double y, double z) {
    	double t_0 = -(x * (z * y));
    	double tmp;
    	if ((z * y) <= -4000.0) {
    		tmp = t_0;
    	} else if ((z * y) <= 1e-9) {
    		tmp = x;
    	} else {
    		tmp = t_0;
    	}
    	return tmp;
    }
    
    NOTE: x, y, and z should be sorted in increasing order before calling this function.
    real(8) function code(x, y, z)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        real(8), intent (in) :: z
        real(8) :: t_0
        real(8) :: tmp
        t_0 = -(x * (z * y))
        if ((z * y) <= (-4000.0d0)) then
            tmp = t_0
        else if ((z * y) <= 1d-9) then
            tmp = x
        else
            tmp = t_0
        end if
        code = tmp
    end function
    
    assert x < y && y < z;
    public static double code(double x, double y, double z) {
    	double t_0 = -(x * (z * y));
    	double tmp;
    	if ((z * y) <= -4000.0) {
    		tmp = t_0;
    	} else if ((z * y) <= 1e-9) {
    		tmp = x;
    	} else {
    		tmp = t_0;
    	}
    	return tmp;
    }
    
    [x, y, z] = sort([x, y, z])
    def code(x, y, z):
    	t_0 = -(x * (z * y))
    	tmp = 0
    	if (z * y) <= -4000.0:
    		tmp = t_0
    	elif (z * y) <= 1e-9:
    		tmp = x
    	else:
    		tmp = t_0
    	return tmp
    
    x, y, z = sort([x, y, z])
    function code(x, y, z)
    	t_0 = Float64(-Float64(x * Float64(z * y)))
    	tmp = 0.0
    	if (Float64(z * y) <= -4000.0)
    		tmp = t_0;
    	elseif (Float64(z * y) <= 1e-9)
    		tmp = x;
    	else
    		tmp = t_0;
    	end
    	return tmp
    end
    
    x, y, z = num2cell(sort([x, y, z])){:}
    function tmp_2 = code(x, y, z)
    	t_0 = -(x * (z * y));
    	tmp = 0.0;
    	if ((z * y) <= -4000.0)
    		tmp = t_0;
    	elseif ((z * y) <= 1e-9)
    		tmp = x;
    	else
    		tmp = t_0;
    	end
    	tmp_2 = tmp;
    end
    
    NOTE: x, y, and z should be sorted in increasing order before calling this function.
    code[x_, y_, z_] := Block[{t$95$0 = (-N[(x * N[(z * y), $MachinePrecision]), $MachinePrecision])}, If[LessEqual[N[(z * y), $MachinePrecision], -4000.0], t$95$0, If[LessEqual[N[(z * y), $MachinePrecision], 1e-9], x, t$95$0]]]
    
    \begin{array}{l}
    [x, y, z] = \mathsf{sort}([x, y, z])\\
    \\
    \begin{array}{l}
    t_0 := -x \cdot \left(z \cdot y\right)\\
    \mathbf{if}\;z \cdot y \leq -4000:\\
    \;\;\;\;t\_0\\
    
    \mathbf{elif}\;z \cdot y \leq 10^{-9}:\\
    \;\;\;\;x\\
    
    \mathbf{else}:\\
    \;\;\;\;t\_0\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if (*.f64 y z) < -4e3 or 1.00000000000000006e-9 < (*.f64 y z)

      1. Initial program 90.6%

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

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

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

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

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

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

          \[\leadsto x \cdot \left(y \cdot \color{blue}{\left(\mathsf{neg}\left(z\right)\right)}\right) \]
        6. neg-lowering-neg.f6488.1

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

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

      if -4e3 < (*.f64 y z) < 1.00000000000000006e-9

      1. Initial program 100.0%

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

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

          \[\leadsto \color{blue}{x} \]
      5. Recombined 2 regimes into one program.
      6. Final simplification92.3%

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

      Alternative 4: 96.0% accurate, 0.7× speedup?

      \[\begin{array}{l} [x, y, z] = \mathsf{sort}([x, y, z])\\ \\ \begin{array}{l} \mathbf{if}\;x \leq 100:\\ \;\;\;\;\mathsf{fma}\left(x \cdot \left(-z\right), y, x\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(1 - z \cdot y\right)\\ \end{array} \end{array} \]
      NOTE: x, y, and z should be sorted in increasing order before calling this function.
      (FPCore (x y z)
       :precision binary64
       (if (<= x 100.0) (fma (* x (- z)) y x) (* x (- 1.0 (* z y)))))
      assert(x < y && y < z);
      double code(double x, double y, double z) {
      	double tmp;
      	if (x <= 100.0) {
      		tmp = fma((x * -z), y, x);
      	} else {
      		tmp = x * (1.0 - (z * y));
      	}
      	return tmp;
      }
      
      x, y, z = sort([x, y, z])
      function code(x, y, z)
      	tmp = 0.0
      	if (x <= 100.0)
      		tmp = fma(Float64(x * Float64(-z)), y, x);
      	else
      		tmp = Float64(x * Float64(1.0 - Float64(z * y)));
      	end
      	return tmp
      end
      
      NOTE: x, y, and z should be sorted in increasing order before calling this function.
      code[x_, y_, z_] := If[LessEqual[x, 100.0], N[(N[(x * (-z)), $MachinePrecision] * y + x), $MachinePrecision], N[(x * N[(1.0 - N[(z * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
      
      \begin{array}{l}
      [x, y, z] = \mathsf{sort}([x, y, z])\\
      \\
      \begin{array}{l}
      \mathbf{if}\;x \leq 100:\\
      \;\;\;\;\mathsf{fma}\left(x \cdot \left(-z\right), y, x\right)\\
      
      \mathbf{else}:\\
      \;\;\;\;x \cdot \left(1 - z \cdot y\right)\\
      
      
      \end{array}
      \end{array}
      
      Derivation
      1. Split input into 2 regimes
      2. if x < 100

        1. Initial program 93.0%

          \[x \cdot \left(1 - y \cdot z\right) \]
        2. Add Preprocessing
        3. Step-by-step derivation
          1. sub-negN/A

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

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

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

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

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

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

            \[\leadsto \left(x \cdot \left(\mathsf{neg}\left(z\right)\right)\right) \cdot y + \color{blue}{x} \]
          8. accelerator-lowering-fma.f64N/A

            \[\leadsto \color{blue}{\mathsf{fma}\left(x \cdot \left(\mathsf{neg}\left(z\right)\right), y, x\right)} \]
          9. *-lowering-*.f64N/A

            \[\leadsto \mathsf{fma}\left(\color{blue}{x \cdot \left(\mathsf{neg}\left(z\right)\right)}, y, x\right) \]
          10. neg-lowering-neg.f6494.9

            \[\leadsto \mathsf{fma}\left(x \cdot \color{blue}{\left(-z\right)}, y, x\right) \]
        4. Applied egg-rr94.9%

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

        if 100 < x

        1. Initial program 100.0%

          \[x \cdot \left(1 - y \cdot z\right) \]
        2. Add Preprocessing
      3. Recombined 2 regimes into one program.
      4. Final simplification96.2%

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

      Alternative 5: 51.2% accurate, 14.0× speedup?

      \[\begin{array}{l} [x, y, z] = \mathsf{sort}([x, y, z])\\ \\ x \end{array} \]
      NOTE: x, y, and z should be sorted in increasing order before calling this function.
      (FPCore (x y z) :precision binary64 x)
      assert(x < y && y < z);
      double code(double x, double y, double z) {
      	return x;
      }
      
      NOTE: x, y, and z should be sorted in increasing order before calling this function.
      real(8) function code(x, y, z)
          real(8), intent (in) :: x
          real(8), intent (in) :: y
          real(8), intent (in) :: z
          code = x
      end function
      
      assert x < y && y < z;
      public static double code(double x, double y, double z) {
      	return x;
      }
      
      [x, y, z] = sort([x, y, z])
      def code(x, y, z):
      	return x
      
      x, y, z = sort([x, y, z])
      function code(x, y, z)
      	return x
      end
      
      x, y, z = num2cell(sort([x, y, z])){:}
      function tmp = code(x, y, z)
      	tmp = x;
      end
      
      NOTE: x, y, and z should be sorted in increasing order before calling this function.
      code[x_, y_, z_] := x
      
      \begin{array}{l}
      [x, y, z] = \mathsf{sort}([x, y, z])\\
      \\
      x
      \end{array}
      
      Derivation
      1. Initial program 94.8%

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

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

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

        Reproduce

        ?
        herbie shell --seed 2024205 
        (FPCore (x y z)
          :name "Data.Colour.RGBSpace.HSV:hsv from colour-2.3.3, I"
          :precision binary64
          (* x (- 1.0 (* y z))))