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

Percentage Accurate: 95.9% → 99.0%
Time: 5.9s
Alternatives: 7
Speedup: 0.6×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 7 alternatives:

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

Initial Program: 95.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: 99.0% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \cdot z \leq -1 \cdot 10^{+269}:\\ \;\;\;\;-z \cdot \left(x \cdot y\right)\\ \mathbf{elif}\;y \cdot z \leq 1.5 \cdot 10^{+76}:\\ \;\;\;\;x \cdot \left(1 - y \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(x \cdot \left(-z\right)\right)\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= (* y z) -1e+269)
   (- (* z (* x y)))
   (if (<= (* y z) 1.5e+76) (* x (- 1.0 (* y z))) (* y (* x (- z))))))
double code(double x, double y, double z) {
	double tmp;
	if ((y * z) <= -1e+269) {
		tmp = -(z * (x * y));
	} else if ((y * z) <= 1.5e+76) {
		tmp = x * (1.0 - (y * z));
	} else {
		tmp = y * (x * -z);
	}
	return tmp;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: tmp
    if ((y * z) <= (-1d+269)) then
        tmp = -(z * (x * y))
    else if ((y * z) <= 1.5d+76) then
        tmp = x * (1.0d0 - (y * z))
    else
        tmp = y * (x * -z)
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if ((y * z) <= -1e+269) {
		tmp = -(z * (x * y));
	} else if ((y * z) <= 1.5e+76) {
		tmp = x * (1.0 - (y * z));
	} else {
		tmp = y * (x * -z);
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if (y * z) <= -1e+269:
		tmp = -(z * (x * y))
	elif (y * z) <= 1.5e+76:
		tmp = x * (1.0 - (y * z))
	else:
		tmp = y * (x * -z)
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (Float64(y * z) <= -1e+269)
		tmp = Float64(-Float64(z * Float64(x * y)));
	elseif (Float64(y * z) <= 1.5e+76)
		tmp = Float64(x * Float64(1.0 - Float64(y * z)));
	else
		tmp = Float64(y * Float64(x * Float64(-z)));
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if ((y * z) <= -1e+269)
		tmp = -(z * (x * y));
	elseif ((y * z) <= 1.5e+76)
		tmp = x * (1.0 - (y * z));
	else
		tmp = y * (x * -z);
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[N[(y * z), $MachinePrecision], -1e+269], (-N[(z * N[(x * y), $MachinePrecision]), $MachinePrecision]), If[LessEqual[N[(y * z), $MachinePrecision], 1.5e+76], N[(x * N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(y * N[(x * (-z)), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq -1 \cdot 10^{+269}:\\
\;\;\;\;-z \cdot \left(x \cdot y\right)\\

\mathbf{elif}\;y \cdot z \leq 1.5 \cdot 10^{+76}:\\
\;\;\;\;x \cdot \left(1 - y \cdot z\right)\\

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


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

    1. Initial program 69.9%

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

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

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

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

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

    if -1e269 < (*.f64 y z) < 1.4999999999999999e76

    1. Initial program 99.9%

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

    if 1.4999999999999999e76 < (*.f64 y z)

    1. Initial program 85.5%

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

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

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

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

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

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

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

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

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

Alternative 2: 97.6% accurate, 0.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := x \cdot \left(y \cdot \left(-z\right)\right)\\ t_1 := -z \cdot \left(x \cdot y\right)\\ \mathbf{if}\;y \cdot z \leq -1 \cdot 10^{+269}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;y \cdot z \leq -1000000:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;y \cdot z \leq 1:\\ \;\;\;\;x\\ \mathbf{elif}\;y \cdot z \leq 5 \cdot 10^{+292}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (* x (* y (- z)))) (t_1 (- (* z (* x y)))))
   (if (<= (* y z) -1e+269)
     t_1
     (if (<= (* y z) -1000000.0)
       t_0
       (if (<= (* y z) 1.0) x (if (<= (* y z) 5e+292) t_0 t_1))))))
double code(double x, double y, double z) {
	double t_0 = x * (y * -z);
	double t_1 = -(z * (x * y));
	double tmp;
	if ((y * z) <= -1e+269) {
		tmp = t_1;
	} else if ((y * z) <= -1000000.0) {
		tmp = t_0;
	} else if ((y * z) <= 1.0) {
		tmp = x;
	} else if ((y * z) <= 5e+292) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	return tmp;
}
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) :: t_1
    real(8) :: tmp
    t_0 = x * (y * -z)
    t_1 = -(z * (x * y))
    if ((y * z) <= (-1d+269)) then
        tmp = t_1
    else if ((y * z) <= (-1000000.0d0)) then
        tmp = t_0
    else if ((y * z) <= 1.0d0) then
        tmp = x
    else if ((y * z) <= 5d+292) then
        tmp = t_0
    else
        tmp = t_1
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double t_0 = x * (y * -z);
	double t_1 = -(z * (x * y));
	double tmp;
	if ((y * z) <= -1e+269) {
		tmp = t_1;
	} else if ((y * z) <= -1000000.0) {
		tmp = t_0;
	} else if ((y * z) <= 1.0) {
		tmp = x;
	} else if ((y * z) <= 5e+292) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(x, y, z):
	t_0 = x * (y * -z)
	t_1 = -(z * (x * y))
	tmp = 0
	if (y * z) <= -1e+269:
		tmp = t_1
	elif (y * z) <= -1000000.0:
		tmp = t_0
	elif (y * z) <= 1.0:
		tmp = x
	elif (y * z) <= 5e+292:
		tmp = t_0
	else:
		tmp = t_1
	return tmp
function code(x, y, z)
	t_0 = Float64(x * Float64(y * Float64(-z)))
	t_1 = Float64(-Float64(z * Float64(x * y)))
	tmp = 0.0
	if (Float64(y * z) <= -1e+269)
		tmp = t_1;
	elseif (Float64(y * z) <= -1000000.0)
		tmp = t_0;
	elseif (Float64(y * z) <= 1.0)
		tmp = x;
	elseif (Float64(y * z) <= 5e+292)
		tmp = t_0;
	else
		tmp = t_1;
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	t_0 = x * (y * -z);
	t_1 = -(z * (x * y));
	tmp = 0.0;
	if ((y * z) <= -1e+269)
		tmp = t_1;
	elseif ((y * z) <= -1000000.0)
		tmp = t_0;
	elseif ((y * z) <= 1.0)
		tmp = x;
	elseif ((y * z) <= 5e+292)
		tmp = t_0;
	else
		tmp = t_1;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[(y * (-z)), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = (-N[(z * N[(x * y), $MachinePrecision]), $MachinePrecision])}, If[LessEqual[N[(y * z), $MachinePrecision], -1e+269], t$95$1, If[LessEqual[N[(y * z), $MachinePrecision], -1000000.0], t$95$0, If[LessEqual[N[(y * z), $MachinePrecision], 1.0], x, If[LessEqual[N[(y * z), $MachinePrecision], 5e+292], t$95$0, t$95$1]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := x \cdot \left(y \cdot \left(-z\right)\right)\\
t_1 := -z \cdot \left(x \cdot y\right)\\
\mathbf{if}\;y \cdot z \leq -1 \cdot 10^{+269}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;y \cdot z \leq -1000000:\\
\;\;\;\;t\_0\\

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

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

\mathbf{else}:\\
\;\;\;\;t\_1\\


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

    1. Initial program 69.2%

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

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

        \[\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} \]
    5. Simplified99.8%

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

    if -1e269 < (*.f64 y z) < -1e6 or 1 < (*.f64 y z) < 4.9999999999999996e292

    1. Initial program 99.7%

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

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

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

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

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

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

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

    1. Initial program 100.0%

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

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

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

Alternative 3: 95.8% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \cdot z \leq -1 \cdot 10^{+269}:\\ \;\;\;\;-z \cdot \left(x \cdot y\right)\\ \mathbf{elif}\;y \cdot z \leq -1000000:\\ \;\;\;\;x \cdot \left(y \cdot \left(-z\right)\right)\\ \mathbf{elif}\;y \cdot z \leq 1:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(x \cdot \left(-z\right)\right)\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= (* y z) -1e+269)
   (- (* z (* x y)))
   (if (<= (* y z) -1000000.0)
     (* x (* y (- z)))
     (if (<= (* y z) 1.0) x (* y (* x (- z)))))))
double code(double x, double y, double z) {
	double tmp;
	if ((y * z) <= -1e+269) {
		tmp = -(z * (x * y));
	} else if ((y * z) <= -1000000.0) {
		tmp = x * (y * -z);
	} else if ((y * z) <= 1.0) {
		tmp = x;
	} else {
		tmp = y * (x * -z);
	}
	return tmp;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: tmp
    if ((y * z) <= (-1d+269)) then
        tmp = -(z * (x * y))
    else if ((y * z) <= (-1000000.0d0)) then
        tmp = x * (y * -z)
    else if ((y * z) <= 1.0d0) then
        tmp = x
    else
        tmp = y * (x * -z)
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if ((y * z) <= -1e+269) {
		tmp = -(z * (x * y));
	} else if ((y * z) <= -1000000.0) {
		tmp = x * (y * -z);
	} else if ((y * z) <= 1.0) {
		tmp = x;
	} else {
		tmp = y * (x * -z);
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if (y * z) <= -1e+269:
		tmp = -(z * (x * y))
	elif (y * z) <= -1000000.0:
		tmp = x * (y * -z)
	elif (y * z) <= 1.0:
		tmp = x
	else:
		tmp = y * (x * -z)
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (Float64(y * z) <= -1e+269)
		tmp = Float64(-Float64(z * Float64(x * y)));
	elseif (Float64(y * z) <= -1000000.0)
		tmp = Float64(x * Float64(y * Float64(-z)));
	elseif (Float64(y * z) <= 1.0)
		tmp = x;
	else
		tmp = Float64(y * Float64(x * Float64(-z)));
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if ((y * z) <= -1e+269)
		tmp = -(z * (x * y));
	elseif ((y * z) <= -1000000.0)
		tmp = x * (y * -z);
	elseif ((y * z) <= 1.0)
		tmp = x;
	else
		tmp = y * (x * -z);
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[N[(y * z), $MachinePrecision], -1e+269], (-N[(z * N[(x * y), $MachinePrecision]), $MachinePrecision]), If[LessEqual[N[(y * z), $MachinePrecision], -1000000.0], N[(x * N[(y * (-z)), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(y * z), $MachinePrecision], 1.0], x, N[(y * N[(x * (-z)), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq -1 \cdot 10^{+269}:\\
\;\;\;\;-z \cdot \left(x \cdot y\right)\\

\mathbf{elif}\;y \cdot z \leq -1000000:\\
\;\;\;\;x \cdot \left(y \cdot \left(-z\right)\right)\\

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

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


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

    1. Initial program 69.9%

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

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

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

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

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

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

    1. Initial program 99.7%

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

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

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

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

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

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

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

    1. Initial program 100.0%

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

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

    if 1 < (*.f64 y z)

    1. Initial program 88.2%

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

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

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

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

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

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

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

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

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

Alternative 4: 93.7% accurate, 0.3× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq -1000000 \lor \neg \left(y \cdot z \leq 1\right):\\
\;\;\;\;x \cdot \left(y \cdot \left(-z\right)\right)\\

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


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

    1. Initial program 89.0%

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

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

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

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

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

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

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

    1. Initial program 100.0%

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

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

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

Alternative 5: 96.0% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq 1500:\\ \;\;\;\;x - y \cdot \left(x \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(1 - y \cdot z\right)\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= x 1500.0) (- x (* y (* x z))) (* x (- 1.0 (* y z)))))
double code(double x, double y, double z) {
	double tmp;
	if (x <= 1500.0) {
		tmp = x - (y * (x * z));
	} else {
		tmp = x * (1.0 - (y * z));
	}
	return tmp;
}
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 <= 1500.0d0) then
        tmp = x - (y * (x * z))
    else
        tmp = x * (1.0d0 - (y * z))
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if (x <= 1500.0) {
		tmp = x - (y * (x * z));
	} else {
		tmp = x * (1.0 - (y * z));
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if x <= 1500.0:
		tmp = x - (y * (x * z))
	else:
		tmp = x * (1.0 - (y * z))
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (x <= 1500.0)
		tmp = Float64(x - Float64(y * Float64(x * z)));
	else
		tmp = Float64(x * Float64(1.0 - Float64(y * z)));
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (x <= 1500.0)
		tmp = x - (y * (x * z));
	else
		tmp = x * (1.0 - (y * z));
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[x, 1500.0], N[(x - N[(y * N[(x * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x * N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq 1500:\\
\;\;\;\;x - y \cdot \left(x \cdot z\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < 1500

    1. Initial program 93.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1500 < x

    1. Initial program 99.9%

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

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

Alternative 6: 51.3% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -8.2 \cdot 10^{+191}:\\ \;\;\;\;\frac{x \cdot y}{y}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \end{array} \]
(FPCore (x y z) :precision binary64 (if (<= y -8.2e+191) (/ (* x y) y) x))
double code(double x, double y, double z) {
	double tmp;
	if (y <= -8.2e+191) {
		tmp = (x * y) / y;
	} else {
		tmp = x;
	}
	return tmp;
}
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 <= (-8.2d+191)) then
        tmp = (x * y) / y
    else
        tmp = x
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if (y <= -8.2e+191) {
		tmp = (x * y) / y;
	} else {
		tmp = x;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if y <= -8.2e+191:
		tmp = (x * y) / y
	else:
		tmp = x
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (y <= -8.2e+191)
		tmp = Float64(Float64(x * y) / y);
	else
		tmp = x;
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (y <= -8.2e+191)
		tmp = (x * y) / y;
	else
		tmp = x;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[y, -8.2e+191], N[(N[(x * y), $MachinePrecision] / y), $MachinePrecision], x]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq -8.2 \cdot 10^{+191}:\\
\;\;\;\;\frac{x \cdot y}{y}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -8.1999999999999998e191

    1. Initial program 85.2%

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

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

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

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

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

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

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

        \[\leadsto y \cdot \left(\color{blue}{\left(-1 \cdot x\right) \cdot z} + \frac{x}{y}\right) \]
      2. fma-define92.6%

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

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

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

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

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

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

    if -8.1999999999999998e191 < y

    1. Initial program 95.8%

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

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

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

Alternative 7: 50.2% accurate, 7.0× speedup?

\[\begin{array}{l} \\ x \end{array} \]
(FPCore (x y z) :precision binary64 x)
double code(double x, double y, double z) {
	return x;
}
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
public static double code(double x, double y, double z) {
	return x;
}
def code(x, y, z):
	return x
function code(x, y, z)
	return x
end
function tmp = code(x, y, z)
	tmp = x;
end
code[x_, y_, z_] := x
\begin{array}{l}

\\
x
\end{array}
Derivation
  1. Initial program 94.7%

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

    \[\leadsto \color{blue}{x} \]
  4. Final simplification52.5%

    \[\leadsto x \]
  5. Add Preprocessing

Reproduce

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