Average Error: 0.2 → 0.2
Time: 8.9s
Precision: binary64
Cost: 6848
\[x + \left(\left(y - x\right) \cdot 6\right) \cdot z \]
\[\mathsf{fma}\left(\left(y - x\right) \cdot 6, 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(Float64(y - x) * 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[(N[(y - x), $MachinePrecision] * 6.0), $MachinePrecision] * z + x), $MachinePrecision]
x + \left(\left(y - x\right) \cdot 6\right) \cdot z
\mathsf{fma}\left(\left(y - x\right) \cdot 6, z, x\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. Simplified0.2

    \[\leadsto \color{blue}{\mathsf{fma}\left(\left(y - x\right) \cdot 6, z, x\right)} \]
    Proof
    (fma.f64 (*.f64 (-.f64 y x) 6) z x): 0 points increase in error, 0 points decrease in error
    (Rewrite<= fma-def_binary64 (+.f64 (*.f64 (*.f64 (-.f64 y x) 6) z) x)): 1 points increase in error, 0 points decrease in error
    (Rewrite<= +-commutative_binary64 (+.f64 x (*.f64 (*.f64 (-.f64 y x) 6) z))): 0 points increase in error, 0 points decrease in error
  3. Final simplification0.2

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

Alternatives

Alternative 1
Error24.4
Cost716
\[\begin{array}{l} t_0 := z \cdot \left(x \cdot -6\right)\\ \mathbf{if}\;z \leq -160033704.54018337:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 5.396997530105683 \cdot 10^{-7}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 3.2 \cdot 10^{+110}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(6 \cdot z\right)\\ \end{array} \]
Alternative 2
Error24.4
Cost716
\[\begin{array}{l} \mathbf{if}\;z \leq -160033704.54018337:\\ \;\;\;\;x \cdot \left(z \cdot -6\right)\\ \mathbf{elif}\;z \leq 5.396997530105683 \cdot 10^{-7}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 3.2 \cdot 10^{+110}:\\ \;\;\;\;z \cdot \left(x \cdot -6\right)\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(6 \cdot z\right)\\ \end{array} \]
Alternative 3
Error24.4
Cost716
\[\begin{array}{l} \mathbf{if}\;z \leq -160033704.54018337:\\ \;\;\;\;-6 \cdot \left(x \cdot z\right)\\ \mathbf{elif}\;z \leq 5.396997530105683 \cdot 10^{-7}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 3.2 \cdot 10^{+110}:\\ \;\;\;\;z \cdot \left(x \cdot -6\right)\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(6 \cdot z\right)\\ \end{array} \]
Alternative 4
Error24.4
Cost716
\[\begin{array}{l} \mathbf{if}\;z \leq -160033704.54018337:\\ \;\;\;\;-6 \cdot \left(x \cdot z\right)\\ \mathbf{elif}\;z \leq 5.396997530105683 \cdot 10^{-7}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 3.2 \cdot 10^{+110}:\\ \;\;\;\;z \cdot \left(x \cdot -6\right)\\ \mathbf{else}:\\ \;\;\;\;6 \cdot \left(y \cdot z\right)\\ \end{array} \]
Alternative 5
Error12.3
Cost712
\[\begin{array}{l} t_0 := \left(y - x\right) \cdot \left(6 \cdot z\right)\\ \mathbf{if}\;z \leq -2.0837208492410545 \cdot 10^{-53}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 8.787229659038187 \cdot 10^{-16}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 6
Error12.3
Cost712
\[\begin{array}{l} t_0 := \left(y - x\right) \cdot \left(6 \cdot z\right)\\ \mathbf{if}\;z \leq -11746.95108953019:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 8.787229659038187 \cdot 10^{-16}:\\ \;\;\;\;x \cdot \left(z \cdot -6 + 1\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 7
Error12.3
Cost712
\[\begin{array}{l} \mathbf{if}\;z \leq -11746.95108953019:\\ \;\;\;\;\left(y - x\right) \cdot \left(6 \cdot z\right)\\ \mathbf{elif}\;z \leq 8.787229659038187 \cdot 10^{-16}:\\ \;\;\;\;x \cdot \left(z \cdot -6 + 1\right)\\ \mathbf{else}:\\ \;\;\;\;\left(\left(y - x\right) \cdot 6\right) \cdot z\\ \end{array} \]
Alternative 8
Error12.3
Cost712
\[\begin{array}{l} \mathbf{if}\;z \leq -11746.95108953019:\\ \;\;\;\;\left(y - x\right) \cdot \left(6 \cdot z\right)\\ \mathbf{elif}\;z \leq 8.787229659038187 \cdot 10^{-16}:\\ \;\;\;\;x + -6 \cdot \left(x \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;\left(\left(y - x\right) \cdot 6\right) \cdot z\\ \end{array} \]
Alternative 9
Error1.2
Cost712
\[\begin{array}{l} \mathbf{if}\;z \leq -165539980012.59372:\\ \;\;\;\;\left(y - x\right) \cdot \left(6 \cdot z\right)\\ \mathbf{elif}\;z \leq 5.396997530105683 \cdot 10^{-7}:\\ \;\;\;\;x + z \cdot \left(y \cdot 6\right)\\ \mathbf{else}:\\ \;\;\;\;\left(\left(y - x\right) \cdot 6\right) \cdot z\\ \end{array} \]
Alternative 10
Error1.2
Cost712
\[\begin{array}{l} \mathbf{if}\;z \leq -165539980012.59372:\\ \;\;\;\;6 \cdot \left(\left(y - x\right) \cdot z\right)\\ \mathbf{elif}\;z \leq 5.396997530105683 \cdot 10^{-7}:\\ \;\;\;\;x + z \cdot \left(y \cdot 6\right)\\ \mathbf{else}:\\ \;\;\;\;\left(\left(y - x\right) \cdot 6\right) \cdot z\\ \end{array} \]
Alternative 11
Error1.1
Cost712
\[\begin{array}{l} \mathbf{if}\;z \leq -165539980012.59372:\\ \;\;\;\;6 \cdot \left(\left(y - x\right) \cdot z\right)\\ \mathbf{elif}\;z \leq 5.396997530105683 \cdot 10^{-7}:\\ \;\;\;\;x + 6 \cdot \left(y \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;\left(\left(y - x\right) \cdot 6\right) \cdot z\\ \end{array} \]
Alternative 12
Error23.6
Cost584
\[\begin{array}{l} t_0 := y \cdot \left(6 \cdot z\right)\\ \mathbf{if}\;z \leq -2.0837208492410545 \cdot 10^{-53}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 8.787229659038187 \cdot 10^{-16}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 13
Error0.2
Cost576
\[x + \left(y - x\right) \cdot \left(6 \cdot z\right) \]
Alternative 14
Error0.2
Cost576
\[x + \left(\left(y - x\right) \cdot 6\right) \cdot z \]
Alternative 15
Error35.0
Cost64
\[x \]

Error

Reproduce

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