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

?

Percentage Accurate: 99.5% → 99.8%
Time: 14.4s
Precision: binary64
Cost: 960

?

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

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.

Herbie found 16 alternatives:

AlternativeAccuracySpeedup

Accuracy vs Speed

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.

Bogosity?

Bogosity

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation?

  1. Initial program 99.5%

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

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

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

Alternatives

Alternative 1
Accuracy99.8%
Cost960
\[4 \cdot \left(y - x\right) + \left(x + -6 \cdot \left(\left(y - x\right) \cdot z\right)\right) \]
Alternative 2
Accuracy50.5%
Cost2037
\[\begin{array}{l} t_0 := -6 \cdot \left(y \cdot z\right)\\ t_1 := x \cdot \left(z \cdot 6\right)\\ \mathbf{if}\;z \leq -9.5 \cdot 10^{+266}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -1.8 \cdot 10^{+173}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -1.4 \cdot 10^{+94}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -2.4 \cdot 10^{+39}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -3.4 \cdot 10^{-11}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -5.5 \cdot 10^{-175}:\\ \;\;\;\;4 \cdot y\\ \mathbf{elif}\;z \leq -6.5 \cdot 10^{-231}:\\ \;\;\;\;x \cdot -3\\ \mathbf{elif}\;z \leq 4.5 \cdot 10^{-301}:\\ \;\;\;\;4 \cdot y\\ \mathbf{elif}\;z \leq 6 \cdot 10^{-129}:\\ \;\;\;\;x \cdot -3\\ \mathbf{elif}\;z \leq 3.1 \cdot 10^{-107}:\\ \;\;\;\;4 \cdot y\\ \mathbf{elif}\;z \leq 0.5:\\ \;\;\;\;x \cdot -3\\ \mathbf{elif}\;z \leq 6.9 \cdot 10^{+168} \lor \neg \left(z \leq 9.5 \cdot 10^{+208}\right):\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 3
Accuracy50.3%
Cost2037
\[\begin{array}{l} t_0 := -6 \cdot \left(y \cdot z\right)\\ t_1 := x \cdot \left(z \cdot 6\right)\\ \mathbf{if}\;z \leq -5.2 \cdot 10^{+266}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -4.8 \cdot 10^{+171}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -1.45 \cdot 10^{+88}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -3.5 \cdot 10^{+39}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -3.4 \cdot 10^{-11}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -2.65 \cdot 10^{-179}:\\ \;\;\;\;4 \cdot y\\ \mathbf{elif}\;z \leq -5.8 \cdot 10^{-232}:\\ \;\;\;\;x \cdot -3\\ \mathbf{elif}\;z \leq 4 \cdot 10^{-301}:\\ \;\;\;\;4 \cdot y\\ \mathbf{elif}\;z \leq 8.8 \cdot 10^{-131}:\\ \;\;\;\;x \cdot -3\\ \mathbf{elif}\;z \leq 1.6 \cdot 10^{-106}:\\ \;\;\;\;4 \cdot y\\ \mathbf{elif}\;z \leq 0.5:\\ \;\;\;\;x \cdot -3\\ \mathbf{elif}\;z \leq 6.9 \cdot 10^{+168} \lor \neg \left(z \leq 2.45 \cdot 10^{+208}\right):\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;z \cdot \left(y \cdot -6\right)\\ \end{array} \]
Alternative 4
Accuracy50.4%
Cost2037
\[\begin{array}{l} t_0 := -6 \cdot \left(y \cdot z\right)\\ t_1 := x \cdot \left(z \cdot 6\right)\\ \mathbf{if}\;z \leq -8.4 \cdot 10^{+266}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -4.5 \cdot 10^{+172}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -9.5 \cdot 10^{+95}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -1.4 \cdot 10^{+38}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -3.4 \cdot 10^{-11}:\\ \;\;\;\;y \cdot \left(-6 \cdot z\right)\\ \mathbf{elif}\;z \leq -1.48 \cdot 10^{-182}:\\ \;\;\;\;4 \cdot y\\ \mathbf{elif}\;z \leq -2.45 \cdot 10^{-230}:\\ \;\;\;\;x \cdot -3\\ \mathbf{elif}\;z \leq 4.4 \cdot 10^{-301}:\\ \;\;\;\;4 \cdot y\\ \mathbf{elif}\;z \leq 9.6 \cdot 10^{-129}:\\ \;\;\;\;x \cdot -3\\ \mathbf{elif}\;z \leq 1.9 \cdot 10^{-108}:\\ \;\;\;\;4 \cdot y\\ \mathbf{elif}\;z \leq 0.5:\\ \;\;\;\;x \cdot -3\\ \mathbf{elif}\;z \leq 7 \cdot 10^{+168} \lor \neg \left(z \leq 1.75 \cdot 10^{+208}\right):\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;z \cdot \left(y \cdot -6\right)\\ \end{array} \]
Alternative 5
Accuracy73.5%
Cost1372
\[\begin{array}{l} t_0 := -6 \cdot \left(\left(y - x\right) \cdot z\right)\\ \mathbf{if}\;z \leq -3.4 \cdot 10^{-11}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -1.7 \cdot 10^{-181}:\\ \;\;\;\;4 \cdot y\\ \mathbf{elif}\;z \leq -3.5 \cdot 10^{-232}:\\ \;\;\;\;x \cdot -3\\ \mathbf{elif}\;z \leq 3.1 \cdot 10^{-301}:\\ \;\;\;\;4 \cdot y\\ \mathbf{elif}\;z \leq 2.15 \cdot 10^{-128}:\\ \;\;\;\;x \cdot -3\\ \mathbf{elif}\;z \leq 3.8 \cdot 10^{-106}:\\ \;\;\;\;4 \cdot y\\ \mathbf{elif}\;z \leq 0.5:\\ \;\;\;\;x \cdot -3\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 6
Accuracy73.7%
Cost1372
\[\begin{array}{l} t_0 := x \cdot \left(-3 + z \cdot 6\right)\\ t_1 := -6 \cdot \left(\left(y - x\right) \cdot z\right)\\ \mathbf{if}\;z \leq -3.4 \cdot 10^{-11}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -4.3 \cdot 10^{-179}:\\ \;\;\;\;4 \cdot y\\ \mathbf{elif}\;z \leq -2.55 \cdot 10^{-232}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 3.05 \cdot 10^{-301}:\\ \;\;\;\;4 \cdot y\\ \mathbf{elif}\;z \leq 3.5 \cdot 10^{-130}:\\ \;\;\;\;x \cdot -3\\ \mathbf{elif}\;z \leq 5 \cdot 10^{-109}:\\ \;\;\;\;4 \cdot y\\ \mathbf{elif}\;z \leq 2700000000000:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 7
Accuracy73.8%
Cost1372
\[\begin{array}{l} t_0 := x \cdot \left(-3 + z \cdot 6\right)\\ \mathbf{if}\;z \leq -3.4 \cdot 10^{-11}:\\ \;\;\;\;-6 \cdot \left(\left(y - x\right) \cdot z\right)\\ \mathbf{elif}\;z \leq -1.75 \cdot 10^{-178}:\\ \;\;\;\;4 \cdot y\\ \mathbf{elif}\;z \leq -5.6 \cdot 10^{-231}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 3.65 \cdot 10^{-301}:\\ \;\;\;\;4 \cdot y\\ \mathbf{elif}\;z \leq 1.35 \cdot 10^{-129}:\\ \;\;\;\;x \cdot -3\\ \mathbf{elif}\;z \leq 1.62 \cdot 10^{-108}:\\ \;\;\;\;4 \cdot y\\ \mathbf{elif}\;z \leq 2700000000000:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;z \cdot \left(\left(y - x\right) \cdot -6\right)\\ \end{array} \]
Alternative 8
Accuracy49.9%
Cost1244
\[\begin{array}{l} t_0 := -6 \cdot \left(y \cdot z\right)\\ \mathbf{if}\;z \leq -3.4 \cdot 10^{-11}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -8.2 \cdot 10^{-179}:\\ \;\;\;\;4 \cdot y\\ \mathbf{elif}\;z \leq -5.7 \cdot 10^{-232}:\\ \;\;\;\;x \cdot -3\\ \mathbf{elif}\;z \leq 4.2 \cdot 10^{-301}:\\ \;\;\;\;4 \cdot y\\ \mathbf{elif}\;z \leq 1.5 \cdot 10^{-127}:\\ \;\;\;\;x \cdot -3\\ \mathbf{elif}\;z \leq 1.2 \cdot 10^{-106}:\\ \;\;\;\;4 \cdot y\\ \mathbf{elif}\;z \leq 0.52:\\ \;\;\;\;x \cdot -3\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 9
Accuracy74.8%
Cost978
\[\begin{array}{l} \mathbf{if}\;x \leq -4.1 \cdot 10^{+29} \lor \neg \left(x \leq -1.28 \cdot 10^{-20} \lor \neg \left(x \leq -1.56 \cdot 10^{-83}\right) \land x \leq 5.5 \cdot 10^{-21}\right):\\ \;\;\;\;x \cdot \left(-3 + z \cdot 6\right)\\ \mathbf{else}:\\ \;\;\;\;\left(0.6666666666666666 - z\right) \cdot \left(y \cdot 6\right)\\ \end{array} \]
Alternative 10
Accuracy74.9%
Cost978
\[\begin{array}{l} \mathbf{if}\;x \leq -1.12 \cdot 10^{+28} \lor \neg \left(x \leq -4.7 \cdot 10^{-18} \lor \neg \left(x \leq -1.8 \cdot 10^{-83}\right) \land x \leq 1.4 \cdot 10^{-19}\right):\\ \;\;\;\;x \cdot \left(-3 + z \cdot 6\right)\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(4 + -6 \cdot z\right)\\ \end{array} \]
Alternative 11
Accuracy97.8%
Cost712
\[\begin{array}{l} \mathbf{if}\;z \leq -0.55:\\ \;\;\;\;-6 \cdot \left(\left(y - x\right) \cdot z\right)\\ \mathbf{elif}\;z \leq 0.58:\\ \;\;\;\;4 \cdot y + x \cdot -3\\ \mathbf{else}:\\ \;\;\;\;z \cdot \left(\left(y - x\right) \cdot -6\right)\\ \end{array} \]
Alternative 12
Accuracy99.5%
Cost704
\[x + \left(0.6666666666666666 - z\right) \cdot \left(\left(y - x\right) \cdot 6\right) \]
Alternative 13
Accuracy99.7%
Cost704
\[x + \left(y - x\right) \cdot \left(6 \cdot \left(0.6666666666666666 - z\right)\right) \]
Alternative 14
Accuracy36.4%
Cost456
\[\begin{array}{l} \mathbf{if}\;x \leq -1.8 \cdot 10^{-83}:\\ \;\;\;\;x \cdot -3\\ \mathbf{elif}\;x \leq 1.45 \cdot 10^{-78}:\\ \;\;\;\;4 \cdot y\\ \mathbf{else}:\\ \;\;\;\;x \cdot -3\\ \end{array} \]
Alternative 15
Accuracy26.2%
Cost192
\[x \cdot -3 \]
Alternative 16
Accuracy2.6%
Cost64
\[x \]

Reproduce?

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