Data.Colour.RGBSpace.HSL:hsl from colour-2.3.3, E

Percentage Accurate: 99.6% → 99.8%
Time: 7.8s
Alternatives: 9
Speedup: 1.0×

Specification

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

\\
x + \left(\left(y - x\right) \cdot 6\right) \cdot z
\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 9 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: 99.6% accurate, 1.0× speedup?

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

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

Alternative 1: 99.8% accurate, 1.0× speedup?

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

\\
x + \left(y - x\right) \cdot \left(6 \cdot z\right)
\end{array}
Derivation
  1. Initial program 99.8%

    \[x + \left(\left(y - x\right) \cdot 6\right) \cdot z \]
  2. Step-by-step derivation
    1. associate-*l*99.9%

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

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

    \[\leadsto x + \left(y - x\right) \cdot \left(6 \cdot z\right) \]

Alternative 2: 60.7% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := 6 \cdot \left(y \cdot z\right)\\ \mathbf{if}\;z \leq -5.3 \cdot 10^{-95}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 1.7 \cdot 10^{-63}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 1.8 \cdot 10^{+159} \lor \neg \left(z \leq 10^{+258}\right):\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;-6 \cdot \left(x \cdot z\right)\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (* 6.0 (* y z))))
   (if (<= z -5.3e-95)
     t_0
     (if (<= z 1.7e-63)
       x
       (if (or (<= z 1.8e+159) (not (<= z 1e+258))) t_0 (* -6.0 (* x z)))))))
double code(double x, double y, double z) {
	double t_0 = 6.0 * (y * z);
	double tmp;
	if (z <= -5.3e-95) {
		tmp = t_0;
	} else if (z <= 1.7e-63) {
		tmp = x;
	} else if ((z <= 1.8e+159) || !(z <= 1e+258)) {
		tmp = t_0;
	} else {
		tmp = -6.0 * (x * z);
	}
	return tmp;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: t_0
    real(8) :: tmp
    t_0 = 6.0d0 * (y * z)
    if (z <= (-5.3d-95)) then
        tmp = t_0
    else if (z <= 1.7d-63) then
        tmp = x
    else if ((z <= 1.8d+159) .or. (.not. (z <= 1d+258))) then
        tmp = t_0
    else
        tmp = (-6.0d0) * (x * z)
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double t_0 = 6.0 * (y * z);
	double tmp;
	if (z <= -5.3e-95) {
		tmp = t_0;
	} else if (z <= 1.7e-63) {
		tmp = x;
	} else if ((z <= 1.8e+159) || !(z <= 1e+258)) {
		tmp = t_0;
	} else {
		tmp = -6.0 * (x * z);
	}
	return tmp;
}
def code(x, y, z):
	t_0 = 6.0 * (y * z)
	tmp = 0
	if z <= -5.3e-95:
		tmp = t_0
	elif z <= 1.7e-63:
		tmp = x
	elif (z <= 1.8e+159) or not (z <= 1e+258):
		tmp = t_0
	else:
		tmp = -6.0 * (x * z)
	return tmp
