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

Error

Target

Original0.2
Target0.2
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. Taylor expanded in y around 0 0.2

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

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

    [Start]0.2

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

    *-commutative [=>]0.2

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

    associate-*l* [<=]0.2

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

    fma-def [=>]0.2

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

    *-commutative [=>]0.2

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

    associate-*r* [<=]0.2

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

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

Alternatives

Alternative 1
Error0.2
Cost6976
\[x + z \cdot \mathsf{fma}\left(6, y, x \cdot -6\right) \]
Alternative 2
Error8.7
Cost713
\[\begin{array}{l} \mathbf{if}\;y \leq -1.25 \cdot 10^{+28} \lor \neg \left(y \leq 2.3 \cdot 10^{-167}\right):\\ \;\;\;\;x + 6 \cdot \left(z \cdot y\right)\\ \mathbf{else}:\\ \;\;\;\;x + -6 \cdot \left(x \cdot z\right)\\ \end{array} \]
Alternative 3
Error8.6
Cost712
\[\begin{array}{l} \mathbf{if}\;y \leq -1.3 \cdot 10^{+23}:\\ \;\;\;\;x + y \cdot \left(z \cdot 6\right)\\ \mathbf{elif}\;y \leq 2.2 \cdot 10^{-165}:\\ \;\;\;\;x + -6 \cdot \left(x \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;x + 6 \cdot \left(z \cdot y\right)\\ \end{array} \]
Alternative 4
Error8.6
Cost712
\[\begin{array}{l} \mathbf{if}\;y \leq -1.3 \cdot 10^{+23}:\\ \;\;\;\;x + y \cdot \left(z \cdot 6\right)\\ \mathbf{elif}\;y \leq 9 \cdot 10^{-167}:\\ \;\;\;\;x + x \cdot \left(-6 \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;x + 6 \cdot \left(z \cdot y\right)\\ \end{array} \]
Alternative 5
Error8.6
Cost712
\[\begin{array}{l} \mathbf{if}\;y \leq -1.3 \cdot 10^{+23}:\\ \;\;\;\;x + y \cdot \left(z \cdot 6\right)\\ \mathbf{elif}\;y \leq 4.5 \cdot 10^{-164}:\\ \;\;\;\;x + x \cdot \left(-6 \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;x + z \cdot \left(6 \cdot y\right)\\ \end{array} \]
Alternative 6
Error0.2
Cost576
\[x + z \cdot \left(6 \cdot \left(y - x\right)\right) \]
Alternative 7
Error23.7
Cost448
\[x + -6 \cdot \left(x \cdot z\right) \]
Alternative 8
Error35.4
Cost64
\[x \]

Error

Reproduce

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