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

Percentage Accurate: 96.0% → 99.8%
Time: 7.4s
Alternatives: 5
Speedup: 0.4×

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: 99.8% accurate, 0.4× speedup?

\[\begin{array}{l} [x, y, z] = \mathsf{sort}([x, y, z])\\ \\ \begin{array}{l} t_0 := \left(\left(-x\right) \cdot y\right) \cdot z\\ \mathbf{if}\;z \cdot y \leq -1 \cdot 10^{+245}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;z \cdot y \leq 10^{+236}:\\ \;\;\;\;x - x \cdot \left(z \cdot y\right)\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \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
 (let* ((t_0 (* (* (- x) y) z)))
   (if (<= (* z y) -1e+245)
     t_0
     (if (<= (* z y) 1e+236) (- x (* x (* z y))) t_0))))
assert(x < y && y < z);
double code(double x, double y, double z) {
	double t_0 = (-x * y) * z;
	double tmp;
	if ((z * y) <= -1e+245) {
		tmp = t_0;
	} else if ((z * y) <= 1e+236) {
		tmp = x - (x * (z * y));
	} else {
		tmp = t_0;
	}
	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) :: t_0
    real(8) :: tmp
    t_0 = (-x * y) * z
    if ((z * y) <= (-1d+245)) then
        tmp = t_0
    else if ((z * y) <= 1d+236) then
        tmp = x - (x * (z * y))
    else
        tmp = t_0
    end if
    code = tmp
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
	double t_0 = (-x * y) * z;
	double tmp;
	if ((z * y) <= -1e+245) {
		tmp = t_0;
	} else if ((z * y) <= 1e+236) {
		tmp = x - (x * (z * y));
	} else {
		tmp = t_0;
	}
	return tmp;
}
[x, y, z] = sort([x, y, z])
def code(x, y, z):
	t_0 = (-x * y) * z
	tmp = 0
	if (z * y) <= -1e+245:
		tmp = t_0
	elif (z * y) <= 1e+236:
		tmp = x - (x * (z * y))
	else:
		tmp = t_0
	return tmp
x, y, z = sort([x, y, z])
function code(x, y, z)
	t_0 = Float64(Float64(Float64(-x) * y) * z)
	tmp = 0.0
	if (Float64(z * y) <= -1e+245)
		tmp = t_0;
	elseif (Float64(z * y) <= 1e+236)
		tmp = Float64(x - Float64(x * Float64(z * y)));
	else
		tmp = t_0;
	end
	return tmp
