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

Percentage Accurate: 95.8% → 97.2%
Time: 6.1s
Alternatives: 6
Speedup: 0.5×

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 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: 95.8% 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: 97.2% accurate, 0.5× speedup?

\[\begin{array}{l} [x, y, z] = \mathsf{sort}([x, y, z])\\ \\ \begin{array}{l} \mathbf{if}\;y \cdot z \leq 2 \cdot 10^{+99}:\\ \;\;\;\;x \cdot \left(1 - y \cdot z\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 (<= (* y z) 2e+99) (* x (- 1.0 (* y z))) (* y (* x (- z)))))
assert(x < y && y < z);
double code(double x, double y, double z) {
	double tmp;
	if ((y * z) <= 2e+99) {
		tmp = x * (1.0 - (y * z));
	} else {
		tmp = y * (x * -z);
	}
	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) :: tmp
    if ((y * z) <= 2d+99) then
        tmp = x * (1.0d0 - (y * z))
    else
        tmp = y * (x * -z)
    end if
    code = tmp
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
	double tmp;
	if ((y * z) <= 2e+99) {
		tmp = x * (1.0 - (y * z));
	} else {
		tmp = y * (x * -z);
	}
	return tmp;
}
[x, y, z] = sort([x, y, z])
def code(x, y, z):
	tmp = 0
	if (y * z) <= 2e+99:
		tmp = x * (1.0 - (y * z))
	else:
		tmp = y * (x * -z)
	return tmp