function code(x, y, z)
	t_0 = Float64(6.0 * Float64(y * z))
	tmp = 0.0
	if (z <= -5.3e-95)
		tmp = t_0;
	elseif (z <= 1.7e-63)
		tmp = x;
	elseif ((z <= 1.8e+159) || !(z <= 1e+258))
		tmp = t_0;
	else
		tmp = Float64(-6.0 * Float64(x * z));
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	t_0 = 6.0 * (y * z);
	tmp = 0.0;
	if (z <= -5.3e-95)
		tmp = t_0;
	elseif (z <= 1.7e-63)
		tmp = x;
	elseif ((z <= 1.8e+159) || ~((z <= 1e+258)))
		tmp = t_0;
	else
		tmp = -6.0 * (x * z);
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := Block[{t$95$0 = N[(6.0 * N[(y * z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -5.3e-95], t$95$0, If[LessEqual[z, 1.7e-63], x, If[Or[LessEqual[z, 1.8e+159], N[Not[LessEqual[z, 1e+258]], $MachinePrecision]], t$95$0, N[(-6.0 * N[(x * z), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := 6 \cdot \left(y \cdot z\right)\\
\mathbf{if}\;z \leq -5.3 \cdot 10^{-95}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;z \leq 1.7 \cdot 10^{-63}:\\
\;\;\;\;x\\

\mathbf{elif}\;z \leq 1.8 \cdot 10^{+159} \lor \neg \left(z \leq 10^{+258}\right):\\
\;\;\;\;t_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if z < -5.2999999999999998e-95 or 1.69999999999999999e-63 < z < 1.80000000000000018e159 or 1.00000000000000006e258 < z

    1. Initial program 99.7%

      \[x + \left(\left(y - x\right) \cdot 6\right) \cdot z \]
    2. Step-by-step derivation
      1. associate-*r*99.9%

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

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

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

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\left(y - x\right) \cdot z, 6, x\right)} \]
    4. Taylor expanded in z around inf 90.5%

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

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

    if -5.2999999999999998e-95 < z < 1.69999999999999999e-63

    1. Initial program 99.9%

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

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

    if 1.80000000000000018e159 < z < 1.00000000000000006e258

    1. Initial program 99.9%

      \[x + \left(\left(y - x\right) \cdot 6\right) \cdot z \]
    2. Step-by-step derivation
      1. associate-*r*99.8%

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

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

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

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\left(y - x\right) \cdot z, 6, x\right)} \]
    4. Taylor expanded in z around inf 99.7%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -5.3 \cdot 10^{-95}:\\ \;\;\;\;6 \cdot \left(y \cdot z\right)\\ \mathbf{elif}\;z \leq 1.7 \cdot 10^{-63}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 1.8 \cdot 10^{+159} \lor \neg \left(z \leq 10^{+258}\right):\\ \;\;\;\;6 \cdot \left(y \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;-6 \cdot \left(x \cdot z\right)\\ \end{array} \]

Alternative 3: 60.6% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := 6 \cdot \left(y \cdot z\right)\\ \mathbf{if}\;z \leq -1.05 \cdot 10^{-95}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 2 \cdot 10^{-64}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 4.4 \cdot 10^{+154} \lor \neg \left(z \leq 7 \cdot 10^{+258}\right):\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;z \cdot \left(x \cdot -6\right)\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (* 6.0 (* y z))))
   (if (<= z -1.05e-95)
     t_0
     (if (<= z 2e-64)
       x
       (if (or (<= z 4.4e+154) (not (<= z 7e+258))) t_0 (* z (* x -6.0)))))))
double code(double x, double y, double z) {
	double t_0 = 6.0 * (y * z);
	double tmp;
	if (z <= -1.05e-95) {
		tmp = t_0;
	} else if (z <= 2e-64) {
		tmp = x;
	} else if ((z <= 4.4e+154) || !(z <= 7e+258)) {
		tmp = t_0;
	} else {
		tmp = z * (x * -6.0);
	}
	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) :: tmp
    t_0 = 6.0d0 * (y * z)
    if (z <= (-1.05d-95)) then
        tmp = t_0
    else if (z <= 2d-64) then
        tmp = x
    else if ((z <= 4.4d+154) .or. (.not. (z <= 7d+258))) then
        tmp = t_0
    else
        tmp = z * (x * (-6.0d0))
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double t_0 = 6.0 * (y * z);
	double tmp;
	if (z <= -1.05e-95) {
		tmp = t_0;
	} else if (z <= 2e-64) {
		tmp = x;
	} else if ((z <= 4.4e+154) || !(z <= 7e+258)) {
		tmp = t_0;
	} else {
		tmp = z * (x * -6.0);
	}
	return tmp;
}
def code(x, y, z):
	t_0 = 6.0 * (y * z)
	tmp = 0
	if z <= -1.05e-95:
		tmp = t_0
	elif z <= 2e-64:
		tmp = x
	elif (z <= 4.4e+154) or not (z <= 7e+258):
		tmp = t_0
	else:
		tmp = z * (x * -6.0)
	return tmp
