?

Average Error: 0.4 → 0.2
Time: 12.3s
Precision: binary64
Cost: 13248

?

\[x + \left(\left(y - x\right) \cdot 6\right) \cdot \left(\frac{2}{3} - z\right) \]
\[\mathsf{fma}\left(y - x, \mathsf{fma}\left(z, -6, 4\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) (fma z -6.0 4.0) 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), fma(z, -6.0, 4.0), 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), fma(z, -6.0, 4.0), 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[(z * -6.0 + 4.0), $MachinePrecision] + x), $MachinePrecision]
x + \left(\left(y - x\right) \cdot 6\right) \cdot \left(\frac{2}{3} - z\right)
\mathsf{fma}\left(y - x, \mathsf{fma}\left(z, -6, 4\right), x\right)

Error?

Derivation?

  1. Initial program 0.4

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

    \[\leadsto \color{blue}{\mathsf{fma}\left(y - x, \mathsf{fma}\left(z, -6, 4\right), x\right)} \]
    Proof

    [Start]0.4

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

    +-commutative [=>]0.4

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

    associate-*l* [=>]0.2

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

    fma-def [=>]0.2

    \[ \color{blue}{\mathsf{fma}\left(y - x, 6 \cdot \left(\frac{2}{3} - z\right), x\right)} \]

    sub-neg [=>]0.2

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

    distribute-lft-in [=>]0.2

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

    +-commutative [=>]0.2

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

    neg-mul-1 [=>]0.2

    \[ \mathsf{fma}\left(y - x, 6 \cdot \color{blue}{\left(-1 \cdot z\right)} + 6 \cdot \frac{2}{3}, x\right) \]

    associate-*r* [=>]0.2

    \[ \mathsf{fma}\left(y - x, \color{blue}{\left(6 \cdot -1\right) \cdot z} + 6 \cdot \frac{2}{3}, x\right) \]

    *-commutative [=>]0.2

    \[ \mathsf{fma}\left(y - x, \color{blue}{z \cdot \left(6 \cdot -1\right)} + 6 \cdot \frac{2}{3}, x\right) \]

    fma-def [=>]0.2

    \[ \mathsf{fma}\left(y - x, \color{blue}{\mathsf{fma}\left(z, 6 \cdot -1, 6 \cdot \frac{2}{3}\right)}, x\right) \]

    metadata-eval [=>]0.2

    \[ \mathsf{fma}\left(y - x, \mathsf{fma}\left(z, \color{blue}{-6}, 6 \cdot \frac{2}{3}\right), x\right) \]

    metadata-eval [=>]0.2

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

    metadata-eval [=>]0.2

    \[ \mathsf{fma}\left(y - x, \mathsf{fma}\left(z, -6, \color{blue}{4}\right), x\right) \]
  3. Final simplification0.2

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

Alternatives

