Average Error: 0.4 → 0.2
Time: 14.7s
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, 8 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, 1 points decrease in error
    (+.f64 (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 (-.f64 y x) 6) (-.f64 (/.f64 2 3) z))) x): 60 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
Error32.3
Cost1376
\[\begin{array}{l} t_0 := x \cdot \left(z \cdot 6\right)\\ t_1 := y \cdot \left(z \cdot -6\right)\\ \mathbf{if}\;z \leq -1.8 \cdot 10^{+161}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -1.35 \cdot 10^{+113}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -14369236934.355503:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 3.771693841740401 \cdot 10^{-286}:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;z \leq 1.2155519884432873 \cdot 10^{-197}:\\ \;\;\;\;x \cdot -3\\ \mathbf{elif}\;z \leq 0.0070897175698634:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;z \leq 2.25 \cdot 10^{+85}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 1.35 \cdot 10^{+232}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 2
Error32.3
Cost1376
\[\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 -1.8 \cdot 10^{+161}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -1.35 \cdot 10^{+113}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -14369236934.355503:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 3.771693841740401 \cdot 10^{-286}:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;z \leq 1.2155519884432873 \cdot 10^{-197}:\\ \;\;\;\;x \cdot -3\\ \mathbf{elif}\;z \leq 0.0070897175698634:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;z \leq 2.25 \cdot 10^{+85}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 1.35 \cdot 10^{+232}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 3
Error32.3
Cost1376
\[\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 -1.8 \cdot 10^{+161}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -1.35 \cdot 10^{+113}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -14369236934.355503:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 3.771693841740401 \cdot 10^{-286}:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;z \leq 1.2155519884432873 \cdot 10^{-197}:\\ \;\;\;\;x \cdot -3\\ \mathbf{elif}\;z \leq 0.0070897175698634:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;z \leq 2.25 \cdot 10^{+85}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 1.35 \cdot 10^{+232}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;z \cdot \left(y \cdot -6\right)\\ \end{array} \]
Alternative 4
Error13.2
Cost1240
\[\begin{array}{l} t_0 := x \cdot \left(-3 - z \cdot -6\right)\\ t_1 := -6 \cdot \left(y \cdot z\right)\\ \mathbf{if}\;z \leq -1.8 \cdot 10^{+161}:\\ \;\;\;\;x \cdot \left(z \cdot 6\right)\\ \mathbf{elif}\;z \leq -1.35 \cdot 10^{+113}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -14369236934.355503:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 0.0070897175698634:\\ \;\;\;\;x \cdot -3 - y \cdot -4\\ \mathbf{elif}\;z \leq 2.25 \cdot 10^{+85}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 1.35 \cdot 10^{+232}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;z \cdot \left(y \cdot -6\right)\\ \end{array} \]
Alternative 5
Error24.9
Cost1112
\[\begin{array}{l} t_0 := x \cdot \left(-3 - z \cdot -6\right)\\ \mathbf{if}\;y \leq -1.837726475861053 \cdot 10^{+85}:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;y \leq -7.959609532306353 \cdot 10^{-32}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq -1.714957899239911 \cdot 10^{-49}:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;y \leq 4459055.469566613:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 5.8 \cdot 10^{+146}:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;y \leq 6.8 \cdot 10^{+196}:\\ \;\;\;\;-6 \cdot \left(y \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;y \cdot 4\\ \end{array} \]
Alternative 6
Error0.3
Cost1088
\[x \cdot \left(1 + -6 \cdot \left(0.6666666666666666 - z\right)\right) + -6 \cdot \left(y \cdot \left(z + -0.6666666666666666\right)\right) \]
Alternative 7
Error1.5
Cost968
\[\begin{array}{l} \mathbf{if}\;z \leq -14369236934.355503:\\ \;\;\;\;x + z \cdot \left(\left(y - x\right) \cdot -6\right)\\ \mathbf{elif}\;z \leq 55125023.02966394:\\ \;\;\;\;-6 \cdot \left(y \cdot \left(z + -0.6666666666666666\right)\right) + x \cdot -3\\ \mathbf{else}:\\ \;\;\;\;-6 \cdot \left(\left(y - x\right) \cdot z\right)\\ \end{array} \]
Alternative 8
Error32.6
Cost848
\[\begin{array}{l} t_0 := x \cdot \left(z \cdot 6\right)\\ \mathbf{if}\;z \leq -14369236934.355503:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 3.771693841740401 \cdot 10^{-286}:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;z \leq 1.2155519884432873 \cdot 10^{-197}:\\ \;\;\;\;x \cdot -3\\ \mathbf{elif}\;z \leq 0.0070897175698634:\\ \;\;\;\;y \cdot 4\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 9
Error34.1
Cost720
\[\begin{array}{l} \mathbf{if}\;x \leq -4.053246846227415 \cdot 10^{+90}:\\ \;\;\;\;x \cdot -3\\ \mathbf{elif}\;x \leq -6847.138990264478:\\ \;\;\;\;y \cdot 4\\ \mathbf{elif}\;x \leq -1.4913429653956874 \cdot 10^{-42}:\\ \;\;\;\;x \cdot -3\\ \mathbf{elif}\;x \leq 2.1180897128004428 \cdot 10^{+52}:\\ \;\;\;\;y \cdot 4\\ \mathbf{else}:\\ \;\;\;\;x \cdot -3\\ \end{array} \]
Alternative 10
Error1.8
Cost712
\[\begin{array}{l} t_0 := -6 \cdot \left(\left(y - x\right) \cdot z\right)\\ \mathbf{if}\;z \leq -74.02233883969043:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 0.0070897175698634:\\ \;\;\;\;x \cdot -3 - y \cdot -4\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 11
Error1.8
Cost712
\[\begin{array}{l} \mathbf{if}\;z \leq -74.02233883969043:\\ \;\;\;\;x + \left(y - x\right) \cdot \left(z \cdot -6\right)\\ \mathbf{elif}\;z \leq 0.0070897175698634:\\ \;\;\;\;x \cdot -3 - y \cdot -4\\ \mathbf{else}:\\ \;\;\;\;-6 \cdot \left(\left(y - x\right) \cdot z\right)\\ \end{array} \]
Alternative 12
Error1.8
Cost712
\[\begin{array}{l} \mathbf{if}\;z \leq -74.02233883969043:\\ \;\;\;\;x + z \cdot \left(\left(y - x\right) \cdot -6\right)\\ \mathbf{elif}\;z \leq 0.0070897175698634:\\ \;\;\;\;x \cdot -3 - y \cdot -4\\ \mathbf{else}:\\ \;\;\;\;-6 \cdot \left(\left(y - x\right) \cdot z\right)\\ \end{array} \]
Alternative 13
Error0.4
Cost704
\[x + \left(0.6666666666666666 - z\right) \cdot \left(\left(y - x\right) \cdot 6\right) \]
Alternative 14
Error43.4
Cost192
\[x \cdot -3 \]
Alternative 15
Error62.4
Cost64
\[x \]

Error

Reproduce

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