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

Percentage Accurate: 96.3% → 93.9%
Time: 7.3s
Alternatives: 5
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 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.3% 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: 93.9% accurate, 0.5× speedup?

\[\begin{array}{l} [y, z] = \mathsf{sort}([y, z])\\ \\ \begin{array}{l} \mathbf{if}\;y \cdot z \leq -500000 \lor \neg \left(y \cdot z \leq 0.2\right):\\ \;\;\;\;y \cdot \left(x \cdot \left(-z\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \end{array} \]
NOTE: y and z should be sorted in increasing order before calling this function.
(FPCore (x y z)
 :precision binary64
 (if (or (<= (* y z) -500000.0) (not (<= (* y z) 0.2))) (* y (* x (- z))) x))
assert(y < z);
double code(double x, double y, double z) {
	double tmp;
	if (((y * z) <= -500000.0) || !((y * z) <= 0.2)) {
		tmp = y * (x * -z);
	} else {
		tmp = x;
	}
	return tmp;
}
NOTE: 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) <= (-500000.0d0)) .or. (.not. ((y * z) <= 0.2d0))) then
        tmp = y * (x * -z)
    else
        tmp = x
    end if
    code = tmp
end function
assert y < z;
public static double code(double x, double y, double z) {
	double tmp;
	if (((y * z) <= -500000.0) || !((y * z) <= 0.2)) {
		tmp = y * (x * -z);
	} else {
		tmp = x;
	}
	return tmp;
}
[y, z] = sort([y, z])
def code(x, y, z):
	tmp = 0
	if ((y * z) <= -500000.0) or not ((y * z) <= 0.2):
		tmp = y * (x * -z)
	else:
		tmp = x
	return tmp
y, z = sort([y, z])
function code(x, y, z)
	tmp = 0.0
	if ((Float64(y * z) <= -500000.0) || !(Float64(y * z) <= 0.2))
		tmp = Float64(y * Float64(x * Float64(-z)));
	else
		tmp = x;
	end
	return tmp
end
y, z = num2cell(sort([y, z])){:}
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (((y * z) <= -500000.0) || ~(((y * z) <= 0.2)))
		tmp = y * (x * -z);
	else
		tmp = x;
	end
	tmp_2 = tmp;