function code(x, y, z)
	t_0 = Float64(6.0 * Float64(y * z))
	tmp = 0.0
	if (z <= -1.05e-95)
		tmp = t_0;
	elseif (z <= 2e-64)
		tmp = x;
	elseif ((z <= 4.4e+154) || !(z <= 7e+258))
		tmp = t_0;
	else
		tmp = Float64(z * Float64(x * -6.0));
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	t_0 = 6.0 * (y * z);
	tmp = 0.0;
	if (z <= -1.05e-95)
		tmp = t_0;
	elseif (z <= 2e-64)
		tmp = x;
	elseif ((z <= 4.4e+154) || ~((z <= 7e+258)))
		tmp = t_0;
	else
		tmp = z * (x * -6.0);
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := Block[{t$95$0 = N[(6.0 * N[(y * z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -1.05e-95], t$95$0, If[LessEqual[z, 2e-64], x, If[Or[LessEqual[z, 4.4e+154], N[Not[LessEqual[z, 7e+258]], $MachinePrecision]], t$95$0, N[(z * N[(x * -6.0), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := 6 \cdot \left(y \cdot z\right)\\
\mathbf{if}\;z \leq -1.05 \cdot 10^{-95}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;z \leq 2 \cdot 10^{-64}:\\
\;\;\;\;x\\

\mathbf{elif}\;z \leq 4.4 \cdot 10^{+154} \lor \neg \left(z \leq 7 \cdot 10^{+258}\right):\\
\;\;\;\;t_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if z < -1.05e-95 or 1.99999999999999993e-64 < z < 4.4000000000000002e154 or 7.0000000000000002e258 < z

    1. Initial program 99.7%

      \[x + \left(\left(y - x\right) \cdot 6\right) \cdot z \]
    2. Step-by-step derivation
      1. associate-*r*99.9%

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

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

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

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\left(y - x\right) \cdot z, 6, x\right)} \]
    4. Taylor expanded in z around inf 90.5%

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

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

    if -1.05e-95 < z < 1.99999999999999993e-64

    1. Initial program 99.9%

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

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

    if 4.4000000000000002e154 < z < 7.0000000000000002e258

    1. Initial program 99.9%

      \[x + \left(\left(y - x\right) \cdot 6\right) \cdot z \]
    2. Step-by-step derivation
      1. associate-*r*99.8%

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

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

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

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\left(y - x\right) \cdot z, 6, x\right)} \]
    4. Taylor expanded in z around inf 99.7%

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

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

        \[\leadsto \color{blue}{\left(x \cdot z\right) \cdot -6} \]
      2. *-commutative61.4%

        \[\leadsto \color{blue}{\left(z \cdot x\right)} \cdot -6 \]
      3. associate-*l*61.4%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -1.05 \cdot 10^{-95}:\\ \;\;\;\;6 \cdot \left(y \cdot z\right)\\ \mathbf{elif}\;z \leq 2 \cdot 10^{-64}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 4.4 \cdot 10^{+154} \lor \neg \left(z \leq 7 \cdot 10^{+258}\right):\\ \;\;\;\;6 \cdot \left(y \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;z \cdot \left(x \cdot -6\right)\\ \end{array} \]

Alternative 4: 83.7% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq -2.55 \cdot 10^{-95} \lor \neg \left(z \leq 1.65 \cdot 10^{-19}\right):\\ \;\;\;\;6 \cdot \left(\left(y - x\right) \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (or (<= z -2.55e-95) (not (<= z 1.65e-19))) (* 6.0 (* (- y x) z)) x))
double code(double x, double y, double z) {
	double tmp;
	if ((z <= -2.55e-95) || !(z <= 1.65e-19)) {
		tmp = 6.0 * ((y - x) * z);
	} else {
		tmp = x;
	}
	return tmp;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: tmp
    if ((z <= (-2.55d-95)) .or. (.not. (z <= 1.65d-19))) then
        tmp = 6.0d0 * ((y - x) * z)
    else
        tmp = x
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if ((z <= -2.55e-95) || !(z <= 1.65e-19)) {
		tmp = 6.0 * ((y - x) * z);
	} else {
		tmp = x;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if (z <= -2.55e-95) or not (z <= 1.65e-19):
		tmp = 6.0 * ((y - x) * z)
	else:
		tmp = x
	return tmp
function code(x, y, z)
	tmp = 0.0
	if ((z <= -2.55e-95) || !(z <= 1.65e-19))
		tmp = Float64(6.0 * Float64(Float64(y - x) * z));
	else
		tmp = x;
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if ((z <= -2.55e-95) || ~((z <= 1.65e-19)))
		tmp = 6.0 * ((y - x) * z);
	else
		tmp = x;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[Or[LessEqual[z, -2.55e-95], N[Not[LessEqual[z, 1.65e-19]], $MachinePrecision]], N[(6.0 * N[(N[(y - x), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.55 \cdot 10^{-95} \lor \neg \left(z \leq 1.65 \cdot 10^{-19}\right):\\
\;\;\;\;6 \cdot \left(\left(y - x\right) \cdot z\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < -2.55e-95 or 1.6499999999999999e-19 < z

    1. Initial program 99.7%

      \[x + \left(\left(y - x\right) \cdot 6\right) \cdot z \]
    2. Step-by-step derivation
      1. associate-*r*99.9%

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

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

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

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\left(y - x\right) \cdot z, 6, x\right)} \]
    4. Taylor expanded in z around inf 93.5%

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

    if -2.55e-95 < z < 1.6499999999999999e-19

    1. Initial program 99.9%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -2.55 \cdot 10^{-95} \lor \neg \left(z \leq 1.65 \cdot 10^{-19}\right):\\ \;\;\;\;6 \cdot \left(\left(y - x\right) \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]

Alternative 5: 98.5% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq -0.17 \lor \neg \left(z \leq 9 \cdot 10^{-17}\right):\\ \;\;\;\;6 \cdot \left(\left(y - x\right) \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;x + 6 \cdot \left(y \cdot z\right)\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (or (<= z -0.17) (not (<= z 9e-17)))
   (* 6.0 (* (- y x) z))
   (+ x (* 6.0 (* y z)))))
double code(double x, double y, double z) {
	double tmp;
	if ((z <= -0.17) || !(z <= 9e-17)) {
		tmp = 6.0 * ((y - x) * z);
	} else {
		tmp = x + (6.0 * (y * z));
	}
	return tmp;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: tmp
    if ((z <= (-0.17d0)) .or. (.not. (z <= 9d-17))) then
        tmp = 6.0d0 * ((y - x) * z)
    else
        tmp = x + (6.0d0 * (y * z))
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if ((z <= -0.17) || !(z <= 9e-17)) {
		tmp = 6.0 * ((y - x) * z);
	} else {
		tmp = x + (6.0 * (y * z));
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if (z <= -0.17) or not (z <= 9e-17):
		tmp = 6.0 * ((y - x) * z)
	else:
		tmp = x + (6.0 * (y * z))
	return tmp
function code(x, y, z)
	tmp = 0.0
	if ((z <= -0.17) || !(z <= 9e-17))
		tmp = Float64(6.0 * Float64(Float64(y - x) * z));
	else
		tmp = Float64(x + Float64(6.0 * Float64(y * z)));
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if ((z <= -0.17) || ~((z <= 9e-17)))
		tmp = 6.0 * ((y - x) * z);
	else
		tmp = x + (6.0 * (y * z));
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[Or[LessEqual[z, -0.17], N[Not[LessEqual[z, 9e-17]], $MachinePrecision]], N[(6.0 * N[(N[(y - x), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision], N[(x + N[(6.0 * N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;z \leq -0.17 \lor \neg \left(z \leq 9 \cdot 10^{-17}\right):\\
\;\;\;\;6 \cdot \left(\left(y - x\right) \cdot z\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < -0.170000000000000012 or 8.99999999999999957e-17 < z

    1. Initial program 99.7%

      \[x + \left(\left(y - x\right) \cdot 6\right) \cdot z \]
    2. Step-by-step derivation
      1. associate-*r*99.9%

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

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

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

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\left(y - x\right) \cdot z, 6, x\right)} \]
    4. Taylor expanded in z around inf 99.0%

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

    if -0.170000000000000012 < z < 8.99999999999999957e-17

    1. Initial program 99.8%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -0.17 \lor \neg \left(z \leq 9 \cdot 10^{-17}\right):\\ \;\;\;\;6 \cdot \left(\left(y - x\right) \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;x + 6 \cdot \left(y \cdot z\right)\\ \end{array} \]

Alternative 6: 98.7% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq -0.175 \lor \neg \left(z \leq 0.165\right):\\ \;\;\;\;6 \cdot \left(\left(y - x\right) \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;x + z \cdot \left(y \cdot 6\right)\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (or (<= z -0.175) (not (<= z 0.165)))
   (* 6.0 (* (- y x) z))
   (+ x (* z (* y 6.0)))))
double code(double x, double y, double z) {
	double tmp;
	if ((z <= -0.175) || !(z <= 0.165)) {
		tmp = 6.0 * ((y - x) * z);
	} else {
		tmp = x + (z * (y * 6.0));
	}
	return tmp;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: tmp
    if ((z <= (-0.175d0)) .or. (.not. (z <= 0.165d0))) then
        tmp = 6.0d0 * ((y - x) * z)
    else
        tmp = x + (z * (y * 6.0d0))
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if ((z <= -0.175) || !(z <= 0.165)) {
		tmp = 6.0 * ((y - x) * z);
	} else {
		tmp = x + (z * (y * 6.0));
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if (z <= -0.175) or not (z <= 0.165):
		tmp = 6.0 * ((y - x) * z)
	else:
		tmp = x + (z * (y * 6.0))
	return tmp
function code(x, y, z)
	tmp = 0.0
	if ((z <= -0.175) || !(z <= 0.165))
		tmp = Float64(6.0 * Float64(Float64(y - x) * z));
	else
		tmp = Float64(x + Float64(z * Float64(y * 6.0)));
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if ((z <= -0.175) || ~((z <= 0.165)))
		tmp = 6.0 * ((y - x) * z);
	else
		tmp = x + (z * (y * 6.0));
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[Or[LessEqual[z, -0.175], N[Not[LessEqual[z, 0.165]], $MachinePrecision]], N[(6.0 * N[(N[(y - x), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision], N[(x + N[(z * N[(y * 6.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < -0.17499999999999999 or 0.165000000000000008 < z

    1. Initial program 99.7%

      \[x + \left(\left(y - x\right) \cdot 6\right) \cdot z \]
    2. Step-by-step derivation
      1. associate-*r*99.9%

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

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

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

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\left(y - x\right) \cdot z, 6, x\right)} \]
    4. Taylor expanded in z around inf 99.0%

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

    if -0.17499999999999999 < z < 0.165000000000000008

    1. Initial program 99.8%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -0.175 \lor \neg \left(z \leq 0.165\right):\\ \;\;\;\;6 \cdot \left(\left(y - x\right) \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;x + z \cdot \left(y \cdot 6\right)\\ \end{array} \]

Alternative 7: 60.1% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq -0.17 \lor \neg \left(z \leq 275000000000\right):\\ \;\;\;\;-6 \cdot \left(x \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (or (<= z -0.17) (not (<= z 275000000000.0))) (* -6.0 (* x z)) x))
double code(double x, double y, double z) {
	double tmp;
	if ((z <= -0.17) || !(z <= 275000000000.0)) {
		tmp = -6.0 * (x * z);
	} else {
		tmp = x;
	}
	return tmp;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: tmp
    if ((z <= (-0.17d0)) .or. (.not. (z <= 275000000000.0d0))) then
        tmp = (-6.0d0) * (x * z)
    else
        tmp = x
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if ((z <= -0.17) || !(z <= 275000000000.0)) {
		tmp = -6.0 * (x * z);
	} else {
		tmp = x;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if (z <= -0.17) or not (z <= 275000000000.0):
		tmp = -6.0 * (x * z)
	else:
		tmp = x
	return tmp
function code(x, y, z)
	tmp = 0.0
	if ((z <= -0.17) || !(z <= 275000000000.0))
		tmp = Float64(-6.0 * Float64(x * z));
	else
		tmp = x;
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if ((z <= -0.17) || ~((z <= 275000000000.0)))
		tmp = -6.0 * (x * z);
	else
		tmp = x;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[Or[LessEqual[z, -0.17], N[Not[LessEqual[z, 275000000000.0]], $MachinePrecision]], N[(-6.0 * N[(x * z), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;z \leq -0.17 \lor \neg \left(z \leq 275000000000\right):\\
\;\;\;\;-6 \cdot \left(x \cdot z\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < -0.170000000000000012 or 2.75e11 < z

    1. Initial program 99.7%

      \[x + \left(\left(y - x\right) \cdot 6\right) \cdot z \]
    2. Step-by-step derivation
      1. associate-*r*99.9%

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

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

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

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\left(y - x\right) \cdot z, 6, x\right)} \]
    4. Taylor expanded in z around inf 99.0%

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

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

        \[\leadsto -6 \cdot \color{blue}{\left(z \cdot x\right)} \]
    7. Simplified46.3%

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

    if -0.170000000000000012 < z < 2.75e11

    1. Initial program 99.9%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -0.17 \lor \neg \left(z \leq 275000000000\right):\\ \;\;\;\;-6 \cdot \left(x \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]

Alternative 8: 99.6% accurate, 1.0× speedup?

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

\\
x + z \cdot \left(\left(y - x\right) \cdot 6\right)
\end{array}
Derivation
  1. Initial program 99.8%

    \[x + \left(\left(y - x\right) \cdot 6\right) \cdot z \]
  2. Final simplification99.8%

    \[\leadsto x + z \cdot \left(\left(y - x\right) \cdot 6\right) \]

Alternative 9: 35.5% accurate, 9.0× speedup?

\[\begin{array}{l} \\ x \end{array} \]
(FPCore (x y z) :precision binary64 x)
double code(double x, double y, double z) {
	return x;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = x
end function
public static double code(double x, double y, double z) {
	return x;
}
def code(x, y, z):
	return x
function code(x, y, z)
	return x
end
function tmp = code(x, y, z)
	tmp = x;
end
code[x_, y_, z_] := x
\begin{array}{l}

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

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

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

    \[\leadsto x \]

Developer target: 99.8% accurate, 1.0× speedup?

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

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

Reproduce

?
herbie shell --seed 2023306 
(FPCore (x y z)
  :name "Data.Colour.RGBSpace.HSL:hsl from colour-2.3.3, E"
  :precision binary64

  :herbie-target
  (- x (* (* 6.0 z) (- x y)))

  (+ x (* (* (- y x) 6.0) z)))