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

?

Percentage Accurate: 99.5% → 99.8%
Time: 11.6s
Precision: binary64
Cost: 6976

?

\[x + \left(\left(y - x\right) \cdot 6\right) \cdot \left(\frac{2}{3} - z\right) \]
\[\mathsf{fma}\left(y - x, 6 \cdot \left(0.6666666666666666 - z\right), x\right) \]
(FPCore (x y z)
 :precision binary64
 (+ x (* (* (- y x) 6.0) (- (/ 2.0 3.0) z))))
(FPCore (x y z)
 :precision binary64
 (fma (- y x) (* 6.0 (- 0.6666666666666666 z)) x))
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 fma((y - x), (6.0 * (0.6666666666666666 - z)), x);
}
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 fma(Float64(y - x), Float64(6.0 * Float64(0.6666666666666666 - z)), x)
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[(y - x), $MachinePrecision] * N[(6.0 * N[(0.6666666666666666 - z), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision]
x + \left(\left(y - x\right) \cdot 6\right) \cdot \left(\frac{2}{3} - z\right)
\mathsf{fma}\left(y - x, 6 \cdot \left(0.6666666666666666 - z\right), x\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 15 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.

Derivation?

  1. Initial program 99.6%

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

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

    \[\leadsto \mathsf{fma}\left(y - x, 6 \cdot \left(0.6666666666666666 - z\right), x\right) \]

Alternatives

Alternative 1
Accuracy50.9%
Cost1772
\[\begin{array}{l} t_0 := -6 \cdot \left(y \cdot z\right)\\ t_1 := 6 \cdot \left(x \cdot z\right)\\ \mathbf{if}\;z \leq -9.4 \cdot 10^{+92}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -1.7 \cdot 10^{+54}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -3.8 \cdot 10^{-5}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -1.05 \cdot 10^{-104}:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;z \leq -2.35 \cdot 10^{-135}:\\ \;\;\;\;x \cdot -3\\ \mathbf{elif}\;z \leq -1.05 \cdot 10^{-242}:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;z \leq 1.28 \cdot 10^{-253}:\\ \;\;\;\;x \cdot -3\\ \mathbf{elif}\;z \leq 2.75 \cdot 10^{-207}:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;z \leq 2.5 \cdot 10^{-30}:\\ \;\;\;\;x \cdot -3\\ \mathbf{elif}\;z \leq 0.52:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;z \leq 3.2 \cdot 10^{+198}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Accuracy51.0%
Cost1772
\[\begin{array}{l} t_0 := y \cdot \left(z \cdot -6\right)\\ t_1 := 6 \cdot \left(x \cdot z\right)\\ \mathbf{if}\;z \leq -7.2 \cdot 10^{+90}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -1 \cdot 10^{+54}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -3.8 \cdot 10^{-5}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -6.3 \cdot 10^{-105}:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;z \leq -9.5 \cdot 10^{-135}:\\ \;\;\;\;x \cdot -3\\ \mathbf{elif}\;z \leq -1.25 \cdot 10^{-242}:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;z \leq 1.1 \cdot 10^{-256}:\\ \;\;\;\;x \cdot -3\\ \mathbf{elif}\;z \leq 2 \cdot 10^{-206}:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;z \leq 2.35 \cdot 10^{-30}:\\ \;\;\;\;x \cdot -3\\ \mathbf{elif}\;z \leq 0.52:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;z \leq 1.18 \cdot 10^{+200}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;-6 \cdot \left(y \cdot z\right)\\ \end{array} \]
Alternative 3
Accuracy51.0%
Cost1772
\[\begin{array}{l} t_0 := y \cdot \left(z \cdot -6\right)\\ \mathbf{if}\;z \leq -5.5 \cdot 10^{+90}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -9 \cdot 10^{+52}:\\ \;\;\;\;z \cdot \left(x \cdot 6\right)\\ \mathbf{elif}\;z \leq -3.8 \cdot 10^{-5}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -1.25 \cdot 10^{-104}:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;z \leq -1.1 \cdot 10^{-134}:\\ \;\;\;\;x \cdot -3\\ \mathbf{elif}\;z \leq -6.8 \cdot 10^{-243}:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;z \leq 2.6 \cdot 10^{-253}:\\ \;\;\;\;x \cdot -3\\ \mathbf{elif}\;z \leq 2.4 \cdot 10^{-207}:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;z \leq 2.05 \cdot 10^{-29}:\\ \;\;\;\;x \cdot -3\\ \mathbf{elif}\;z \leq 0.52:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;z \leq 5.2 \cdot 10^{+197}:\\ \;\;\;\;6 \cdot \left(x \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;-6 \cdot \left(y \cdot z\right)\\ \end{array} \]
Alternative 4
Accuracy52.1%
Cost1640
\[\begin{array}{l} t_0 := 6 \cdot \left(y \cdot \left(0.6666666666666666 - z\right)\right)\\ \mathbf{if}\;z \leq -4.8 \cdot 10^{+93}:\\ \;\;\;\;y \cdot \left(z \cdot -6\right)\\ \mathbf{elif}\;z \leq -5.5 \cdot 10^{+54}:\\ \;\;\;\;z \cdot \left(x \cdot 6\right)\\ \mathbf{elif}\;z \leq -1.15 \cdot 10^{-104}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -1.7 \cdot 10^{-135}:\\ \;\;\;\;x \cdot -3\\ \mathbf{elif}\;z \leq -1.1 \cdot 10^{-242}:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;z \leq 1.65 \cdot 10^{-254}:\\ \;\;\;\;x \cdot -3\\ \mathbf{elif}\;z \leq 1.8 \cdot 10^{-207}:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;z \leq 4.6 \cdot 10^{-33}:\\ \;\;\;\;x \cdot -3\\ \mathbf{elif}\;z \leq 1.15 \cdot 10^{+23}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 10^{+198}:\\ \;\;\;\;6 \cdot \left(x \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;-6 \cdot \left(y \cdot z\right)\\ \end{array} \]
Alternative 5
Accuracy73.8%
Cost1504
\[\begin{array}{l} t_0 := 6 \cdot \left(y \cdot \left(0.6666666666666666 - z\right)\right)\\ t_1 := z \cdot \left(6 \cdot \left(x - y\right)\right)\\ \mathbf{if}\;z \leq -6.4 \cdot 10^{+16}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -8.2 \cdot 10^{-105}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -1.7 \cdot 10^{-135}:\\ \;\;\;\;x \cdot -3\\ \mathbf{elif}\;z \leq -6.2 \cdot 10^{-243}:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;z \leq 1.4 \cdot 10^{-255}:\\ \;\;\;\;x \cdot \left(-3 + 6 \cdot z\right)\\ \mathbf{elif}\;z \leq 1.9 \cdot 10^{-206}:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;z \leq 7.2 \cdot 10^{-31}:\\ \;\;\;\;x \cdot -3\\ \mathbf{elif}\;z \leq 2.1:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 6
Accuracy73.9%
Cost1504
\[\begin{array}{l} t_0 := y \cdot \left(4 + z \cdot -6\right)\\ t_1 := z \cdot \left(6 \cdot \left(x - y\right)\right)\\ \mathbf{if}\;z \leq -6.4 \cdot 10^{+16}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -9.5 \cdot 10^{-105}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -3.5 \cdot 10^{-135}:\\ \;\;\;\;x \cdot -3\\ \mathbf{elif}\;z \leq -6.8 \cdot 10^{-243}:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;z \leq 7.2 \cdot 10^{-256}:\\ \;\;\;\;x \cdot \left(-3 + 6 \cdot z\right)\\ \mathbf{elif}\;z \leq 7.5 \cdot 10^{-207}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 1.22 \cdot 10^{-33}:\\ \;\;\;\;x \cdot -3\\ \mathbf{elif}\;z \leq 2.1:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 7
Accuracy73.8%
Cost1504
\[\begin{array}{l} t_0 := y \cdot \left(4 + z \cdot -6\right)\\ \mathbf{if}\;z \leq -6.4 \cdot 10^{+16}:\\ \;\;\;\;z \cdot \left(6 \cdot \left(x - y\right)\right)\\ \mathbf{elif}\;z \leq -1.28 \cdot 10^{-104}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -3.2 \cdot 10^{-134}:\\ \;\;\;\;x \cdot -3\\ \mathbf{elif}\;z \leq -1.4 \cdot 10^{-242}:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;z \leq 8.8 \cdot 10^{-251}:\\ \;\;\;\;x \cdot \left(-3 + 6 \cdot z\right)\\ \mathbf{elif}\;z \leq 2.1 \cdot 10^{-206}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 1.96 \cdot 10^{-32}:\\ \;\;\;\;x \cdot -3\\ \mathbf{elif}\;z \leq 2.1:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\left(y - x\right) \cdot \left(z \cdot -6\right)\\ \end{array} \]
Alternative 8
Accuracy50.6%
Cost1376
\[\begin{array}{l} t_0 := -6 \cdot \left(y \cdot z\right)\\ \mathbf{if}\;z \leq -3.8 \cdot 10^{-5}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -8.6 \cdot 10^{-105}:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;z \leq -9.5 \cdot 10^{-135}:\\ \;\;\;\;x \cdot -3\\ \mathbf{elif}\;z \leq -1.3 \cdot 10^{-242}:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;z \leq 5.7 \cdot 10^{-251}:\\ \;\;\;\;x \cdot -3\\ \mathbf{elif}\;z \leq 1.15 \cdot 10^{-206}:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;z \leq 1.24 \cdot 10^{-29}:\\ \;\;\;\;x \cdot -3\\ \mathbf{elif}\;z \leq 0.66:\\ \;\;\;\;y \cdot 4\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 9
Accuracy74.5%
Cost978
\[\begin{array}{l} \mathbf{if}\;y \leq -17000000000000 \lor \neg \left(y \leq 1.95 \cdot 10^{-115} \lor \neg \left(y \leq 1.3 \cdot 10^{-60}\right) \land y \leq 2.2 \cdot 10^{+18}\right):\\ \;\;\;\;6 \cdot \left(y \cdot \left(0.6666666666666666 - z\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(-3 + 6 \cdot z\right)\\ \end{array} \]
Alternative 10
Accuracy97.6%
Cost712
\[\begin{array}{l} \mathbf{if}\;z \leq -0.55:\\ \;\;\;\;z \cdot \left(6 \cdot \left(x - y\right)\right)\\ \mathbf{elif}\;z \leq 0.62:\\ \;\;\;\;y \cdot 4 + x \cdot -3\\ \mathbf{else}:\\ \;\;\;\;\left(y - x\right) \cdot \left(z \cdot -6\right)\\ \end{array} \]
Alternative 11
Accuracy99.5%
Cost704
\[x + \left(0.6666666666666666 - z\right) \cdot \left(\left(y - x\right) \cdot 6\right) \]
Alternative 12
Accuracy99.7%
Cost704
\[x + \left(y - x\right) \cdot \left(6 \cdot \left(0.6666666666666666 - z\right)\right) \]
Alternative 13
Accuracy39.0%
Cost456
\[\begin{array}{l} \mathbf{if}\;y \leq -1.85 \cdot 10^{+21}:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;y \leq 7.6 \cdot 10^{+21}:\\ \;\;\;\;x \cdot -3\\ \mathbf{else}:\\ \;\;\;\;y \cdot 4\\ \end{array} \]
Alternative 14
Accuracy26.3%
Cost192
\[y \cdot 4 \]

Reproduce?

herbie shell --seed 2023161 
(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))))