end
NOTE: y and z should be sorted in increasing order before calling this function.
code[x_, y_, z_] := If[Or[LessEqual[N[(y * z), $MachinePrecision], -500000.0], N[Not[LessEqual[N[(y * z), $MachinePrecision], 0.2]], $MachinePrecision]], N[(y * N[(x * (-z)), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
[y, z] = \mathsf{sort}([y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq -500000 \lor \neg \left(y \cdot z \leq 0.2\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) < -5e5 or 0.20000000000000001 < (*.f64 y z)

    1. Initial program 91.7%

      \[x \cdot \left(1 - y \cdot z\right) \]
    2. Step-by-step derivation
      1. remove-double-neg91.7%

        \[\leadsto \color{blue}{-\left(-x \cdot \left(1 - y \cdot z\right)\right)} \]
      2. distribute-lft-neg-out91.7%

        \[\leadsto -\color{blue}{\left(-x\right) \cdot \left(1 - y \cdot z\right)} \]
      3. neg-mul-191.7%

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

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

        \[\leadsto \color{blue}{\left(-x\right) \cdot \left(\left(1 - y \cdot z\right) \cdot -1\right)} \]
      6. distribute-lft-neg-in91.7%

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

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

        \[\leadsto x \cdot \left(-\color{blue}{-1 \cdot \left(1 - y \cdot z\right)}\right) \]
      9. neg-mul-191.7%

        \[\leadsto x \cdot \left(-\color{blue}{\left(-\left(1 - y \cdot z\right)\right)}\right) \]
      10. remove-double-neg91.7%

        \[\leadsto x \cdot \color{blue}{\left(1 - y \cdot z\right)} \]
      11. cancel-sign-sub-inv91.7%

        \[\leadsto x \cdot \color{blue}{\left(1 + \left(-y\right) \cdot z\right)} \]
      12. +-commutative91.7%

        \[\leadsto x \cdot \color{blue}{\left(\left(-y\right) \cdot z + 1\right)} \]
      13. distribute-lft-neg-out91.7%

        \[\leadsto x \cdot \left(\color{blue}{\left(-y \cdot z\right)} + 1\right) \]
      14. metadata-eval91.7%

        \[\leadsto x \cdot \left(\left(-y \cdot z\right) + \color{blue}{\left(--1\right)}\right) \]
      15. distribute-neg-in91.7%

        \[\leadsto x \cdot \color{blue}{\left(-\left(y \cdot z + -1\right)\right)} \]
      16. fma-def91.7%

        \[\leadsto x \cdot \left(-\color{blue}{\mathsf{fma}\left(y, z, -1\right)}\right) \]
    3. Simplified91.7%

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

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

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

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

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

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

    if -5e5 < (*.f64 y z) < 0.20000000000000001

    1. Initial program 100.0%

      \[x \cdot \left(1 - y \cdot z\right) \]
    2. Step-by-step derivation
      1. remove-double-neg100.0%

        \[\leadsto \color{blue}{-\left(-x \cdot \left(1 - y \cdot z\right)\right)} \]
      2. distribute-lft-neg-out100.0%

        \[\leadsto -\color{blue}{\left(-x\right) \cdot \left(1 - y \cdot z\right)} \]
      3. neg-mul-1100.0%

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

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

        \[\leadsto \color{blue}{\left(-x\right) \cdot \left(\left(1 - y \cdot z\right) \cdot -1\right)} \]
      6. distribute-lft-neg-in100.0%

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

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

        \[\leadsto x \cdot \left(-\color{blue}{-1 \cdot \left(1 - y \cdot z\right)}\right) \]
      9. neg-mul-1100.0%

        \[\leadsto x \cdot \left(-\color{blue}{\left(-\left(1 - y \cdot z\right)\right)}\right) \]
      10. remove-double-neg100.0%

        \[\leadsto x \cdot \color{blue}{\left(1 - y \cdot z\right)} \]
      11. cancel-sign-sub-inv100.0%

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

        \[\leadsto x \cdot \color{blue}{\left(\left(-y\right) \cdot z + 1\right)} \]
      13. distribute-lft-neg-out100.0%

        \[\leadsto x \cdot \left(\color{blue}{\left(-y \cdot z\right)} + 1\right) \]
      14. metadata-eval100.0%

        \[\leadsto x \cdot \left(\left(-y \cdot z\right) + \color{blue}{\left(--1\right)}\right) \]
      15. distribute-neg-in100.0%

        \[\leadsto x \cdot \color{blue}{\left(-\left(y \cdot z + -1\right)\right)} \]
      16. fma-def100.0%

        \[\leadsto x \cdot \left(-\color{blue}{\mathsf{fma}\left(y, z, -1\right)}\right) \]
    3. Simplified100.0%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \cdot z \leq -500000 \lor \neg \left(y \cdot z \leq 0.2\right):\\ \;\;\;\;y \cdot \left(x \cdot \left(-z\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]

Alternative 2: 96.3% accurate, 0.1× speedup?

\[\begin{array}{l} [y, z] = \mathsf{sort}([y, z])\\ \\ \begin{array}{l} \mathbf{if}\;x \cdot \left(1 - y \cdot z\right) \leq \infty:\\ \;\;\;\;x \cdot \left(-\mathsf{fma}\left(y, z, -1\right)\right)\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(x \cdot \left(-z\right)\right)\\ \end{array} \end{array} \]
NOTE: y and z should be sorted in increasing order before calling this function.
(FPCore (x y z)
 :precision binary64
 (if (<= (* x (- 1.0 (* y z))) INFINITY)
   (* x (- (fma y z -1.0)))
   (* y (* x (- z)))))
assert(y < z);
double code(double x, double y, double z) {
	double tmp;
	if ((x * (1.0 - (y * z))) <= ((double) INFINITY)) {
		tmp = x * -fma(y, z, -1.0);
	} else {
		tmp = y * (x * -z);
	}
	return tmp;
}
y, z = sort([y, z])
function code(x, y, z)
	tmp = 0.0
	if (Float64(x * Float64(1.0 - Float64(y * z))) <= Inf)
		tmp = Float64(x * Float64(-fma(y, z, -1.0)));
	else
		tmp = Float64(y * Float64(x * Float64(-z)));
	end
	return tmp
end
NOTE: y and z should be sorted in increasing order before calling this function.
code[x_, y_, z_] := If[LessEqual[N[(x * N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], Infinity], N[(x * (-N[(y * z + -1.0), $MachinePrecision])), $MachinePrecision], N[(y * N[(x * (-z)), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[y, z] = \mathsf{sort}([y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;x \cdot \left(1 - y \cdot z\right) \leq \infty:\\
\;\;\;\;x \cdot \left(-\mathsf{fma}\left(y, z, -1\right)\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 x (-.f64 1 (*.f64 y z))) < +inf.0

    1. Initial program 95.4%

      \[x \cdot \left(1 - y \cdot z\right) \]
    2. Step-by-step derivation
      1. remove-double-neg95.4%

        \[\leadsto \color{blue}{-\left(-x \cdot \left(1 - y \cdot z\right)\right)} \]
      2. distribute-lft-neg-out95.4%

        \[\leadsto -\color{blue}{\left(-x\right) \cdot \left(1 - y \cdot z\right)} \]
      3. neg-mul-195.4%

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

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

        \[\leadsto \color{blue}{\left(-x\right) \cdot \left(\left(1 - y \cdot z\right) \cdot -1\right)} \]
      6. distribute-lft-neg-in95.4%

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

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

        \[\leadsto x \cdot \left(-\color{blue}{-1 \cdot \left(1 - y \cdot z\right)}\right) \]
      9. neg-mul-195.4%

        \[\leadsto x \cdot \left(-\color{blue}{\left(-\left(1 - y \cdot z\right)\right)}\right) \]
      10. remove-double-neg95.4%

        \[\leadsto x \cdot \color{blue}{\left(1 - y \cdot z\right)} \]
      11. cancel-sign-sub-inv95.4%

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

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

        \[\leadsto x \cdot \left(\color{blue}{\left(-y \cdot z\right)} + 1\right) \]
      14. metadata-eval95.4%

        \[\leadsto x \cdot \left(\left(-y \cdot z\right) + \color{blue}{\left(--1\right)}\right) \]
      15. distribute-neg-in95.4%

        \[\leadsto x \cdot \color{blue}{\left(-\left(y \cdot z + -1\right)\right)} \]
      16. fma-def95.4%

        \[\leadsto x \cdot \left(-\color{blue}{\mathsf{fma}\left(y, z, -1\right)}\right) \]
    3. Simplified95.4%

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

    if +inf.0 < (*.f64 x (-.f64 1 (*.f64 y z)))

    1. Initial program 95.4%

      \[x \cdot \left(1 - y \cdot z\right) \]
    2. Step-by-step derivation
      1. remove-double-neg95.4%

        \[\leadsto \color{blue}{-\left(-x \cdot \left(1 - y \cdot z\right)\right)} \]
      2. distribute-lft-neg-out95.4%

        \[\leadsto -\color{blue}{\left(-x\right) \cdot \left(1 - y \cdot z\right)} \]
      3. neg-mul-195.4%

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

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

        \[\leadsto \color{blue}{\left(-x\right) \cdot \left(\left(1 - y \cdot z\right) \cdot -1\right)} \]
      6. distribute-lft-neg-in95.4%

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

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

        \[\leadsto x \cdot \left(-\color{blue}{-1 \cdot \left(1 - y \cdot z\right)}\right) \]
      9. neg-mul-195.4%

        \[\leadsto x \cdot \left(-\color{blue}{\left(-\left(1 - y \cdot z\right)\right)}\right) \]
      10. remove-double-neg95.4%

        \[\leadsto x \cdot \color{blue}{\left(1 - y \cdot z\right)} \]
      11. cancel-sign-sub-inv95.4%

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

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

        \[\leadsto x \cdot \left(\color{blue}{\left(-y \cdot z\right)} + 1\right) \]
      14. metadata-eval95.4%

        \[\leadsto x \cdot \left(\left(-y \cdot z\right) + \color{blue}{\left(--1\right)}\right) \]
      15. distribute-neg-in95.4%

        \[\leadsto x \cdot \color{blue}{\left(-\left(y \cdot z + -1\right)\right)} \]
      16. fma-def95.4%

        \[\leadsto x \cdot \left(-\color{blue}{\mathsf{fma}\left(y, z, -1\right)}\right) \]
    3. Simplified95.4%

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

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

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

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

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

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

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

Alternative 3: 96.3% accurate, 0.5× speedup?

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

\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 x (-.f64 1 (*.f64 y z))) < +inf.0

    1. Initial program 95.4%

      \[x \cdot \left(1 - y \cdot z\right) \]

    if +inf.0 < (*.f64 x (-.f64 1 (*.f64 y z)))

    1. Initial program 95.4%

      \[x \cdot \left(1 - y \cdot z\right) \]
    2. Step-by-step derivation
      1. remove-double-neg95.4%

        \[\leadsto \color{blue}{-\left(-x \cdot \left(1 - y \cdot z\right)\right)} \]
      2. distribute-lft-neg-out95.4%

        \[\leadsto -\color{blue}{\left(-x\right) \cdot \left(1 - y \cdot z\right)} \]
      3. neg-mul-195.4%

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

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

        \[\leadsto \color{blue}{\left(-x\right) \cdot \left(\left(1 - y \cdot z\right) \cdot -1\right)} \]
      6. distribute-lft-neg-in95.4%

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

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

        \[\leadsto x \cdot \left(-\color{blue}{-1 \cdot \left(1 - y \cdot z\right)}\right) \]
      9. neg-mul-195.4%

        \[\leadsto x \cdot \left(-\color{blue}{\left(-\left(1 - y \cdot z\right)\right)}\right) \]
      10. remove-double-neg95.4%

        \[\leadsto x \cdot \color{blue}{\left(1 - y \cdot z\right)} \]
      11. cancel-sign-sub-inv95.4%

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

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

        \[\leadsto x \cdot \left(\color{blue}{\left(-y \cdot z\right)} + 1\right) \]
      14. metadata-eval95.4%

        \[\leadsto x \cdot \left(\left(-y \cdot z\right) + \color{blue}{\left(--1\right)}\right) \]
      15. distribute-neg-in95.4%

        \[\leadsto x \cdot \color{blue}{\left(-\left(y \cdot z + -1\right)\right)} \]
      16. fma-def95.4%

        \[\leadsto x \cdot \left(-\color{blue}{\mathsf{fma}\left(y, z, -1\right)}\right) \]
    3. Simplified95.4%

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \cdot \left(1 - y \cdot z\right) \leq \infty:\\ \;\;\;\;x \cdot \left(1 - y \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(x \cdot \left(-z\right)\right)\\ \end{array} \]

Alternative 4: 94.1% accurate, 0.5× speedup?

\[\begin{array}{l} [y, z] = \mathsf{sort}([y, z])\\ \\ \begin{array}{l} \mathbf{if}\;y \cdot z \leq -500000 \lor \neg \left(y \cdot z \leq 0.2\right):\\ \;\;\;\;x \cdot \left(y \cdot \left(-z\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \end{array} \]
NOTE: y and z should be sorted in increasing order before calling this function.
(FPCore (x y z)
 :precision binary64
 (if (or (<= (* y z) -500000.0) (not (<= (* y z) 0.2))) (* x (* y (- z))) x))
assert(y < z);
double code(double x, double y, double z) {
	double tmp;
	if (((y * z) <= -500000.0) || !((y * z) <= 0.2)) {
		tmp = x * (y * -z);
	} else {
		tmp = x;
	}
	return tmp;
}
NOTE: 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) <= (-500000.0d0)) .or. (.not. ((y * z) <= 0.2d0))) then
        tmp = x * (y * -z)
    else
        tmp = x
    end if
    code = tmp
end function
assert y < z;
public static double code(double x, double y, double z) {
	double tmp;
	if (((y * z) <= -500000.0) || !((y * z) <= 0.2)) {
		tmp = x * (y * -z);
	} else {
		tmp = x;
	}
	return tmp;
}
[y, z] = sort([y, z])
def code(x, y, z):
	tmp = 0
	if ((y * z) <= -500000.0) or not ((y * z) <= 0.2):
		tmp = x * (y * -z)
	else:
		tmp = x
	return tmp
y, z = sort([y, z])
function code(x, y, z)
	tmp = 0.0
	if ((Float64(y * z) <= -500000.0) || !(Float64(y * z) <= 0.2))
		tmp = Float64(x * Float64(y * Float64(-z)));
	else
		tmp = x;
	end
	return tmp
end
y, z = num2cell(sort([y, z])){:}
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (((y * z) <= -500000.0) || ~(((y * z) <= 0.2)))
		tmp = x * (y * -z);
	else
		tmp = x;
	end
	tmp_2 = tmp;
end
NOTE: y and z should be sorted in increasing order before calling this function.
code[x_, y_, z_] := If[Or[LessEqual[N[(y * z), $MachinePrecision], -500000.0], N[Not[LessEqual[N[(y * z), $MachinePrecision], 0.2]], $MachinePrecision]], N[(x * N[(y * (-z)), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
[y, z] = \mathsf{sort}([y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq -500000 \lor \neg \left(y \cdot z \leq 0.2\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) < -5e5 or 0.20000000000000001 < (*.f64 y z)

    1. Initial program 91.7%

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

      \[\leadsto x \cdot \color{blue}{\left(-1 \cdot \left(y \cdot z\right)\right)} \]
    3. Step-by-step derivation
      1. associate-*r*90.7%

        \[\leadsto x \cdot \color{blue}{\left(\left(-1 \cdot y\right) \cdot z\right)} \]
      2. neg-mul-190.7%

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

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

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

    if -5e5 < (*.f64 y z) < 0.20000000000000001

    1. Initial program 100.0%

      \[x \cdot \left(1 - y \cdot z\right) \]
    2. Step-by-step derivation
      1. remove-double-neg100.0%

        \[\leadsto \color{blue}{-\left(-x \cdot \left(1 - y \cdot z\right)\right)} \]
      2. distribute-lft-neg-out100.0%

        \[\leadsto -\color{blue}{\left(-x\right) \cdot \left(1 - y \cdot z\right)} \]
      3. neg-mul-1100.0%

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

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

        \[\leadsto \color{blue}{\left(-x\right) \cdot \left(\left(1 - y \cdot z\right) \cdot -1\right)} \]
      6. distribute-lft-neg-in100.0%

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

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

        \[\leadsto x \cdot \left(-\color{blue}{-1 \cdot \left(1 - y \cdot z\right)}\right) \]
      9. neg-mul-1100.0%

        \[\leadsto x \cdot \left(-\color{blue}{\left(-\left(1 - y \cdot z\right)\right)}\right) \]
      10. remove-double-neg100.0%

        \[\leadsto x \cdot \color{blue}{\left(1 - y \cdot z\right)} \]
      11. cancel-sign-sub-inv100.0%

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

        \[\leadsto x \cdot \color{blue}{\left(\left(-y\right) \cdot z + 1\right)} \]
      13. distribute-lft-neg-out100.0%

        \[\leadsto x \cdot \left(\color{blue}{\left(-y \cdot z\right)} + 1\right) \]
      14. metadata-eval100.0%

        \[\leadsto x \cdot \left(\left(-y \cdot z\right) + \color{blue}{\left(--1\right)}\right) \]
      15. distribute-neg-in100.0%

        \[\leadsto x \cdot \color{blue}{\left(-\left(y \cdot z + -1\right)\right)} \]
      16. fma-def100.0%

        \[\leadsto x \cdot \left(-\color{blue}{\mathsf{fma}\left(y, z, -1\right)}\right) \]
    3. Simplified100.0%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \cdot z \leq -500000 \lor \neg \left(y \cdot z \leq 0.2\right):\\ \;\;\;\;x \cdot \left(y \cdot \left(-z\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]

Alternative 5: 50.8% accurate, 7.0× speedup?

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

    \[x \cdot \left(1 - y \cdot z\right) \]
  2. Step-by-step derivation
    1. remove-double-neg95.4%

      \[\leadsto \color{blue}{-\left(-x \cdot \left(1 - y \cdot z\right)\right)} \]
    2. distribute-lft-neg-out95.4%

      \[\leadsto -\color{blue}{\left(-x\right) \cdot \left(1 - y \cdot z\right)} \]
    3. neg-mul-195.4%

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

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

      \[\leadsto \color{blue}{\left(-x\right) \cdot \left(\left(1 - y \cdot z\right) \cdot -1\right)} \]
    6. distribute-lft-neg-in95.4%

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

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

      \[\leadsto x \cdot \left(-\color{blue}{-1 \cdot \left(1 - y \cdot z\right)}\right) \]
    9. neg-mul-195.4%

      \[\leadsto x \cdot \left(-\color{blue}{\left(-\left(1 - y \cdot z\right)\right)}\right) \]
    10. remove-double-neg95.4%

      \[\leadsto x \cdot \color{blue}{\left(1 - y \cdot z\right)} \]
    11. cancel-sign-sub-inv95.4%

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

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

      \[\leadsto x \cdot \left(\color{blue}{\left(-y \cdot z\right)} + 1\right) \]
    14. metadata-eval95.4%

      \[\leadsto x \cdot \left(\left(-y \cdot z\right) + \color{blue}{\left(--1\right)}\right) \]
    15. distribute-neg-in95.4%

      \[\leadsto x \cdot \color{blue}{\left(-\left(y \cdot z + -1\right)\right)} \]
    16. fma-def95.4%

      \[\leadsto x \cdot \left(-\color{blue}{\mathsf{fma}\left(y, z, -1\right)}\right) \]
  3. Simplified95.4%

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

    \[\leadsto \color{blue}{x} \]
  5. Final simplification46.3%

    \[\leadsto x \]

Reproduce

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