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

Percentage Accurate: 95.6% → 99.7%
Time: 7.4s
Alternatives: 10
Speedup: 0.6×

Specification

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

\\
x \cdot \left(1 - \left(1 - y\right) \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 10 alternatives:

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

Initial Program: 95.6% accurate, 1.0× speedup?

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

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

Alternative 1: 99.7% accurate, 0.6× speedup?

\[\begin{array}{l} x\_m = \left|x\right| \\ x\_s = \mathsf{copysign}\left(1, x\right) \\ x\_s \cdot \begin{array}{l} \mathbf{if}\;x\_m \leq 2 \cdot 10^{-43}:\\ \;\;\;\;x\_m + z \cdot \left(x\_m \cdot \left(-1 + y\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x\_m - x\_m \cdot \left(z \cdot \left(1 - y\right)\right)\\ \end{array} \end{array} \]
x\_m = (fabs.f64 x)
x\_s = (copysign.f64 #s(literal 1 binary64) x)
(FPCore (x_s x_m y z)
 :precision binary64
 (*
  x_s
  (if (<= x_m 2e-43)
    (+ x_m (* z (* x_m (+ -1.0 y))))
    (- x_m (* x_m (* z (- 1.0 y)))))))
x\_m = fabs(x);
x\_s = copysign(1.0, x);
double code(double x_s, double x_m, double y, double z) {
	double tmp;
	if (x_m <= 2e-43) {
		tmp = x_m + (z * (x_m * (-1.0 + y)));
	} else {
		tmp = x_m - (x_m * (z * (1.0 - y)));
	}
	return x_s * tmp;
}
x\_m = abs(x)
x\_s = copysign(1.0d0, x)
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 <= 2d-43) then
        tmp = x_m + (z * (x_m * ((-1.0d0) + y)))
    else
        tmp = x_m - (x_m * (z * (1.0d0 - y)))
    end if
    code = x_s * tmp
end function
x\_m = Math.abs(x);
x\_s = Math.copySign(1.0, x);
public static double code(double x_s, double x_m, double y, double z) {
	double tmp;
	if (x_m <= 2e-43) {
		tmp = x_m + (z * (x_m * (-1.0 + y)));
	} else {
		tmp = x_m - (x_m * (z * (1.0 - y)));
	}
	return x_s * tmp;
}
x\_m = math.fabs(x)
x\_s = math.copysign(1.0, x)
def code(x_s, x_m, y, z):
	tmp = 0
	if x_m <= 2e-43:
		tmp = x_m + (z * (x_m * (-1.0 + y)))
	else:
		tmp = x_m - (x_m * (z * (1.0 - y)))
	return x_s * tmp
x\_m = abs(x)
x\_s = copysign(1.0, x)
function code(x_s, x_m, y, z)
	tmp = 0.0
	if (x_m <= 2e-43)
		tmp = Float64(x_m + Float64(z * Float64(x_m * Float64(-1.0 + y))));
	else
		tmp = Float64(x_m - Float64(x_m * Float64(z * Float64(1.0 - y))));
	end
	return Float64(x_s * tmp)
end
x\_m = abs(x);
x\_s = sign(x) * abs(1.0);
function tmp_2 = code(x_s, x_m, y, z)
	tmp = 0.0;
	if (x_m <= 2e-43)
		tmp = x_m + (z * (x_m * (-1.0 + y)));
	else
		tmp = x_m - (x_m * (z * (1.0 - 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]
code[x$95$s_, x$95$m_, y_, z_] := N[(x$95$s * If[LessEqual[x$95$m, 2e-43], N[(x$95$m + N[(z * N[(x$95$m * N[(-1.0 + y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x$95$m - N[(x$95$m * N[(z * N[(1.0 - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
x\_m = \left|x\right|
\\
x\_s = \mathsf{copysign}\left(1, x\right)

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

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


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

    1. Initial program 96.3%

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

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

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

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

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

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

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

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

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

    if 2.00000000000000015e-43 < x

    1. Initial program 99.9%

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

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

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

Alternative 2: 98.7% accurate, 0.5× speedup?

\[\begin{array}{l} x\_m = \left|x\right| \\ x\_s = \mathsf{copysign}\left(1, x\right) \\ x\_s \cdot \begin{array}{l} \mathbf{if}\;z \leq -92 \lor \neg \left(z \leq 2.85 \cdot 10^{-5}\right):\\ \;\;\;\;z \cdot \left(x\_m \cdot \left(-1 + y\right)\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 #s(literal 1 binary64) x)
(FPCore (x_s x_m y z)
 :precision binary64
 (*
  x_s
  (if (or (<= z -92.0) (not (<= z 2.85e-5)))
    (* z (* x_m (+ -1.0 y)))
    (+ x_m (* x_m (* z y))))))
x\_m = fabs(x);
x\_s = copysign(1.0, x);
double code(double x_s, double x_m, double y, double z) {
	double tmp;
	if ((z <= -92.0) || !(z <= 2.85e-5)) {
		tmp = z * (x_m * (-1.0 + y));
	} else {
		tmp = x_m + (x_m * (z * y));
	}
	return x_s * tmp;
}
x\_m = abs(x)
x\_s = copysign(1.0d0, x)
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 ((z <= (-92.0d0)) .or. (.not. (z <= 2.85d-5))) then
        tmp = z * (x_m * ((-1.0d0) + 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);
public static double code(double x_s, double x_m, double y, double z) {
	double tmp;
	if ((z <= -92.0) || !(z <= 2.85e-5)) {
		tmp = z * (x_m * (-1.0 + 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)
def code(x_s, x_m, y, z):
	tmp = 0
	if (z <= -92.0) or not (z <= 2.85e-5):
		tmp = z * (x_m * (-1.0 + y))
	else:
		tmp = x_m + (x_m * (z * y))
	return x_s * tmp
x\_m = abs(x)
x\_s = copysign(1.0, x)
function code(x_s, x_m, y, z)
	tmp = 0.0
	if ((z <= -92.0) || !(z <= 2.85e-5))
		tmp = Float64(z * Float64(x_m * Float64(-1.0 + 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);
function tmp_2 = code(x_s, x_m, y, z)
	tmp = 0.0;
	if ((z <= -92.0) || ~((z <= 2.85e-5)))
		tmp = z * (x_m * (-1.0 + 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]
code[x$95$s_, x$95$m_, y_, z_] := N[(x$95$s * If[Or[LessEqual[z, -92.0], N[Not[LessEqual[z, 2.85e-5]], $MachinePrecision]], N[(z * N[(x$95$m * N[(-1.0 + 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\_s \cdot \begin{array}{l}
\mathbf{if}\;z \leq -92 \lor \neg \left(z \leq 2.85 \cdot 10^{-5}\right):\\
\;\;\;\;z \cdot \left(x\_m \cdot \left(-1 + y\right)\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 z < -92 or 2.8500000000000002e-5 < z

    1. Initial program 94.7%

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

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

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

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

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

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

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

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

    if -92 < z < 2.8500000000000002e-5

    1. Initial program 99.8%

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

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

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

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

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

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

Alternative 3: 98.7% accurate, 0.5× speedup?

\[\begin{array}{l} x\_m = \left|x\right| \\ x\_s = \mathsf{copysign}\left(1, x\right) \\ x\_s \cdot \begin{array}{l} \mathbf{if}\;z \leq -92 \lor \neg \left(z \leq 2.85 \cdot 10^{-5}\right):\\ \;\;\;\;z \cdot \left(x\_m \cdot \left(-1 + y\right)\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 #s(literal 1 binary64) x)
(FPCore (x_s x_m y z)
 :precision binary64
 (*
  x_s
  (if (or (<= z -92.0) (not (<= z 2.85e-5)))
    (* z (* x_m (+ -1.0 y)))
    (* x_m (+ 1.0 (* z y))))))
x\_m = fabs(x);
x\_s = copysign(1.0, x);
double code(double x_s, double x_m, double y, double z) {
	double tmp;
	if ((z <= -92.0) || !(z <= 2.85e-5)) {
		tmp = z * (x_m * (-1.0 + y));
	} else {
		tmp = x_m * (1.0 + (z * y));
	}
	return x_s * tmp;
}
x\_m = abs(x)
x\_s = copysign(1.0d0, x)
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 ((z <= (-92.0d0)) .or. (.not. (z <= 2.85d-5))) then
        tmp = z * (x_m * ((-1.0d0) + 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);
public static double code(double x_s, double x_m, double y, double z) {
	double tmp;
	if ((z <= -92.0) || !(z <= 2.85e-5)) {
		tmp = z * (x_m * (-1.0 + 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)
def code(x_s, x_m, y, z):
	tmp = 0
	if (z <= -92.0) or not (z <= 2.85e-5):
		tmp = z * (x_m * (-1.0 + y))
	else:
		tmp = x_m * (1.0 + (z * y))
	return x_s * tmp
x\_m = abs(x)
x\_s = copysign(1.0, x)
function code(x_s, x_m, y, z)
	tmp = 0.0
	if ((z <= -92.0) || !(z <= 2.85e-5))
		tmp = Float64(z * Float64(x_m * Float64(-1.0 + 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);
function tmp_2 = code(x_s, x_m, y, z)
	tmp = 0.0;
	if ((z <= -92.0) || ~((z <= 2.85e-5)))
		tmp = z * (x_m * (-1.0 + 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]
code[x$95$s_, x$95$m_, y_, z_] := N[(x$95$s * If[Or[LessEqual[z, -92.0], N[Not[LessEqual[z, 2.85e-5]], $MachinePrecision]], N[(z * N[(x$95$m * N[(-1.0 + 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\_s \cdot \begin{array}{l}
\mathbf{if}\;z \leq -92 \lor \neg \left(z \leq 2.85 \cdot 10^{-5}\right):\\
\;\;\;\;z \cdot \left(x\_m \cdot \left(-1 + y\right)\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 z < -92 or 2.8500000000000002e-5 < z

    1. Initial program 94.7%

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

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

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

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

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

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

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

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

    if -92 < z < 2.8500000000000002e-5

    1. Initial program 99.8%

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

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

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

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

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

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

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

Alternative 4: 58.6% accurate, 0.6× speedup?

\[\begin{array}{l} x\_m = \left|x\right| \\ x\_s = \mathsf{copysign}\left(1, x\right) \\ x\_s \cdot \begin{array}{l} \mathbf{if}\;y \leq -50000 \lor \neg \left(y \leq 1.72 \cdot 10^{+47}\right):\\ \;\;\;\;x\_m \cdot \left(z \cdot y\right)\\ \mathbf{else}:\\ \;\;\;\;x\_m\\ \end{array} \end{array} \]
x\_m = (fabs.f64 x)
x\_s = (copysign.f64 #s(literal 1 binary64) x)
(FPCore (x_s x_m y z)
 :precision binary64
 (* x_s (if (or (<= y -50000.0) (not (<= y 1.72e+47))) (* x_m (* z y)) x_m)))
x\_m = fabs(x);
x\_s = copysign(1.0, x);
double code(double x_s, double x_m, double y, double z) {
	double tmp;
	if ((y <= -50000.0) || !(y <= 1.72e+47)) {
		tmp = x_m * (z * y);
	} else {
		tmp = x_m;
	}
	return x_s * tmp;
}
x\_m = abs(x)
x\_s = copysign(1.0d0, x)
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 <= (-50000.0d0)) .or. (.not. (y <= 1.72d+47))) 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);
public static double code(double x_s, double x_m, double y, double z) {
	double tmp;
	if ((y <= -50000.0) || !(y <= 1.72e+47)) {
		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)
def code(x_s, x_m, y, z):
	tmp = 0
	if (y <= -50000.0) or not (y <= 1.72e+47):
		tmp = x_m * (z * y)
	else:
		tmp = x_m
	return x_s * tmp
x\_m = abs(x)
x\_s = copysign(1.0, x)
function code(x_s, x_m, y, z)
	tmp = 0.0
	if ((y <= -50000.0) || !(y <= 1.72e+47))
		tmp = Float64(x_m * Float64(z * y));
	else
		tmp = x_m;
	end
	return Float64(x_s * tmp)
end
x\_m = abs(x);
x\_s = sign(x) * abs(1.0);
function tmp_2 = code(x_s, x_m, y, z)
	tmp = 0.0;
	if ((y <= -50000.0) || ~((y <= 1.72e+47)))
		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]
code[x$95$s_, x$95$m_, y_, z_] := N[(x$95$s * If[Or[LessEqual[y, -50000.0], N[Not[LessEqual[y, 1.72e+47]], $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\_s \cdot \begin{array}{l}
\mathbf{if}\;y \leq -50000 \lor \neg \left(y \leq 1.72 \cdot 10^{+47}\right):\\
\;\;\;\;x\_m \cdot \left(z \cdot y\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -5e4 or 1.72000000000000002e47 < y

    1. Initial program 94.7%

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

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

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

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

    if -5e4 < y < 1.72000000000000002e47

    1. Initial program 100.0%

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

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

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

Alternative 5: 82.0% accurate, 0.6× speedup?

\[\begin{array}{l} x\_m = \left|x\right| \\ x\_s = \mathsf{copysign}\left(1, x\right) \\ x\_s \cdot \begin{array}{l} \mathbf{if}\;y \leq -9 \cdot 10^{+64} \lor \neg \left(y \leq 2.9 \cdot 10^{+34}\right):\\ \;\;\;\;x\_m \cdot \left(z \cdot y\right)\\ \mathbf{else}:\\ \;\;\;\;x\_m \cdot \left(1 - z\right)\\ \end{array} \end{array} \]
x\_m = (fabs.f64 x)
x\_s = (copysign.f64 #s(literal 1 binary64) x)
(FPCore (x_s x_m y z)
 :precision binary64
 (*
  x_s
  (if (or (<= y -9e+64) (not (<= y 2.9e+34)))
    (* x_m (* z y))
    (* x_m (- 1.0 z)))))
x\_m = fabs(x);
x\_s = copysign(1.0, x);
double code(double x_s, double x_m, double y, double z) {
	double tmp;
	if ((y <= -9e+64) || !(y <= 2.9e+34)) {
		tmp = x_m * (z * y);
	} else {
		tmp = x_m * (1.0 - z);
	}
	return x_s * tmp;
}
x\_m = abs(x)
x\_s = copysign(1.0d0, x)
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 <= (-9d+64)) .or. (.not. (y <= 2.9d+34))) then
        tmp = x_m * (z * y)
    else
        tmp = x_m * (1.0d0 - z)
    end if
    code = x_s * tmp
end function
x\_m = Math.abs(x);
x\_s = Math.copySign(1.0, x);
public static double code(double x_s, double x_m, double y, double z) {
	double tmp;
	if ((y <= -9e+64) || !(y <= 2.9e+34)) {
		tmp = x_m * (z * y);
	} else {
		tmp = x_m * (1.0 - z);
	}
	return x_s * tmp;
}
x\_m = math.fabs(x)
x\_s = math.copysign(1.0, x)
def code(x_s, x_m, y, z):
	tmp = 0
	if (y <= -9e+64) or not (y <= 2.9e+34):
		tmp = x_m * (z * y)
	else:
		tmp = x_m * (1.0 - z)
	return x_s * tmp
x\_m = abs(x)
x\_s = copysign(1.0, x)
function code(x_s, x_m, y, z)
	tmp = 0.0
	if ((y <= -9e+64) || !(y <= 2.9e+34))
		tmp = Float64(x_m * Float64(z * y));
	else
		tmp = Float64(x_m * Float64(1.0 - z));
	end
	return Float64(x_s * tmp)
end
x\_m = abs(x);
x\_s = sign(x) * abs(1.0);
function tmp_2 = code(x_s, x_m, y, z)
	tmp = 0.0;
	if ((y <= -9e+64) || ~((y <= 2.9e+34)))
		tmp = x_m * (z * y);
	else
		tmp = x_m * (1.0 - 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]
code[x$95$s_, x$95$m_, y_, z_] := N[(x$95$s * If[Or[LessEqual[y, -9e+64], N[Not[LessEqual[y, 2.9e+34]], $MachinePrecision]], N[(x$95$m * N[(z * y), $MachinePrecision]), $MachinePrecision], N[(x$95$m * N[(1.0 - z), $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
x\_m = \left|x\right|
\\
x\_s = \mathsf{copysign}\left(1, x\right)

\\
x\_s \cdot \begin{array}{l}
\mathbf{if}\;y \leq -9 \cdot 10^{+64} \lor \neg \left(y \leq 2.9 \cdot 10^{+34}\right):\\
\;\;\;\;x\_m \cdot \left(z \cdot y\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -8.99999999999999946e64 or 2.9000000000000001e34 < y

    1. Initial program 94.0%

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

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

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

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

    if -8.99999999999999946e64 < y < 2.9000000000000001e34

    1. Initial program 100.0%

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

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

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

Alternative 6: 83.3% accurate, 0.6× speedup?

\[\begin{array}{l} x\_m = \left|x\right| \\ x\_s = \mathsf{copysign}\left(1, x\right) \\ x\_s \cdot \begin{array}{l} \mathbf{if}\;y \leq -7.8 \cdot 10^{+64}:\\ \;\;\;\;x\_m \cdot \left(z \cdot y\right)\\ \mathbf{elif}\;y \leq 2.9 \cdot 10^{+35}:\\ \;\;\;\;x\_m \cdot \left(1 - z\right)\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(x\_m \cdot z\right)\\ \end{array} \end{array} \]
x\_m = (fabs.f64 x)
x\_s = (copysign.f64 #s(literal 1 binary64) x)
(FPCore (x_s x_m y z)
 :precision binary64
 (*
  x_s
  (if (<= y -7.8e+64)
    (* x_m (* z y))
    (if (<= y 2.9e+35) (* x_m (- 1.0 z)) (* y (* x_m z))))))
x\_m = fabs(x);
x\_s = copysign(1.0, x);
double code(double x_s, double x_m, double y, double z) {
	double tmp;
	if (y <= -7.8e+64) {
		tmp = x_m * (z * y);
	} else if (y <= 2.9e+35) {
		tmp = x_m * (1.0 - z);
	} else {
		tmp = y * (x_m * z);
	}
	return x_s * tmp;
}
x\_m = abs(x)
x\_s = copysign(1.0d0, x)
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 <= (-7.8d+64)) then
        tmp = x_m * (z * y)
    else if (y <= 2.9d+35) then
        tmp = x_m * (1.0d0 - z)
    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);
public static double code(double x_s, double x_m, double y, double z) {
	double tmp;
	if (y <= -7.8e+64) {
		tmp = x_m * (z * y);
	} else if (y <= 2.9e+35) {
		tmp = x_m * (1.0 - z);
	} else {
		tmp = y * (x_m * z);
	}
	return x_s * tmp;
}
x\_m = math.fabs(x)
x\_s = math.copysign(1.0, x)
def code(x_s, x_m, y, z):
	tmp = 0
	if y <= -7.8e+64:
		tmp = x_m * (z * y)
	elif y <= 2.9e+35:
		tmp = x_m * (1.0 - z)
	else:
		tmp = y * (x_m * z)
	return x_s * tmp
x\_m = abs(x)
x\_s = copysign(1.0, x)
function code(x_s, x_m, y, z)
	tmp = 0.0
	if (y <= -7.8e+64)
		tmp = Float64(x_m * Float64(z * y));
	elseif (y <= 2.9e+35)
		tmp = Float64(x_m * Float64(1.0 - z));
	else
		tmp = Float64(y * Float64(x_m * z));
	end
	return Float64(x_s * tmp)
end
x\_m = abs(x);
x\_s = sign(x) * abs(1.0);
function tmp_2 = code(x_s, x_m, y, z)
	tmp = 0.0;
	if (y <= -7.8e+64)
		tmp = x_m * (z * y);
	elseif (y <= 2.9e+35)
		tmp = x_m * (1.0 - z);
	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]
code[x$95$s_, x$95$m_, y_, z_] := N[(x$95$s * If[LessEqual[y, -7.8e+64], N[(x$95$m * N[(z * y), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 2.9e+35], N[(x$95$m * N[(1.0 - z), $MachinePrecision]), $MachinePrecision], 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\_s \cdot \begin{array}{l}
\mathbf{if}\;y \leq -7.8 \cdot 10^{+64}:\\
\;\;\;\;x\_m \cdot \left(z \cdot y\right)\\

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

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


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

    1. Initial program 97.9%

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

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

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

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

    if -7.7999999999999996e64 < y < 2.89999999999999995e35

    1. Initial program 100.0%

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

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

    if 2.89999999999999995e35 < y

    1. Initial program 90.9%

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

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

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

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

Alternative 7: 83.3% accurate, 0.6× speedup?

\[\begin{array}{l} x\_m = \left|x\right| \\ x\_s = \mathsf{copysign}\left(1, x\right) \\ x\_s \cdot \begin{array}{l} \mathbf{if}\;y \leq -7.5 \cdot 10^{+64}:\\ \;\;\;\;x\_m \cdot \left(z \cdot y\right)\\ \mathbf{elif}\;y \leq 2.45 \cdot 10^{+35}:\\ \;\;\;\;x\_m - x\_m \cdot z\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(x\_m \cdot z\right)\\ \end{array} \end{array} \]
x\_m = (fabs.f64 x)
x\_s = (copysign.f64 #s(literal 1 binary64) x)
(FPCore (x_s x_m y z)
 :precision binary64
 (*
  x_s
  (if (<= y -7.5e+64)
    (* x_m (* z y))
    (if (<= y 2.45e+35) (- x_m (* x_m z)) (* y (* x_m z))))))
x\_m = fabs(x);
x\_s = copysign(1.0, x);
double code(double x_s, double x_m, double y, double z) {
	double tmp;
	if (y <= -7.5e+64) {
		tmp = x_m * (z * y);
	} else if (y <= 2.45e+35) {
		tmp = x_m - (x_m * z);
	} else {
		tmp = y * (x_m * z);
	}
	return x_s * tmp;
}
x\_m = abs(x)
x\_s = copysign(1.0d0, x)
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 <= (-7.5d+64)) then
        tmp = x_m * (z * y)
    else if (y <= 2.45d+35) then
        tmp = x_m - (x_m * z)
    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);
public static double code(double x_s, double x_m, double y, double z) {
	double tmp;
	if (y <= -7.5e+64) {
		tmp = x_m * (z * y);
	} else if (y <= 2.45e+35) {
		tmp = x_m - (x_m * z);
	} else {
		tmp = y * (x_m * z);
	}
	return x_s * tmp;
}
x\_m = math.fabs(x)
x\_s = math.copysign(1.0, x)
def code(x_s, x_m, y, z):
	tmp = 0
	if y <= -7.5e+64:
		tmp = x_m * (z * y)
	elif y <= 2.45e+35:
		tmp = x_m - (x_m * z)
	else:
		tmp = y * (x_m * z)
	return x_s * tmp
x\_m = abs(x)
x\_s = copysign(1.0, x)
function code(x_s, x_m, y, z)
	tmp = 0.0
	if (y <= -7.5e+64)
		tmp = Float64(x_m * Float64(z * y));
	elseif (y <= 2.45e+35)
		tmp = Float64(x_m - Float64(x_m * z));
	else
		tmp = Float64(y * Float64(x_m * z));
	end
	return Float64(x_s * tmp)
end
x\_m = abs(x);
x\_s = sign(x) * abs(1.0);
function tmp_2 = code(x_s, x_m, y, z)
	tmp = 0.0;
	if (y <= -7.5e+64)
		tmp = x_m * (z * y);
	elseif (y <= 2.45e+35)
		tmp = x_m - (x_m * z);
	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]
code[x$95$s_, x$95$m_, y_, z_] := N[(x$95$s * If[LessEqual[y, -7.5e+64], N[(x$95$m * N[(z * y), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 2.45e+35], N[(x$95$m - N[(x$95$m * z), $MachinePrecision]), $MachinePrecision], 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\_s \cdot \begin{array}{l}
\mathbf{if}\;y \leq -7.5 \cdot 10^{+64}:\\
\;\;\;\;x\_m \cdot \left(z \cdot y\right)\\

\mathbf{elif}\;y \leq 2.45 \cdot 10^{+35}:\\
\;\;\;\;x\_m - x\_m \cdot z\\

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


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

    1. Initial program 97.9%

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

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

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

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

    if -7.5000000000000005e64 < y < 2.45000000000000013e35

    1. Initial program 100.0%

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

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

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

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

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

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

    if 2.45000000000000013e35 < y

    1. Initial program 90.9%

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

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

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

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

Alternative 8: 97.2% accurate, 0.6× speedup?

\[\begin{array}{l} x\_m = \left|x\right| \\ x\_s = \mathsf{copysign}\left(1, x\right) \\ x\_s \cdot \begin{array}{l} \mathbf{if}\;z \leq -2.35 \cdot 10^{+134}:\\ \;\;\;\;z \cdot \left(x\_m \cdot \left(-1 + y\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x\_m \cdot \left(1 + z \cdot \left(-1 + y\right)\right)\\ \end{array} \end{array} \]
x\_m = (fabs.f64 x)
x\_s = (copysign.f64 #s(literal 1 binary64) x)
(FPCore (x_s x_m y z)
 :precision binary64
 (*
  x_s
  (if (<= z -2.35e+134)
    (* z (* x_m (+ -1.0 y)))
    (* x_m (+ 1.0 (* z (+ -1.0 y)))))))
x\_m = fabs(x);
x\_s = copysign(1.0, x);
double code(double x_s, double x_m, double y, double z) {
	double tmp;
	if (z <= -2.35e+134) {
		tmp = z * (x_m * (-1.0 + y));
	} else {
		tmp = x_m * (1.0 + (z * (-1.0 + y)));
	}
	return x_s * tmp;
}
x\_m = abs(x)
x\_s = copysign(1.0d0, x)
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 (z <= (-2.35d+134)) then
        tmp = z * (x_m * ((-1.0d0) + y))
    else
        tmp = x_m * (1.0d0 + (z * ((-1.0d0) + y)))
    end if
    code = x_s * tmp
end function
x\_m = Math.abs(x);
x\_s = Math.copySign(1.0, x);
public static double code(double x_s, double x_m, double y, double z) {
	double tmp;
	if (z <= -2.35e+134) {
		tmp = z * (x_m * (-1.0 + y));
	} else {
		tmp = x_m * (1.0 + (z * (-1.0 + y)));
	}
	return x_s * tmp;
}
x\_m = math.fabs(x)
x\_s = math.copysign(1.0, x)
def code(x_s, x_m, y, z):
	tmp = 0
	if z <= -2.35e+134:
		tmp = z * (x_m * (-1.0 + y))
	else:
		tmp = x_m * (1.0 + (z * (-1.0 + y)))
	return x_s * tmp
x\_m = abs(x)
x\_s = copysign(1.0, x)
function code(x_s, x_m, y, z)
	tmp = 0.0
	if (z <= -2.35e+134)
		tmp = Float64(z * Float64(x_m * Float64(-1.0 + y)));
	else
		tmp = Float64(x_m * Float64(1.0 + Float64(z * Float64(-1.0 + y))));
	end
	return Float64(x_s * tmp)
end
x\_m = abs(x);
x\_s = sign(x) * abs(1.0);
function tmp_2 = code(x_s, x_m, y, z)
	tmp = 0.0;
	if (z <= -2.35e+134)
		tmp = z * (x_m * (-1.0 + y));
	else
		tmp = x_m * (1.0 + (z * (-1.0 + 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]
code[x$95$s_, x$95$m_, y_, z_] := N[(x$95$s * If[LessEqual[z, -2.35e+134], N[(z * N[(x$95$m * N[(-1.0 + y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x$95$m * N[(1.0 + N[(z * N[(-1.0 + y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
x\_m = \left|x\right|
\\
x\_s = \mathsf{copysign}\left(1, x\right)

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < -2.35000000000000013e134

    1. Initial program 88.8%

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

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

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

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

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

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

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

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

    if -2.35000000000000013e134 < z

    1. Initial program 99.0%

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

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

Alternative 9: 97.2% accurate, 0.6× speedup?

\[\begin{array}{l} x\_m = \left|x\right| \\ x\_s = \mathsf{copysign}\left(1, x\right) \\ x\_s \cdot \begin{array}{l} \mathbf{if}\;z \leq -3.3 \cdot 10^{+134}:\\ \;\;\;\;z \cdot \left(x\_m \cdot \left(-1 + y\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x\_m - x\_m \cdot \left(z \cdot \left(1 - y\right)\right)\\ \end{array} \end{array} \]
x\_m = (fabs.f64 x)
x\_s = (copysign.f64 #s(literal 1 binary64) x)
(FPCore (x_s x_m y z)
 :precision binary64
 (*
  x_s
  (if (<= z -3.3e+134)
    (* z (* x_m (+ -1.0 y)))
    (- x_m (* x_m (* z (- 1.0 y)))))))
x\_m = fabs(x);
x\_s = copysign(1.0, x);
double code(double x_s, double x_m, double y, double z) {
	double tmp;
	if (z <= -3.3e+134) {
		tmp = z * (x_m * (-1.0 + y));
	} else {
		tmp = x_m - (x_m * (z * (1.0 - y)));
	}
	return x_s * tmp;
}
x\_m = abs(x)
x\_s = copysign(1.0d0, x)
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 (z <= (-3.3d+134)) then
        tmp = z * (x_m * ((-1.0d0) + y))
    else
        tmp = x_m - (x_m * (z * (1.0d0 - y)))
    end if
    code = x_s * tmp
end function
x\_m = Math.abs(x);
x\_s = Math.copySign(1.0, x);
public static double code(double x_s, double x_m, double y, double z) {
	double tmp;
	if (z <= -3.3e+134) {
		tmp = z * (x_m * (-1.0 + y));
	} else {
		tmp = x_m - (x_m * (z * (1.0 - y)));
	}
	return x_s * tmp;
}
x\_m = math.fabs(x)
x\_s = math.copysign(1.0, x)
def code(x_s, x_m, y, z):
	tmp = 0
	if z <= -3.3e+134:
		tmp = z * (x_m * (-1.0 + y))
	else:
		tmp = x_m - (x_m * (z * (1.0 - y)))
	return x_s * tmp
x\_m = abs(x)
x\_s = copysign(1.0, x)
function code(x_s, x_m, y, z)
	tmp = 0.0
	if (z <= -3.3e+134)
		tmp = Float64(z * Float64(x_m * Float64(-1.0 + y)));
	else
		tmp = Float64(x_m - Float64(x_m * Float64(z * Float64(1.0 - y))));
	end
	return Float64(x_s * tmp)
end
x\_m = abs(x);
x\_s = sign(x) * abs(1.0);
function tmp_2 = code(x_s, x_m, y, z)
	tmp = 0.0;
	if (z <= -3.3e+134)
		tmp = z * (x_m * (-1.0 + y));
	else
		tmp = x_m - (x_m * (z * (1.0 - 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]
code[x$95$s_, x$95$m_, y_, z_] := N[(x$95$s * If[LessEqual[z, -3.3e+134], N[(z * N[(x$95$m * N[(-1.0 + y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x$95$m - N[(x$95$m * N[(z * N[(1.0 - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
x\_m = \left|x\right|
\\
x\_s = \mathsf{copysign}\left(1, x\right)

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < -3.3e134

    1. Initial program 88.8%

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

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

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

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

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

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

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

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

    if -3.3e134 < z

    1. Initial program 99.0%

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

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

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

Alternative 10: 39.1% accurate, 9.0× speedup?

\[\begin{array}{l} x\_m = \left|x\right| \\ x\_s = \mathsf{copysign}\left(1, x\right) \\ x\_s \cdot x\_m \end{array} \]
x\_m = (fabs.f64 x)
x\_s = (copysign.f64 #s(literal 1 binary64) x)
(FPCore (x_s x_m y z) :precision binary64 (* x_s x_m))
x\_m = fabs(x);
x\_s = copysign(1.0, x);
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)
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);
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)
def code(x_s, x_m, y, z):
	return x_s * x_m
x\_m = abs(x)
x\_s = copysign(1.0, x)
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);
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]
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\_s \cdot x\_m
\end{array}
Derivation
  1. Initial program 97.3%

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

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

    \[\leadsto x \]
  5. Add Preprocessing

Developer target: 99.5% accurate, 0.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := x \cdot \left(1 - \left(1 - y\right) \cdot z\right)\\ t_1 := x + \left(1 - y\right) \cdot \left(\left(-z\right) \cdot x\right)\\ \mathbf{if}\;t\_0 < -1.618195973607049 \cdot 10^{+50}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;t\_0 < 3.892237649663903 \cdot 10^{+134}:\\ \;\;\;\;\left(x \cdot y\right) \cdot z - \left(x \cdot z - x\right)\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (* x (- 1.0 (* (- 1.0 y) z))))
        (t_1 (+ x (* (- 1.0 y) (* (- z) x)))))
   (if (< t_0 -1.618195973607049e+50)
     t_1
     (if (< t_0 3.892237649663903e+134) (- (* (* x y) z) (- (* x z) x)) t_1))))
double code(double x, double y, double z) {
	double t_0 = x * (1.0 - ((1.0 - y) * z));
	double t_1 = x + ((1.0 - y) * (-z * x));
	double tmp;
	if (t_0 < -1.618195973607049e+50) {
		tmp = t_1;
	} else if (t_0 < 3.892237649663903e+134) {
		tmp = ((x * y) * z) - ((x * z) - x);
	} else {
		tmp = t_1;
	}
	return tmp;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = x * (1.0d0 - ((1.0d0 - y) * z))
    t_1 = x + ((1.0d0 - y) * (-z * x))
    if (t_0 < (-1.618195973607049d+50)) then
        tmp = t_1
    else if (t_0 < 3.892237649663903d+134) then
        tmp = ((x * y) * z) - ((x * z) - x)
    else
        tmp = t_1
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double t_0 = x * (1.0 - ((1.0 - y) * z));
	double t_1 = x + ((1.0 - y) * (-z * x));
	double tmp;
	if (t_0 < -1.618195973607049e+50) {
		tmp = t_1;
	} else if (t_0 < 3.892237649663903e+134) {
		tmp = ((x * y) * z) - ((x * z) - x);
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(x, y, z):
	t_0 = x * (1.0 - ((1.0 - y) * z))
	t_1 = x + ((1.0 - y) * (-z * x))
	tmp = 0
	if t_0 < -1.618195973607049e+50:
		tmp = t_1
	elif t_0 < 3.892237649663903e+134:
		tmp = ((x * y) * z) - ((x * z) - x)
	else:
		tmp = t_1
	return tmp
function code(x, y, z)
	t_0 = Float64(x * Float64(1.0 - Float64(Float64(1.0 - y) * z)))
	t_1 = Float64(x + Float64(Float64(1.0 - y) * Float64(Float64(-z) * x)))
	tmp = 0.0
	if (t_0 < -1.618195973607049e+50)
		tmp = t_1;
	elseif (t_0 < 3.892237649663903e+134)
		tmp = Float64(Float64(Float64(x * y) * z) - Float64(Float64(x * z) - x));
	else
		tmp = t_1;
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	t_0 = x * (1.0 - ((1.0 - y) * z));
	t_1 = x + ((1.0 - y) * (-z * x));
	tmp = 0.0;
	if (t_0 < -1.618195973607049e+50)
		tmp = t_1;
	elseif (t_0 < 3.892237649663903e+134)
		tmp = ((x * y) * z) - ((x * z) - x);
	else
		tmp = t_1;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[(1.0 - N[(N[(1.0 - y), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(x + N[(N[(1.0 - y), $MachinePrecision] * N[((-z) * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[Less[t$95$0, -1.618195973607049e+50], t$95$1, If[Less[t$95$0, 3.892237649663903e+134], N[(N[(N[(x * y), $MachinePrecision] * z), $MachinePrecision] - N[(N[(x * z), $MachinePrecision] - x), $MachinePrecision]), $MachinePrecision], t$95$1]]]]
\begin{array}{l}

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

\mathbf{elif}\;t\_0 < 3.892237649663903 \cdot 10^{+134}:\\
\;\;\;\;\left(x \cdot y\right) \cdot z - \left(x \cdot z - x\right)\\

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


\end{array}
\end{array}

Reproduce

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

  :alt
  (if (< (* x (- 1.0 (* (- 1.0 y) z))) -1.618195973607049e+50) (+ x (* (- 1.0 y) (* (- z) x))) (if (< (* x (- 1.0 (* (- 1.0 y) z))) 3.892237649663903e+134) (- (* (* x y) z) (- (* x z) x)) (+ x (* (- 1.0 y) (* (- z) x)))))

  (* x (- 1.0 (* (- 1.0 y) z))))