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

Percentage Accurate: 96.0% → 97.9%
Time: 5.9s
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.0% 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.9% accurate, 0.5× speedup?

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

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


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

    1. Initial program 80.8%

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

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

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

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

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

      \[\leadsto \color{blue}{x + \left(y \cdot \left(-z\right)\right) \cdot x} \]
    5. Step-by-step derivation
      1. distribute-rgt-neg-out80.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto x - \color{blue}{x \cdot \left(y \cdot \left(-z\right)\right)} \]
      16. add-sqr-sqrt0.3%

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

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

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

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

      \[\leadsto \color{blue}{x - x \cdot \left(y \cdot z\right)} \]
    7. Step-by-step derivation
      1. expm1-log1p-u31.8%

        \[\leadsto x - \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(x \cdot \left(y \cdot z\right)\right)\right)} \]
      2. expm1-udef28.0%

        \[\leadsto x - \color{blue}{\left(e^{\mathsf{log1p}\left(x \cdot \left(y \cdot z\right)\right)} - 1\right)} \]
      3. associate-*r*35.0%

        \[\leadsto x - \left(e^{\mathsf{log1p}\left(\color{blue}{\left(x \cdot y\right) \cdot z}\right)} - 1\right) \]
    8. Applied egg-rr35.0%

      \[\leadsto x - \color{blue}{\left(e^{\mathsf{log1p}\left(\left(x \cdot y\right) \cdot z\right)} - 1\right)} \]
    9. Step-by-step derivation
      1. expm1-def38.8%

        \[\leadsto x - \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\left(x \cdot y\right) \cdot z\right)\right)} \]
      2. expm1-log1p99.8%

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

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

      \[\leadsto x - \color{blue}{z \cdot \left(x \cdot y\right)} \]
    11. Taylor expanded in z around inf 80.8%

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

        \[\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. *-commutative99.8%

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

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

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

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

    if -4.00000000000000007e205 < (*.f64 y z)

    1. Initial program 98.2%

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

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

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

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

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

      \[\leadsto \color{blue}{x + \left(y \cdot \left(-z\right)\right) \cdot x} \]
    5. Step-by-step derivation
      1. distribute-rgt-neg-out98.3%

        \[\leadsto x + \color{blue}{\left(-y \cdot z\right)} \cdot x \]
      2. distribute-lft-neg-out98.3%

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

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

        \[\leadsto x + \left(-y \cdot \color{blue}{\left(x \cdot z\right)}\right) \]
      5. distribute-lft-neg-in93.6%

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

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

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

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

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

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

        \[\leadsto x + \left(-y\right) \cdot \left(-\color{blue}{z \cdot x}\right) \]
      12. distribute-lft-neg-in45.8%

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

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

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

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

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

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

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

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

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

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

Alternative 2: 74.4% accurate, 0.4× speedup?

\[\begin{array}{l} [x, y, z] = \mathsf{sort}([x, y, z])\\ \\ \begin{array}{l} \mathbf{if}\;z \leq -1.4 \cdot 10^{-113} \lor \neg \left(z \leq 1.7 \cdot 10^{+48}\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 (<= z -1.4e-113) (not (<= z 1.7e+48))) (* (* y z) (- x)) x))
assert(x < y && y < z);
double code(double x, double y, double z) {
	double tmp;
	if ((z <= -1.4e-113) || !(z <= 1.7e+48)) {
		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 ((z <= (-1.4d-113)) .or. (.not. (z <= 1.7d+48))) 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 ((z <= -1.4e-113) || !(z <= 1.7e+48)) {
		tmp = (y * z) * -x;
	} else {
		tmp = x;
	}
	return tmp;
}
[x, y, z] = sort([x, y, z])
def code(x, y, z):
	tmp = 0
	if (z <= -1.4e-113) or not (z <= 1.7e+48):
		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 ((z <= -1.4e-113) || !(z <= 1.7e+48))
		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 ((z <= -1.4e-113) || ~((z <= 1.7e+48)))
		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[z, -1.4e-113], N[Not[LessEqual[z, 1.7e+48]], $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}\;z \leq -1.4 \cdot 10^{-113} \lor \neg \left(z \leq 1.7 \cdot 10^{+48}\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 z < -1.4e-113 or 1.7000000000000002e48 < z

    1. Initial program 94.3%

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

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

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

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

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

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

    if -1.4e-113 < z < 1.7000000000000002e48

    1. Initial program 99.9%

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

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

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

Alternative 3: 76.1% accurate, 0.4× speedup?

\[\begin{array}{l} [x, y, z] = \mathsf{sort}([x, y, z])\\ \\ \begin{array}{l} \mathbf{if}\;z \leq -3.7 \cdot 10^{-114} \lor \neg \left(z \leq 6.8 \cdot 10^{+47}\right):\\ \;\;\;\;y \cdot \left(-z \cdot 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 (<= z -3.7e-114) (not (<= z 6.8e+47))) (* y (- (* z x))) x))
assert(x < y && y < z);
double code(double x, double y, double z) {
	double tmp;
	if ((z <= -3.7e-114) || !(z <= 6.8e+47)) {
		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 ((z <= (-3.7d-114)) .or. (.not. (z <= 6.8d+47))) 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 ((z <= -3.7e-114) || !(z <= 6.8e+47)) {
		tmp = y * -(z * x);
	} else {
		tmp = x;
	}
	return tmp;
}
[x, y, z] = sort([x, y, z])
def code(x, y, z):
	tmp = 0
	if (z <= -3.7e-114) or not (z <= 6.8e+47):
		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 ((z <= -3.7e-114) || !(z <= 6.8e+47))
		tmp = Float64(y * Float64(-Float64(z * 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 ((z <= -3.7e-114) || ~((z <= 6.8e+47)))
		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[z, -3.7e-114], N[Not[LessEqual[z, 6.8e+47]], $MachinePrecision]], N[(y * (-N[(z * x), $MachinePrecision])), $MachinePrecision], x]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.7 \cdot 10^{-114} \lor \neg \left(z \leq 6.8 \cdot 10^{+47}\right):\\
\;\;\;\;y \cdot \left(-z \cdot x\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < -3.69999999999999965e-114 or 6.7999999999999996e47 < z

    1. Initial program 94.3%

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

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

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

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

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

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

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

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

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

    if -3.69999999999999965e-114 < z < 6.7999999999999996e47

    1. Initial program 99.9%

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

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

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

Alternative 4: 97.9% accurate, 0.5× speedup?

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

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


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

    1. Initial program 80.8%

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

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

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

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

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

      \[\leadsto \color{blue}{x + \left(y \cdot \left(-z\right)\right) \cdot x} \]
    5. Step-by-step derivation
      1. distribute-rgt-neg-out80.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto x - \color{blue}{x \cdot \left(y \cdot \left(-z\right)\right)} \]
      16. add-sqr-sqrt0.3%

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

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

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

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

      \[\leadsto \color{blue}{x - x \cdot \left(y \cdot z\right)} \]
    7. Step-by-step derivation
      1. expm1-log1p-u31.8%

        \[\leadsto x - \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(x \cdot \left(y \cdot z\right)\right)\right)} \]
      2. expm1-udef28.0%

        \[\leadsto x - \color{blue}{\left(e^{\mathsf{log1p}\left(x \cdot \left(y \cdot z\right)\right)} - 1\right)} \]
      3. associate-*r*35.0%

        \[\leadsto x - \left(e^{\mathsf{log1p}\left(\color{blue}{\left(x \cdot y\right) \cdot z}\right)} - 1\right) \]
    8. Applied egg-rr35.0%

      \[\leadsto x - \color{blue}{\left(e^{\mathsf{log1p}\left(\left(x \cdot y\right) \cdot z\right)} - 1\right)} \]
    9. Step-by-step derivation
      1. expm1-def38.8%

        \[\leadsto x - \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\left(x \cdot y\right) \cdot z\right)\right)} \]
      2. expm1-log1p99.8%

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

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

      \[\leadsto x - \color{blue}{z \cdot \left(x \cdot y\right)} \]
    11. Taylor expanded in z around inf 80.8%

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

        \[\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. *-commutative99.8%

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

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

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

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

    if -4.00000000000000007e205 < (*.f64 y z)

    1. Initial program 98.2%

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

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

Alternative 5: 50.6% 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 96.5%

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

    \[\leadsto \color{blue}{x} \]
  4. Final simplification44.6%

    \[\leadsto x \]
  5. Add Preprocessing

Reproduce

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