Average Error: 0.4 → 0.2
Time: 17.5s
Precision: binary64
Cost: 13248
\[x + \left(\left(y - x\right) \cdot 6\right) \cdot \left(\frac{2}{3} - z\right) \]
\[\mathsf{fma}\left(y - x, \mathsf{fma}\left(z, -6, 4\right), x\right) \]
(FPCore (x y z)
 :precision binary64
 (+ x (* (* (- y x) 6.0) (- (/ 2.0 3.0) z))))
(FPCore (x y z) :precision binary64 (fma (- y x) (fma z -6.0 4.0) x))
double code(double x, double y, double z) {
	return x + (((y - x) * 6.0) * ((2.0 / 3.0) - z));
}
double code(double x, double y, double z) {
	return fma((y - x), fma(z, -6.0, 4.0), x);
}
function code(x, y, z)
	return Float64(x + Float64(Float64(Float64(y - x) * 6.0) * Float64(Float64(2.0 / 3.0) - z)))
end
function code(x, y, z)
	return fma(Float64(y - x), fma(z, -6.0, 4.0), x)
end
code[x_, y_, z_] := N[(x + N[(N[(N[(y - x), $MachinePrecision] * 6.0), $MachinePrecision] * N[(N[(2.0 / 3.0), $MachinePrecision] - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_] := N[(N[(y - x), $MachinePrecision] * N[(z * -6.0 + 4.0), $MachinePrecision] + x), $MachinePrecision]
x + \left(\left(y - x\right) \cdot 6\right) \cdot \left(\frac{2}{3} - z\right)
\mathsf{fma}\left(y - x, \mathsf{fma}\left(z, -6, 4\right), x\right)

Error

Derivation

  1. Initial program 0.4

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

    \[\leadsto \color{blue}{\mathsf{fma}\left(y - x, \mathsf{fma}\left(z, -6, 4\right), x\right)} \]
    Proof
    (fma.f64 (-.f64 y x) (fma.f64 z -6 4) x): 0 points increase in error, 0 points decrease in error
    (fma.f64 (-.f64 y x) (fma.f64 z (Rewrite<= metadata-eval (*.f64 6 -1)) 4) x): 0 points increase in error, 0 points decrease in error
    (fma.f64 (-.f64 y x) (fma.f64 z (*.f64 6 -1) (Rewrite<= metadata-eval (*.f64 2/3 6))) x): 0 points increase in error, 0 points decrease in error
    (fma.f64 (-.f64 y x) (fma.f64 z (*.f64 6 -1) (*.f64 (Rewrite<= metadata-eval (/.f64 2 3)) 6)) x): 0 points increase in error, 0 points decrease in error
    (fma.f64 (-.f64 y x) (Rewrite<= fma-def_binary64 (+.f64 (*.f64 z (*.f64 6 -1)) (*.f64 (/.f64 2 3) 6))) x): 6 points increase in error, 4 points decrease in error
    (fma.f64 (-.f64 y x) (+.f64 (*.f64 z (Rewrite=> metadata-eval -6)) (*.f64 (/.f64 2 3) 6)) x): 0 points increase in error, 0 points decrease in error
    (fma.f64 (-.f64 y x) (+.f64 (*.f64 z (Rewrite<= metadata-eval (neg.f64 6))) (*.f64 (/.f64 2 3) 6)) x): 0 points increase in error, 0 points decrease in error
    (fma.f64 (-.f64 y x) (+.f64 (Rewrite<= distribute-rgt-neg-in_binary64 (neg.f64 (*.f64 z 6))) (*.f64 (/.f64 2 3) 6)) x): 0 points increase in error, 0 points decrease in error
    (fma.f64 (-.f64 y x) (+.f64 (Rewrite<= distribute-lft-neg-out_binary64 (*.f64 (neg.f64 z) 6)) (*.f64 (/.f64 2 3) 6)) x): 0 points increase in error, 0 points decrease in error
    (fma.f64 (-.f64 y x) (Rewrite<= distribute-rgt-in_binary64 (*.f64 6 (+.f64 (neg.f64 z) (/.f64 2 3)))) x): 5 points increase in error, 1 points decrease in error
    (fma.f64 (-.f64 y x) (*.f64 6 (Rewrite<= +-commutative_binary64 (+.f64 (/.f64 2 3) (neg.f64 z)))) x): 0 points increase in error, 0 points decrease in error
    (fma.f64 (-.f64 y x) (*.f64 6 (Rewrite<= sub-neg_binary64 (-.f64 (/.f64 2 3) z))) x): 0 points increase in error, 0 points decrease in error
    (Rewrite<= fma-def_binary64 (+.f64 (*.f64 (-.f64 y x) (*.f64 6 (-.f64 (/.f64 2 3) z))) x)): 2 points increase in error, 0 points decrease in error
    (+.f64 (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 (-.f64 y x) 6) (-.f64 (/.f64 2 3) z))) x): 71 points increase in error, 16 points decrease in error
    (Rewrite<= +-commutative_binary64 (+.f64 x (*.f64 (*.f64 (-.f64 y x) 6) (-.f64 (/.f64 2 3) z)))): 0 points increase in error, 0 points decrease in error
  3. Final simplification0.2

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

Alternatives

Alternative 1
Error32.7
Cost1640
\[\begin{array}{l} t_0 := 6 \cdot \left(x \cdot z\right)\\ \mathbf{if}\;z \leq -2.5 \cdot 10^{+30}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -2.8336577908746:\\ \;\;\;\;y \cdot \left(z \cdot -6\right)\\ \mathbf{elif}\;z \leq -9.120357607441309 \cdot 10^{-231}:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;z \leq -6.5561114883047586 \cdot 10^{-307}:\\ \;\;\;\;x \cdot -3\\ \mathbf{elif}\;z \leq 7.628658154896722 \cdot 10^{-254}:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;z \leq 1.2309951603746475 \cdot 10^{-167}:\\ \;\;\;\;x \cdot -3\\ \mathbf{elif}\;z \leq 1.5933465963260094 \cdot 10^{-123}:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;z \leq 3.1480850704842524 \cdot 10^{-23}:\\ \;\;\;\;x \cdot -3\\ \mathbf{elif}\;z \leq 6.4 \cdot 10^{+185}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 1.65 \cdot 10^{+267}:\\ \;\;\;\;-6 \cdot \left(y \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Error32.7
Cost1640
\[\begin{array}{l} t_0 := 6 \cdot \left(x \cdot z\right)\\ \mathbf{if}\;z \leq -2.5 \cdot 10^{+30}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -2.8336577908746:\\ \;\;\;\;y \cdot \left(z \cdot -6\right)\\ \mathbf{elif}\;z \leq -9.120357607441309 \cdot 10^{-231}:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;z \leq -6.5561114883047586 \cdot 10^{-307}:\\ \;\;\;\;x \cdot -3\\ \mathbf{elif}\;z \leq 7.628658154896722 \cdot 10^{-254}:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;z \leq 1.2309951603746475 \cdot 10^{-167}:\\ \;\;\;\;x \cdot -3\\ \mathbf{elif}\;z \leq 1.5933465963260094 \cdot 10^{-123}:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;z \leq 3.1480850704842524 \cdot 10^{-23}:\\ \;\;\;\;x \cdot -3\\ \mathbf{elif}\;z \leq 6.4 \cdot 10^{+185}:\\ \;\;\;\;z \cdot \left(x \cdot 6\right)\\ \mathbf{elif}\;z \leq 1.65 \cdot 10^{+267}:\\ \;\;\;\;-6 \cdot \left(y \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 3
Error32.4
Cost1244
\[\begin{array}{l} t_0 := z \cdot \left(y \cdot -6\right)\\ \mathbf{if}\;z \leq -2.8336577908746:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -9.120357607441309 \cdot 10^{-231}:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;z \leq -6.5561114883047586 \cdot 10^{-307}:\\ \;\;\;\;x \cdot -3\\ \mathbf{elif}\;z \leq 7.628658154896722 \cdot 10^{-254}:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;z \leq 1.2309951603746475 \cdot 10^{-167}:\\ \;\;\;\;x \cdot -3\\ \mathbf{elif}\;z \leq 1.5933465963260094 \cdot 10^{-123}:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;z \leq 8.640531797436794 \cdot 10^{-8}:\\ \;\;\;\;x \cdot -3\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 4
Error32.4
Cost1244
\[\begin{array}{l} \mathbf{if}\;z \leq -2.8336577908746:\\ \;\;\;\;y \cdot \left(z \cdot -6\right)\\ \mathbf{elif}\;z \leq -9.120357607441309 \cdot 10^{-231}:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;z \leq -6.5561114883047586 \cdot 10^{-307}:\\ \;\;\;\;x \cdot -3\\ \mathbf{elif}\;z \leq 7.628658154896722 \cdot 10^{-254}:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;z \leq 1.2309951603746475 \cdot 10^{-167}:\\ \;\;\;\;x \cdot -3\\ \mathbf{elif}\;z \leq 1.5933465963260094 \cdot 10^{-123}:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;z \leq 8.640531797436794 \cdot 10^{-8}:\\ \;\;\;\;x \cdot -3\\ \mathbf{else}:\\ \;\;\;\;z \cdot \left(y \cdot -6\right)\\ \end{array} \]
Alternative 5
Error32.4
Cost1244
\[\begin{array}{l} \mathbf{if}\;z \leq -2.8336577908746:\\ \;\;\;\;y \cdot \left(z \cdot -6\right)\\ \mathbf{elif}\;z \leq -9.120357607441309 \cdot 10^{-231}:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;z \leq -6.5561114883047586 \cdot 10^{-307}:\\ \;\;\;\;x \cdot -3\\ \mathbf{elif}\;z \leq 7.628658154896722 \cdot 10^{-254}:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;z \leq 1.2309951603746475 \cdot 10^{-167}:\\ \;\;\;\;x \cdot -3\\ \mathbf{elif}\;z \leq 1.5933465963260094 \cdot 10^{-123}:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;z \leq 8.640531797436794 \cdot 10^{-8}:\\ \;\;\;\;x \cdot -3\\ \mathbf{else}:\\ \;\;\;\;-6 \cdot \left(y \cdot z\right)\\ \end{array} \]
Alternative 6
Error12.8
Cost980
\[\begin{array}{l} t_0 := 6 \cdot \left(x \cdot z\right)\\ \mathbf{if}\;z \leq -2.5 \cdot 10^{+30}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -2.8336577908746:\\ \;\;\;\;y \cdot \left(z \cdot -6\right)\\ \mathbf{elif}\;z \leq 8.640531797436794 \cdot 10^{-8}:\\ \;\;\;\;x \cdot -3 + y \cdot 4\\ \mathbf{elif}\;z \leq 6.4 \cdot 10^{+185}:\\ \;\;\;\;z \cdot \left(x \cdot 6\right)\\ \mathbf{elif}\;z \leq 1.65 \cdot 10^{+267}:\\ \;\;\;\;-6 \cdot \left(y \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 7
Error12.4
Cost980
\[\begin{array}{l} t_0 := 6 \cdot \left(x \cdot z\right)\\ \mathbf{if}\;z \leq -2.5 \cdot 10^{+30}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -2.8336577908746:\\ \;\;\;\;y \cdot \left(z \cdot -6\right)\\ \mathbf{elif}\;z \leq 8.640531797436794 \cdot 10^{-8}:\\ \;\;\;\;x \cdot -3 + y \cdot 4\\ \mathbf{elif}\;z \leq 6.4 \cdot 10^{+185}:\\ \;\;\;\;x \cdot \left(-3 + z \cdot 6\right)\\ \mathbf{elif}\;z \leq 1.65 \cdot 10^{+267}:\\ \;\;\;\;-6 \cdot \left(y \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 8
Error12.2
Cost980
\[\begin{array}{l} t_0 := 6 \cdot \left(x \cdot z\right)\\ \mathbf{if}\;z \leq -2.5 \cdot 10^{+30}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -0.00010447843474553522:\\ \;\;\;\;y \cdot \left(4 + z \cdot -6\right)\\ \mathbf{elif}\;z \leq 8.640531797436794 \cdot 10^{-8}:\\ \;\;\;\;x \cdot -3 + y \cdot 4\\ \mathbf{elif}\;z \leq 6.4 \cdot 10^{+185}:\\ \;\;\;\;x \cdot \left(-3 + z \cdot 6\right)\\ \mathbf{elif}\;z \leq 1.65 \cdot 10^{+267}:\\ \;\;\;\;-6 \cdot \left(y \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 9
Error1.3
Cost968
\[\begin{array}{l} \mathbf{if}\;z \leq -22135179597288.445:\\ \;\;\;\;-6 \cdot \left(\left(y - x\right) \cdot z\right)\\ \mathbf{elif}\;z \leq 32260064354.296925:\\ \;\;\;\;x \cdot -3 + 6 \cdot \left(y \cdot \left(0.6666666666666666 - z\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(y - x\right) \cdot \left(z \cdot -6\right)\\ \end{array} \]
Alternative 10
Error1.3
Cost968
\[\begin{array}{l} \mathbf{if}\;z \leq -22135179597288.445:\\ \;\;\;\;6 \cdot \left(x \cdot z\right) + -6 \cdot \left(y \cdot z\right)\\ \mathbf{elif}\;z \leq 32260064354.296925:\\ \;\;\;\;x \cdot -3 + 6 \cdot \left(y \cdot \left(0.6666666666666666 - z\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(y - x\right) \cdot \left(z \cdot -6\right)\\ \end{array} \]
Alternative 11
Error0.2
Cost960
\[\left(y - x\right) \cdot 4 + \left(x + -6 \cdot \left(\left(y - x\right) \cdot z\right)\right) \]
Alternative 12
Error1.8
Cost840
\[\begin{array}{l} \mathbf{if}\;z \leq -2.8336577908746:\\ \;\;\;\;-6 \cdot \left(\left(y - x\right) \cdot z\right)\\ \mathbf{elif}\;z \leq 8.640531797436794 \cdot 10^{-8}:\\ \;\;\;\;x \cdot -3 + y \cdot 4\\ \mathbf{else}:\\ \;\;\;\;x + \left(y - x\right) \cdot \left(z \cdot -6\right)\\ \end{array} \]
Alternative 13
Error0.5
Cost832
\[x + \frac{0.6666666666666666 - z}{\frac{1}{\left(y - x\right) \cdot 6}} \]
Alternative 14
Error1.8
Cost712
\[\begin{array}{l} t_0 := -6 \cdot \left(\left(y - x\right) \cdot z\right)\\ \mathbf{if}\;z \leq -2.8336577908746:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 8.640531797436794 \cdot 10^{-8}:\\ \;\;\;\;x \cdot -3 + y \cdot 4\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 15
Error1.8
Cost712
\[\begin{array}{l} \mathbf{if}\;z \leq -2.8336577908746:\\ \;\;\;\;-6 \cdot \left(\left(y - x\right) \cdot z\right)\\ \mathbf{elif}\;z \leq 8.640531797436794 \cdot 10^{-8}:\\ \;\;\;\;x \cdot -3 + y \cdot 4\\ \mathbf{else}:\\ \;\;\;\;\left(y - x\right) \cdot \left(z \cdot -6\right)\\ \end{array} \]
Alternative 16
Error0.4
Cost704
\[x + \left(0.6666666666666666 - z\right) \cdot \left(\left(y - x\right) \cdot 6\right) \]
Alternative 17
Error33.8
Cost456
\[\begin{array}{l} \mathbf{if}\;y \leq -2.1554593573151173 \cdot 10^{-80}:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;y \leq 9.921352872830167 \cdot 10^{-11}:\\ \;\;\;\;x \cdot -3\\ \mathbf{else}:\\ \;\;\;\;y \cdot 4\\ \end{array} \]
Alternative 18
Error43.2
Cost192
\[x \cdot -3 \]
Alternative 19
Error62.3
Cost64
\[x \]

Error

Reproduce

herbie shell --seed 2022316 
(FPCore (x y z)
  :name "Data.Colour.RGBSpace.HSL:hsl from colour-2.3.3, D"
  :precision binary64
  (+ x (* (* (- y x) 6.0) (- (/ 2.0 3.0) z))))