Average Error: 0.4 → 0.2
Time: 13.3s
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): 4 points increase in error, 6 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): 4 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)): 1 points increase in error, 1 points decrease in error
    (+.f64 (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 (-.f64 y x) 6) (-.f64 (/.f64 2 3) z))) x): 62 points increase in error, 20 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
Error33.3
Cost1376
\[\begin{array}{l} t_0 := z \cdot \left(y \cdot -6\right)\\ \mathbf{if}\;z \leq -1.9 \cdot 10^{+173}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -2.4203105798509114 \cdot 10^{-6}:\\ \;\;\;\;x \cdot \left(z \cdot 6\right)\\ \mathbf{elif}\;z \leq -6.980857731895762 \cdot 10^{-304}:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;z \leq 4.216083883107624 \cdot 10^{-211}:\\ \;\;\;\;x \cdot -3\\ \mathbf{elif}\;z \leq 1.0640712581888335 \cdot 10^{-141}:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;z \leq 3.2477175009371946 \cdot 10^{-69}:\\ \;\;\;\;x \cdot -3\\ \mathbf{elif}\;z \leq 4.2078831460431275 \cdot 10^{-23}:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;z \leq 1.4231125978861493 \cdot 10^{+23}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;6 \cdot \left(x \cdot z\right)\\ \end{array} \]
Alternative 2
Error33.0
Cost1112
\[\begin{array}{l} \mathbf{if}\;z \leq -1.9 \cdot 10^{+173}:\\ \;\;\;\;y \cdot \left(z \cdot -6\right)\\ \mathbf{elif}\;z \leq -2.4203105798509114 \cdot 10^{-6}:\\ \;\;\;\;x \cdot \left(z \cdot 6\right)\\ \mathbf{elif}\;z \leq -6.980857731895762 \cdot 10^{-304}:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;z \leq 4.216083883107624 \cdot 10^{-211}:\\ \;\;\;\;x \cdot -3\\ \mathbf{elif}\;z \leq 1.0640712581888335 \cdot 10^{-141}:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;z \leq 3.1713488635460527 \cdot 10^{-16}:\\ \;\;\;\;x \cdot -3\\ \mathbf{else}:\\ \;\;\;\;6 \cdot \left(x \cdot z\right)\\ \end{array} \]
Alternative 3
Error0.2
Cost960
\[\left(y - x\right) \cdot 4 + \left(x + -6 \cdot \left(\left(y - x\right) \cdot z\right)\right) \]
Alternative 4
Error12.9
Cost844
\[\begin{array}{l} \mathbf{if}\;z \leq -1.9 \cdot 10^{+173}:\\ \;\;\;\;z \cdot \left(y \cdot -6\right)\\ \mathbf{elif}\;z \leq -34.09398674516787:\\ \;\;\;\;x \cdot \left(z \cdot 6\right)\\ \mathbf{elif}\;z \leq 1.1690437629557916 \cdot 10^{-11}:\\ \;\;\;\;y \cdot 4 + x \cdot -3\\ \mathbf{else}:\\ \;\;\;\;6 \cdot \left(x \cdot z\right)\\ \end{array} \]
Alternative 5
Error2.0
Cost712
\[\begin{array}{l} t_0 := z \cdot \left(\left(y - x\right) \cdot -6\right)\\ \mathbf{if}\;z \leq -34.09398674516787:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 1.1690437629557916 \cdot 10^{-11}:\\ \;\;\;\;y \cdot 4 + x \cdot -3\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 6
Error0.4
Cost704
\[x + \left(\left(y - x\right) \cdot 6\right) \cdot \left(0.6666666666666666 - z\right) \]
Alternative 7
Error34.2
Cost456
\[\begin{array}{l} \mathbf{if}\;x \leq -9.8 \cdot 10^{+104}:\\ \;\;\;\;x \cdot -3\\ \mathbf{elif}\;x \leq 2.7011118584103607 \cdot 10^{-50}:\\ \;\;\;\;y \cdot 4\\ \mathbf{else}:\\ \;\;\;\;x \cdot -3\\ \end{array} \]
Alternative 8
Error43.0
Cost192
\[y \cdot 4 \]

Error

Reproduce

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