?

Average Error: 0.3 → 0.2
Time: 9.0s
Precision: binary64
Cost: 6848

?

\[x + \left(\left(y - x\right) \cdot 6\right) \cdot z \]
\[\mathsf{fma}\left(y - x, 6 \cdot z, x\right) \]
(FPCore (x y z) :precision binary64 (+ x (* (* (- y x) 6.0) z)))
(FPCore (x y z) :precision binary64 (fma (- y x) (* 6.0 z) 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((y - x), (6.0 * z), 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(Float64(y - x), Float64(6.0 * z), 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[(N[(y - x), $MachinePrecision] * N[(6.0 * z), $MachinePrecision] + x), $MachinePrecision]
x + \left(\left(y - x\right) \cdot 6\right) \cdot z
\mathsf{fma}\left(y - x, 6 \cdot z, x\right)

Error?

Target

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

Derivation?

  1. Initial program 0.3

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

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

    [Start]0.3

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

    +-commutative [=>]0.3

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

    associate-*l* [=>]0.2

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

    fma-def [=>]0.2

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

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

Alternatives

Alternative 1
Error14.4
Cost978
\[\begin{array}{l} \mathbf{if}\;x \leq -4.8 \cdot 10^{+60} \lor \neg \left(x \leq -1.6 \cdot 10^{-29} \lor \neg \left(x \leq -8.5 \cdot 10^{-100}\right) \land x \leq 7.8 \cdot 10^{-7}\right):\\ \;\;\;\;x \cdot \left(1 + z \cdot -6\right)\\ \mathbf{else}:\\ \;\;\;\;z \cdot \left(\left(y - x\right) \cdot 6\right)\\ \end{array} \]
Alternative 2
Error12.4
Cost713
\[\begin{array}{l} \mathbf{if}\;z \leq -2.5 \cdot 10^{-17} \lor \neg \left(z \leq 0.00082\right):\\ \;\;\;\;z \cdot \left(\left(y - x\right) \cdot 6\right)\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 3
Error1.1
Cost713
\[\begin{array}{l} \mathbf{if}\;z \leq -0.165 \lor \neg \left(z \leq 0.0132\right):\\ \;\;\;\;z \cdot \left(\left(y - x\right) \cdot 6\right)\\ \mathbf{else}:\\ \;\;\;\;x + z \cdot \left(y \cdot 6\right)\\ \end{array} \]
Alternative 4
Error24.2
Cost585
\[\begin{array}{l} \mathbf{if}\;z \leq -8.2 \cdot 10^{-7} \lor \neg \left(z \leq 0.165\right):\\ \;\;\;\;-6 \cdot \left(x \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 5
Error23.6
Cost585
\[\begin{array}{l} \mathbf{if}\;z \leq -2.4 \cdot 10^{-16} \lor \neg \left(z \leq 0.00082\right):\\ \;\;\;\;6 \cdot \left(y \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 6
Error23.6
Cost584
\[\begin{array}{l} \mathbf{if}\;z \leq -4.8 \cdot 10^{-16}:\\ \;\;\;\;z \cdot \left(y \cdot 6\right)\\ \mathbf{elif}\;z \leq 0.00082:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;6 \cdot \left(y \cdot z\right)\\ \end{array} \]
Alternative 7
Error0.3
Cost576
\[x + z \cdot \left(\left(y - x\right) \cdot 6\right) \]
Alternative 8
Error0.2
Cost576
\[x + \left(y - x\right) \cdot \left(6 \cdot z\right) \]
Alternative 9
Error34.7
Cost64
\[x \]

Error

Reproduce?

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