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

Percentage Accurate: 99.5% → 99.5%
Time: 1.7s
Alternatives: 10
Speedup: 1.0×

Specification

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

\\
x + \left(\left(y - x\right) \cdot 6\right) \cdot \left(\frac{2}{3} - 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: 99.5% accurate, 1.0× speedup?

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

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

Alternative 1: 99.5% accurate, 1.0× speedup?

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

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

    \[x + \left(\left(y - x\right) \cdot 6\right) \cdot \left(\frac{2}{3} - z\right) \]
  2. Add Preprocessing
  3. Add Preprocessing

Alternative 2: 53.9% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{2}{3} - z\\ t_1 := x + \left(y - x\right) \cdot t\_0\\ \mathbf{if}\;t\_0 \leq 0.17:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;t\_0 \leq 5.2:\\ \;\;\;\;x + \left(x + \left(x + \left(y - x\right) \cdot 6\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (- (/ 2.0 3.0) z)) (t_1 (+ x (* (- y x) t_0))))
   (if (<= t_0 0.17)
     t_1
     (if (<= t_0 5.2) (+ x (+ x (+ x (* (- y x) 6.0)))) t_1))))
double code(double x, double y, double z) {
	double t_0 = (2.0 / 3.0) - z;
	double t_1 = x + ((y - x) * t_0);
	double tmp;
	if (t_0 <= 0.17) {
		tmp = t_1;
	} else if (t_0 <= 5.2) {
		tmp = x + (x + (x + ((y - x) * 6.0)));
	} else {
		tmp = t_1;
	}
	return tmp;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = (2.0d0 / 3.0d0) - z
    t_1 = x + ((y - x) * t_0)
    if (t_0 <= 0.17d0) then
        tmp = t_1
    else if (t_0 <= 5.2d0) then
        tmp = x + (x + (x + ((y - x) * 6.0d0)))
    else
        tmp = t_1
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double t_0 = (2.0 / 3.0) - z;
	double t_1 = x + ((y - x) * t_0);
	double tmp;
	if (t_0 <= 0.17) {
		tmp = t_1;
	} else if (t_0 <= 5.2) {
		tmp = x + (x + (x + ((y - x) * 6.0)));
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(x, y, z):
	t_0 = (2.0 / 3.0) - z
	t_1 = x + ((y - x) * t_0)
	tmp = 0
	if t_0 <= 0.17:
		tmp = t_1
	elif t_0 <= 5.2:
		tmp = x + (x + (x + ((y - x) * 6.0)))
	else:
		tmp = t_1
	return tmp
function code(x, y, z)
	t_0 = Float64(Float64(2.0 / 3.0) - z)
	t_1 = Float64(x + Float64(Float64(y - x) * t_0))
	tmp = 0.0
	if (t_0 <= 0.17)
		tmp = t_1;
	elseif (t_0 <= 5.2)
		tmp = Float64(x + Float64(x + Float64(x + Float64(Float64(y - x) * 6.0))));
	else
		tmp = t_1;
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	t_0 = (2.0 / 3.0) - z;
	t_1 = x + ((y - x) * t_0);
	tmp = 0.0;
	if (t_0 <= 0.17)
		tmp = t_1;
	elseif (t_0 <= 5.2)
		tmp = x + (x + (x + ((y - x) * 6.0)));
	else
		tmp = t_1;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(2.0 / 3.0), $MachinePrecision] - z), $MachinePrecision]}, Block[{t$95$1 = N[(x + N[(N[(y - x), $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 0.17], t$95$1, If[LessEqual[t$95$0, 5.2], N[(x + N[(x + N[(x + N[(N[(y - x), $MachinePrecision] * 6.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$1]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{2}{3} - z\\
t_1 := x + \left(y - x\right) \cdot t\_0\\
\mathbf{if}\;t\_0 \leq 0.17:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;t\_0 \leq 5.2:\\
\;\;\;\;x + \left(x + \left(x + \left(y - x\right) \cdot 6\right)\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (-.f64 (/.f64 #s(literal 2 binary64) #s(literal 3 binary64)) z) < 0.170000000000000012 or 5.20000000000000018 < (-.f64 (/.f64 #s(literal 2 binary64) #s(literal 3 binary64)) z)

    1. Initial program 99.8%

      \[x + \left(\left(y - x\right) \cdot 6\right) \cdot \left(\frac{2}{3} - z\right) \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0

      \[\leadsto x + \color{blue}{\left(6 \cdot y\right)} \cdot \left(\frac{2}{3} - z\right) \]
    4. Applied rewrites54.0%

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

    if 0.170000000000000012 < (-.f64 (/.f64 #s(literal 2 binary64) #s(literal 3 binary64)) z) < 5.20000000000000018

    1. Initial program 99.3%

      \[x + \left(\left(y - x\right) \cdot 6\right) \cdot \left(\frac{2}{3} - z\right) \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0

      \[\leadsto x + \color{blue}{\left(-6 \cdot \left(x \cdot \left(\frac{2}{3} - z\right)\right) + 6 \cdot \left(y \cdot \left(\frac{2}{3} - z\right)\right)\right)} \]
    4. Applied rewrites19.7%

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

      \[\leadsto x + \left(y + -1 \cdot x\right) \cdot 6 \]
    6. Applied rewrites48.6%

      \[\leadsto x + \left(x + \left(y - x\right) \cdot \left(\frac{2}{3} - z\right)\right) \cdot 6 \]
    7. Taylor expanded in x around inf

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

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

Alternative 3: 53.9% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{2}{3} - z\\ t_1 := \left(y - x\right) \cdot t\_0\\ \mathbf{if}\;t\_0 \leq 0.21:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;t\_0 \leq 4.8:\\ \;\;\;\;x + \left(x + \left(x + \left(y - x\right) \cdot 6\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (- (/ 2.0 3.0) z)) (t_1 (* (- y x) t_0)))
   (if (<= t_0 0.21)
     t_1
     (if (<= t_0 4.8) (+ x (+ x (+ x (* (- y x) 6.0)))) t_1))))
double code(double x, double y, double z) {
	double t_0 = (2.0 / 3.0) - z;
	double t_1 = (y - x) * t_0;
	double tmp;
	if (t_0 <= 0.21) {
		tmp = t_1;
	} else if (t_0 <= 4.8) {
		tmp = x + (x + (x + ((y - x) * 6.0)));
	} else {
		tmp = t_1;
	}
	return tmp;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = (2.0d0 / 3.0d0) - z
    t_1 = (y - x) * t_0
    if (t_0 <= 0.21d0) then
        tmp = t_1
    else if (t_0 <= 4.8d0) then
        tmp = x + (x + (x + ((y - x) * 6.0d0)))
    else
        tmp = t_1
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double t_0 = (2.0 / 3.0) - z;
	double t_1 = (y - x) * t_0;
	double tmp;
	if (t_0 <= 0.21) {
		tmp = t_1;
	} else if (t_0 <= 4.8) {
		tmp = x + (x + (x + ((y - x) * 6.0)));
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(x, y, z):
	t_0 = (2.0 / 3.0) - z
	t_1 = (y - x) * t_0
	tmp = 0
	if t_0 <= 0.21:
		tmp = t_1
	elif t_0 <= 4.8:
		tmp = x + (x + (x + ((y - x) * 6.0)))
	else:
		tmp = t_1
	return tmp
function code(x, y, z)
	t_0 = Float64(Float64(2.0 / 3.0) - z)
	t_1 = Float64(Float64(y - x) * t_0)
	tmp = 0.0
	if (t_0 <= 0.21)
		tmp = t_1;
	elseif (t_0 <= 4.8)
		tmp = Float64(x + Float64(x + Float64(x + Float64(Float64(y - x) * 6.0))));
	else
		tmp = t_1;
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	t_0 = (2.0 / 3.0) - z;
	t_1 = (y - x) * t_0;
	tmp = 0.0;
	if (t_0 <= 0.21)
		tmp = t_1;
	elseif (t_0 <= 4.8)
		tmp = x + (x + (x + ((y - x) * 6.0)));
	else
		tmp = t_1;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(2.0 / 3.0), $MachinePrecision] - z), $MachinePrecision]}, Block[{t$95$1 = N[(N[(y - x), $MachinePrecision] * t$95$0), $MachinePrecision]}, If[LessEqual[t$95$0, 0.21], t$95$1, If[LessEqual[t$95$0, 4.8], N[(x + N[(x + N[(x + N[(N[(y - x), $MachinePrecision] * 6.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$1]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{2}{3} - z\\
t_1 := \left(y - x\right) \cdot t\_0\\
\mathbf{if}\;t\_0 \leq 0.21:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;t\_0 \leq 4.8:\\
\;\;\;\;x + \left(x + \left(x + \left(y - x\right) \cdot 6\right)\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (-.f64 (/.f64 #s(literal 2 binary64) #s(literal 3 binary64)) z) < 0.209999999999999992 or 4.79999999999999982 < (-.f64 (/.f64 #s(literal 2 binary64) #s(literal 3 binary64)) z)

    1. Initial program 99.8%

      \[x + \left(\left(y - x\right) \cdot 6\right) \cdot \left(\frac{2}{3} - z\right) \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0

      \[\leadsto \color{blue}{6 \cdot \left(y \cdot \left(\frac{2}{3} - z\right)\right) + x \cdot \left(1 + -6 \cdot \left(\frac{2}{3} - z\right)\right)} \]
    4. Applied rewrites98.5%

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

      \[\leadsto \left(6 \cdot y\right) \cdot \left(\color{blue}{\frac{2}{3}} - z\right) \]
    6. Applied rewrites54.0%

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

    if 0.209999999999999992 < (-.f64 (/.f64 #s(literal 2 binary64) #s(literal 3 binary64)) z) < 4.79999999999999982

    1. Initial program 99.3%

      \[x + \left(\left(y - x\right) \cdot 6\right) \cdot \left(\frac{2}{3} - z\right) \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0

      \[\leadsto x + \color{blue}{\left(-6 \cdot \left(x \cdot \left(\frac{2}{3} - z\right)\right) + 6 \cdot \left(y \cdot \left(\frac{2}{3} - z\right)\right)\right)} \]
    4. Applied rewrites19.7%

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

      \[\leadsto x + \left(y + -1 \cdot x\right) \cdot 6 \]
    6. Applied rewrites48.6%

      \[\leadsto x + \left(x + \left(y - x\right) \cdot \left(\frac{2}{3} - z\right)\right) \cdot 6 \]
    7. Taylor expanded in x around inf

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

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

Alternative 4: 78.8% accurate, 0.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.2 \cdot 10^{+237}:\\
\;\;\;\;x + \left(x + \left(x + \left(y - x\right) \cdot 6\right)\right)\\

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


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

    1. Initial program 99.7%

      \[x + \left(\left(y - x\right) \cdot 6\right) \cdot \left(\frac{2}{3} - z\right) \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0

      \[\leadsto x + \color{blue}{\left(-6 \cdot \left(x \cdot \left(\frac{2}{3} - z\right)\right) + 6 \cdot \left(y \cdot \left(\frac{2}{3} - z\right)\right)\right)} \]
    4. Applied rewrites18.5%

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

      \[\leadsto x + \left(y + -1 \cdot x\right) \cdot 6 \]
    6. Applied rewrites9.2%

      \[\leadsto x + \left(x + \left(y - x\right) \cdot \left(\frac{2}{3} - z\right)\right) \cdot 6 \]
    7. Taylor expanded in x around inf

      \[\leadsto x + \color{blue}{x \cdot \left(-6 \cdot \left(\frac{2}{3} - z\right) + 6 \cdot \frac{y \cdot \left(\frac{2}{3} - z\right)}{x}\right)} \]
    8. Applied rewrites82.7%

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

    if -3.20000000000000017e237 < x

    1. Initial program 99.5%

      \[x + \left(\left(y - x\right) \cdot 6\right) \cdot \left(\frac{2}{3} - z\right) \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0

      \[\leadsto x + \color{blue}{\left(-6 \cdot \left(x \cdot \left(\frac{2}{3} - z\right)\right) + 6 \cdot \left(y \cdot \left(\frac{2}{3} - z\right)\right)\right)} \]
    4. Applied rewrites11.3%

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

      \[\leadsto x + \left(y + -1 \cdot x\right) \cdot 6 \]
    6. Applied rewrites75.8%

      \[\leadsto x + \left(x + \left(y - x\right) \cdot \left(\frac{2}{3} - z\right)\right) \cdot 6 \]
    7. Taylor expanded in x around inf

      \[\leadsto x + \left(x \cdot \left(\frac{y}{x} - 1\right)\right) \cdot 6 \]
    8. Applied rewrites99.5%

      \[\leadsto x + \left(\left(y - x\right) \cdot \left(\frac{2}{3} - z\right)\right) \cdot 6 \]
    9. Taylor expanded in x around 0

      \[\leadsto \color{blue}{6 \cdot \left(y \cdot \left(\frac{2}{3} - z\right)\right) + x \cdot \left(1 + -6 \cdot \left(\frac{2}{3} - z\right)\right)} \]
    10. Applied rewrites80.4%

      \[\leadsto \color{blue}{\left(\left(y - x\right) \cdot \left(\frac{2}{3} - z\right)\right) \cdot 6} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 5: 99.5% accurate, 1.0× speedup?

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

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

    \[x + \left(\left(y - x\right) \cdot 6\right) \cdot \left(\frac{2}{3} - z\right) \]
  2. Add Preprocessing
  3. Taylor expanded in x around 0

    \[\leadsto x + \color{blue}{\left(-6 \cdot \left(x \cdot \left(\frac{2}{3} - z\right)\right) + 6 \cdot \left(y \cdot \left(\frac{2}{3} - z\right)\right)\right)} \]
  4. Applied rewrites11.6%

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

    \[\leadsto x + \left(y + -1 \cdot x\right) \cdot 6 \]
  6. Applied rewrites73.0%

    \[\leadsto x + \left(x + \left(y - x\right) \cdot \left(\frac{2}{3} - z\right)\right) \cdot 6 \]
  7. Taylor expanded in x around inf

    \[\leadsto x + \left(x \cdot \left(\frac{y}{x} - 1\right)\right) \cdot 6 \]
  8. Applied rewrites99.5%

    \[\leadsto x + \left(\left(y - x\right) \cdot \left(\frac{2}{3} - z\right)\right) \cdot 6 \]
  9. Add Preprocessing

Alternative 6: 30.5% accurate, 1.7× speedup?

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

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

    \[x + \left(\left(y - x\right) \cdot 6\right) \cdot \left(\frac{2}{3} - z\right) \]
  2. Add Preprocessing
  3. Taylor expanded in x around 0

    \[\leadsto x + \color{blue}{\left(-6 \cdot \left(x \cdot \left(\frac{2}{3} - z\right)\right) + 6 \cdot \left(y \cdot \left(\frac{2}{3} - z\right)\right)\right)} \]
  4. Applied rewrites11.6%

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

    \[\leadsto x + \left(y + -1 \cdot x\right) \cdot 6 \]
  6. Applied rewrites73.0%

    \[\leadsto x + \left(x + \left(y - x\right) \cdot \left(\frac{2}{3} - z\right)\right) \cdot 6 \]
  7. Taylor expanded in x around inf

    \[\leadsto x + \color{blue}{x \cdot \left(-6 \cdot \left(\frac{2}{3} - z\right) + 6 \cdot \frac{y \cdot \left(\frac{2}{3} - z\right)}{x}\right)} \]
  8. Applied rewrites30.5%

    \[\leadsto x + \color{blue}{\left(x + \left(x + \left(y - x\right) \cdot 6\right)\right)} \]
  9. Add Preprocessing

Alternative 7: 12.2% accurate, 2.1× speedup?

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

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

    \[x + \left(\left(y - x\right) \cdot 6\right) \cdot \left(\frac{2}{3} - z\right) \]
  2. Add Preprocessing
  3. Taylor expanded in x around 0

    \[\leadsto x + \color{blue}{\left(-6 \cdot \left(x \cdot \left(\frac{2}{3} - z\right)\right) + 6 \cdot \left(y \cdot \left(\frac{2}{3} - z\right)\right)\right)} \]
  4. Applied rewrites11.6%

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

    \[\leadsto x + \left(-6 \cdot x + \color{blue}{6 \cdot y}\right) \]
  6. Applied rewrites12.0%

    \[\leadsto x + \left(x + \color{blue}{\left(y - x\right) \cdot 6}\right) \]
  7. Add Preprocessing

Alternative 8: 11.9% accurate, 2.6× speedup?

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

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

    \[x + \left(\left(y - x\right) \cdot 6\right) \cdot \left(\frac{2}{3} - z\right) \]
  2. Add Preprocessing
  3. Taylor expanded in x around 0

    \[\leadsto x + \color{blue}{\left(-6 \cdot \left(x \cdot \left(\frac{2}{3} - z\right)\right) + 6 \cdot \left(y \cdot \left(\frac{2}{3} - z\right)\right)\right)} \]
  4. Applied rewrites11.6%

    \[\leadsto x + \color{blue}{\left(y - x\right) \cdot 6} \]
  5. Add Preprocessing

Alternative 9: 11.7% accurate, 3.4× speedup?

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

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

    \[x + \left(\left(y - x\right) \cdot 6\right) \cdot \left(\frac{2}{3} - z\right) \]
  2. Add Preprocessing
  3. Taylor expanded in x around 0

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

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

    \[\leadsto -6 \cdot \left(x \cdot \left(\frac{2}{3} - z\right)\right) + \color{blue}{6 \cdot \left(y \cdot \left(\frac{2}{3} - z\right)\right)} \]
  6. Applied rewrites11.4%

    \[\leadsto \left(y - x\right) \cdot \color{blue}{6} \]
  7. Add Preprocessing

Alternative 10: 10.6% accurate, 7.8× speedup?

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

\\
y - x
\end{array}
Derivation
  1. Initial program 99.6%

    \[x + \left(\left(y - x\right) \cdot 6\right) \cdot \left(\frac{2}{3} - z\right) \]
  2. Add Preprocessing
  3. Taylor expanded in x around 0

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

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

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

    \[\leadsto \color{blue}{y - x} \]
  7. Add Preprocessing

Reproduce

?
herbie shell --seed 2024321 
(FPCore (x y z)
  :name "Data.Colour.RGBSpace.HSL:hsl from colour-2.3.3, D"
  :precision binary64
  :pre (TRUE)
  (+ x (* (* (- y x) 6.0) (- (/ 2.0 3.0) z))))