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

Percentage Accurate: 95.7% → 97.7%
Time: 5.7s
Alternatives: 7
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 7 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.7% 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.7% accurate, 0.5× speedup?

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

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


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

    1. Initial program 98.6%

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

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

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

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

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

      \[\leadsto \color{blue}{x + \left(y \cdot \left(-z\right)\right) \cdot x} \]
    5. Step-by-step derivation
      1. *-commutative98.6%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto x - \color{blue}{x \cdot \left(y \cdot \left(-z\right)\right)} \]
      12. *-commutative55.0%

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

        \[\leadsto x - \color{blue}{y \cdot \left(\left(-z\right) \cdot x\right)} \]
      14. add-sqr-sqrt21.7%

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

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

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

        \[\leadsto x - y \cdot \left(\color{blue}{\left(\sqrt{z} \cdot \sqrt{z}\right)} \cdot x\right) \]
      18. add-sqr-sqrt94.6%

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

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

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

    if 9.9999999999999998e178 < (*.f64 y z)

    1. Initial program 73.2%

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

      \[\leadsto \color{blue}{y \cdot \left(-1 \cdot \left(x \cdot z\right) + \frac{x}{y}\right)} \]
    4. Taylor expanded in z around inf 96.3%

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

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

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

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

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

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

Alternative 2: 93.5% accurate, 0.3× speedup?

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 y z) < -2e7 or 0.5 < (*.f64 y z)

    1. Initial program 91.6%

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

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

        \[\leadsto \color{blue}{-x \cdot \left(y \cdot z\right)} \]
      2. distribute-rgt-neg-in89.5%

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

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

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

    if -2e7 < (*.f64 y z) < 0.5

    1. Initial program 100.0%

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

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

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

Alternative 3: 94.0% accurate, 0.3× speedup?

\[\begin{array}{l} [x, y, z] = \mathsf{sort}([x, y, z])\\ \\ \begin{array}{l} \mathbf{if}\;y \cdot z \leq -20000000:\\ \;\;\;\;z \cdot \left(y \cdot \left(-x\right)\right)\\ \mathbf{elif}\;y \cdot z \leq 0.5:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;\left(-y\right) \cdot \left(z \cdot x\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) -20000000.0)
   (* z (* y (- x)))
   (if (<= (* y z) 0.5) x (* (- y) (* z x)))))
assert(x < y && y < z);
double code(double x, double y, double z) {
	double tmp;
	if ((y * z) <= -20000000.0) {
		tmp = z * (y * -x);
	} else if ((y * z) <= 0.5) {
		tmp = x;
	} else {
		tmp = -y * (z * 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) <= (-20000000.0d0)) then
        tmp = z * (y * -x)
    else if ((y * z) <= 0.5d0) then
        tmp = x
    else
        tmp = -y * (z * 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) <= -20000000.0) {
		tmp = z * (y * -x);
	} else if ((y * z) <= 0.5) {
		tmp = x;
	} else {
		tmp = -y * (z * x);
	}
	return tmp;
}
[x, y, z] = sort([x, y, z])
def code(x, y, z):
	tmp = 0
	if (y * z) <= -20000000.0:
		tmp = z * (y * -x)
	elif (y * z) <= 0.5:
		tmp = x
	else:
		tmp = -y * (z * x)
	return tmp
