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

Percentage Accurate: 95.9% → 96.8%
Time: 7.5s
Alternatives: 6
Speedup: 0.5×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 6 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 95.9% 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: 96.8% accurate, 0.5× speedup?

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

\mathbf{else}:\\
\;\;\;\;z \cdot \frac{x}{\frac{-1}{y}}\\


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

    1. Initial program 99.0%

      \[x \cdot \left(1 - y \cdot z\right) \]
    2. Step-by-step derivation
      1. flip--84.0%

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

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

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

        \[\leadsto \frac{x \cdot \left(1 - \color{blue}{{\left(y \cdot z\right)}^{2}}\right)}{1 + y \cdot z} \]
    3. Applied egg-rr80.7%

      \[\leadsto \color{blue}{\frac{x \cdot \left(1 - {\left(y \cdot z\right)}^{2}\right)}{1 + y \cdot z}} \]
    4. Step-by-step derivation
      1. associate-/l*84.0%

        \[\leadsto \color{blue}{\frac{x}{\frac{1 + y \cdot z}{1 - {\left(y \cdot z\right)}^{2}}}} \]
    5. Simplified84.0%

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

      \[\leadsto \color{blue}{\frac{\left(1 - {y}^{2} \cdot {z}^{2}\right) \cdot x}{y \cdot z + 1}} \]
    7. Step-by-step derivation
      1. fma-def67.5%

        \[\leadsto \frac{\left(1 - {y}^{2} \cdot {z}^{2}\right) \cdot x}{\color{blue}{\mathsf{fma}\left(y, z, 1\right)}} \]
      2. associate-/l*67.1%

        \[\leadsto \color{blue}{\frac{1 - {y}^{2} \cdot {z}^{2}}{\frac{\mathsf{fma}\left(y, z, 1\right)}{x}}} \]
      3. div-sub67.1%

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

        \[\leadsto \frac{1}{\frac{\mathsf{fma}\left(y, z, 1\right)}{x}} - \frac{\color{blue}{\left(y \cdot y\right)} \cdot {z}^{2}}{\frac{\mathsf{fma}\left(y, z, 1\right)}{x}} \]
      5. unpow267.1%

        \[\leadsto \frac{1}{\frac{\mathsf{fma}\left(y, z, 1\right)}{x}} - \frac{\left(y \cdot y\right) \cdot \color{blue}{\left(z \cdot z\right)}}{\frac{\mathsf{fma}\left(y, z, 1\right)}{x}} \]
      6. swap-sqr81.9%

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

        \[\leadsto \frac{1}{\frac{\mathsf{fma}\left(y, z, 1\right)}{x}} - \frac{\color{blue}{{\left(y \cdot z\right)}^{2}}}{\frac{\mathsf{fma}\left(y, z, 1\right)}{x}} \]
      8. div-sub81.9%

        \[\leadsto \color{blue}{\frac{1 - {\left(y \cdot z\right)}^{2}}{\frac{\mathsf{fma}\left(y, z, 1\right)}{x}}} \]
      9. unpow281.9%

        \[\leadsto \frac{1 - \color{blue}{\left(y \cdot z\right) \cdot \left(y \cdot z\right)}}{\frac{\mathsf{fma}\left(y, z, 1\right)}{x}} \]
      10. swap-sqr67.1%

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

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

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

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

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

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

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

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

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

    if 5.00000000000000016e281 < (*.f64 x (-.f64 1 (*.f64 y z)))

    1. Initial program 81.1%

      \[x \cdot \left(1 - y \cdot z\right) \]
    2. Step-by-step derivation
      1. flip--41.7%

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

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

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

        \[\leadsto \frac{x \cdot \left(1 - \color{blue}{{\left(y \cdot z\right)}^{2}}\right)}{1 + y \cdot z} \]
    3. Applied egg-rr41.7%

      \[\leadsto \color{blue}{\frac{x \cdot \left(1 - {\left(y \cdot z\right)}^{2}\right)}{1 + y \cdot z}} \]
    4. Step-by-step derivation
      1. associate-/l*41.7%

        \[\leadsto \color{blue}{\frac{x}{\frac{1 + y \cdot z}{1 - {\left(y \cdot z\right)}^{2}}}} \]
    5. Simplified41.7%

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

      \[\leadsto \frac{x}{\color{blue}{\frac{-1}{y \cdot z}}} \]
    7. Step-by-step derivation
      1. associate-/r*81.1%

        \[\leadsto \frac{x}{\color{blue}{\frac{\frac{-1}{y}}{z}}} \]
    8. Simplified81.1%

      \[\leadsto \frac{x}{\color{blue}{\frac{\frac{-1}{y}}{z}}} \]
    9. Step-by-step derivation
      1. add-cube-cbrt81.1%

        \[\leadsto \frac{\color{blue}{\left(\sqrt[3]{x} \cdot \sqrt[3]{x}\right) \cdot \sqrt[3]{x}}}{\frac{\frac{-1}{y}}{z}} \]
      2. div-inv81.1%

        \[\leadsto \frac{\left(\sqrt[3]{x} \cdot \sqrt[3]{x}\right) \cdot \sqrt[3]{x}}{\color{blue}{\frac{-1}{y} \cdot \frac{1}{z}}} \]
      3. times-frac99.4%

        \[\leadsto \color{blue}{\frac{\sqrt[3]{x} \cdot \sqrt[3]{x}}{\frac{-1}{y}} \cdot \frac{\sqrt[3]{x}}{\frac{1}{z}}} \]
      4. pow299.4%

        \[\leadsto \frac{\color{blue}{{\left(\sqrt[3]{x}\right)}^{2}}}{\frac{-1}{y}} \cdot \frac{\sqrt[3]{x}}{\frac{1}{z}} \]
    10. Applied egg-rr99.4%

      \[\leadsto \color{blue}{\frac{{\left(\sqrt[3]{x}\right)}^{2}}{\frac{-1}{y}} \cdot \frac{\sqrt[3]{x}}{\frac{1}{z}}} \]
    11. Step-by-step derivation
      1. associate-/r/99.3%

        \[\leadsto \frac{{\left(\sqrt[3]{x}\right)}^{2}}{\frac{-1}{y}} \cdot \color{blue}{\left(\frac{\sqrt[3]{x}}{1} \cdot z\right)} \]
      2. /-rgt-identity99.3%

        \[\leadsto \frac{{\left(\sqrt[3]{x}\right)}^{2}}{\frac{-1}{y}} \cdot \left(\color{blue}{\sqrt[3]{x}} \cdot z\right) \]
      3. associate-*r*99.3%

        \[\leadsto \color{blue}{\left(\frac{{\left(\sqrt[3]{x}\right)}^{2}}{\frac{-1}{y}} \cdot \sqrt[3]{x}\right) \cdot z} \]
      4. associate-*l/99.3%

        \[\leadsto \color{blue}{\frac{{\left(\sqrt[3]{x}\right)}^{2} \cdot \sqrt[3]{x}}{\frac{-1}{y}}} \cdot z \]
      5. unpow299.3%

        \[\leadsto \frac{\color{blue}{\left(\sqrt[3]{x} \cdot \sqrt[3]{x}\right)} \cdot \sqrt[3]{x}}{\frac{-1}{y}} \cdot z \]
      6. rem-3cbrt-lft99.8%

        \[\leadsto \frac{\color{blue}{x}}{\frac{-1}{y}} \cdot z \]
    12. Simplified99.8%

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

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