end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
	t_0 = (-x * y) * z;
	tmp = 0.0;
	if ((z * y) <= -1e+245)
		tmp = t_0;
	elseif ((z * y) <= 1e+236)
		tmp = x - (x * (z * y));
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function.
code[x_, y_, z_] := Block[{t$95$0 = N[(N[((-x) * y), $MachinePrecision] * z), $MachinePrecision]}, If[LessEqual[N[(z * y), $MachinePrecision], -1e+245], t$95$0, If[LessEqual[N[(z * y), $MachinePrecision], 1e+236], N[(x - N[(x * N[(z * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
t_0 := \left(\left(-x\right) \cdot y\right) \cdot z\\
\mathbf{if}\;z \cdot y \leq -1 \cdot 10^{+245}:\\
\;\;\;\;t\_0\\

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

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


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

    1. Initial program 78.5%

      \[x \cdot \left(1 - y \cdot z\right) \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto \color{blue}{x \cdot \left(1 - y \cdot z\right)} \]
      2. lift--.f64N/A

        \[\leadsto x \cdot \color{blue}{\left(1 - y \cdot z\right)} \]
      3. sub-negN/A

        \[\leadsto x \cdot \color{blue}{\left(1 + \left(\mathsf{neg}\left(y \cdot z\right)\right)\right)} \]
      4. +-commutativeN/A

        \[\leadsto x \cdot \color{blue}{\left(\left(\mathsf{neg}\left(y \cdot z\right)\right) + 1\right)} \]
      5. distribute-lft-inN/A

        \[\leadsto \color{blue}{x \cdot \left(\mathsf{neg}\left(y \cdot z\right)\right) + x \cdot 1} \]
      6. lift-*.f64N/A

        \[\leadsto x \cdot \left(\mathsf{neg}\left(\color{blue}{y \cdot z}\right)\right) + x \cdot 1 \]
      7. distribute-lft-neg-inN/A

        \[\leadsto x \cdot \color{blue}{\left(\left(\mathsf{neg}\left(y\right)\right) \cdot z\right)} + x \cdot 1 \]
      8. associate-*r*N/A

        \[\leadsto \color{blue}{\left(x \cdot \left(\mathsf{neg}\left(y\right)\right)\right) \cdot z} + x \cdot 1 \]
      9. *-rgt-identityN/A

        \[\leadsto \left(x \cdot \left(\mathsf{neg}\left(y\right)\right)\right) \cdot z + \color{blue}{x} \]
      10. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(x \cdot \left(\mathsf{neg}\left(y\right)\right), z, x\right)} \]
      11. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{x \cdot \left(\mathsf{neg}\left(y\right)\right)}, z, x\right) \]
      12. lower-neg.f6499.9

        \[\leadsto \mathsf{fma}\left(x \cdot \color{blue}{\left(-y\right)}, z, x\right) \]
    4. Applied rewrites99.9%

      \[\leadsto \color{blue}{\mathsf{fma}\left(x \cdot \left(-y\right), z, x\right)} \]
    5. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{x \cdot \left(-y\right)}, z, x\right) \]
      2. *-commutativeN/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{\left(-y\right) \cdot x}, z, x\right) \]
      3. lift-neg.f64N/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{\left(\mathsf{neg}\left(y\right)\right)} \cdot x, z, x\right) \]
      4. neg-sub0N/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{\left(0 - y\right)} \cdot x, z, x\right) \]
      5. flip3--N/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{{0}^{3} - {y}^{3}}{0 \cdot 0 + \left(y \cdot y + 0 \cdot y\right)}} \cdot x, z, x\right) \]
      6. associate-*l/N/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{\left({0}^{3} - {y}^{3}\right) \cdot x}{0 \cdot 0 + \left(y \cdot y + 0 \cdot y\right)}}, z, x\right) \]
      7. metadata-evalN/A

        \[\leadsto \mathsf{fma}\left(\frac{\left({0}^{3} - {y}^{3}\right) \cdot x}{\color{blue}{0} + \left(y \cdot y + 0 \cdot y\right)}, z, x\right) \]
      8. +-lft-identityN/A

        \[\leadsto \mathsf{fma}\left(\frac{\left({0}^{3} - {y}^{3}\right) \cdot x}{\color{blue}{y \cdot y + 0 \cdot y}}, z, x\right) \]
      9. distribute-rgt-outN/A

        \[\leadsto \mathsf{fma}\left(\frac{\left({0}^{3} - {y}^{3}\right) \cdot x}{\color{blue}{y \cdot \left(y + 0\right)}}, z, x\right) \]
      10. +-commutativeN/A

        \[\leadsto \mathsf{fma}\left(\frac{\left({0}^{3} - {y}^{3}\right) \cdot x}{y \cdot \color{blue}{\left(0 + y\right)}}, z, x\right) \]
      11. +-lft-identityN/A

        \[\leadsto \mathsf{fma}\left(\frac{\left({0}^{3} - {y}^{3}\right) \cdot x}{y \cdot \color{blue}{y}}, z, x\right) \]
      12. lower-/.f64N/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{\left({0}^{3} - {y}^{3}\right) \cdot x}{y \cdot y}}, z, x\right) \]
      13. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{\color{blue}{\left({0}^{3} - {y}^{3}\right) \cdot x}}{y \cdot y}, z, x\right) \]
      14. metadata-evalN/A

        \[\leadsto \mathsf{fma}\left(\frac{\left(\color{blue}{0} - {y}^{3}\right) \cdot x}{y \cdot y}, z, x\right) \]
      15. sub0-negN/A

        \[\leadsto \mathsf{fma}\left(\frac{\color{blue}{\left(\mathsf{neg}\left({y}^{3}\right)\right)} \cdot x}{y \cdot y}, z, x\right) \]
      16. lower-neg.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{\color{blue}{\left(-{y}^{3}\right)} \cdot x}{y \cdot y}, z, x\right) \]
      17. lower-pow.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{\left(-\color{blue}{{y}^{3}}\right) \cdot x}{y \cdot y}, z, x\right) \]
      18. lower-*.f6434.0

        \[\leadsto \mathsf{fma}\left(\frac{\left(-{y}^{3}\right) \cdot x}{\color{blue}{y \cdot y}}, z, x\right) \]
    6. Applied rewrites34.0%

      \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{\left(-{y}^{3}\right) \cdot x}{y \cdot y}}, z, x\right) \]
    7. Taylor expanded in z around inf

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

        \[\leadsto \color{blue}{\mathsf{neg}\left(x \cdot \left(y \cdot z\right)\right)} \]
      2. associate-*r*N/A

        \[\leadsto \mathsf{neg}\left(\color{blue}{\left(x \cdot y\right) \cdot z}\right) \]
      3. *-commutativeN/A

        \[\leadsto \mathsf{neg}\left(\color{blue}{z \cdot \left(x \cdot y\right)}\right) \]
      4. distribute-lft-neg-inN/A

        \[\leadsto \color{blue}{\left(\mathsf{neg}\left(z\right)\right) \cdot \left(x \cdot y\right)} \]
      5. mul-1-negN/A

        \[\leadsto \color{blue}{\left(-1 \cdot z\right)} \cdot \left(x \cdot y\right) \]
      6. lower-*.f64N/A

        \[\leadsto \color{blue}{\left(-1 \cdot z\right) \cdot \left(x \cdot y\right)} \]
      7. mul-1-negN/A

        \[\leadsto \color{blue}{\left(\mathsf{neg}\left(z\right)\right)} \cdot \left(x \cdot y\right) \]
      8. lower-neg.f64N/A

        \[\leadsto \color{blue}{\left(-z\right)} \cdot \left(x \cdot y\right) \]
      9. *-commutativeN/A

        \[\leadsto \left(-z\right) \cdot \color{blue}{\left(y \cdot x\right)} \]
      10. lower-*.f6499.9

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

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

    if -1.00000000000000004e245 < (*.f64 y z) < 1.00000000000000005e236

    1. Initial program 99.8%

      \[x \cdot \left(1 - y \cdot z\right) \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto \color{blue}{x \cdot \left(1 - y \cdot z\right)} \]
      2. lift--.f64N/A

        \[\leadsto x \cdot \color{blue}{\left(1 - y \cdot z\right)} \]
      3. sub-negN/A

        \[\leadsto x \cdot \color{blue}{\left(1 + \left(\mathsf{neg}\left(y \cdot z\right)\right)\right)} \]
      4. distribute-rgt-inN/A

        \[\leadsto \color{blue}{1 \cdot x + \left(\mathsf{neg}\left(y \cdot z\right)\right) \cdot x} \]
      5. *-lft-identityN/A

        \[\leadsto \color{blue}{x} + \left(\mathsf{neg}\left(y \cdot z\right)\right) \cdot x \]
      6. distribute-lft-neg-outN/A

        \[\leadsto x + \color{blue}{\left(\mathsf{neg}\left(\left(y \cdot z\right) \cdot x\right)\right)} \]
      7. unsub-negN/A

        \[\leadsto \color{blue}{x - \left(y \cdot z\right) \cdot x} \]
      8. lower--.f64N/A

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

        \[\leadsto x - \color{blue}{\left(y \cdot z\right) \cdot x} \]
      10. lift-*.f64N/A

        \[\leadsto x - \color{blue}{\left(y \cdot z\right)} \cdot x \]
      11. *-commutativeN/A

        \[\leadsto x - \color{blue}{\left(z \cdot y\right)} \cdot x \]
      12. lower-*.f6499.9

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

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

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

Alternative 2: 99.8% accurate, 0.4× speedup?