x, y, z = sort([x, y, z])
function code(x, y, z)
	tmp = 0.0
	if (Float64(y * z) <= -20000000.0)
		tmp = Float64(z * Float64(y * Float64(-x)));
	elseif (Float64(y * z) <= 0.5)
		tmp = x;
	else
		tmp = Float64(Float64(-y) * Float64(z * 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) <= -20000000.0)
		tmp = z * (y * -x);
	elseif ((y * z) <= 0.5)
		tmp = x;
	else
		tmp = -y * (z * 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[LessEqual[N[(y * z), $MachinePrecision], -20000000.0], N[(z * N[(y * (-x)), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(y * z), $MachinePrecision], 0.5], x, N[((-y) * N[(z * x), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq -20000000:\\
\;\;\;\;z \cdot \left(y \cdot \left(-x\right)\right)\\

\mathbf{elif}\;y \cdot z \leq 0.5:\\
\;\;\;\;x\\

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


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

    1. Initial program 96.0%

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

      \[\leadsto \color{blue}{z \cdot \left(-1 \cdot \left(x \cdot y\right) + \frac{x}{z}\right)} \]
    4. Taylor expanded in y around inf 89.8%

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

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

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

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

    if -2e7 < (*.f64 y z) < 0.5

    1. Initial program 100.0%

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

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

    if 0.5 < (*.f64 y z)

    1. Initial program 85.3%

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

      \[\leadsto \color{blue}{y \cdot \left(-1 \cdot \left(x \cdot z\right) + \frac{x}{y}\right)} \]
    4. Taylor expanded in z around inf 91.3%

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

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

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

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

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

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

Alternative 4: 93.9% accurate, 0.3× speedup?

\[\begin{array}{l} [x, y, z] = \mathsf{sort}([x, y, z])\\ \\ \begin{array}{l} \mathbf{if}\;y \cdot z \leq -20000000:\\ \;\;\;\;\left(y \cdot z\right) \cdot \left(-x\right)\\ \mathbf{elif}\;y \cdot z \leq 0.5:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;\left(-y\right) \cdot \left(z \cdot x\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) -20000000.0)
   (* (* y z) (- x))
   (if (<= (* y z) 0.5) x (* (- y) (* z x)))))
assert(x < y && y < z);
double code(double x, double y, double z) {
	double tmp;
	if ((y * z) <= -20000000.0) {
		tmp = (y * z) * -x;
	} else if ((y * z) <= 0.5) {
		tmp = x;
	} else {
		tmp = -y * (z * 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) <= (-20000000.0d0)) then
        tmp = (y * z) * -x
    else if ((y * z) <= 0.5d0) then
        tmp = x
    else
        tmp = -y * (z * 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) <= -20000000.0) {
		tmp = (y * z) * -x;
	} else if ((y * z) <= 0.5) {
		tmp = x;
	} else {
		tmp = -y * (z * x);
	}
	return tmp;
}
[x, y, z] = sort([x, y, z])
def code(x, y, z):
	tmp = 0
	if (y * z) <= -20000000.0:
		tmp = (y * z) * -x
	elif (y * z) <= 0.5:
		tmp = x
	else:
		tmp = -y * (z * x)
	return tmp
x, y, z = sort([x, y, z])
function code(x, y, z)
	tmp = 0.0
	if (Float64(y * z) <= -20000000.0)
		tmp = Float64(Float64(y * z) * Float64(-x));
	elseif (Float64(y * z) <= 0.5)
		tmp = x;
	else
		tmp = Float64(Float64(-y) * Float64(z * 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) <= -20000000.0)
		tmp = (y * z) * -x;
	elseif ((y * z) <= 0.5)
		tmp = x;
	else
		tmp = -y * (z * 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[LessEqual[N[(y * z), $MachinePrecision], -20000000.0], N[(N[(y * z), $MachinePrecision] * (-x)), $MachinePrecision], If[LessEqual[N[(y * z), $MachinePrecision], 0.5], x, N[((-y) * N[(z * x), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq -20000000:\\
\;\;\;\;\left(y \cdot z\right) \cdot \left(-x\right)\\

\mathbf{elif}\;y \cdot z \leq 0.5:\\
\;\;\;\;x\\

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


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

    1. Initial program 96.0%

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

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

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

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

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

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

    if -2e7 < (*.f64 y z) < 0.5

    1. Initial program 100.0%

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

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

    if 0.5 < (*.f64 y z)

    1. Initial program 85.3%

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

      \[\leadsto \color{blue}{y \cdot \left(-1 \cdot \left(x \cdot z\right) + \frac{x}{y}\right)} \]
    4. Taylor expanded in z around inf 91.3%

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

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

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

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

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

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

Alternative 5: 97.7% accurate, 0.5× speedup?

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

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


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

    1. Initial program 98.6%

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

    if 9.9999999999999998e178 < (*.f64 y z)

    1. Initial program 73.2%

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

      \[\leadsto \color{blue}{y \cdot \left(-1 \cdot \left(x \cdot z\right) + \frac{x}{y}\right)} \]
    4. Taylor expanded in z around inf 96.3%

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

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

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

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

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

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

Alternative 6: 53.1% accurate, 0.6× speedup?

\[\begin{array}{l} [x, y, z] = \mathsf{sort}([x, y, z])\\ \\ \begin{array}{l} \mathbf{if}\;y \cdot z \leq -5 \cdot 10^{+63}:\\ \;\;\;\;\frac{y \cdot x}{y}\\ \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 (<= (* y z) -5e+63) (/ (* y x) y) x))
assert(x < y && y < z);
double code(double x, double y, double z) {
	double tmp;
	if ((y * z) <= -5e+63) {
		tmp = (y * x) / y;
	} 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) <= (-5d+63)) then
        tmp = (y * x) / y
    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) <= -5e+63) {
		tmp = (y * x) / y;
	} else {
		tmp = x;
	}
	return tmp;
}
[x, y, z] = sort([x, y, z])
def code(x, y, z):
	tmp = 0
	if (y * z) <= -5e+63:
		tmp = (y * x) / y
	else:
		tmp = x
	return tmp
x, y, z = sort([x, y, z])
function code(x, y, z)
	tmp = 0.0
	if (Float64(y * z) <= -5e+63)
		tmp = Float64(Float64(y * x) / y);
	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) <= -5e+63)
		tmp = (y * x) / y;
	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[LessEqual[N[(y * z), $MachinePrecision], -5e+63], N[(N[(y * x), $MachinePrecision] / y), $MachinePrecision], x]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq -5 \cdot 10^{+63}:\\
\;\;\;\;\frac{y \cdot x}{y}\\

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


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

    1. Initial program 95.3%

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

      \[\leadsto \color{blue}{y \cdot \left(-1 \cdot \left(x \cdot z\right) + \frac{x}{y}\right)} \]
    4. Taylor expanded in z around 0 8.1%

      \[\leadsto y \cdot \color{blue}{\frac{x}{y}} \]
    5. Step-by-step derivation
      1. *-commutative8.1%

        \[\leadsto \color{blue}{\frac{x}{y} \cdot y} \]
      2. associate-*l/26.7%

        \[\leadsto \color{blue}{\frac{x \cdot y}{y}} \]
    6. Applied egg-rr26.7%

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

    if -5.00000000000000011e63 < (*.f64 y z)

    1. Initial program 96.0%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \cdot z \leq -5 \cdot 10^{+63}:\\ \;\;\;\;\frac{y \cdot x}{y}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 49.5% 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 95.8%

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

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

Reproduce

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