?

Average Error: 0.66% → 0.3%
Time: 15.7s
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.66

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

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

    [Start]0.66

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

    +-commutative [=>]0.66

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

    associate-*l* [=>]0.35

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

    fma-def [=>]0.32

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

    sub-neg [=>]0.32

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

    distribute-lft-in [=>]0.31

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

    +-commutative [=>]0.31

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

    neg-mul-1 [=>]0.31

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

    associate-*r* [=>]0.31

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

    *-commutative [=>]0.31

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

    fma-def [=>]0.3

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

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

    metadata-eval [=>]0.3

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

    metadata-eval [=>]0.3

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

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

Alternatives

Alternative 1
Error0.38%
Cost7360
\[\mathsf{fma}\left(-3, x, 6 \cdot \left(x \cdot z\right)\right) + 6 \cdot \left(y \cdot \left(0.6666666666666666 - z\right)\right) \]
Alternative 2
Error32.97%
Cost1636
\[\begin{array}{l} t_0 := -6 \cdot \left(\left(y - x\right) \cdot z\right)\\ \mathbf{if}\;z \leq -2.2 \cdot 10^{+16}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -2.35 \cdot 10^{-34}:\\ \;\;\;\;6 \cdot \left(y \cdot \left(0.6666666666666666 - z\right)\right)\\ \mathbf{elif}\;z \leq -2.45 \cdot 10^{-108}:\\ \;\;\;\;x \cdot -3\\ \mathbf{elif}\;z \leq -5.6 \cdot 10^{-202}:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;z \leq -2 \cdot 10^{-254}:\\ \;\;\;\;x \cdot -3\\ \mathbf{elif}\;z \leq 6.5 \cdot 10^{-235}:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;z \leq 1.25 \cdot 10^{-188}:\\ \;\;\;\;x \cdot -3\\ \mathbf{elif}\;z \leq 9.2 \cdot 10^{-113}:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;z \leq 0.5:\\ \;\;\;\;x \cdot -3\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 3
Error51.09%
Cost1508
\[\begin{array}{l} t_0 := -6 \cdot \left(y \cdot z\right)\\ \mathbf{if}\;z \leq -8.8 \cdot 10^{+89}:\\ \;\;\;\;6 \cdot \left(x \cdot z\right)\\ \mathbf{elif}\;z \leq -4.35 \cdot 10^{-7}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -4.15 \cdot 10^{-109}:\\ \;\;\;\;x \cdot -3\\ \mathbf{elif}\;z \leq -3.7 \cdot 10^{-202}:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;z \leq -2.6 \cdot 10^{-258}:\\ \;\;\;\;x \cdot -3\\ \mathbf{elif}\;z \leq 7 \cdot 10^{-235}:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;z \leq 2.6 \cdot 10^{-195}:\\ \;\;\;\;x \cdot -3\\ \mathbf{elif}\;z \leq 8.5 \cdot 10^{-113}:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;z \leq 0.62:\\ \;\;\;\;x \cdot -3\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 4
Error51.08%
Cost1508
\[\begin{array}{l} \mathbf{if}\;z \leq -9 \cdot 10^{+97}:\\ \;\;\;\;6 \cdot \left(x \cdot z\right)\\ \mathbf{elif}\;z \leq -4.35 \cdot 10^{-7}:\\ \;\;\;\;z \cdot \left(y \cdot -6\right)\\ \mathbf{elif}\;z \leq -2.95 \cdot 10^{-108}:\\ \;\;\;\;x \cdot -3\\ \mathbf{elif}\;z \leq -7.8 \cdot 10^{-202}:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;z \leq -2.5 \cdot 10^{-253}:\\ \;\;\;\;x \cdot -3\\ \mathbf{elif}\;z \leq 7.6 \cdot 10^{-235}:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;z \leq 5.5 \cdot 10^{-193}:\\ \;\;\;\;x \cdot -3\\ \mathbf{elif}\;z \leq 6.5 \cdot 10^{-113}:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;z \leq 0.68:\\ \;\;\;\;x \cdot -3\\ \mathbf{else}:\\ \;\;\;\;-6 \cdot \left(y \cdot z\right)\\ \end{array} \]
Alternative 5
Error33.3%
Cost1504
\[\begin{array}{l} t_0 := -6 \cdot \left(\left(y - x\right) \cdot z\right)\\ \mathbf{if}\;z \leq -4.35 \cdot 10^{-7}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -1.65 \cdot 10^{-108}:\\ \;\;\;\;x \cdot -3\\ \mathbf{elif}\;z \leq -1.22 \cdot 10^{-201}:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;z \leq -2.4 \cdot 10^{-258}:\\ \;\;\;\;x \cdot -3\\ \mathbf{elif}\;z \leq 3.5 \cdot 10^{-235}:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;z \leq 1.2 \cdot 10^{-181}:\\ \;\;\;\;x \cdot -3\\ \mathbf{elif}\;z \leq 1.65 \cdot 10^{-112}:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;z \leq 0.5:\\ \;\;\;\;x \cdot -3\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 6
Error32.38%
Cost1504
\[\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 -0.4:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -3.8 \cdot 10^{-109}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -6.6 \cdot 10^{-202}:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;z \leq -4.3 \cdot 10^{-254}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 8.6 \cdot 10^{-235}:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;z \leq 1.46 \cdot 10^{-195}:\\ \;\;\;\;x \cdot -3\\ \mathbf{elif}\;z \leq 1.75 \cdot 10^{-112}:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;z \leq 170000000:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 7
Error32.47%
Cost1504
\[\begin{array}{l} t_0 := x \cdot \left(-3 + z \cdot 6\right)\\ t_1 := z \cdot \left(\left(y - x\right) \cdot -6\right)\\ \mathbf{if}\;z \leq -0.4:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -2.3 \cdot 10^{-108}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -1.85 \cdot 10^{-202}:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;z \leq -3.3 \cdot 10^{-254}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 5.3 \cdot 10^{-235}:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;z \leq 1.2 \cdot 10^{-186}:\\ \;\;\;\;x \cdot -3\\ \mathbf{elif}\;z \leq 5.5 \cdot 10^{-113}:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;z \leq 180000000:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 8
Error50.92%
Cost1376
\[\begin{array}{l} t_0 := -6 \cdot \left(y \cdot z\right)\\ \mathbf{if}\;z \leq -4.35 \cdot 10^{-7}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -6.2 \cdot 10^{-109}:\\ \;\;\;\;x \cdot -3\\ \mathbf{elif}\;z \leq -5.8 \cdot 10^{-202}:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;z \leq -2.1 \cdot 10^{-253}:\\ \;\;\;\;x \cdot -3\\ \mathbf{elif}\;z \leq 2.4 \cdot 10^{-235}:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;z \leq 5.5 \cdot 10^{-184}:\\ \;\;\;\;x \cdot -3\\ \mathbf{elif}\;z \leq 8.2 \cdot 10^{-113}:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;z \leq 0.5:\\ \;\;\;\;x \cdot -3\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 9
Error0.48%
Cost1088
\[6 \cdot \left(y \cdot \left(0.6666666666666666 - z\right)\right) + x \cdot \left(1 + -6 \cdot \left(0.6666666666666666 - z\right)\right) \]
Alternative 10
Error0.52%
Cost832
\[x + \frac{\left(y - x\right) \cdot 6}{\frac{1}{0.6666666666666666 - z}} \]
Alternative 11
Error2.83%
Cost713
\[\begin{array}{l} \mathbf{if}\;z \leq -0.6 \lor \neg \left(z \leq 0.58\right):\\ \;\;\;\;z \cdot \left(\left(y - x\right) \cdot -6\right)\\ \mathbf{else}:\\ \;\;\;\;y \cdot 4 + x \cdot -3\\ \end{array} \]
Alternative 12
Error0.66%
Cost704
\[x + \left(0.6666666666666666 - z\right) \cdot \left(\left(y - x\right) \cdot 6\right) \]
Alternative 13
Error53.44%
Cost456
\[\begin{array}{l} \mathbf{if}\;x \leq -6.5 \cdot 10^{+67}:\\ \;\;\;\;x \cdot -3\\ \mathbf{elif}\;x \leq 7.8 \cdot 10^{-82}:\\ \;\;\;\;y \cdot 4\\ \mathbf{else}:\\ \;\;\;\;x \cdot -3\\ \end{array} \]
Alternative 14
Error67.15%
Cost192
\[y \cdot 4 \]

Error

Reproduce?

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