Alternative 2: 97.0% 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 4 \cdot 10^{+287}:\\ \;\;\;\;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 4e+287) 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 <= 4e+287) {
		tmp = t_0;
	} else {
		tmp = y * (x * -z);
	}
	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) :: t_0
    real(8) :: tmp
    t_0 = x * (1.0d0 - (y * z))
    if (t_0 <= 4d+287) then
        tmp = t_0
    else
        tmp = y * (x * -z)
    end if
    code = tmp
end function
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 <= 4e+287) {
		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 <= 4e+287:
		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 <= 4e+287)
		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 <= 4e+287)
		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, 4e+287], 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 4 \cdot 10^{+287}:\\
\;\;\;\;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))) < 4.0000000000000003e287

    1. Initial program 99.0%

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

    if 4.0000000000000003e287 < (*.f64 x (-.f64 1 (*.f64 y z)))

    1. Initial program 80.5%

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

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

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

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

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

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

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

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

Alternative 3: 96.8% 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 5 \cdot 10^{+281}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;z \cdot \frac{x}{\frac{-1}{y}}\\ \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 5e+281) t_0 (* z (/ x (/ -1.0 y))))))
assert(y < z);
double code(double x, double y, double z) {
	double t_0 = x * (1.0 - (y * z));
	double tmp;
	if (t_0 <= 5e+281) {
		tmp = t_0;
	} else {
		tmp = z * (x / (-1.0 / y));
	}
	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) :: t_0
    real(8) :: tmp
    t_0 = x * (1.0d0 - (y * z))
    if (t_0 <= 5d+281) then
        tmp = t_0
    else
        tmp = z * (x / ((-1.0d0) / y))
    end if
    code = tmp