x, y, z = sort([x, y, z])
function code(x, y, z)
	tmp = 0.0
	if (Float64(y * z) <= 2e+99)
		tmp = Float64(x * Float64(1.0 - Float64(y * z)));
	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 ((y * z) <= 2e+99)
		tmp = x * (1.0 - (y * z));
	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[(y * z), $MachinePrecision], 2e+99], N[(x * N[(1.0 - N[(y * z), $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}\;y \cdot z \leq 2 \cdot 10^{+99}:\\
\;\;\;\;x \cdot \left(1 - y \cdot z\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 y z) < 1.9999999999999999e99

    1. Initial program 98.4%

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

    if 1.9999999999999999e99 < (*.f64 y z)

    1. Initial program 81.9%

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

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

        \[\leadsto \color{blue}{-x \cdot \left(y \cdot z\right)} \]
      2. associate-*r*99.8%

        \[\leadsto -\color{blue}{\left(x \cdot y\right) \cdot z} \]
      3. distribute-rgt-neg-in99.8%

        \[\leadsto \color{blue}{\left(x \cdot y\right) \cdot \left(-z\right)} \]
      4. *-commutative99.8%

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

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

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

Alternative 2: 93.4% accurate, 0.3× speedup?

\[\begin{array}{l} [x, y, z] = \mathsf{sort}([x, y, z])\\ \\ \begin{array}{l} t_0 := x \cdot \left(y \cdot \left(-z\right)\right)\\ \mathbf{if}\;y \cdot z \leq -4 \cdot 10^{+35}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;y \cdot z \leq 2 \cdot 10^{-8}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \cdot z \leq 10^{+186}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;z \cdot \left(x \cdot \left(-y\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
 (let* ((t_0 (* x (* y (- z)))))
   (if (<= (* y z) -4e+35)
     t_0
     (if (<= (* y z) 2e-8) x (if (<= (* y z) 1e+186) t_0 (* z (* x (- y))))))))
assert(x < y && y < z);
double code(double x, double y, double z) {
	double t_0 = x * (y * -z);
	double tmp;
	if ((y * z) <= -4e+35) {
		tmp = t_0;
	} else if ((y * z) <= 2e-8) {
		tmp = x;
	} else if ((y * z) <= 1e+186) {
		tmp = t_0;
	} else {
		tmp = z * (x * -y);
	}
	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 * (y * -z)
    if ((y * z) <= (-4d+35)) then
        tmp = t_0
    else if ((y * z) <= 2d-8) then
        tmp = x
    else if ((y * z) <= 1d+186) then
        tmp = t_0
    else
        tmp = z * (x * -y)
    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 * (y * -z);
	double tmp;
	if ((y * z) <= -4e+35) {
		tmp = t_0;
	} else if ((y * z) <= 2e-8) {
		tmp = x;
	} else if ((y * z) <= 1e+186) {
		tmp = t_0;
	} else {
		tmp = z * (x * -y);
	}
	return tmp;
}
[x, y, z] = sort([x, y, z])
def code(x, y, z):
	t_0 = x * (y * -z)
	tmp = 0
	if (y * z) <= -4e+35:
		tmp = t_0
	elif (y * z) <= 2e-8:
		tmp = x
	elif (y * z) <= 1e+186:
		tmp = t_0
	else:
		tmp = z * (x * -y)
	return tmp
x, y, z = sort([x, y, z])
function code(x, y, z)
	t_0 = Float64(x * Float64(y * Float64(-z)))
	tmp = 0.0
	if (Float64(y * z) <= -4e+35)
		tmp = t_0;
	elseif (Float64(y * z) <= 2e-8)
		tmp = x;
	elseif (Float64(y * z) <= 1e+186)
		tmp = t_0;
	else
		tmp = Float64(z * Float64(x * Float64(-y)));
	end
	return tmp
end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
	t_0 = x * (y * -z);
	tmp = 0.0;
	if ((y * z) <= -4e+35)
		tmp = t_0;
	elseif ((y * z) <= 2e-8)
		tmp = x;
	elseif ((y * z) <= 1e+186)
		tmp = t_0;
	else
		tmp = z * (x * -y);
	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[(y * (-z)), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(y * z), $MachinePrecision], -4e+35], t$95$0, If[LessEqual[N[(y * z), $MachinePrecision], 2e-8], x, If[LessEqual[N[(y * z), $MachinePrecision], 1e+186], t$95$0, N[(z * N[(x * (-y)), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
t_0 := x \cdot \left(y \cdot \left(-z\right)\right)\\
\mathbf{if}\;y \cdot z \leq -4 \cdot 10^{+35}:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;y \cdot z \leq 10^{+186}:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (*.f64 y z) < -3.9999999999999999e35 or 2e-8 < (*.f64 y z) < 9.9999999999999998e185

    1. Initial program 97.0%

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

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

        \[\leadsto \color{blue}{-x \cdot \left(y \cdot z\right)} \]
      2. associate-*r*89.7%

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

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

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

    if -3.9999999999999999e35 < (*.f64 y z) < 2e-8

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{x} \]

    if 9.9999999999999998e185 < (*.f64 y z)

    1. Initial program 75.5%

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

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

        \[\leadsto \color{blue}{-x \cdot \left(y \cdot z\right)} \]
      2. associate-*r*99.7%

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

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

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

Alternative 3: 92.4% accurate, 0.3× speedup?

\[\begin{array}{l} [x, y, z] = \mathsf{sort}([x, y, z])\\ \\ \begin{array}{l} \mathbf{if}\;y \cdot z \leq -4 \cdot 10^{+35} \lor \neg \left(y \cdot z \leq 2 \cdot 10^{-8}\right):\\ \;\;\;\;y \cdot \left(x \cdot \left(-z\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x\\ \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 (or (<= (* y z) -4e+35) (not (<= (* y z) 2e-8))) (* y (* x (- z))) x))
assert(x < y && y < z);
double code(double x, double y, double z) {
	double tmp;
	if (((y * z) <= -4e+35) || !((y * z) <= 2e-8)) {
		tmp = y * (x * -z);
	} else {
		tmp = x;
	}
	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) :: tmp
    if (((y * z) <= (-4d+35)) .or. (.not. ((y * z) <= 2d-8))) then
        tmp = y * (x * -z)
    else
        tmp = x
    end if
    code = tmp
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
	double tmp;
	if (((y * z) <= -4e+35) || !((y * z) <= 2e-8)) {
		tmp = y * (x * -z);
	} else {
		tmp = x;
	}
	return tmp;
}
[x, y, z] = sort([x, y, z])
def code(x, y, z):
	tmp = 0
	if ((y * z) <= -4e+35) or not ((y * z) <= 2e-8):
		tmp = y * (x * -z)
	else:
		tmp = x
	return tmp
x, y, z = sort([x, y, z])
function code(x, y, z)
	tmp = 0.0
	if ((Float64(y * z) <= -4e+35) || !(Float64(y * z) <= 2e-8))
		tmp = Float64(y * Float64(x * Float64(-z)));
	else
		tmp = x;
	end
	return tmp
end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (((y * z) <= -4e+35) || ~(((y * z) <= 2e-8)))
		tmp = y * (x * -z);
	else
		tmp = x;
	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[Or[LessEqual[N[(y * z), $MachinePrecision], -4e+35], N[Not[LessEqual[N[(y * z), $MachinePrecision], 2e-8]], $MachinePrecision]], N[(y * N[(x * (-z)), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq -4 \cdot 10^{+35} \lor \neg \left(y \cdot z \leq 2 \cdot 10^{-8}\right):\\
\;\;\;\;y \cdot \left(x \cdot \left(-z\right)\right)\\

\mathbf{else}:\\
\;\;\;\;x\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 y z) < -3.9999999999999999e35 or 2e-8 < (*.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 90.0%

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

        \[\leadsto \color{blue}{-x \cdot \left(y \cdot z\right)} \]
      2. associate-*r*92.7%

        \[\leadsto -\color{blue}{\left(x \cdot y\right) \cdot z} \]
      3. distribute-rgt-neg-in92.7%

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

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

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

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

    if -3.9999999999999999e35 < (*.f64 y z) < 2e-8

    1. Initial program 100.0%

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

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

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

Alternative 4: 93.7% accurate, 0.3× speedup?

\[\begin{array}{l} [x, y, z] = \mathsf{sort}([x, y, z])\\ \\ \begin{array}{l} \mathbf{if}\;y \cdot z \leq -1 \lor \neg \left(y \cdot z \leq 1\right):\\ \;\;\;\;x \cdot \left(y \cdot \left(-z\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x\\ \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 (or (<= (* y z) -1.0) (not (<= (* y z) 1.0))) (* x (* y (- z))) x))
assert(x < y && y < z);
double code(double x, double y, double z) {
	double tmp;
	if (((y * z) <= -1.0) || !((y * z) <= 1.0)) {
		tmp = x * (y * -z);
	} else {
		tmp = x;
	}
	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) :: tmp
    if (((y * z) <= (-1.0d0)) .or. (.not. ((y * z) <= 1.0d0))) then
        tmp = x * (y * -z)
    else
        tmp = x
    end if
    code = tmp
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
	double tmp;
	if (((y * z) <= -1.0) || !((y * z) <= 1.0)) {
		tmp = x * (y * -z);
	} else {
		tmp = x;
	}
	return tmp;
}
[x, y, z] = sort([x, y, z])
def code(x, y, z):
	tmp = 0
	if ((y * z) <= -1.0) or not ((y * z) <= 1.0):
		tmp = x * (y * -z)
	else:
		tmp = x
	return tmp
x, y, z = sort([x, y, z])
function code(x, y, z)
	tmp = 0.0
	if ((Float64(y * z) <= -1.0) || !(Float64(y * z) <= 1.0))
		tmp = Float64(x * Float64(y * Float64(-z)));
	else
		tmp = x;
	end
	return tmp
end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (((y * z) <= -1.0) || ~(((y * z) <= 1.0)))
		tmp = x * (y * -z);
	else
		tmp = x;
	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[Or[LessEqual[N[(y * z), $MachinePrecision], -1.0], N[Not[LessEqual[N[(y * z), $MachinePrecision], 1.0]], $MachinePrecision]], N[(x * N[(y * (-z)), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq -1 \lor \neg \left(y \cdot z \leq 1\right):\\
\;\;\;\;x \cdot \left(y \cdot \left(-z\right)\right)\\

\mathbf{else}:\\
\;\;\;\;x\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 y z) < -1 or 1 < (*.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 90.0%

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

        \[\leadsto \color{blue}{-x \cdot \left(y \cdot z\right)} \]
      2. associate-*r*92.7%

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

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

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

    if -1 < (*.f64 y z) < 1

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{x} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification93.9%

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

Alternative 5: 94.2% accurate, 1.0× speedup?

\[\begin{array}{l} [x, y, z] = \mathsf{sort}([x, y, z])\\ \\ x - y \cdot \left(x \cdot z\right) \end{array} \]
NOTE: x, y, and z should be sorted in increasing order before calling this function.
(FPCore (x y z) :precision binary64 (- x (* y (* x z))))
assert(x < y && y < z);
double code(double x, double y, double z) {
	return x - (y * (x * z));
}
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 - (y * (x * z))
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
	return x - (y * (x * z));
}
[x, y, z] = sort([x, y, z])
def code(x, y, z):
	return x - (y * (x * z))
x, y, z = sort([x, y, z])
function code(x, y, z)
	return Float64(x - Float64(y * Float64(x * z)))
end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp = code(x, y, z)
	tmp = x - (y * (x * z));
end
NOTE: x, y, and z should be sorted in increasing order before calling this function.
code[x_, y_, z_] := N[(x - N[(y * N[(x * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
x - y \cdot \left(x \cdot z\right)
\end{array}
Derivation
  1. Initial program 94.7%

    \[x \cdot \left(1 - y \cdot z\right) \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. sub-neg94.7%

      \[\leadsto x \cdot \color{blue}{\left(1 + \left(-y \cdot z\right)\right)} \]
    2. distribute-rgt-in94.7%

      \[\leadsto \color{blue}{1 \cdot x + \left(-y \cdot z\right) \cdot x} \]
    3. *-un-lft-identity94.7%

      \[\leadsto \color{blue}{x} + \left(-y \cdot z\right) \cdot x \]
    4. distribute-rgt-neg-in94.7%

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

    \[\leadsto \color{blue}{x + \left(y \cdot \left(-z\right)\right) \cdot x} \]
  5. Step-by-step derivation
    1. add-sqr-sqrt55.8%

      \[\leadsto x + \color{blue}{\left(\sqrt{y \cdot \left(-z\right)} \cdot \sqrt{y \cdot \left(-z\right)}\right)} \cdot x \]
    2. sqrt-unprod63.4%

      \[\leadsto x + \color{blue}{\sqrt{\left(y \cdot \left(-z\right)\right) \cdot \left(y \cdot \left(-z\right)\right)}} \cdot x \]
    3. distribute-rgt-neg-out63.4%

      \[\leadsto x + \sqrt{\color{blue}{\left(-y \cdot z\right)} \cdot \left(y \cdot \left(-z\right)\right)} \cdot x \]
    4. distribute-rgt-neg-out63.4%

      \[\leadsto x + \sqrt{\left(-y \cdot z\right) \cdot \color{blue}{\left(-y \cdot z\right)}} \cdot x \]
    5. sqr-neg63.4%

      \[\leadsto x + \sqrt{\color{blue}{\left(y \cdot z\right) \cdot \left(y \cdot z\right)}} \cdot x \]
    6. sqrt-prod26.7%

      \[\leadsto x + \color{blue}{\left(\sqrt{y \cdot z} \cdot \sqrt{y \cdot z}\right)} \cdot x \]
    7. add-sqr-sqrt43.4%

      \[\leadsto x + \color{blue}{\left(y \cdot z\right)} \cdot x \]
    8. cancel-sign-sub43.4%

      \[\leadsto \color{blue}{x - \left(-y \cdot z\right) \cdot x} \]
    9. distribute-rgt-neg-out43.4%

      \[\leadsto x - \color{blue}{\left(y \cdot \left(-z\right)\right)} \cdot x \]
    10. associate-*l*43.1%

      \[\leadsto x - \color{blue}{y \cdot \left(\left(-z\right) \cdot x\right)} \]
    11. add-sqr-sqrt22.8%

      \[\leadsto x - y \cdot \left(\color{blue}{\left(\sqrt{-z} \cdot \sqrt{-z}\right)} \cdot x\right) \]
    12. sqrt-unprod60.4%

      \[\leadsto x - y \cdot \left(\color{blue}{\sqrt{\left(-z\right) \cdot \left(-z\right)}} \cdot x\right) \]
    13. sqr-neg60.4%

      \[\leadsto x - y \cdot \left(\sqrt{\color{blue}{z \cdot z}} \cdot x\right) \]
    14. sqrt-unprod48.2%

      \[\leadsto x - y \cdot \left(\color{blue}{\left(\sqrt{z} \cdot \sqrt{z}\right)} \cdot x\right) \]
    15. add-sqr-sqrt95.9%

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

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

    \[\leadsto x - y \cdot \left(x \cdot z\right) \]
  8. Add Preprocessing

Alternative 6: 50.1% accurate, 7.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.7%

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

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

Reproduce

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