Average Error: 0.2 → 0.2
Time: 2.5s
Precision: binary64
\[x + \left(\left(y - x\right) \cdot 6\right) \cdot z \]
\[\mathsf{fma}\left(6, y \cdot z - z \cdot x, x\right) \]
(FPCore (x y z) :precision binary64 (+ x (* (* (- y x) 6.0) z)))
(FPCore (x y z) :precision binary64 (fma 6.0 (- (* y z) (* z x)) x))
double code(double x, double y, double z) {
	return x + (((y - x) * 6.0) * z);
}
double code(double x, double y, double z) {
	return fma(6.0, ((y * z) - (z * x)), x);
}
function code(x, y, z)
	return Float64(x + Float64(Float64(Float64(y - x) * 6.0) * z))
end
function code(x, y, z)
	return fma(6.0, Float64(Float64(y * z) - Float64(z * x)), x)
end
code[x_, y_, z_] := N[(x + N[(N[(N[(y - x), $MachinePrecision] * 6.0), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_] := N[(6.0 * N[(N[(y * z), $MachinePrecision] - N[(z * x), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision]
x + \left(\left(y - x\right) \cdot 6\right) \cdot z
\mathsf{fma}\left(6, y \cdot z - z \cdot x, x\right)

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original0.2
Target0.1
Herbie0.2
\[x - \left(6 \cdot z\right) \cdot \left(x - y\right) \]

Derivation

  1. Initial program 0.2

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

    \[\leadsto \color{blue}{\mathsf{fma}\left(6, \left(y - x\right) \cdot z, x\right)} \]
  3. Taylor expanded in y around 0 0.2

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

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

Reproduce

herbie shell --seed 2022153 
(FPCore (x y z)
  :name "Data.Colour.RGBSpace.HSL:hsl from colour-2.3.3, E"
  :precision binary64

  :herbie-target
  (- x (* (* 6.0 z) (- x y)))

  (+ x (* (* (- y x) 6.0) z)))