Average Error: 0.3 → 0.3
Time: 8.4s
Precision: binary64
Cost: 6976
\[x + \left(\left(y - x\right) \cdot 6\right) \cdot z \]
\[x + \mathsf{fma}\left(6, y, x \cdot -6\right) \cdot z \]
(FPCore (x y z) :precision binary64 (+ x (* (* (- y x) 6.0) z)))
(FPCore (x y z) :precision binary64 (+ x (* (fma 6.0 y (* x -6.0)) z)))
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, y, (x * -6.0)) * z);
}
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 + Float64(fma(6.0, y, Float64(x * -6.0)) * z))
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[(N[(6.0 * y + N[(x * -6.0), $MachinePrecision]), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
x + \left(\left(y - x\right) \cdot 6\right) \cdot z
x + \mathsf{fma}\left(6, y, x \cdot -6\right) \cdot z

Error

Target

Original0.3
Target0.2
Herbie0.3
\[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. Taylor expanded in y around 0 0.3

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

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

    [Start]0.3

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

    fma-def [=>]0.3

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

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

Alternatives

Alternative 1
Error23.9
Cost849
\[\begin{array}{l} t_0 := 6 \cdot \left(y \cdot z\right)\\ \mathbf{if}\;z \leq -6 \cdot 10^{-70}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 0.00065:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 1.36 \cdot 10^{+124} \lor \neg \left(z \leq 2 \cdot 10^{+178}\right):\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;-6 \cdot \left(x \cdot z\right)\\ \end{array} \]
Alternative 2
Error24.0
Cost849
\[\begin{array}{l} \mathbf{if}\;z \leq -6.5 \cdot 10^{-70}:\\ \;\;\;\;y \cdot \left(6 \cdot z\right)\\ \mathbf{elif}\;z \leq 0.00086:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 1.3 \cdot 10^{+134} \lor \neg \left(z \leq 5.6 \cdot 10^{+177}\right):\\ \;\;\;\;6 \cdot \left(y \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;-6 \cdot \left(x \cdot z\right)\\ \end{array} \]
Alternative 3
Error24.0
Cost849
\[\begin{array}{l} \mathbf{if}\;z \leq -6.5 \cdot 10^{-70}:\\ \;\;\;\;z \cdot \left(6 \cdot y\right)\\ \mathbf{elif}\;z \leq 0.0065:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 2.7 \cdot 10^{+125} \lor \neg \left(z \leq 1.25 \cdot 10^{+178}\right):\\ \;\;\;\;6 \cdot \left(y \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;-6 \cdot \left(x \cdot z\right)\\ \end{array} \]
Alternative 4
Error12.6
Cost713
\[\begin{array}{l} \mathbf{if}\;z \leq -6.5 \cdot 10^{-70} \lor \neg \left(z \leq 0.00065\right):\\ \;\;\;\;6 \cdot \left(z \cdot \left(y - x\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 5
Error12.6
Cost712
\[\begin{array}{l} \mathbf{if}\;z \leq -5.2 \cdot 10^{-70}:\\ \;\;\;\;z \cdot \left(6 \cdot \left(y - x\right)\right)\\ \mathbf{elif}\;z \leq 0.00065:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;6 \cdot \left(z \cdot \left(y - x\right)\right)\\ \end{array} \]
Alternative 6
Error12.7
Cost712
\[\begin{array}{l} \mathbf{if}\;z \leq -6.5 \cdot 10^{-70}:\\ \;\;\;\;z \cdot \left(6 \cdot \left(y - x\right)\right)\\ \mathbf{elif}\;z \leq 86000000000000:\\ \;\;\;\;x \cdot \left(1 + -6 \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;6 \cdot \left(z \cdot \left(y - x\right)\right)\\ \end{array} \]
Alternative 7
Error1.0
Cost712
\[\begin{array}{l} \mathbf{if}\;z \leq -24500:\\ \;\;\;\;z \cdot \left(6 \cdot \left(y - x\right)\right)\\ \mathbf{elif}\;z \leq 0.165:\\ \;\;\;\;x + 6 \cdot \left(y \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;6 \cdot \left(z \cdot \left(y - x\right)\right)\\ \end{array} \]
Alternative 8
Error24.2
Cost585
\[\begin{array}{l} \mathbf{if}\;z \leq -0.17 \lor \neg \left(z \leq 0.165\right):\\ \;\;\;\;-6 \cdot \left(x \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 9
Error0.3
Cost576
\[x + z \cdot \left(6 \cdot \left(y - x\right)\right) \]
Alternative 10
Error34.8
Cost64
\[x \]

Error

Reproduce

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