end function
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 <= 5e+281) {
		tmp = t_0;
	} else {
		tmp = z * (x / (-1.0 / y));
	}
	return tmp;
}
[y, z] = sort([y, z])
def code(x, y, z):
	t_0 = x * (1.0 - (y * z))
	tmp = 0
	if t_0 <= 5e+281:
		tmp = t_0
	else:
		tmp = z * (x / (-1.0 / y))
	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 <= 5e+281)
		tmp = t_0;
	else
		tmp = Float64(z * Float64(x / Float64(-1.0 / y)));
	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 <= 5e+281)
		tmp = t_0;
	else
		tmp = z * (x / (-1.0 / y));
	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, 5e+281], t$95$0, N[(z * N[(x / N[(-1.0 / y), $MachinePrecision]), $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 5 \cdot 10^{+281}:\\
\;\;\;\;t_0\\

\mathbf{else}:\\
\;\;\;\;z \cdot \frac{x}{\frac{-1}{y}}\\


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

    1. Initial program 99.0%

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

    if 5.00000000000000016e281 < (*.f64 x (-.f64 1 (*.f64 y z)))

    1. Initial program 81.1%

      \[x \cdot \left(1 - y \cdot z\right) \]
    2. Step-by-step derivation
      1. flip--41.7%

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

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

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

        \[\leadsto \frac{x \cdot \left(1 - \color{blue}{{\left(y \cdot z\right)}^{2}}\right)}{1 + y \cdot z} \]
    3. Applied egg-rr41.7%

      \[\leadsto \color{blue}{\frac{x \cdot \left(1 - {\left(y \cdot z\right)}^{2}\right)}{1 + y \cdot z}} \]
    4. Step-by-step derivation
      1. associate-/l*41.7%

        \[\leadsto \color{blue}{\frac{x}{\frac{1 + y \cdot z}{1 - {\left(y \cdot z\right)}^{2}}}} \]
    5. Simplified41.7%

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

      \[\leadsto \frac{x}{\color{blue}{\frac{-1}{y \cdot z}}} \]
    7. Step-by-step derivation
      1. associate-/r*81.1%

        \[\leadsto \frac{x}{\color{blue}{\frac{\frac{-1}{y}}{z}}} \]
    8. Simplified81.1%

      \[\leadsto \frac{x}{\color{blue}{\frac{\frac{-1}{y}}{z}}} \]
    9. Step-by-step derivation
      1. add-cube-cbrt81.1%

        \[\leadsto \frac{\color{blue}{\left(\sqrt[3]{x} \cdot \sqrt[3]{x}\right) \cdot \sqrt[3]{x}}}{\frac{\frac{-1}{y}}{z}} \]
      2. div-inv81.1%

        \[\leadsto \frac{\left(\sqrt[3]{x} \cdot \sqrt[3]{x}\right) \cdot \sqrt[3]{x}}{\color{blue}{\frac{-1}{y} \cdot \frac{1}{z}}} \]
      3. times-frac99.4%

        \[\leadsto \color{blue}{\frac{\sqrt[3]{x} \cdot \sqrt[3]{x}}{\frac{-1}{y}} \cdot \frac{\sqrt[3]{x}}{\frac{1}{z}}} \]
      4. pow299.4%

        \[\leadsto \frac{\color{blue}{{\left(\sqrt[3]{x}\right)}^{2}}}{\frac{-1}{y}} \cdot \frac{\sqrt[3]{x}}{\frac{1}{z}} \]
    10. Applied egg-rr99.4%

      \[\leadsto \color{blue}{\frac{{\left(\sqrt[3]{x}\right)}^{2}}{\frac{-1}{y}} \cdot \frac{\sqrt[3]{x}}{\frac{1}{z}}} \]
    11. Step-by-step derivation
      1. associate-/r/99.3%

        \[\leadsto \frac{{\left(\sqrt[3]{x}\right)}^{2}}{\frac{-1}{y}} \cdot \color{blue}{\left(\frac{\sqrt[3]{x}}{1} \cdot z\right)} \]
      2. /-rgt-identity99.3%

        \[\leadsto \frac{{\left(\sqrt[3]{x}\right)}^{2}}{\frac{-1}{y}} \cdot \left(\color{blue}{\sqrt[3]{x}} \cdot z\right) \]
      3. associate-*r*99.3%

        \[\leadsto \color{blue}{\left(\frac{{\left(\sqrt[3]{x}\right)}^{2}}{\frac{-1}{y}} \cdot \sqrt[3]{x}\right) \cdot z} \]
      4. associate-*l/99.3%

        \[\leadsto \color{blue}{\frac{{\left(\sqrt[3]{x}\right)}^{2} \cdot \sqrt[3]{x}}{\frac{-1}{y}}} \cdot z \]
      5. unpow299.3%

        \[\leadsto \frac{\color{blue}{\left(\sqrt[3]{x} \cdot \sqrt[3]{x}\right)} \cdot \sqrt[3]{x}}{\frac{-1}{y}} \cdot z \]
      6. rem-3cbrt-lft99.8%

        \[\leadsto \frac{\color{blue}{x}}{\frac{-1}{y}} \cdot z \]
    12. Simplified99.8%

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

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

Alternative 4: 73.5% accurate, 0.7× speedup?

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

    1. Initial program 94.6%

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

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

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

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

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

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

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

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

    if -1.70000000000000016e79 < y < 6.99999999999999991e-151

    1. Initial program 99.9%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -1.7 \cdot 10^{+79} \lor \neg \left(y \leq 7 \cdot 10^{-151}\right):\\ \;\;\;\;x \cdot \left(y \cdot \left(-z\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]

Alternative 5: 74.1% accurate, 0.7× speedup?

\[\begin{array}{l} [y, z] = \mathsf{sort}([y, z])\\ \\ \begin{array}{l} \mathbf{if}\;y \leq -5 \cdot 10^{+78}:\\ \;\;\;\;x \cdot \left(y \cdot \left(-z\right)\right)\\ \mathbf{elif}\;y \leq 1.55 \cdot 10^{-145}:\\ \;\;\;\;x\\ \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 (<= y -5e+78)
   (* x (* y (- z)))
   (if (<= y 1.55e-145) x (* y (* x (- z))))))
assert(y < z);
double code(double x, double y, double z) {
	double tmp;
	if (y <= -5e+78) {
		tmp = x * (y * -z);
	} else if (y <= 1.55e-145) {
		tmp = x;
	} else {
		tmp = y * (x * -z);
	}
	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 <= (-5d+78)) then
        tmp = x * (y * -z)
    else if (y <= 1.55d-145) then
        tmp = x
    else
        tmp = y * (x * -z)
    end if
    code = tmp
end function
assert y < z;
public static double code(double x, double y, double z) {
	double tmp;
	if (y <= -5e+78) {
		tmp = x * (y * -z);
	} else if (y <= 1.55e-145) {
		tmp = x;
	} else {
		tmp = y * (x * -z);
	}
	return tmp;
}
[y, z] = sort([y, z])
def code(x, y, z):
	tmp = 0
	if y <= -5e+78:
		tmp = x * (y * -z)
	elif y <= 1.55e-145:
		tmp = x
	else:
		tmp = y * (x * -z)
	return tmp
y, z = sort([y, z])
function code(x, y, z)
	tmp = 0.0
	if (y <= -5e+78)
		tmp = Float64(x * Float64(y * Float64(-z)));
	elseif (y <= 1.55e-145)
		tmp = x;
	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)
	tmp = 0.0;
	if (y <= -5e+78)
		tmp = x * (y * -z);
	elseif (y <= 1.55e-145)
		tmp = x;
	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_] := If[LessEqual[y, -5e+78], N[(x * N[(y * (-z)), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 1.55e-145], x, N[(y * N[(x * (-z)), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[y, z] = \mathsf{sort}([y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5 \cdot 10^{+78}:\\
\;\;\;\;x \cdot \left(y \cdot \left(-z\right)\right)\\

\mathbf{elif}\;y \leq 1.55 \cdot 10^{-145}:\\
\;\;\;\;x\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if y < -4.99999999999999984e78

    1. Initial program 94.5%

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

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

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

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

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

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

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

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

    if -4.99999999999999984e78 < y < 1.55e-145

    1. Initial program 99.9%

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

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

    if 1.55e-145 < y

    1. Initial program 94.4%

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -5 \cdot 10^{+78}:\\ \;\;\;\;x \cdot \left(y \cdot \left(-z\right)\right)\\ \mathbf{elif}\;y \leq 1.55 \cdot 10^{-145}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(x \cdot \left(-z\right)\right)\\ \end{array} \]

Alternative 6: 50.6% 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 97.0%

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

    \[\leadsto \color{blue}{x} \]
  3. Final simplification54.2%

    \[\leadsto x \]

Reproduce

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