?

Average Error: 0.51% → 0.3%
Time: 10.3s
Precision: binary64
Cost: 7104

?

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

Error?

Target

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

Derivation?

  1. Initial program 0.51

    \[x + \left(\left(y - x\right) \cdot 6\right) \cdot z \]
  2. Taylor expanded in x around 0 0.31

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

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

    [Start]0.31

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

    fma-def [=>]0.3

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

    *-commutative [=>]0.3

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

    *-commutative [=>]0.3

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

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

Alternatives

Alternative 1
Error0.29%
Cost6848
\[\mathsf{fma}\left(y - x, 6 \cdot z, x\right) \]
Alternative 2
Error37.78%
Cost1114
\[\begin{array}{l} t_0 := 6 \cdot \left(z \cdot y\right)\\ \mathbf{if}\;z \leq -9.6 \cdot 10^{+28}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -7000000:\\ \;\;\;\;-6 \cdot \left(z \cdot x\right)\\ \mathbf{elif}\;z \leq -0.026 \lor \neg \left(z \leq -2.3 \cdot 10^{-64}\right) \land \left(z \leq -2.25 \cdot 10^{-111} \lor \neg \left(z \leq 1.8 \cdot 10^{-43}\right)\right):\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 3
Error37.79%
Cost1112
\[\begin{array}{l} t_0 := 6 \cdot \left(z \cdot y\right)\\ \mathbf{if}\;z \leq -8 \cdot 10^{+32}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -7600000:\\ \;\;\;\;-6 \cdot \left(z \cdot x\right)\\ \mathbf{elif}\;z \leq -0.026:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -2.5 \cdot 10^{-64}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq -1.04 \cdot 10^{-110}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 2.8 \cdot 10^{-42}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(6 \cdot z\right)\\ \end{array} \]
Alternative 4
Error37.84%
Cost1112
\[\begin{array}{l} t_0 := 6 \cdot \left(z \cdot y\right)\\ \mathbf{if}\;z \leq -1.12 \cdot 10^{+33}:\\ \;\;\;\;z \cdot \left(6 \cdot y\right)\\ \mathbf{elif}\;z \leq -7600000:\\ \;\;\;\;-6 \cdot \left(z \cdot x\right)\\ \mathbf{elif}\;z \leq -0.026:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -1.05 \cdot 10^{-64}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq -4 \cdot 10^{-110}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 1.4 \cdot 10^{-44}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(6 \cdot z\right)\\ \end{array} \]
Alternative 5
Error20.25%
Cost977
\[\begin{array}{l} \mathbf{if}\;z \leq -0.026:\\ \;\;\;\;z \cdot \left(6 \cdot \left(y - x\right)\right)\\ \mathbf{elif}\;z \leq -9.5 \cdot 10^{-64}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq -1.16 \cdot 10^{-114} \lor \neg \left(z \leq 2.15 \cdot 10^{-44}\right):\\ \;\;\;\;\left(y - x\right) \cdot \left(6 \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 6
Error21.53%
Cost977
\[\begin{array}{l} t_0 := x \cdot \left(1 + z \cdot -6\right)\\ \mathbf{if}\;x \leq -1.4 \cdot 10^{+26}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -2.3 \cdot 10^{-138}:\\ \;\;\;\;\left(y - x\right) \cdot \left(6 \cdot z\right)\\ \mathbf{elif}\;x \leq -3.9 \cdot 10^{-146} \lor \neg \left(x \leq 8.2 \cdot 10^{-66}\right):\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;z \cdot \left(6 \cdot \left(y - x\right)\right)\\ \end{array} \]
Alternative 7
Error20.09%
Cost976
\[\begin{array}{l} t_0 := z \cdot \left(6 \cdot \left(y - x\right)\right)\\ \mathbf{if}\;z \leq -0.026:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -8 \cdot 10^{-65}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq -4.5 \cdot 10^{-110}:\\ \;\;\;\;6 \cdot \left(z \cdot y\right)\\ \mathbf{elif}\;z \leq 2.1 \cdot 10^{-44}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 8
Error1.6%
Cost712
\[\begin{array}{l} \mathbf{if}\;z \leq -0.165:\\ \;\;\;\;z \cdot \left(6 \cdot \left(y - x\right)\right)\\ \mathbf{elif}\;z \leq 44:\\ \;\;\;\;x + z \cdot \left(6 \cdot y\right)\\ \mathbf{else}:\\ \;\;\;\;\left(y - x\right) \cdot \left(6 \cdot z\right)\\ \end{array} \]
Alternative 9
Error38.18%
Cost585
\[\begin{array}{l} \mathbf{if}\;z \leq -0.06 \lor \neg \left(z \leq 1.86 \cdot 10^{+18}\right):\\ \;\;\;\;-6 \cdot \left(z \cdot x\right)\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 10
Error0.51%
Cost576
\[x + z \cdot \left(6 \cdot \left(y - x\right)\right) \]
Alternative 11
Error0.29%
Cost576
\[x + \left(y - x\right) \cdot \left(6 \cdot z\right) \]
Alternative 12
Error54.27%
Cost64
\[x \]

Error

Reproduce?

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