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

Percentage Accurate: 96.1% → 97.5%
Time: 6.0s
Alternatives: 7
Speedup: 1.0×

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: 96.1% accurate, 1.0× speedup?

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

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

Alternative 1: 97.5% accurate, 0.6× speedup?

\[\begin{array}{l} x_m = \left|x\right| \\ x_s = \mathsf{copysign}\left(1, x\right) \\ [x_m, y, z] = \mathsf{sort}([x_m, y, z])\\ \\ x\_s \cdot \begin{array}{l} \mathbf{if}\;x\_m \leq 5 \cdot 10^{-31}:\\ \;\;\;\;x\_m - z \cdot \left(x\_m \cdot y\right)\\ \mathbf{else}:\\ \;\;\;\;x\_m - x\_m \cdot \left(z \cdot y\right)\\ \end{array} \end{array} \]
x_m = (fabs.f64 x)
x_s = (copysign.f64 1 x)
NOTE: x_m, y, and z should be sorted in increasing order before calling this function.
(FPCore (x_s x_m y z)
 :precision binary64
 (* x_s (if (<= x_m 5e-31) (- x_m (* z (* x_m y))) (- x_m (* x_m (* z y))))))
x_m = fabs(x);
x_s = copysign(1.0, x);
assert(x_m < y && y < z);
double code(double x_s, double x_m, double y, double z) {
	double tmp;
	if (x_m <= 5e-31) {
		tmp = x_m - (z * (x_m * y));
	} else {
		tmp = x_m - (x_m * (z * y));
	}
	return x_s * tmp;
}
x_m = abs(x)
x_s = copysign(1.0d0, x)
NOTE: x_m, y, and z should be sorted in increasing order before calling this function.
real(8) function code(x_s, x_m, y, z)
    real(8), intent (in) :: x_s
    real(8), intent (in) :: x_m
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: tmp
    if (x_m <= 5d-31) then
        tmp = x_m - (z * (x_m * y))
    else
        tmp = x_m - (x_m * (z * y))
    end if
    code = x_s * tmp
end function
x_m = Math.abs(x);
x_s = Math.copySign(1.0, x);
assert x_m < y && y < z;
public static double code(double x_s, double x_m, double y, double z) {
	double tmp;
	if (x_m <= 5e-31) {
		tmp = x_m - (z * (x_m * y));
	} else {
		tmp = x_m - (x_m * (z * y));
	}
	return x_s * tmp;
}
x_m = math.fabs(x)
x_s = math.copysign(1.0, x)
[x_m, y, z] = sort([x_m, y, z])
def code(x_s, x_m, y, z):
	tmp = 0
	if x_m <= 5e-31:
		tmp = x_m - (z * (x_m * y))
	else:
		tmp = x_m - (x_m * (z * y))
	return x_s * tmp
x_m = abs(x)
x_s = copysign(1.0, x)
x_m, y, z = sort([x_m, y, z])
function code(x_s, x_m, y, z)
	tmp = 0.0
	if (x_m <= 5e-31)
		tmp = Float64(x_m - Float64(z * Float64(x_m * y)));
	else
		tmp = Float64(x_m - Float64(x_m * Float64(z * y)));
	end
	return Float64(x_s * tmp)
end
x_m = abs(x);
x_s = sign(x) * abs(1.0);
x_m, y, z = num2cell(sort([x_m, y, z])){:}
function tmp_2 = code(x_s, x_m, y, z)
	tmp = 0.0;
	if (x_m <= 5e-31)
		tmp = x_m - (z * (x_m * y));
	else
		tmp = x_m - (x_m * (z * y));
	end
	tmp_2 = x_s * tmp;
