Average Error: 0.4 → 0.2
Time: 10.4s
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)

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, 6 \cdot \left(0.6666666666666666 - z\right), x\right)} \]
    Proof
    (fma.f64 (-.f64 y x) (*.f64 6 (-.f64 2/3 z)) x): 0 points increase in error, 0 points decrease in error
    (fma.f64 (-.f64 y x) (*.f64 6 (-.f64 (Rewrite<= metadata-eval (/.f64 2 3)) z)) x): 0 points increase in error, 0 points decrease in error
    (Rewrite<= fma-def_binary64 (+.f64 (*.f64 (-.f64 y x) (*.f64 6 (-.f64 (/.f64 2 3) z))) x)): 3 points increase in error, 1 points decrease in error
    (+.f64 (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 (-.f64 y x) 6) (-.f64 (/.f64 2 3) z))) x): 68 points increase in error, 18 points decrease in error
    (Rewrite<= +-commutative_binary64 (+.f64 x (*.f64 (*.f64 (-.f64 y x) 6) (-.f64 (/.f64 2 3) z)))): 0 points increase in error, 0 points decrease in error
  3. Final simplification0.2

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

Alternatives

Alternative 1
Error20.8
Cost1504
\[\begin{array}{l} t_0 := x \cdot \left(-3 + 6 \cdot z\right)\\ t_1 := -6 \cdot \left(\left(y - x\right) \cdot z\right)\\ \mathbf{if}\;z \leq -11000000:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -1.2 \cdot 10^{-30}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -4.8 \cdot 10^{-60}:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;z \leq -2.5 \cdot 10^{-138}:\\ \;\;\;\;x \cdot -3\\ \mathbf{elif}\;z \leq -4.2 \cdot 10^{-184}:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;z \leq 6.3 \cdot 10^{-239}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 5.4 \cdot 10^{-160}:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;z \leq 180000:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 2
Error32.5
Cost1244
\[\begin{array}{l} t_0 := 6 \cdot \left(x \cdot z\right)\\ \mathbf{if}\;z \leq -0.23:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -1.85 \cdot 10^{-183}:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;z \leq 4.4 \cdot 10^{-241}:\\ \;\;\;\;x \cdot -3\\ \mathbf{elif}\;z \leq 4.2 \cdot 10^{-160}:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;z \leq 0.5:\\ \;\;\;\;x \cdot -3\\ \mathbf{elif}\;z \leq 8 \cdot 10^{+51}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 1.85 \cdot 10^{+129}:\\ \;\;\;\;-6 \cdot \left(y \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 3
Error32.4
Cost1244
\[\begin{array}{l} t_0 := 6 \cdot \left(x \cdot z\right)\\ \mathbf{if}\;z \leq -0.105:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -1.7 \cdot 10^{-183}:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;z \leq 8 \cdot 10^{-239}:\\ \;\;\;\;x \cdot -3\\ \mathbf{elif}\;z \leq 4.4 \cdot 10^{-160}:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;z \leq 0.5:\\ \;\;\;\;x \cdot -3\\ \mathbf{elif}\;z \leq 2.5 \cdot 10^{+49}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 2.1 \cdot 10^{+123}:\\ \;\;\;\;z \cdot \left(y \cdot -6\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 4
Error32.5
Cost1244
\[\begin{array}{l} t_0 := z \cdot \left(x \cdot 6\right)\\ \mathbf{if}\;z \leq -0.041:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -4.2 \cdot 10^{-184}:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;z \leq 1.66 \cdot 10^{-239}:\\ \;\;\;\;x \cdot -3\\ \mathbf{elif}\;z \leq 4.8 \cdot 10^{-160}:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;z \leq 0.5:\\ \;\;\;\;x \cdot -3\\ \mathbf{elif}\;z \leq 3.9 \cdot 10^{+56}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 1.9 \cdot 10^{+123}:\\ \;\;\;\;z \cdot \left(y \cdot -6\right)\\ \mathbf{else}:\\ \;\;\;\;6 \cdot \left(x \cdot z\right)\\ \end{array} \]
Alternative 5
Error32.5
Cost1244
\[\begin{array}{l} t_0 := z \cdot \left(x \cdot 6\right)\\ \mathbf{if}\;z \leq -0.021:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -1.16 \cdot 10^{-183}:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;z \leq 9.5 \cdot 10^{-240}:\\ \;\;\;\;x \cdot -3\\ \mathbf{elif}\;z \leq 4.2 \cdot 10^{-160}:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;z \leq 0.5:\\ \;\;\;\;x \cdot -3\\ \mathbf{elif}\;z \leq 4.5 \cdot 10^{+56}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 1.3 \cdot 10^{+128}:\\ \;\;\;\;y \cdot \left(z \cdot -6\right)\\ \mathbf{else}:\\ \;\;\;\;6 \cdot \left(x \cdot z\right)\\ \end{array} \]
Alternative 6
Error32.5
Cost1244
\[\begin{array}{l} t_0 := x \cdot \left(6 \cdot z\right)\\ \mathbf{if}\;z \leq -0.0074:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -1.25 \cdot 10^{-183}:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;z \leq 1.65 \cdot 10^{-239}:\\ \;\;\;\;x \cdot -3\\ \mathbf{elif}\;z \leq 4.9 \cdot 10^{-160}:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;z \leq 0.5:\\ \;\;\;\;x \cdot -3\\ \mathbf{elif}\;z \leq 10^{+49}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 8 \cdot 10^{+123}:\\ \;\;\;\;y \cdot \left(z \cdot -6\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 7
Error21.1
Cost1108
\[\begin{array}{l} t_0 := -6 \cdot \left(\left(y - x\right) \cdot z\right)\\ \mathbf{if}\;z \leq -0.027:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -4.2 \cdot 10^{-184}:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;z \leq 4 \cdot 10^{-240}:\\ \;\;\;\;x \cdot -3\\ \mathbf{elif}\;z \leq 4.7 \cdot 10^{-160}:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;z \leq 0.5:\\ \;\;\;\;x \cdot -3\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 8
Error32.3
Cost980
\[\begin{array}{l} t_0 := -6 \cdot \left(y \cdot z\right)\\ \mathbf{if}\;z \leq -52:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -9.4 \cdot 10^{-184}:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;z \leq 4.4 \cdot 10^{-241}:\\ \;\;\;\;x \cdot -3\\ \mathbf{elif}\;z \leq 4.4 \cdot 10^{-160}:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;z \leq 0.5:\\ \;\;\;\;x \cdot -3\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 9
Error0.2
Cost960
\[\left(y - x\right) \cdot 4 + \left(x + -6 \cdot \left(\left(y - x\right) \cdot z\right)\right) \]
Alternative 10
Error1.8
Cost840
\[\begin{array}{l} \mathbf{if}\;z \leq -0.58:\\ \;\;\;\;-6 \cdot \left(\left(y - x\right) \cdot z\right)\\ \mathbf{elif}\;z \leq 0.5:\\ \;\;\;\;y \cdot 4 + x \cdot -3\\ \mathbf{else}:\\ \;\;\;\;\frac{z \cdot -6}{\frac{1}{y - x}}\\ \end{array} \]
Alternative 11
Error16.6
Cost712
\[\begin{array}{l} t_0 := x \cdot \left(-3 + 6 \cdot z\right)\\ \mathbf{if}\;x \leq -6.6 \cdot 10^{-31}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 1.5 \cdot 10^{-43}:\\ \;\;\;\;y \cdot \left(4 + z \cdot -6\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 12
Error1.7
Cost712
\[\begin{array}{l} t_0 := -6 \cdot \left(\left(y - x\right) \cdot z\right)\\ \mathbf{if}\;z \leq -0.55:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 0.5:\\ \;\;\;\;y \cdot 4 + x \cdot -3\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \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.2
Cost704
\[x + \left(y - x\right) \cdot \left(6 \cdot \left(0.6666666666666666 - z\right)\right) \]
Alternative 15
Error33.5
Cost456
\[\begin{array}{l} \mathbf{if}\;x \leq -2.1 \cdot 10^{+26}:\\ \;\;\;\;x \cdot -3\\ \mathbf{elif}\;x \leq 3.5 \cdot 10^{-43}:\\ \;\;\;\;y \cdot 4\\ \mathbf{else}:\\ \;\;\;\;x \cdot -3\\ \end{array} \]
Alternative 16
Error43.0
Cost192
\[y \cdot 4 \]

Error

Reproduce

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