Alternative 1
Error0.3
Cost7360
\[\mathsf{fma}\left(1 + -6 \cdot \left(0.6666666666666666 - z\right), x, \left(0.6666666666666666 - z\right) \cdot \left(y \cdot 6\right)\right) \]
Alternative 2
Error33.0
Cost1244
\[\begin{array}{l} t_0 := -6 \cdot \left(y \cdot z\right)\\ \mathbf{if}\;z \leq -1.35 \cdot 10^{-9}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -2.6 \cdot 10^{-140}:\\ \;\;\;\;x \cdot -3\\ \mathbf{elif}\;z \leq -9.2 \cdot 10^{-202}:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;z \leq -3.4 \cdot 10^{-288}:\\ \;\;\;\;x \cdot -3\\ \mathbf{elif}\;z \leq 7 \cdot 10^{-268}:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;z \leq 0.65:\\ \;\;\;\;x \cdot -3\\ \mathbf{elif}\;z \leq 4.5 \cdot 10^{+77}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;6 \cdot \left(x \cdot z\right)\\ \end{array} \]
Alternative 3
Error33.0
Cost1244
\[\begin{array}{l} t_0 := -6 \cdot \left(y \cdot z\right)\\ \mathbf{if}\;z \leq -1.35 \cdot 10^{-9}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -3.5 \cdot 10^{-140}:\\ \;\;\;\;x \cdot -3\\ \mathbf{elif}\;z \leq -8.2 \cdot 10^{-202}:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;z \leq -3.6 \cdot 10^{-287}:\\ \;\;\;\;x \cdot -3\\ \mathbf{elif}\;z \leq 2.6 \cdot 10^{-267}:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;z \leq 0.66:\\ \;\;\;\;x \cdot -3\\ \mathbf{elif}\;z \leq 3 \cdot 10^{+77}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;z \cdot \left(x \cdot 6\right)\\ \end{array} \]
Alternative 4
Error33.1
Cost1244
\[\begin{array}{l} \mathbf{if}\;z \leq -1.35 \cdot 10^{-9}:\\ \;\;\;\;y \cdot \left(z \cdot -6\right)\\ \mathbf{elif}\;z \leq -3.2 \cdot 10^{-140}:\\ \;\;\;\;x \cdot -3\\ \mathbf{elif}\;z \leq -3.8 \cdot 10^{-203}:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;z \leq -1.7 \cdot 10^{-286}:\\ \;\;\;\;x \cdot -3\\ \mathbf{elif}\;z \leq 8.2 \cdot 10^{-273}:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;z \leq 0.6:\\ \;\;\;\;x \cdot -3\\ \mathbf{elif}\;z \leq 3.5 \cdot 10^{+77}:\\ \;\;\;\;-6 \cdot \left(y \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;z \cdot \left(x \cdot 6\right)\\ \end{array} \]
Alternative 5
Error22.1
Cost1240
\[\begin{array}{l} t_0 := -6 \cdot \left(\left(y - x\right) \cdot z\right)\\ \mathbf{if}\;z \leq -1.35 \cdot 10^{-9}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -2.2 \cdot 10^{-139}:\\ \;\;\;\;x \cdot -3\\ \mathbf{elif}\;z \leq -4.1 \cdot 10^{-203}:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;z \leq -1.35 \cdot 10^{-286}:\\ \;\;\;\;x \cdot -3\\ \mathbf{elif}\;z \leq 2.6 \cdot 10^{-264}:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;z \leq 0.5:\\ \;\;\;\;x \cdot -3\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 6
Error21.7
Cost1240
\[\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 -1.35 \cdot 10^{-9}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -3.5 \cdot 10^{-140}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -1.7 \cdot 10^{-204}:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;z \leq -1.55 \cdot 10^{-286}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 1.35 \cdot 10^{-276}:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;z \leq 64000:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 7
Error21.7
Cost1240
\[\begin{array}{l} t_0 := x \cdot \left(-3 + z \cdot 6\right)\\ \mathbf{if}\;z \leq -1.35 \cdot 10^{-9}:\\ \;\;\;\;-6 \cdot \left(\left(y - x\right) \cdot z\right)\\ \mathbf{elif}\;z \leq -9 \cdot 10^{-140}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -8.1 \cdot 10^{-202}:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;z \leq -2.85 \cdot 10^{-288}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 8 \cdot 10^{-265}:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;z \leq 420000:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;z \cdot \left(\left(y - x\right) \cdot -6\right)\\ \end{array} \]
Alternative 8
Error33.1
Cost1112
\[\begin{array}{l} t_0 := -6 \cdot \left(y \cdot z\right)\\ \mathbf{if}\;z \leq -1.35 \cdot 10^{-9}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -3.1 \cdot 10^{-140}:\\ \;\;\;\;x \cdot -3\\ \mathbf{elif}\;z \leq -4.3 \cdot 10^{-204}:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;z \leq -6 \cdot 10^{-288}:\\ \;\;\;\;x \cdot -3\\ \mathbf{elif}\;z \leq 2.25 \cdot 10^{-271}:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;z \leq 0.6:\\ \;\;\;\;x \cdot -3\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 9
Error0.3
Cost1088
\[x \cdot \left(1 + -6 \cdot \left(0.6666666666666666 - z\right)\right) + 6 \cdot \left(y \cdot \left(0.6666666666666666 - z\right)\right) \]
Alternative 10
Error18.5
Cost978
\[\begin{array}{l} \mathbf{if}\;x \leq -4.8 \cdot 10^{+60} \lor \neg \left(x \leq -1.25 \cdot 10^{-10} \lor \neg \left(x \leq -1.5 \cdot 10^{-99}\right) \land x \leq 1.45 \cdot 10^{+38}\right):\\ \;\;\;\;x \cdot \left(-3 + z \cdot 6\right)\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(4 + z \cdot -6\right)\\ \end{array} \]
Alternative 11
Error2.0
Cost844
\[\begin{array}{l} \mathbf{if}\;z \leq -0.54:\\ \;\;\;\;-6 \cdot \left(\left(y - x\right) \cdot z\right)\\ \mathbf{elif}\;z \leq 9 \cdot 10^{-18}:\\ \;\;\;\;x \cdot -3 + y \cdot 4\\ \mathbf{elif}\;z \leq 205000:\\ \;\;\;\;x \cdot \left(-3 + z \cdot 6\right)\\ \mathbf{else}:\\ \;\;\;\;z \cdot \left(\left(y - x\right) \cdot -6\right)\\ \end{array} \]
Alternative 12
Error33.6
Cost721
\[\begin{array}{l} \mathbf{if}\;y \leq -3.6 \cdot 10^{+132}:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;y \leq -5.9 \cdot 10^{+103} \lor \neg \left(y \leq -4.1 \cdot 10^{+36}\right) \land y \leq 1.7 \cdot 10^{+80}:\\ \;\;\;\;x \cdot -3\\ \mathbf{else}:\\ \;\;\;\;y \cdot 4\\ \end{array} \]
Alternative 13
Error0.4
Cost704
\[x + \left(0.6666666666666666 - z\right) \cdot \left(\left(y - x\right) \cdot 6\right) \]
Alternative 14
Error0.3
Cost704
\[x + \frac{y - x}{-0.16666666666666666} \cdot \left(z + -0.6666666666666666\right) \]
Alternative 15
Error0.2
Cost704
\[x + \left(y - x\right) \cdot \left(\left(0.6666666666666666 - z\right) \cdot 6\right) \]
Alternative 16
Error43.1
Cost192
\[x \cdot -3 \]

Error

Reproduce?

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