\[\begin{array}{l} [x, y, z] = \mathsf{sort}([x, y, z])\\ \\ \begin{array}{l} t_0 := \left(\left(-x\right) \cdot y\right) \cdot z\\ \mathbf{if}\;z \cdot y \leq -1 \cdot 10^{+245}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;z \cdot y \leq 10^{+236}:\\ \;\;\;\;\left(1 - z \cdot y\right) \cdot x\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \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
 (let* ((t_0 (* (* (- x) y) z)))
   (if (<= (* z y) -1e+245)
     t_0
     (if (<= (* z y) 1e+236) (* (- 1.0 (* z y)) x) t_0))))
assert(x < y && y < z);
double code(double x, double y, double z) {
	double t_0 = (-x * y) * z;
	double tmp;
	if ((z * y) <= -1e+245) {
		tmp = t_0;
	} else if ((z * y) <= 1e+236) {
		tmp = (1.0 - (z * y)) * x;
	} else {
		tmp = t_0;
	}
	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) :: t_0
    real(8) :: tmp
    t_0 = (-x * y) * z
    if ((z * y) <= (-1d+245)) then
        tmp = t_0
    else if ((z * y) <= 1d+236) then
        tmp = (1.0d0 - (z * y)) * x
    else
        tmp = t_0
    end if
    code = tmp
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
	double t_0 = (-x * y) * z;
	double tmp;
	if ((z * y) <= -1e+245) {
		tmp = t_0;
	} else if ((z * y) <= 1e+236) {
		tmp = (1.0 - (z * y)) * x;
	} else {
		tmp = t_0;
	}
	return tmp;
}
[x, y, z] = sort([x, y, z])
def code(x, y, z):
	t_0 = (-x * y) * z
	tmp = 0
	if (z * y) <= -1e+245:
		tmp = t_0
	elif (z * y) <= 1e+236:
		tmp = (1.0 - (z * y)) * x
	else:
		tmp = t_0
	return tmp
x, y, z = sort([x, y, z])
function code(x, y, z)
	t_0 = Float64(Float64(Float64(-x) * y) * z)
	tmp = 0.0
	if (Float64(z * y) <= -1e+245)
		tmp = t_0;
	elseif (Float64(z * y) <= 1e+236)
		tmp = Float64(Float64(1.0 - Float64(z * y)) * x);
	else
		tmp = t_0;
	end
	return tmp
end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
	t_0 = (-x * y) * z;
	tmp = 0.0;
	if ((z * y) <= -1e+245)
		tmp = t_0;
	elseif ((z * y) <= 1e+236)
		tmp = (1.0 - (z * y)) * x;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function.
code[x_, y_, z_] := Block[{t$95$0 = N[(N[((-x) * y), $MachinePrecision] * z), $MachinePrecision]}, If[LessEqual[N[(z * y), $MachinePrecision], -1e+245], t$95$0, If[LessEqual[N[(z * y), $MachinePrecision], 1e+236], N[(N[(1.0 - N[(z * y), $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
t_0 := \left(\left(-x\right) \cdot y\right) \cdot z\\
\mathbf{if}\;z \cdot y \leq -1 \cdot 10^{+245}:\\
\;\;\;\;t\_0\\

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

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


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

    1. Initial program 78.5%

      \[x \cdot \left(1 - y \cdot z\right) \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto \color{blue}{x \cdot \left(1 - y \cdot z\right)} \]
      2. lift--.f64N/A

        \[\leadsto x \cdot \color{blue}{\left(1 - y \cdot z\right)} \]
      3. sub-negN/A

        \[\leadsto x \cdot \color{blue}{\left(1 + \left(\mathsf{neg}\left(y \cdot z\right)\right)\right)} \]
      4. +-commutativeN/A

        \[\leadsto x \cdot \color{blue}{\left(\left(\mathsf{neg}\left(y \cdot z\right)\right) + 1\right)} \]
      5. distribute-lft-inN/A

        \[\leadsto \color{blue}{x \cdot \left(\mathsf{neg}\left(y \cdot z\right)\right) + x \cdot 1} \]
      6. lift-*.f64N/A

        \[\leadsto x \cdot \left(\mathsf{neg}\left(\color{blue}{y \cdot z}\right)\right) + x \cdot 1 \]
      7. distribute-lft-neg-inN/A

        \[\leadsto x \cdot \color{blue}{\left(\left(\mathsf{neg}\left(y\right)\right) \cdot z\right)} + x \cdot 1 \]
      8. associate-*r*N/A

        \[\leadsto \color{blue}{\left(x \cdot \left(\mathsf{neg}\left(y\right)\right)\right) \cdot z} + x \cdot 1 \]
      9. *-rgt-identityN/A

        \[\leadsto \left(x \cdot \left(\mathsf{neg}\left(y\right)\right)\right) \cdot z + \color{blue}{x} \]
      10. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(x \cdot \left(\mathsf{neg}\left(y\right)\right), z, x\right)} \]
      11. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{x \cdot \left(\mathsf{neg}\left(y\right)\right)}, z, x\right) \]
      12. lower-neg.f6499.9

        \[\leadsto \mathsf{fma}\left(x \cdot \color{blue}{\left(-y\right)}, z, x\right) \]
    4. Applied rewrites99.9%

      \[\leadsto \color{blue}{\mathsf{fma}\left(x \cdot \left(-y\right), z, x\right)} \]
    5. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{x \cdot \left(-y\right)}, z, x\right) \]
      2. *-commutativeN/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{\left(-y\right) \cdot x}, z, x\right) \]
      3. lift-neg.f64N/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{\left(\mathsf{neg}\left(y\right)\right)} \cdot x, z, x\right) \]
      4. neg-sub0N/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{\left(0 - y\right)} \cdot x, z, x\right) \]
      5. flip3--N/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{{0}^{3} - {y}^{3}}{0 \cdot 0 + \left(y \cdot y + 0 \cdot y\right)}} \cdot x, z, x\right) \]
      6. associate-*l/N/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{\left({0}^{3} - {y}^{3}\right) \cdot x}{0 \cdot 0 + \left(y \cdot y + 0 \cdot y\right)}}, z, x\right) \]
      7. metadata-evalN/A

        \[\leadsto \mathsf{fma}\left(\frac{\left({0}^{3} - {y}^{3}\right) \cdot x}{\color{blue}{0} + \left(y \cdot y + 0 \cdot y\right)}, z, x\right) \]
      8. +-lft-identityN/A

        \[\leadsto \mathsf{fma}\left(\frac{\left({0}^{3} - {y}^{3}\right) \cdot x}{\color{blue}{y \cdot y + 0 \cdot y}}, z, x\right) \]
      9. distribute-rgt-outN/A

        \[\leadsto \mathsf{fma}\left(\frac{\left({0}^{3} - {y}^{3}\right) \cdot x}{\color{blue}{y \cdot \left(y + 0\right)}}, z, x\right) \]
      10. +-commutativeN/A

        \[\leadsto \mathsf{fma}\left(\frac{\left({0}^{3} - {y}^{3}\right) \cdot x}{y \cdot \color{blue}{\left(0 + y\right)}}, z, x\right) \]
      11. +-lft-identityN/A

        \[\leadsto \mathsf{fma}\left(\frac{\left({0}^{3} - {y}^{3}\right) \cdot x}{y \cdot \color{blue}{y}}, z, x\right) \]
      12. lower-/.f64N/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{\left({0}^{3} - {y}^{3}\right) \cdot x}{y \cdot y}}, z, x\right) \]
      13. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{\color{blue}{\left({0}^{3} - {y}^{3}\right) \cdot x}}{y \cdot y}, z, x\right) \]
      14. metadata-evalN/A

        \[\leadsto \mathsf{fma}\left(\frac{\left(\color{blue}{0} - {y}^{3}\right) \cdot x}{y \cdot y}, z, x\right) \]
      15. sub0-negN/A

        \[\leadsto \mathsf{fma}\left(\frac{\color{blue}{\left(\mathsf{neg}\left({y}^{3}\right)\right)} \cdot x}{y \cdot y}, z, x\right) \]
      16. lower-neg.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{\color{blue}{\left(-{y}^{3}\right)} \cdot x}{y \cdot y}, z, x\right) \]
      17. lower-pow.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{\left(-\color{blue}{{y}^{3}}\right) \cdot x}{y \cdot y}, z, x\right) \]
      18. lower-*.f6434.0

        \[\leadsto \mathsf{fma}\left(\frac{\left(-{y}^{3}\right) \cdot x}{\color{blue}{y \cdot y}}, z, x\right) \]
    6. Applied rewrites34.0%

      \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{\left(-{y}^{3}\right) \cdot x}{y \cdot y}}, z, x\right) \]
    7. Taylor expanded in z around inf

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

        \[\leadsto \color{blue}{\mathsf{neg}\left(x \cdot \left(y \cdot z\right)\right)} \]
      2. associate-*r*N/A

        \[\leadsto \mathsf{neg}\left(\color{blue}{\left(x \cdot y\right) \cdot z}\right) \]
      3. *-commutativeN/A

        \[\leadsto \mathsf{neg}\left(\color{blue}{z \cdot \left(x \cdot y\right)}\right) \]
      4. distribute-lft-neg-inN/A

        \[\leadsto \color{blue}{\left(\mathsf{neg}\left(z\right)\right) \cdot \left(x \cdot y\right)} \]
      5. mul-1-negN/A

        \[\leadsto \color{blue}{\left(-1 \cdot z\right)} \cdot \left(x \cdot y\right) \]
      6. lower-*.f64N/A

        \[\leadsto \color{blue}{\left(-1 \cdot z\right) \cdot \left(x \cdot y\right)} \]
      7. mul-1-negN/A

        \[\leadsto \color{blue}{\left(\mathsf{neg}\left(z\right)\right)} \cdot \left(x \cdot y\right) \]
      8. lower-neg.f64N/A

        \[\leadsto \color{blue}{\left(-z\right)} \cdot \left(x \cdot y\right) \]
      9. *-commutativeN/A

        \[\leadsto \left(-z\right) \cdot \color{blue}{\left(y \cdot x\right)} \]
      10. lower-*.f6499.9

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

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

    if -1.00000000000000004e245 < (*.f64 y z) < 1.00000000000000005e236

    1. Initial program 99.8%

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

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

