Average Error: 0.4 → 0.2
Time: 9.1s
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)): 4 points increase in error, 2 points decrease in error
    (+.f64 (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 (-.f64 y x) 6) (-.f64 (/.f64 2 3) z))) x): 62 points increase in error, 14 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
Error33.1
Cost1244
\[\begin{array}{l} t_0 := 6 \cdot \left(x \cdot z\right)\\ \mathbf{if}\;z \leq -2.7 \cdot 10^{+192}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -9.5 \cdot 10^{+144}:\\ \;\;\;\;-6 \cdot \left(y \cdot z\right)\\ \mathbf{elif}\;z \leq -1.1 \cdot 10^{-24}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -3.5 \cdot 10^{-118}:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;z \leq -3 \cdot 10^{-219}:\\ \;\;\;\;x \cdot -3\\ \mathbf{elif}\;z \leq 6 \cdot 10^{-46}:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;z \leq 0.5:\\ \;\;\;\;x \cdot -3\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Error33.1
Cost1244
\[\begin{array}{l} t_0 := x \cdot \left(6 \cdot z\right)\\ \mathbf{if}\;z \leq -7.1 \cdot 10^{+192}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -4.8 \cdot 10^{+145}:\\ \;\;\;\;-6 \cdot \left(y \cdot z\right)\\ \mathbf{elif}\;z \leq -1.1 \cdot 10^{-24}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -2.8 \cdot 10^{-117}:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;z \leq -1.65 \cdot 10^{-219}:\\ \;\;\;\;x \cdot -3\\ \mathbf{elif}\;z \leq 7.8 \cdot 10^{-46}:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;z \leq 0.5:\\ \;\;\;\;x \cdot -3\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 3
Error33.1
Cost1244
\[\begin{array}{l} t_0 := x \cdot \left(6 \cdot z\right)\\ \mathbf{if}\;z \leq -4.1 \cdot 10^{+192}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -2.25 \cdot 10^{+142}:\\ \;\;\;\;y \cdot \left(z \cdot -6\right)\\ \mathbf{elif}\;z \leq -1.1 \cdot 10^{-24}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -3.8 \cdot 10^{-117}:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;z \leq -1.25 \cdot 10^{-213}:\\ \;\;\;\;x \cdot -3\\ \mathbf{elif}\;z \leq 8 \cdot 10^{-46}:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;z \leq 0.5:\\ \;\;\;\;x \cdot -3\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 4
Error33.1
Cost1244
\[\begin{array}{l} t_0 := x \cdot \left(6 \cdot z\right)\\ \mathbf{if}\;z \leq -2.35 \cdot 10^{+192}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -1.5 \cdot 10^{+140}:\\ \;\;\;\;z \cdot \left(y \cdot -6\right)\\ \mathbf{elif}\;z \leq -1.1 \cdot 10^{-24}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -1.05 \cdot 10^{-117}:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;z \leq -1.3 \cdot 10^{-215}:\\ \;\;\;\;x \cdot -3\\ \mathbf{elif}\;z \leq 5.7 \cdot 10^{-46}:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;z \leq 0.5:\\ \;\;\;\;x \cdot -3\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 5
Error21.3
Cost1240
\[\begin{array}{l} t_0 := -6 \cdot \left(\left(y - x\right) \cdot z\right)\\ \mathbf{if}\;z \leq -1.1 \cdot 10^{-24}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -6.5 \cdot 10^{-118}:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;z \leq -8.5 \cdot 10^{-216}:\\ \;\;\;\;x \cdot -3\\ \mathbf{elif}\;z \leq 8.4 \cdot 10^{-46}:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;z \leq 3.9 \cdot 10^{-16}:\\ \;\;\;\;x \cdot -3\\ \mathbf{elif}\;z \leq 740000:\\ \;\;\;\;6 \cdot \left(y \cdot \left(0.6666666666666666 - z\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 6
Error21.6
Cost1108
\[\begin{array}{l} t_0 := -6 \cdot \left(\left(y - x\right) \cdot z\right)\\ \mathbf{if}\;z \leq -1.1 \cdot 10^{-24}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -7.4 \cdot 10^{-118}:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;z \leq -3.05 \cdot 10^{-217}:\\ \;\;\;\;x \cdot -3\\ \mathbf{elif}\;z \leq 1.02 \cdot 10^{-45}:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;z \leq 0.5:\\ \;\;\;\;x \cdot -3\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 7
Error20.4
Cost1108
\[\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 -22000000:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -1.4 \cdot 10^{-216}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 5.3 \cdot 10^{-46}:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;z \leq 3.9 \cdot 10^{-16}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 350000:\\ \;\;\;\;y \cdot \left(6 \cdot \left(0.6666666666666666 - z\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 8
Error20.3
Cost1108
\[\begin{array}{l} t_0 := x \cdot \left(-3 + 6 \cdot z\right)\\ t_1 := z \cdot \left(\left(y - x\right) \cdot -6\right)\\ \mathbf{if}\;z \leq -13500000:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -1 \cdot 10^{-213}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 7.8 \cdot 10^{-46}:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;z \leq 3.4 \cdot 10^{-15}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 100000:\\ \;\;\;\;y \cdot \left(6 \cdot \left(0.6666666666666666 - z\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 9
Error20.3
Cost1108
\[\begin{array}{l} t_0 := x \cdot \left(-3 + 6 \cdot z\right)\\ \mathbf{if}\;z \leq -7000000:\\ \;\;\;\;\left(y - x\right) \cdot \left(z \cdot -6\right)\\ \mathbf{elif}\;z \leq -6.5 \cdot 10^{-218}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 6.4 \cdot 10^{-46}:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;z \leq 8.5 \cdot 10^{-16}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 900000:\\ \;\;\;\;y \cdot \left(6 \cdot \left(0.6666666666666666 - z\right)\right)\\ \mathbf{else}:\\ \;\;\;\;z \cdot \left(\left(y - x\right) \cdot -6\right)\\ \end{array} \]
Alternative 10
Error32.8
Cost980
\[\begin{array}{l} t_0 := -6 \cdot \left(y \cdot z\right)\\ \mathbf{if}\;z \leq -4400000:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -3.2 \cdot 10^{-117}:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;z \leq -2 \cdot 10^{-217}:\\ \;\;\;\;x \cdot -3\\ \mathbf{elif}\;z \leq 9.8 \cdot 10^{-46}:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;z \leq 0.66:\\ \;\;\;\;x \cdot -3\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 11
Error20.3
Cost976
\[\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 -32000000:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -2.2 \cdot 10^{-214}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 9.2 \cdot 10^{-46}:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;z \leq 7.5 \cdot 10^{+14}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 12
Error1.9
Cost712
\[\begin{array}{l} \mathbf{if}\;z \leq -0.6:\\ \;\;\;\;\left(y - x\right) \cdot \left(z \cdot -6\right)\\ \mathbf{elif}\;z \leq 0.66:\\ \;\;\;\;y \cdot 4 + x \cdot -3\\ \mathbf{else}:\\ \;\;\;\;z \cdot \left(\left(y - x\right) \cdot -6\right)\\ \end{array} \]
Alternative 13
Error0.2
Cost704
\[x + \left(y - x\right) \cdot \left(6 \cdot \left(0.6666666666666666 - z\right)\right) \]
Alternative 14
Error34.3
Cost456
\[\begin{array}{l} \mathbf{if}\;y \leq -0.0006:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;y \leq 3.45 \cdot 10^{-59}:\\ \;\;\;\;x \cdot -3\\ \mathbf{else}:\\ \;\;\;\;y \cdot 4\\ \end{array} \]
Alternative 15
Error43.6
Cost192
\[y \cdot 4 \]

Error

Reproduce

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