?

Average Error: 0.35% → 0.26%
Time: 9.1s
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.35%
Target0.26%
Herbie0.26%
\[x - \left(6 \cdot z\right) \cdot \left(x - y\right) \]

Derivation?

  1. Initial program 0.35

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

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

    [Start]0.35

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

    +-commutative [=>]0.35

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

    associate-*l* [=>]0.26

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

    fma-def [=>]0.26

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

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

Alternatives

Alternative 1
Error37.51%
Cost1246
\[\begin{array}{l} t_0 := -6 \cdot \left(x \cdot z\right)\\ t_1 := 6 \cdot \left(y \cdot z\right)\\ \mathbf{if}\;z \leq -115000000:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -3.8 \cdot 10^{-22}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 1.72 \cdot 10^{-12}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 3050000 \lor \neg \left(z \leq 1.2 \cdot 10^{+61}\right) \land \left(z \leq 3.45 \cdot 10^{+227} \lor \neg \left(z \leq 9 \cdot 10^{+260}\right)\right):\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Error37.29%
Cost1245
\[\begin{array}{l} t_0 := x \cdot \left(z \cdot -6\right)\\ t_1 := 6 \cdot \left(y \cdot z\right)\\ \mathbf{if}\;z \leq -80000000000000:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -4.1 \cdot 10^{-23}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 5 \cdot 10^{-14}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 3700000:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 4.5 \cdot 10^{+69}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 2.75 \cdot 10^{+228} \lor \neg \left(z \leq 2.6 \cdot 10^{+257}\right):\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;-6 \cdot \left(x \cdot z\right)\\ \end{array} \]
Alternative 3
Error37.39%
Cost1245
\[\begin{array}{l} t_0 := x \cdot \left(z \cdot -6\right)\\ t_1 := y \cdot \left(6 \cdot z\right)\\ \mathbf{if}\;z \leq -4100000000:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -3.65 \cdot 10^{-22}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 1.11 \cdot 10^{-13}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 3300000:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 1.2 \cdot 10^{+78}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 1.3 \cdot 10^{+224} \lor \neg \left(z \leq 7.5 \cdot 10^{+257}\right):\\ \;\;\;\;6 \cdot \left(y \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;-6 \cdot \left(x \cdot z\right)\\ \end{array} \]
Alternative 4
Error37.33%
Cost1245
\[\begin{array}{l} t_0 := y \cdot \left(6 \cdot z\right)\\ \mathbf{if}\;z \leq -54000000000000:\\ \;\;\;\;x \cdot \left(z \cdot -6\right)\\ \mathbf{elif}\;z \leq -7.4 \cdot 10^{-23}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 2.85 \cdot 10^{-14}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 1720000:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 2.45 \cdot 10^{+61}:\\ \;\;\;\;z \cdot \left(x \cdot -6\right)\\ \mathbf{elif}\;z \leq 5.7 \cdot 10^{+227} \lor \neg \left(z \leq 7.5 \cdot 10^{+258}\right):\\ \;\;\;\;6 \cdot \left(y \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;-6 \cdot \left(x \cdot z\right)\\ \end{array} \]
Alternative 5
Error37.34%
Cost1244
\[\begin{array}{l} t_0 := z \cdot \left(y \cdot 6\right)\\ \mathbf{if}\;z \leq -50000000000000:\\ \;\;\;\;x \cdot \left(z \cdot -6\right)\\ \mathbf{elif}\;z \leq -4.4 \cdot 10^{-24}:\\ \;\;\;\;y \cdot \left(6 \cdot z\right)\\ \mathbf{elif}\;z \leq 8.2 \cdot 10^{-13}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 3700000:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 1.8 \cdot 10^{+60}:\\ \;\;\;\;z \cdot \left(x \cdot -6\right)\\ \mathbf{elif}\;z \leq 8 \cdot 10^{+225}:\\ \;\;\;\;6 \cdot \left(y \cdot z\right)\\ \mathbf{elif}\;z \leq 2.6 \cdot 10^{+260}:\\ \;\;\;\;-6 \cdot \left(x \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 6
Error1.66%
Cost840
\[\begin{array}{l} \mathbf{if}\;z \leq -125:\\ \;\;\;\;\left(y - x\right) \cdot \left(6 \cdot z\right)\\ \mathbf{elif}\;z \leq 7.2 \cdot 10^{-6}:\\ \;\;\;\;x + z \cdot \left(y \cdot 6\right)\\ \mathbf{else}:\\ \;\;\;\;z \cdot \left(y \cdot 6 + x \cdot -6\right)\\ \end{array} \]
Alternative 7
Error19.22%
Cost713
\[\begin{array}{l} \mathbf{if}\;z \leq -1.4 \cdot 10^{-22} \lor \neg \left(z \leq 8.3 \cdot 10^{-13}\right):\\ \;\;\;\;6 \cdot \left(\left(y - x\right) \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 8
Error19.17%
Cost713
\[\begin{array}{l} \mathbf{if}\;z \leq -6 \cdot 10^{-23} \lor \neg \left(z \leq 1.08 \cdot 10^{-13}\right):\\ \;\;\;\;\left(y - x\right) \cdot \left(6 \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 9
Error19.09%
Cost713
\[\begin{array}{l} \mathbf{if}\;z \leq -3.05 \cdot 10^{-24} \lor \neg \left(z \leq 5.2 \cdot 10^{-7}\right):\\ \;\;\;\;\left(y - x\right) \cdot \left(6 \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(1 + z \cdot -6\right)\\ \end{array} \]
Alternative 10
Error1.72%
Cost713
\[\begin{array}{l} \mathbf{if}\;z \leq -125 \lor \neg \left(z \leq 175000\right):\\ \;\;\;\;\left(y - x\right) \cdot \left(6 \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;x + z \cdot \left(y \cdot 6\right)\\ \end{array} \]
Alternative 11
Error38.51%
Cost585
\[\begin{array}{l} \mathbf{if}\;z \leq -125 \lor \neg \left(z \leq 175000\right):\\ \;\;\;\;-6 \cdot \left(x \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 12
Error0.35%
Cost576
\[x + z \cdot \left(\left(y - x\right) \cdot 6\right) \]
Alternative 13
Error0.26%
Cost576
\[x + \left(y - x\right) \cdot \left(6 \cdot z\right) \]
Alternative 14
Error55.88%
Cost64
\[x \]

Error

Reproduce?

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