?

Average Error: 0.58% → 0.31%
Time: 14.0s
Precision: binary64
Cost: 19904

?

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

Error?

Derivation?

  1. Initial program 0.58

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

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

    [Start]0.58

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

    +-commutative [=>]0.58

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

    associate-*l* [=>]0.34

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

    fma-def [=>]0.34

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

    sub-neg [=>]0.34

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

    distribute-lft-in [=>]0.32

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

    +-commutative [=>]0.32

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

    neg-mul-1 [=>]0.32

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

    associate-*r* [=>]0.32

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

    *-commutative [=>]0.32

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

    fma-def [=>]0.32

    \[ \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.32

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

    metadata-eval [=>]0.32

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

    metadata-eval [=>]0.32

    \[ \mathsf{fma}\left(y - x, \mathsf{fma}\left(z, -6, \color{blue}{4}\right), x\right) \]
  3. Applied egg-rr0.32

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

    \[\leadsto \color{blue}{4 \cdot y + \left(\left(6 \cdot z - 3\right) \cdot x + -6 \cdot \left(y \cdot z\right)\right)} \]
  5. Simplified0.31

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

    [Start]0.32

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

    fma-def [=>]0.32

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

    fma-def [=>]0.32

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

    fma-neg [=>]0.32

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

    metadata-eval [=>]0.32

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

    associate-*r* [=>]0.31

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

    *-commutative [<=]0.31

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

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

Alternatives

Alternative 1
Error0.32%
Cost13248
\[\mathsf{fma}\left(y - x, \mathsf{fma}\left(z, -6, 4\right), x\right) \]
Alternative 2
Error32.26%
Cost1504
\[\begin{array}{l} t_0 := 6 \cdot \left(z \cdot \left(x - y\right)\right)\\ \mathbf{if}\;z \leq -3.7 \cdot 10^{-6}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -2.9 \cdot 10^{-145}:\\ \;\;\;\;-3 \cdot x\\ \mathbf{elif}\;z \leq -1.3 \cdot 10^{-229}:\\ \;\;\;\;4 \cdot y\\ \mathbf{elif}\;z \leq 1.05 \cdot 10^{-234}:\\ \;\;\;\;-3 \cdot x\\ \mathbf{elif}\;z \leq 3.2 \cdot 10^{-84}:\\ \;\;\;\;4 \cdot y\\ \mathbf{elif}\;z \leq 5.4 \cdot 10^{-62}:\\ \;\;\;\;-3 \cdot x\\ \mathbf{elif}\;z \leq 6.4 \cdot 10^{-40}:\\ \;\;\;\;4 \cdot y\\ \mathbf{elif}\;z \leq 0.5:\\ \;\;\;\;-3 \cdot x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 3
Error31.38%
Cost1504
\[\begin{array}{l} t_0 := x \cdot \left(-3 + 6 \cdot z\right)\\ t_1 := 6 \cdot \left(z \cdot \left(x - y\right)\right)\\ \mathbf{if}\;z \leq -3.7 \cdot 10^{-6}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -3.6 \cdot 10^{-147}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -5 \cdot 10^{-231}:\\ \;\;\;\;4 \cdot y\\ \mathbf{elif}\;z \leq 3.2 \cdot 10^{-233}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 1.7 \cdot 10^{-84}:\\ \;\;\;\;4 \cdot y\\ \mathbf{elif}\;z \leq 2.3 \cdot 10^{-65}:\\ \;\;\;\;-3 \cdot x\\ \mathbf{elif}\;z \leq 2.15 \cdot 10^{-39}:\\ \;\;\;\;4 \cdot y\\ \mathbf{elif}\;z \leq 550000:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 4
Error31.56%
Cost1504
\[\begin{array}{l} t_0 := x \cdot \left(-3 + 6 \cdot z\right)\\ t_1 := z \cdot \left(6 \cdot \left(x - y\right)\right)\\ \mathbf{if}\;z \leq -3.7 \cdot 10^{-6}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -1.45 \cdot 10^{-145}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -3 \cdot 10^{-227}:\\ \;\;\;\;4 \cdot y\\ \mathbf{elif}\;z \leq 1.75 \cdot 10^{-234}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 2.6 \cdot 10^{-84}:\\ \;\;\;\;4 \cdot y\\ \mathbf{elif}\;z \leq 5.5 \cdot 10^{-64}:\\ \;\;\;\;-3 \cdot x\\ \mathbf{elif}\;z \leq 8 \cdot 10^{-40}:\\ \;\;\;\;4 \cdot y\\ \mathbf{elif}\;z \leq 960000:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 5
Error50.38%
Cost1376
\[\begin{array}{l} t_0 := -6 \cdot \left(y \cdot z\right)\\ \mathbf{if}\;z \leq -3.7 \cdot 10^{-6}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -1.05 \cdot 10^{-145}:\\ \;\;\;\;-3 \cdot x\\ \mathbf{elif}\;z \leq -1.2 \cdot 10^{-228}:\\ \;\;\;\;4 \cdot y\\ \mathbf{elif}\;z \leq 3.2 \cdot 10^{-232}:\\ \;\;\;\;-3 \cdot x\\ \mathbf{elif}\;z \leq 6.6 \cdot 10^{-85}:\\ \;\;\;\;4 \cdot y\\ \mathbf{elif}\;z \leq 5.8 \cdot 10^{-62}:\\ \;\;\;\;-3 \cdot x\\ \mathbf{elif}\;z \leq 1.35 \cdot 10^{-39}:\\ \;\;\;\;4 \cdot y\\ \mathbf{elif}\;z \leq 0.62:\\ \;\;\;\;-3 \cdot x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 6
Error50.35%
Cost1376
\[\begin{array}{l} t_0 := 6 \cdot \left(z \cdot x\right)\\ \mathbf{if}\;z \leq -180000:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -4.5 \cdot 10^{-147}:\\ \;\;\;\;-3 \cdot x\\ \mathbf{elif}\;z \leq -9 \cdot 10^{-230}:\\ \;\;\;\;4 \cdot y\\ \mathbf{elif}\;z \leq 2.2 \cdot 10^{-234}:\\ \;\;\;\;-3 \cdot x\\ \mathbf{elif}\;z \leq 2.15 \cdot 10^{-85}:\\ \;\;\;\;4 \cdot y\\ \mathbf{elif}\;z \leq 8.3 \cdot 10^{-66}:\\ \;\;\;\;-3 \cdot x\\ \mathbf{elif}\;z \leq 9 \cdot 10^{-40}:\\ \;\;\;\;4 \cdot y\\ \mathbf{elif}\;z \leq 460000000:\\ \;\;\;\;-3 \cdot x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 7
Error50.31%
Cost1376
\[\begin{array}{l} \mathbf{if}\;z \leq -180000:\\ \;\;\;\;6 \cdot \left(z \cdot x\right)\\ \mathbf{elif}\;z \leq -2.3 \cdot 10^{-147}:\\ \;\;\;\;-3 \cdot x\\ \mathbf{elif}\;z \leq -1.7 \cdot 10^{-227}:\\ \;\;\;\;4 \cdot y\\ \mathbf{elif}\;z \leq 9.5 \cdot 10^{-236}:\\ \;\;\;\;-3 \cdot x\\ \mathbf{elif}\;z \leq 2.8 \cdot 10^{-86}:\\ \;\;\;\;4 \cdot y\\ \mathbf{elif}\;z \leq 8.8 \cdot 10^{-66}:\\ \;\;\;\;-3 \cdot x\\ \mathbf{elif}\;z \leq 5.9 \cdot 10^{-40}:\\ \;\;\;\;4 \cdot y\\ \mathbf{elif}\;z \leq 460000000:\\ \;\;\;\;-3 \cdot x\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(6 \cdot z\right)\\ \end{array} \]
Alternative 8
Error27.48%
Cost978
\[\begin{array}{l} \mathbf{if}\;y \leq -9500000000 \lor \neg \left(y \leq -5.5 \cdot 10^{-27} \lor \neg \left(y \leq -3.8 \cdot 10^{-111}\right) \land y \leq 205000000000\right):\\ \;\;\;\;y \cdot \left(4 - 6 \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(-3 + 6 \cdot z\right)\\ \end{array} \]
Alternative 9
Error0.32%
Cost960
\[\left(x - \left(y - x\right) \cdot \left(6 \cdot z\right)\right) + 4 \cdot \left(y - x\right) \]
Alternative 10
Error3.08%
Cost840
\[\begin{array}{l} t_0 := z \cdot \left(6 \cdot \left(x - y\right)\right)\\ \mathbf{if}\;z \leq -0.6:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 0.52:\\ \;\;\;\;4 \cdot y - x \cdot 3\\ \mathbf{else}:\\ \;\;\;\;x + t_0\\ \end{array} \]
Alternative 11
Error0.45%
Cost832
\[x + \frac{6 \cdot \left(y - x\right)}{\frac{1}{0.6666666666666666 - z}} \]
Alternative 12
Error55.27%
Cost721
\[\begin{array}{l} \mathbf{if}\;y \leq -5.8 \cdot 10^{+118}:\\ \;\;\;\;4 \cdot y\\ \mathbf{elif}\;y \leq -2.7 \cdot 10^{-27} \lor \neg \left(y \leq -3.8 \cdot 10^{-111}\right) \land y \leq 75000000000:\\ \;\;\;\;-3 \cdot x\\ \mathbf{else}:\\ \;\;\;\;4 \cdot y\\ \end{array} \]
Alternative 13
Error3.07%
Cost713
\[\begin{array}{l} \mathbf{if}\;z \leq -0.58 \lor \neg \left(z \leq 0.64\right):\\ \;\;\;\;z \cdot \left(6 \cdot \left(x - y\right)\right)\\ \mathbf{else}:\\ \;\;\;\;4 \cdot y - x \cdot 3\\ \end{array} \]
Alternative 14
Error0.58%
Cost704
\[x + \left(6 \cdot \left(y - x\right)\right) \cdot \left(0.6666666666666666 - z\right) \]
Alternative 15
Error0.51%
Cost704
\[x + \left(0.6666666666666666 - z\right) \cdot \frac{x - y}{-0.16666666666666666} \]
Alternative 16
Error67.95%
Cost192
\[4 \cdot y \]

Error

Reproduce?

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