Alternative 3: 94.3% accurate, 0.4× speedup?

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

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

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


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

    1. Initial program 92.3%

      \[x \cdot \left(1 - y \cdot z\right) \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto \color{blue}{x \cdot \left(1 - y \cdot z\right)} \]
      2. lift--.f64N/A

        \[\leadsto x \cdot \color{blue}{\left(1 - y \cdot z\right)} \]
      3. sub-negN/A

        \[\leadsto x \cdot \color{blue}{\left(1 + \left(\mathsf{neg}\left(y \cdot z\right)\right)\right)} \]
      4. +-commutativeN/A

        \[\leadsto x \cdot \color{blue}{\left(\left(\mathsf{neg}\left(y \cdot z\right)\right) + 1\right)} \]
      5. distribute-lft-inN/A

        \[\leadsto \color{blue}{x \cdot \left(\mathsf{neg}\left(y \cdot z\right)\right) + x \cdot 1} \]
      6. lift-*.f64N/A

        \[\leadsto x \cdot \left(\mathsf{neg}\left(\color{blue}{y \cdot z}\right)\right) + x \cdot 1 \]
      7. distribute-lft-neg-inN/A

        \[\leadsto x \cdot \color{blue}{\left(\left(\mathsf{neg}\left(y\right)\right) \cdot z\right)} + x \cdot 1 \]
      8. associate-*r*N/A

        \[\leadsto \color{blue}{\left(x \cdot \left(\mathsf{neg}\left(y\right)\right)\right) \cdot z} + x \cdot 1 \]
      9. *-rgt-identityN/A

        \[\leadsto \left(x \cdot \left(\mathsf{neg}\left(y\right)\right)\right) \cdot z + \color{blue}{x} \]
      10. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(x \cdot \left(\mathsf{neg}\left(y\right)\right), z, x\right)} \]
      11. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{x \cdot \left(\mathsf{neg}\left(y\right)\right)}, z, x\right) \]
      12. lower-neg.f6495.3

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(x \cdot \left(-y\right), z, x\right)} \]
    5. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{x \cdot \left(-y\right)}, z, x\right) \]
      2. *-commutativeN/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{\left(-y\right) \cdot x}, z, x\right) \]
      3. lift-neg.f64N/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{\left(\mathsf{neg}\left(y\right)\right)} \cdot x, z, x\right) \]
      4. neg-sub0N/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{\left(0 - y\right)} \cdot x, z, x\right) \]
      5. flip3--N/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{{0}^{3} - {y}^{3}}{0 \cdot 0 + \left(y \cdot y + 0 \cdot y\right)}} \cdot x, z, x\right) \]
      6. associate-*l/N/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{\left({0}^{3} - {y}^{3}\right) \cdot x}{0 \cdot 0 + \left(y \cdot y + 0 \cdot y\right)}}, z, x\right) \]
      7. metadata-evalN/A

        \[\leadsto \mathsf{fma}\left(\frac{\left({0}^{3} - {y}^{3}\right) \cdot x}{\color{blue}{0} + \left(y \cdot y + 0 \cdot y\right)}, z, x\right) \]
      8. +-lft-identityN/A

        \[\leadsto \mathsf{fma}\left(\frac{\left({0}^{3} - {y}^{3}\right) \cdot x}{\color{blue}{y \cdot y + 0 \cdot y}}, z, x\right) \]
      9. distribute-rgt-outN/A

        \[\leadsto \mathsf{fma}\left(\frac{\left({0}^{3} - {y}^{3}\right) \cdot x}{\color{blue}{y \cdot \left(y + 0\right)}}, z, x\right) \]
      10. +-commutativeN/A

        \[\leadsto \mathsf{fma}\left(\frac{\left({0}^{3} - {y}^{3}\right) \cdot x}{y \cdot \color{blue}{\left(0 + y\right)}}, z, x\right) \]
      11. +-lft-identityN/A

        \[\leadsto \mathsf{fma}\left(\frac{\left({0}^{3} - {y}^{3}\right) \cdot x}{y \cdot \color{blue}{y}}, z, x\right) \]
      12. lower-/.f64N/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{\left({0}^{3} - {y}^{3}\right) \cdot x}{y \cdot y}}, z, x\right) \]
      13. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{\color{blue}{\left({0}^{3} - {y}^{3}\right) \cdot x}}{y \cdot y}, z, x\right) \]
      14. metadata-evalN/A

        \[\leadsto \mathsf{fma}\left(\frac{\left(\color{blue}{0} - {y}^{3}\right) \cdot x}{y \cdot y}, z, x\right) \]
      15. sub0-negN/A

        \[\leadsto \mathsf{fma}\left(\frac{\color{blue}{\left(\mathsf{neg}\left({y}^{3}\right)\right)} \cdot x}{y \cdot y}, z, x\right) \]
      16. lower-neg.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{\color{blue}{\left(-{y}^{3}\right)} \cdot x}{y \cdot y}, z, x\right) \]
      17. lower-pow.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{\left(-\color{blue}{{y}^{3}}\right) \cdot x}{y \cdot y}, z, x\right) \]
      18. lower-*.f6434.4

        \[\leadsto \mathsf{fma}\left(\frac{\left(-{y}^{3}\right) \cdot x}{\color{blue}{y \cdot y}}, z, x\right) \]
    6. Applied rewrites34.4%

      \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{\left(-{y}^{3}\right) \cdot x}{y \cdot y}}, z, x\right) \]
    7. Taylor expanded in z around inf

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

        \[\leadsto \color{blue}{\mathsf{neg}\left(x \cdot \left(y \cdot z\right)\right)} \]
      2. associate-*r*N/A

        \[\leadsto \mathsf{neg}\left(\color{blue}{\left(x \cdot y\right) \cdot z}\right) \]
      3. *-commutativeN/A

        \[\leadsto \mathsf{neg}\left(\color{blue}{z \cdot \left(x \cdot y\right)}\right) \]
      4. distribute-lft-neg-inN/A

        \[\leadsto \color{blue}{\left(\mathsf{neg}\left(z\right)\right) \cdot \left(x \cdot y\right)} \]
      5. mul-1-negN/A

        \[\leadsto \color{blue}{\left(-1 \cdot z\right)} \cdot \left(x \cdot y\right) \]
      6. lower-*.f64N/A

        \[\leadsto \color{blue}{\left(-1 \cdot z\right) \cdot \left(x \cdot y\right)} \]
      7. mul-1-negN/A

        \[\leadsto \color{blue}{\left(\mathsf{neg}\left(z\right)\right)} \cdot \left(x \cdot y\right) \]
      8. lower-neg.f64N/A

        \[\leadsto \color{blue}{\left(-z\right)} \cdot \left(x \cdot y\right) \]
      9. *-commutativeN/A

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

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

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

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

      if -1e4 < (*.f64 y z) < 0.0050000000000000001

      1. Initial program 100.0%

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

        \[\leadsto x \cdot \color{blue}{1} \]
      4. Step-by-step derivation
        1. Applied rewrites97.9%

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

        if 0.0050000000000000001 < (*.f64 y z)

        1. Initial program 92.1%

          \[x \cdot \left(1 - y \cdot z\right) \]
        2. Add Preprocessing
        3. Step-by-step derivation
          1. lift-*.f64N/A

            \[\leadsto \color{blue}{x \cdot \left(1 - y \cdot z\right)} \]
          2. lift--.f64N/A

            \[\leadsto x \cdot \color{blue}{\left(1 - y \cdot z\right)} \]
          3. sub-negN/A

            \[\leadsto x \cdot \color{blue}{\left(1 + \left(\mathsf{neg}\left(y \cdot z\right)\right)\right)} \]
          4. +-commutativeN/A

            \[\leadsto x \cdot \color{blue}{\left(\left(\mathsf{neg}\left(y \cdot z\right)\right) + 1\right)} \]
          5. distribute-lft-inN/A

            \[\leadsto \color{blue}{x \cdot \left(\mathsf{neg}\left(y \cdot z\right)\right) + x \cdot 1} \]
          6. lift-*.f64N/A

            \[\leadsto x \cdot \left(\mathsf{neg}\left(\color{blue}{y \cdot z}\right)\right) + x \cdot 1 \]
          7. distribute-lft-neg-inN/A

            \[\leadsto x \cdot \color{blue}{\left(\left(\mathsf{neg}\left(y\right)\right) \cdot z\right)} + x \cdot 1 \]
          8. associate-*r*N/A

            \[\leadsto \color{blue}{\left(x \cdot \left(\mathsf{neg}\left(y\right)\right)\right) \cdot z} + x \cdot 1 \]
          9. *-rgt-identityN/A

            \[\leadsto \left(x \cdot \left(\mathsf{neg}\left(y\right)\right)\right) \cdot z + \color{blue}{x} \]
          10. lower-fma.f64N/A

            \[\leadsto \color{blue}{\mathsf{fma}\left(x \cdot \left(\mathsf{neg}\left(y\right)\right), z, x\right)} \]
          11. lower-*.f64N/A

            \[\leadsto \mathsf{fma}\left(\color{blue}{x \cdot \left(\mathsf{neg}\left(y\right)\right)}, z, x\right) \]
          12. lower-neg.f6491.6

            \[\leadsto \mathsf{fma}\left(x \cdot \color{blue}{\left(-y\right)}, z, x\right) \]
        4. Applied rewrites91.6%

          \[\leadsto \color{blue}{\mathsf{fma}\left(x \cdot \left(-y\right), z, x\right)} \]
        5. Step-by-step derivation
          1. lift-*.f64N/A

            \[\leadsto \mathsf{fma}\left(\color{blue}{x \cdot \left(-y\right)}, z, x\right) \]
          2. *-commutativeN/A

            \[\leadsto \mathsf{fma}\left(\color{blue}{\left(-y\right) \cdot x}, z, x\right) \]
          3. lift-neg.f64N/A

            \[\leadsto \mathsf{fma}\left(\color{blue}{\left(\mathsf{neg}\left(y\right)\right)} \cdot x, z, x\right) \]
          4. neg-sub0N/A

            \[\leadsto \mathsf{fma}\left(\color{blue}{\left(0 - y\right)} \cdot x, z, x\right) \]
          5. flip3--N/A

            \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{{0}^{3} - {y}^{3}}{0 \cdot 0 + \left(y \cdot y + 0 \cdot y\right)}} \cdot x, z, x\right) \]
          6. associate-*l/N/A

            \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{\left({0}^{3} - {y}^{3}\right) \cdot x}{0 \cdot 0 + \left(y \cdot y + 0 \cdot y\right)}}, z, x\right) \]
          7. metadata-evalN/A

            \[\leadsto \mathsf{fma}\left(\frac{\left({0}^{3} - {y}^{3}\right) \cdot x}{\color{blue}{0} + \left(y \cdot y + 0 \cdot y\right)}, z, x\right) \]
          8. +-lft-identityN/A

            \[\leadsto \mathsf{fma}\left(\frac{\left({0}^{3} - {y}^{3}\right) \cdot x}{\color{blue}{y \cdot y + 0 \cdot y}}, z, x\right) \]
          9. distribute-rgt-outN/A

            \[\leadsto \mathsf{fma}\left(\frac{\left({0}^{3} - {y}^{3}\right) \cdot x}{\color{blue}{y \cdot \left(y + 0\right)}}, z, x\right) \]
          10. +-commutativeN/A

            \[\leadsto \mathsf{fma}\left(\frac{\left({0}^{3} - {y}^{3}\right) \cdot x}{y \cdot \color{blue}{\left(0 + y\right)}}, z, x\right) \]
          11. +-lft-identityN/A

            \[\leadsto \mathsf{fma}\left(\frac{\left({0}^{3} - {y}^{3}\right) \cdot x}{y \cdot \color{blue}{y}}, z, x\right) \]
          12. lower-/.f64N/A

            \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{\left({0}^{3} - {y}^{3}\right) \cdot x}{y \cdot y}}, z, x\right) \]
          13. lower-*.f64N/A

            \[\leadsto \mathsf{fma}\left(\frac{\color{blue}{\left({0}^{3} - {y}^{3}\right) \cdot x}}{y \cdot y}, z, x\right) \]
          14. metadata-evalN/A

            \[\leadsto \mathsf{fma}\left(\frac{\left(\color{blue}{0} - {y}^{3}\right) \cdot x}{y \cdot y}, z, x\right) \]
          15. sub0-negN/A

            \[\leadsto \mathsf{fma}\left(\frac{\color{blue}{\left(\mathsf{neg}\left({y}^{3}\right)\right)} \cdot x}{y \cdot y}, z, x\right) \]
          16. lower-neg.f64N/A

            \[\leadsto \mathsf{fma}\left(\frac{\color{blue}{\left(-{y}^{3}\right)} \cdot x}{y \cdot y}, z, x\right) \]
          17. lower-pow.f64N/A

            \[\leadsto \mathsf{fma}\left(\frac{\left(-\color{blue}{{y}^{3}}\right) \cdot x}{y \cdot y}, z, x\right) \]
          18. lower-*.f6430.6

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

          \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{\left(-{y}^{3}\right) \cdot x}{y \cdot y}}, z, x\right) \]
        7. Taylor expanded in z around inf

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

            \[\leadsto \color{blue}{\mathsf{neg}\left(x \cdot \left(y \cdot z\right)\right)} \]
          2. associate-*r*N/A

            \[\leadsto \mathsf{neg}\left(\color{blue}{\left(x \cdot y\right) \cdot z}\right) \]
          3. *-commutativeN/A

            \[\leadsto \mathsf{neg}\left(\color{blue}{z \cdot \left(x \cdot y\right)}\right) \]
          4. distribute-lft-neg-inN/A

            \[\leadsto \color{blue}{\left(\mathsf{neg}\left(z\right)\right) \cdot \left(x \cdot y\right)} \]
          5. mul-1-negN/A

            \[\leadsto \color{blue}{\left(-1 \cdot z\right)} \cdot \left(x \cdot y\right) \]
          6. lower-*.f64N/A

            \[\leadsto \color{blue}{\left(-1 \cdot z\right) \cdot \left(x \cdot y\right)} \]
          7. mul-1-negN/A

            \[\leadsto \color{blue}{\left(\mathsf{neg}\left(z\right)\right)} \cdot \left(x \cdot y\right) \]
          8. lower-neg.f64N/A

            \[\leadsto \color{blue}{\left(-z\right)} \cdot \left(x \cdot y\right) \]
          9. *-commutativeN/A

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

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

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

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

      Alternative 4: 94.2% accurate, 0.4× speedup?

      \[\begin{array}{l} [x, y, z] = \mathsf{sort}([x, y, z])\\ \\ \begin{array}{l} t_0 := \left(\left(-x\right) \cdot y\right) \cdot z\\ \mathbf{if}\;z \cdot y \leq -100000:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;z \cdot y \leq 0.005:\\ \;\;\;\;1 \cdot x\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \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
       (let* ((t_0 (* (* (- x) y) z)))
         (if (<= (* z y) -100000.0) t_0 (if (<= (* z y) 0.005) (* 1.0 x) t_0))))
      assert(x < y && y < z);
      double code(double x, double y, double z) {
      	double t_0 = (-x * y) * z;
      	double tmp;
      	if ((z * y) <= -100000.0) {
      		tmp = t_0;
      	} else if ((z * y) <= 0.005) {
      		tmp = 1.0 * x;
      	} else {
      		tmp = t_0;
      	}
      	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) :: t_0
          real(8) :: tmp
          t_0 = (-x * y) * z
          if ((z * y) <= (-100000.0d0)) then
              tmp = t_0
          else if ((z * y) <= 0.005d0) then
              tmp = 1.0d0 * x
          else
              tmp = t_0
          end if
          code = tmp
      end function
      
      assert x < y && y < z;
      public static double code(double x, double y, double z) {
      	double t_0 = (-x * y) * z;
      	double tmp;
      	if ((z * y) <= -100000.0) {
      		tmp = t_0;
      	} else if ((z * y) <= 0.005) {
      		tmp = 1.0 * x;
      	} else {
      		tmp = t_0;
      	}
      	return tmp;
      }
      
      [x, y, z] = sort([x, y, z])
      def code(x, y, z):
      	t_0 = (-x * y) * z
      	tmp = 0
      	if (z * y) <= -100000.0:
      		tmp = t_0
      	elif (z * y) <= 0.005:
      		tmp = 1.0 * x
      	else:
      		tmp = t_0
      	return tmp
      
      x, y, z = sort([x, y, z])
      function code(x, y, z)
      	t_0 = Float64(Float64(Float64(-x) * y) * z)
      	tmp = 0.0
      	if (Float64(z * y) <= -100000.0)
      		tmp = t_0;
      	elseif (Float64(z * y) <= 0.005)
      		tmp = Float64(1.0 * x);
      	else
      		tmp = t_0;
      	end
      	return tmp
      end
      
      x, y, z = num2cell(sort([x, y, z])){:}
      function tmp_2 = code(x, y, z)
      	t_0 = (-x * y) * z;
      	tmp = 0.0;
      	if ((z * y) <= -100000.0)
      		tmp = t_0;
      	elseif ((z * y) <= 0.005)
      		tmp = 1.0 * x;
      	else
      		tmp = t_0;
      	end
      	tmp_2 = tmp;
      end
      
      NOTE: x, y, and z should be sorted in increasing order before calling this function.
      code[x_, y_, z_] := Block[{t$95$0 = N[(N[((-x) * y), $MachinePrecision] * z), $MachinePrecision]}, If[LessEqual[N[(z * y), $MachinePrecision], -100000.0], t$95$0, If[LessEqual[N[(z * y), $MachinePrecision], 0.005], N[(1.0 * x), $MachinePrecision], t$95$0]]]
      
      \begin{array}{l}
      [x, y, z] = \mathsf{sort}([x, y, z])\\
      \\
      \begin{array}{l}
      t_0 := \left(\left(-x\right) \cdot y\right) \cdot z\\
      \mathbf{if}\;z \cdot y \leq -100000:\\
      \;\;\;\;t\_0\\
      
      \mathbf{elif}\;z \cdot y \leq 0.005:\\
      \;\;\;\;1 \cdot x\\
      
      \mathbf{else}:\\
      \;\;\;\;t\_0\\
      
      
      \end{array}
      \end{array}
      
      Derivation
      1. Split input into 2 regimes
      2. if (*.f64 y z) < -1e5 or 0.0050000000000000001 < (*.f64 y z)

        1. Initial program 92.1%

          \[x \cdot \left(1 - y \cdot z\right) \]
        2. Add Preprocessing
        3. Step-by-step derivation
          1. lift-*.f64N/A

            \[\leadsto \color{blue}{x \cdot \left(1 - y \cdot z\right)} \]
          2. lift--.f64N/A

            \[\leadsto x \cdot \color{blue}{\left(1 - y \cdot z\right)} \]
          3. sub-negN/A

            \[\leadsto x \cdot \color{blue}{\left(1 + \left(\mathsf{neg}\left(y \cdot z\right)\right)\right)} \]
          4. +-commutativeN/A

            \[\leadsto x \cdot \color{blue}{\left(\left(\mathsf{neg}\left(y \cdot z\right)\right) + 1\right)} \]
          5. distribute-lft-inN/A

            \[\leadsto \color{blue}{x \cdot \left(\mathsf{neg}\left(y \cdot z\right)\right) + x \cdot 1} \]
          6. lift-*.f64N/A

            \[\leadsto x \cdot \left(\mathsf{neg}\left(\color{blue}{y \cdot z}\right)\right) + x \cdot 1 \]
          7. distribute-lft-neg-inN/A

            \[\leadsto x \cdot \color{blue}{\left(\left(\mathsf{neg}\left(y\right)\right) \cdot z\right)} + x \cdot 1 \]
          8. associate-*r*N/A

            \[\leadsto \color{blue}{\left(x \cdot \left(\mathsf{neg}\left(y\right)\right)\right) \cdot z} + x \cdot 1 \]
          9. *-rgt-identityN/A

            \[\leadsto \left(x \cdot \left(\mathsf{neg}\left(y\right)\right)\right) \cdot z + \color{blue}{x} \]
          10. lower-fma.f64N/A

            \[\leadsto \color{blue}{\mathsf{fma}\left(x \cdot \left(\mathsf{neg}\left(y\right)\right), z, x\right)} \]
          11. lower-*.f64N/A

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

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

          \[\leadsto \color{blue}{\mathsf{fma}\left(x \cdot \left(-y\right), z, x\right)} \]
        5. Step-by-step derivation
          1. lift-*.f64N/A

            \[\leadsto \mathsf{fma}\left(\color{blue}{x \cdot \left(-y\right)}, z, x\right) \]
          2. *-commutativeN/A

            \[\leadsto \mathsf{fma}\left(\color{blue}{\left(-y\right) \cdot x}, z, x\right) \]
          3. lift-neg.f64N/A

            \[\leadsto \mathsf{fma}\left(\color{blue}{\left(\mathsf{neg}\left(y\right)\right)} \cdot x, z, x\right) \]
          4. neg-sub0N/A

            \[\leadsto \mathsf{fma}\left(\color{blue}{\left(0 - y\right)} \cdot x, z, x\right) \]
          5. flip3--N/A

            \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{{0}^{3} - {y}^{3}}{0 \cdot 0 + \left(y \cdot y + 0 \cdot y\right)}} \cdot x, z, x\right) \]
          6. associate-*l/N/A

            \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{\left({0}^{3} - {y}^{3}\right) \cdot x}{0 \cdot 0 + \left(y \cdot y + 0 \cdot y\right)}}, z, x\right) \]
          7. metadata-evalN/A

            \[\leadsto \mathsf{fma}\left(\frac{\left({0}^{3} - {y}^{3}\right) \cdot x}{\color{blue}{0} + \left(y \cdot y + 0 \cdot y\right)}, z, x\right) \]
          8. +-lft-identityN/A

            \[\leadsto \mathsf{fma}\left(\frac{\left({0}^{3} - {y}^{3}\right) \cdot x}{\color{blue}{y \cdot y + 0 \cdot y}}, z, x\right) \]
          9. distribute-rgt-outN/A

            \[\leadsto \mathsf{fma}\left(\frac{\left({0}^{3} - {y}^{3}\right) \cdot x}{\color{blue}{y \cdot \left(y + 0\right)}}, z, x\right) \]
          10. +-commutativeN/A

            \[\leadsto \mathsf{fma}\left(\frac{\left({0}^{3} - {y}^{3}\right) \cdot x}{y \cdot \color{blue}{\left(0 + y\right)}}, z, x\right) \]
          11. +-lft-identityN/A

            \[\leadsto \mathsf{fma}\left(\frac{\left({0}^{3} - {y}^{3}\right) \cdot x}{y \cdot \color{blue}{y}}, z, x\right) \]
          12. lower-/.f64N/A

            \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{\left({0}^{3} - {y}^{3}\right) \cdot x}{y \cdot y}}, z, x\right) \]
          13. lower-*.f64N/A

            \[\leadsto \mathsf{fma}\left(\frac{\color{blue}{\left({0}^{3} - {y}^{3}\right) \cdot x}}{y \cdot y}, z, x\right) \]
          14. metadata-evalN/A

            \[\leadsto \mathsf{fma}\left(\frac{\left(\color{blue}{0} - {y}^{3}\right) \cdot x}{y \cdot y}, z, x\right) \]
          15. sub0-negN/A

            \[\leadsto \mathsf{fma}\left(\frac{\color{blue}{\left(\mathsf{neg}\left({y}^{3}\right)\right)} \cdot x}{y \cdot y}, z, x\right) \]
          16. lower-neg.f64N/A

            \[\leadsto \mathsf{fma}\left(\frac{\color{blue}{\left(-{y}^{3}\right)} \cdot x}{y \cdot y}, z, x\right) \]
          17. lower-pow.f64N/A

            \[\leadsto \mathsf{fma}\left(\frac{\left(-\color{blue}{{y}^{3}}\right) \cdot x}{y \cdot y}, z, x\right) \]
          18. lower-*.f6432.4

            \[\leadsto \mathsf{fma}\left(\frac{\left(-{y}^{3}\right) \cdot x}{\color{blue}{y \cdot y}}, z, x\right) \]
        6. Applied rewrites32.4%

          \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{\left(-{y}^{3}\right) \cdot x}{y \cdot y}}, z, x\right) \]
        7. Taylor expanded in z around inf

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

            \[\leadsto \color{blue}{\mathsf{neg}\left(x \cdot \left(y \cdot z\right)\right)} \]
          2. associate-*r*N/A

            \[\leadsto \mathsf{neg}\left(\color{blue}{\left(x \cdot y\right) \cdot z}\right) \]
          3. *-commutativeN/A

            \[\leadsto \mathsf{neg}\left(\color{blue}{z \cdot \left(x \cdot y\right)}\right) \]
          4. distribute-lft-neg-inN/A

            \[\leadsto \color{blue}{\left(\mathsf{neg}\left(z\right)\right) \cdot \left(x \cdot y\right)} \]
          5. mul-1-negN/A

            \[\leadsto \color{blue}{\left(-1 \cdot z\right)} \cdot \left(x \cdot y\right) \]
          6. lower-*.f64N/A

            \[\leadsto \color{blue}{\left(-1 \cdot z\right) \cdot \left(x \cdot y\right)} \]
          7. mul-1-negN/A

            \[\leadsto \color{blue}{\left(\mathsf{neg}\left(z\right)\right)} \cdot \left(x \cdot y\right) \]
          8. lower-neg.f64N/A

            \[\leadsto \color{blue}{\left(-z\right)} \cdot \left(x \cdot y\right) \]
          9. *-commutativeN/A

            \[\leadsto \left(-z\right) \cdot \color{blue}{\left(y \cdot x\right)} \]
          10. lower-*.f6491.2

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

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

        if -1e5 < (*.f64 y z) < 0.0050000000000000001

        1. Initial program 100.0%

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

          \[\leadsto x \cdot \color{blue}{1} \]
        4. Step-by-step derivation
          1. Applied rewrites97.1%

            \[\leadsto x \cdot \color{blue}{1} \]
        5. Recombined 2 regimes into one program.
        6. Final simplification93.7%

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

        Alternative 5: 50.6% accurate, 2.3× speedup?

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

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

          \[\leadsto x \cdot \color{blue}{1} \]
        4. Step-by-step derivation
          1. Applied rewrites42.8%

            \[\leadsto x \cdot \color{blue}{1} \]
          2. Final simplification42.8%

            \[\leadsto 1 \cdot x \]
          3. Add Preprocessing

          Reproduce

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