end
x_m = N[Abs[x], $MachinePrecision]
x_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: x_m, y, and z should be sorted in increasing order before calling this function.
code[x$95$s_, x$95$m_, y_, z_] := N[(x$95$s * If[LessEqual[x$95$m, 5e-31], N[(x$95$m - N[(z * N[(x$95$m * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x$95$m - N[(x$95$m * N[(z * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
x_s = \mathsf{copysign}\left(1, x\right)
\\
[x_m, y, z] = \mathsf{sort}([x_m, y, z])\\
\\
x\_s \cdot \begin{array}{l}
\mathbf{if}\;x\_m \leq 5 \cdot 10^{-31}:\\
\;\;\;\;x\_m - z \cdot \left(x\_m \cdot y\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < 5e-31

    1. Initial program 95.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 5e-31 < x

    1. Initial program 99.9%

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

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

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

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

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

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

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

Alternative 2: 73.8% accurate, 0.4× speedup?

\[\begin{array}{l} x_m = \left|x\right| \\ x_s = \mathsf{copysign}\left(1, x\right) \\ [x_m, y, z] = \mathsf{sort}([x_m, y, z])\\ \\ x\_s \cdot \begin{array}{l} \mathbf{if}\;y \leq -3.9 \cdot 10^{+46} \lor \neg \left(y \leq 1.05 \cdot 10^{-101}\right):\\ \;\;\;\;x\_m \cdot \left(z \cdot \left(-y\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x\_m\\ \end{array} \end{array} \]
x_m = (fabs.f64 x)
x_s = (copysign.f64 1 x)
NOTE: x_m, y, and z should be sorted in increasing order before calling this function.
(FPCore (x_s x_m y z)
 :precision binary64
 (*
  x_s
  (if (or (<= y -3.9e+46) (not (<= y 1.05e-101))) (* x_m (* z (- y))) x_m)))
x_m = fabs(x);
x_s = copysign(1.0, x);
assert(x_m < y && y < z);
double code(double x_s, double x_m, double y, double z) {
	double tmp;
	if ((y <= -3.9e+46) || !(y <= 1.05e-101)) {
		tmp = x_m * (z * -y);
	} else {
		tmp = x_m;
	}
	return x_s * tmp;
}
x_m = abs(x)
x_s = copysign(1.0d0, x)
NOTE: x_m, y, and z should be sorted in increasing order before calling this function.
real(8) function code(x_s, x_m, y, z)
    real(8), intent (in) :: x_s
    real(8), intent (in) :: x_m
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: tmp
    if ((y <= (-3.9d+46)) .or. (.not. (y <= 1.05d-101))) then
        tmp = x_m * (z * -y)
    else
        tmp = x_m
    end if
    code = x_s * tmp
end function
x_m = Math.abs(x);
x_s = Math.copySign(1.0, x);
assert x_m < y && y < z;
public static double code(double x_s, double x_m, double y, double z) {
	double tmp;
	if ((y <= -3.9e+46) || !(y <= 1.05e-101)) {
		tmp = x_m * (z * -y);
	} else {
		tmp = x_m;
	}
	return x_s * tmp;
}
x_m = math.fabs(x)
x_s = math.copysign(1.0, x)
[x_m, y, z] = sort([x_m, y, z])
def code(x_s, x_m, y, z):
	tmp = 0
	if (y <= -3.9e+46) or not (y <= 1.05e-101):
		tmp = x_m * (z * -y)
	else:
		tmp = x_m
	return x_s * tmp
x_m = abs(x)
x_s = copysign(1.0, x)
x_m, y, z = sort([x_m, y, z])
function code(x_s, x_m, y, z)
	tmp = 0.0
	if ((y <= -3.9e+46) || !(y <= 1.05e-101))
		tmp = Float64(x_m * Float64(z * Float64(-y)));
	else
		tmp = x_m;
	end
	return Float64(x_s * tmp)
end
x_m = abs(x);
x_s = sign(x) * abs(1.0);
x_m, y, z = num2cell(sort([x_m, y, z])){:}
function tmp_2 = code(x_s, x_m, y, z)
	tmp = 0.0;
	if ((y <= -3.9e+46) || ~((y <= 1.05e-101)))
		tmp = x_m * (z * -y);
	else
		tmp = x_m;
	end
	tmp_2 = x_s * tmp;
end
x_m = N[Abs[x], $MachinePrecision]
x_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: x_m, y, and z should be sorted in increasing order before calling this function.
code[x$95$s_, x$95$m_, y_, z_] := N[(x$95$s * If[Or[LessEqual[y, -3.9e+46], N[Not[LessEqual[y, 1.05e-101]], $MachinePrecision]], N[(x$95$m * N[(z * (-y)), $MachinePrecision]), $MachinePrecision], x$95$m]), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
x_s = \mathsf{copysign}\left(1, x\right)
\\
[x_m, y, z] = \mathsf{sort}([x_m, y, z])\\
\\
x\_s \cdot \begin{array}{l}
\mathbf{if}\;y \leq -3.9 \cdot 10^{+46} \lor \neg \left(y \leq 1.05 \cdot 10^{-101}\right):\\
\;\;\;\;x\_m \cdot \left(z \cdot \left(-y\right)\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -3.89999999999999995e46 or 1.05000000000000008e-101 < y

    1. Initial program 94.3%

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

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

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

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

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

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

    if -3.89999999999999995e46 < y < 1.05000000000000008e-101

    1. Initial program 99.9%

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

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

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

Alternative 3: 75.7% accurate, 0.4× speedup?

\[\begin{array}{l} x_m = \left|x\right| \\ x_s = \mathsf{copysign}\left(1, x\right) \\ [x_m, y, z] = \mathsf{sort}([x_m, y, z])\\ \\ x\_s \cdot \begin{array}{l} \mathbf{if}\;y \leq -1.1 \cdot 10^{+46} \lor \neg \left(y \leq 1.05 \cdot 10^{-101}\right):\\ \;\;\;\;z \cdot \left(x\_m \cdot \left(-y\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x\_m\\ \end{array} \end{array} \]
x_m = (fabs.f64 x)
x_s = (copysign.f64 1 x)
NOTE: x_m, y, and z should be sorted in increasing order before calling this function.
(FPCore (x_s x_m y z)
 :precision binary64
 (*
  x_s
  (if (or (<= y -1.1e+46) (not (<= y 1.05e-101))) (* z (* x_m (- y))) x_m)))
x_m = fabs(x);
x_s = copysign(1.0, x);
assert(x_m < y && y < z);
double code(double x_s, double x_m, double y, double z) {
	double tmp;
	if ((y <= -1.1e+46) || !(y <= 1.05e-101)) {
		tmp = z * (x_m * -y);
	} else {
		tmp = x_m;
	}
	return x_s * tmp;
}
x_m = abs(x)
x_s = copysign(1.0d0, x)
NOTE: x_m, y, and z should be sorted in increasing order before calling this function.
real(8) function code(x_s, x_m, y, z)
    real(8), intent (in) :: x_s
    real(8), intent (in) :: x_m
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: tmp
    if ((y <= (-1.1d+46)) .or. (.not. (y <= 1.05d-101))) then
        tmp = z * (x_m * -y)
    else
        tmp = x_m
    end if
    code = x_s * tmp
end function
x_m = Math.abs(x);
x_s = Math.copySign(1.0, x);
assert x_m < y && y < z;
public static double code(double x_s, double x_m, double y, double z) {
	double tmp;
	if ((y <= -1.1e+46) || !(y <= 1.05e-101)) {
		tmp = z * (x_m * -y);
	} else {
		tmp = x_m;
	}
	return x_s * tmp;
}
x_m = math.fabs(x)
x_s = math.copysign(1.0, x)
[x_m, y, z] = sort([x_m, y, z])
def code(x_s, x_m, y, z):
	tmp = 0
	if (y <= -1.1e+46) or not (y <= 1.05e-101):
		tmp = z * (x_m * -y)
	else:
		tmp = x_m
	return x_s * tmp
x_m = abs(x)
x_s = copysign(1.0, x)
x_m, y, z = sort([x_m, y, z])
function code(x_s, x_m, y, z)
	tmp = 0.0
	if ((y <= -1.1e+46) || !(y <= 1.05e-101))
		tmp = Float64(z * Float64(x_m * Float64(-y)));
	else
		tmp = x_m;
	end
	return Float64(x_s * tmp)
end
x_m = abs(x);
x_s = sign(x) * abs(1.0);
x_m, y, z = num2cell(sort([x_m, y, z])){:}
function tmp_2 = code(x_s, x_m, y, z)
	tmp = 0.0;
	if ((y <= -1.1e+46) || ~((y <= 1.05e-101)))
		tmp = z * (x_m * -y);
	else
		tmp = x_m;
	end
	tmp_2 = x_s * tmp;
end
x_m = N[Abs[x], $MachinePrecision]
x_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: x_m, y, and z should be sorted in increasing order before calling this function.
code[x$95$s_, x$95$m_, y_, z_] := N[(x$95$s * If[Or[LessEqual[y, -1.1e+46], N[Not[LessEqual[y, 1.05e-101]], $MachinePrecision]], N[(z * N[(x$95$m * (-y)), $MachinePrecision]), $MachinePrecision], x$95$m]), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
x_s = \mathsf{copysign}\left(1, x\right)
\\
[x_m, y, z] = \mathsf{sort}([x_m, y, z])\\
\\
x\_s \cdot \begin{array}{l}
\mathbf{if}\;y \leq -1.1 \cdot 10^{+46} \lor \neg \left(y \leq 1.05 \cdot 10^{-101}\right):\\
\;\;\;\;z \cdot \left(x\_m \cdot \left(-y\right)\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -1.1e46 or 1.05000000000000008e-101 < y

    1. Initial program 94.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto x - \color{blue}{\left(-z\right) \cdot \left(x \cdot y\right)} \]
      18. add-sqr-sqrt11.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.1e46 < y < 1.05000000000000008e-101

    1. Initial program 99.9%

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

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

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

Alternative 4: 74.4% accurate, 0.4× speedup?

\[\begin{array}{l} x_m = \left|x\right| \\ x_s = \mathsf{copysign}\left(1, x\right) \\ [x_m, y, z] = \mathsf{sort}([x_m, y, z])\\ \\ x\_s \cdot \begin{array}{l} \mathbf{if}\;y \leq -6.2 \cdot 10^{+45}:\\ \;\;\;\;x\_m \cdot \left(z \cdot \left(-y\right)\right)\\ \mathbf{elif}\;y \leq 7.6 \cdot 10^{-102}:\\ \;\;\;\;x\_m\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(x\_m \cdot \left(-z\right)\right)\\ \end{array} \end{array} \]
x_m = (fabs.f64 x)
x_s = (copysign.f64 1 x)
NOTE: x_m, y, and z should be sorted in increasing order before calling this function.
(FPCore (x_s x_m y z)
 :precision binary64
 (*
  x_s
  (if (<= y -6.2e+45)
    (* x_m (* z (- y)))
    (if (<= y 7.6e-102) x_m (* y (* x_m (- z)))))))
x_m = fabs(x);
x_s = copysign(1.0, x);
assert(x_m < y && y < z);
double code(double x_s, double x_m, double y, double z) {
	double tmp;
	if (y <= -6.2e+45) {
		tmp = x_m * (z * -y);
	} else if (y <= 7.6e-102) {
		tmp = x_m;
	} else {
		tmp = y * (x_m * -z);
	}
	return x_s * tmp;
}
x_m = abs(x)
x_s = copysign(1.0d0, x)
NOTE: x_m, y, and z should be sorted in increasing order before calling this function.
real(8) function code(x_s, x_m, y, z)
    real(8), intent (in) :: x_s
    real(8), intent (in) :: x_m
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: tmp
    if (y <= (-6.2d+45)) then
        tmp = x_m * (z * -y)
    else if (y <= 7.6d-102) then
        tmp = x_m
    else
        tmp = y * (x_m * -z)
    end if
    code = x_s * tmp
end function
x_m = Math.abs(x);
x_s = Math.copySign(1.0, x);
assert x_m < y && y < z;
public static double code(double x_s, double x_m, double y, double z) {
	double tmp;
	if (y <= -6.2e+45) {
		tmp = x_m * (z * -y);
	} else if (y <= 7.6e-102) {
		tmp = x_m;
	} else {
		tmp = y * (x_m * -z);
	}
	return x_s * tmp;
}
x_m = math.fabs(x)
x_s = math.copysign(1.0, x)
[x_m, y, z] = sort([x_m, y, z])
def code(x_s, x_m, y, z):
	tmp = 0
	if y <= -6.2e+45:
		tmp = x_m * (z * -y)
	elif y <= 7.6e-102:
		tmp = x_m
	else:
		tmp = y * (x_m * -z)
	return x_s * tmp
x_m = abs(x)
x_s = copysign(1.0, x)
x_m, y, z = sort([x_m, y, z])
function code(x_s, x_m, y, z)
	tmp = 0.0
	if (y <= -6.2e+45)
		tmp = Float64(x_m * Float64(z * Float64(-y)));
	elseif (y <= 7.6e-102)
		tmp = x_m;
	else
		tmp = Float64(y * Float64(x_m * Float64(-z)));
	end
	return Float64(x_s * tmp)
end
x_m = abs(x);
x_s = sign(x) * abs(1.0);
x_m, y, z = num2cell(sort([x_m, y, z])){:}
function tmp_2 = code(x_s, x_m, y, z)
	tmp = 0.0;
	if (y <= -6.2e+45)
		tmp = x_m * (z * -y);
	elseif (y <= 7.6e-102)
		tmp = x_m;
	else
		tmp = y * (x_m * -z);
	end
	tmp_2 = x_s * tmp;
end
x_m = N[Abs[x], $MachinePrecision]
x_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: x_m, y, and z should be sorted in increasing order before calling this function.
code[x$95$s_, x$95$m_, y_, z_] := N[(x$95$s * If[LessEqual[y, -6.2e+45], N[(x$95$m * N[(z * (-y)), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 7.6e-102], x$95$m, N[(y * N[(x$95$m * (-z)), $MachinePrecision]), $MachinePrecision]]]), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
x_s = \mathsf{copysign}\left(1, x\right)
\\
[x_m, y, z] = \mathsf{sort}([x_m, y, z])\\
\\
x\_s \cdot \begin{array}{l}
\mathbf{if}\;y \leq -6.2 \cdot 10^{+45}:\\
\;\;\;\;x\_m \cdot \left(z \cdot \left(-y\right)\right)\\

\mathbf{elif}\;y \leq 7.6 \cdot 10^{-102}:\\
\;\;\;\;x\_m\\

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


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

    1. Initial program 91.6%

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

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

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

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

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

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

    if -6.19999999999999975e45 < y < 7.60000000000000052e-102

    1. Initial program 99.9%

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

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

    if 7.60000000000000052e-102 < y

    1. Initial program 96.3%

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

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

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

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

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

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

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

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

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

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

Alternative 5: 97.5% accurate, 0.6× speedup?

\[\begin{array}{l} x_m = \left|x\right| \\ x_s = \mathsf{copysign}\left(1, x\right) \\ [x_m, y, z] = \mathsf{sort}([x_m, y, z])\\ \\ x\_s \cdot \begin{array}{l} \mathbf{if}\;x\_m \leq 5 \cdot 10^{-31}:\\ \;\;\;\;x\_m - z \cdot \left(x\_m \cdot y\right)\\ \mathbf{else}:\\ \;\;\;\;x\_m \cdot \left(1 - z \cdot y\right)\\ \end{array} \end{array} \]
x_m = (fabs.f64 x)
x_s = (copysign.f64 1 x)
NOTE: x_m, y, and z should be sorted in increasing order before calling this function.
(FPCore (x_s x_m y z)
 :precision binary64
 (* x_s (if (<= x_m 5e-31) (- x_m (* z (* x_m y))) (* x_m (- 1.0 (* z y))))))
x_m = fabs(x);
x_s = copysign(1.0, x);
assert(x_m < y && y < z);
double code(double x_s, double x_m, double y, double z) {
	double tmp;
	if (x_m <= 5e-31) {
		tmp = x_m - (z * (x_m * y));
	} else {
		tmp = x_m * (1.0 - (z * y));
	}
	return x_s * tmp;
}
x_m = abs(x)
x_s = copysign(1.0d0, x)
NOTE: x_m, y, and z should be sorted in increasing order before calling this function.
real(8) function code(x_s, x_m, y, z)
    real(8), intent (in) :: x_s
    real(8), intent (in) :: x_m
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: tmp
    if (x_m <= 5d-31) then
        tmp = x_m - (z * (x_m * y))
    else
        tmp = x_m * (1.0d0 - (z * y))
    end if
    code = x_s * tmp
end function
x_m = Math.abs(x);
x_s = Math.copySign(1.0, x);
assert x_m < y && y < z;
public static double code(double x_s, double x_m, double y, double z) {
	double tmp;
	if (x_m <= 5e-31) {
		tmp = x_m - (z * (x_m * y));
	} else {
		tmp = x_m * (1.0 - (z * y));
	}
	return x_s * tmp;
}
x_m = math.fabs(x)
x_s = math.copysign(1.0, x)
[x_m, y, z] = sort([x_m, y, z])
def code(x_s, x_m, y, z):
	tmp = 0
	if x_m <= 5e-31:
		tmp = x_m - (z * (x_m * y))
	else:
		tmp = x_m * (1.0 - (z * y))
	return x_s * tmp
x_m = abs(x)
x_s = copysign(1.0, x)
x_m, y, z = sort([x_m, y, z])
function code(x_s, x_m, y, z)
	tmp = 0.0
	if (x_m <= 5e-31)
		tmp = Float64(x_m - Float64(z * Float64(x_m * y)));
	else
		tmp = Float64(x_m * Float64(1.0 - Float64(z * y)));
	end
	return Float64(x_s * tmp)
end
x_m = abs(x);
x_s = sign(x) * abs(1.0);
x_m, y, z = num2cell(sort([x_m, y, z])){:}
function tmp_2 = code(x_s, x_m, y, z)
	tmp = 0.0;
	if (x_m <= 5e-31)
		tmp = x_m - (z * (x_m * y));
	else
		tmp = x_m * (1.0 - (z * y));
	end
	tmp_2 = x_s * tmp;
end
x_m = N[Abs[x], $MachinePrecision]
x_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: x_m, y, and z should be sorted in increasing order before calling this function.
code[x$95$s_, x$95$m_, y_, z_] := N[(x$95$s * If[LessEqual[x$95$m, 5e-31], N[(x$95$m - N[(z * N[(x$95$m * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x$95$m * N[(1.0 - N[(z * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
x_s = \mathsf{copysign}\left(1, x\right)
\\
[x_m, y, z] = \mathsf{sort}([x_m, y, z])\\
\\
x\_s \cdot \begin{array}{l}
\mathbf{if}\;x\_m \leq 5 \cdot 10^{-31}:\\
\;\;\;\;x\_m - z \cdot \left(x\_m \cdot y\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < 5e-31

    1. Initial program 95.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 5e-31 < 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 simplification93.6%

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

Alternative 6: 96.1% accurate, 1.0× speedup?

\[\begin{array}{l} x_m = \left|x\right| \\ x_s = \mathsf{copysign}\left(1, x\right) \\ [x_m, y, z] = \mathsf{sort}([x_m, y, z])\\ \\ x\_s \cdot \left(x\_m \cdot \left(1 - z \cdot y\right)\right) \end{array} \]
x_m = (fabs.f64 x)
x_s = (copysign.f64 1 x)
NOTE: x_m, y, and z should be sorted in increasing order before calling this function.
(FPCore (x_s x_m y z) :precision binary64 (* x_s (* x_m (- 1.0 (* z y)))))
x_m = fabs(x);
x_s = copysign(1.0, x);
assert(x_m < y && y < z);
double code(double x_s, double x_m, double y, double z) {
	return x_s * (x_m * (1.0 - (z * y)));
}
x_m = abs(x)
x_s = copysign(1.0d0, x)
NOTE: x_m, y, and z should be sorted in increasing order before calling this function.
real(8) function code(x_s, x_m, y, z)
    real(8), intent (in) :: x_s
    real(8), intent (in) :: x_m
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = x_s * (x_m * (1.0d0 - (z * y)))
end function
x_m = Math.abs(x);
x_s = Math.copySign(1.0, x);
assert x_m < y && y < z;
public static double code(double x_s, double x_m, double y, double z) {
	return x_s * (x_m * (1.0 - (z * y)));
}
x_m = math.fabs(x)
x_s = math.copysign(1.0, x)
[x_m, y, z] = sort([x_m, y, z])
def code(x_s, x_m, y, z):
	return x_s * (x_m * (1.0 - (z * y)))
x_m = abs(x)
x_s = copysign(1.0, x)
x_m, y, z = sort([x_m, y, z])
function code(x_s, x_m, y, z)
	return Float64(x_s * Float64(x_m * Float64(1.0 - Float64(z * y))))
end
x_m = abs(x);
x_s = sign(x) * abs(1.0);
x_m, y, z = num2cell(sort([x_m, y, z])){:}
function tmp = code(x_s, x_m, y, z)
	tmp = x_s * (x_m * (1.0 - (z * y)));
end
x_m = N[Abs[x], $MachinePrecision]
x_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: x_m, y, and z should be sorted in increasing order before calling this function.
code[x$95$s_, x$95$m_, y_, z_] := N[(x$95$s * N[(x$95$m * N[(1.0 - N[(z * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
x_s = \mathsf{copysign}\left(1, x\right)
\\
[x_m, y, z] = \mathsf{sort}([x_m, y, z])\\
\\
x\_s \cdot \left(x\_m \cdot \left(1 - z \cdot y\right)\right)
\end{array}
Derivation
  1. Initial program 97.0%

    \[x \cdot \left(1 - y \cdot z\right) \]
  2. Add Preprocessing
  3. Final simplification97.0%

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

Alternative 7: 50.3% accurate, 7.0× speedup?

\[\begin{array}{l} x_m = \left|x\right| \\ x_s = \mathsf{copysign}\left(1, x\right) \\ [x_m, y, z] = \mathsf{sort}([x_m, y, z])\\ \\ x\_s \cdot x\_m \end{array} \]
x_m = (fabs.f64 x)
x_s = (copysign.f64 1 x)
NOTE: x_m, y, and z should be sorted in increasing order before calling this function.
(FPCore (x_s x_m y z) :precision binary64 (* x_s x_m))
x_m = fabs(x);
x_s = copysign(1.0, x);
assert(x_m < y && y < z);
double code(double x_s, double x_m, double y, double z) {
	return x_s * x_m;
}
x_m = abs(x)
x_s = copysign(1.0d0, x)
NOTE: x_m, y, and z should be sorted in increasing order before calling this function.
real(8) function code(x_s, x_m, y, z)
    real(8), intent (in) :: x_s
    real(8), intent (in) :: x_m
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = x_s * x_m
end function
x_m = Math.abs(x);
x_s = Math.copySign(1.0, x);
assert x_m < y && y < z;
public static double code(double x_s, double x_m, double y, double z) {
	return x_s * x_m;
}
x_m = math.fabs(x)
x_s = math.copysign(1.0, x)
[x_m, y, z] = sort([x_m, y, z])
def code(x_s, x_m, y, z):
	return x_s * x_m
x_m = abs(x)
x_s = copysign(1.0, x)
x_m, y, z = sort([x_m, y, z])
function code(x_s, x_m, y, z)
	return Float64(x_s * x_m)
end
x_m = abs(x);
x_s = sign(x) * abs(1.0);
x_m, y, z = num2cell(sort([x_m, y, z])){:}
function tmp = code(x_s, x_m, y, z)
	tmp = x_s * x_m;
end
x_m = N[Abs[x], $MachinePrecision]
x_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: x_m, y, and z should be sorted in increasing order before calling this function.
code[x$95$s_, x$95$m_, y_, z_] := N[(x$95$s * x$95$m), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
x_s = \mathsf{copysign}\left(1, x\right)
\\
[x_m, y, z] = \mathsf{sort}([x_m, y, z])\\
\\
x\_s \cdot x\_m
\end{array}
Derivation
  1. Initial program 97.0%

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

    \[\leadsto \color{blue}{x} \]
  4. Final simplification55.2%

    \[\leadsto x \]
  5. Add Preprocessing

Reproduce

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