Average Error: 0.0 → 0.0
Time: 3.2s
Precision: binary64
Cost: 6720
\[ \begin{array}{c}[x, y] = \mathsf{sort}([x, y])\\ \end{array} \]
\[\left(x + y\right) - x \cdot y \]
\[\mathsf{fma}\left(x, 1 - y, y\right) \]
(FPCore (x y) :precision binary64 (- (+ x y) (* x y)))
(FPCore (x y) :precision binary64 (fma x (- 1.0 y) y))
double code(double x, double y) {
	return (x + y) - (x * y);
}
double code(double x, double y) {
	return fma(x, (1.0 - y), y);
}
function code(x, y)
	return Float64(Float64(x + y) - Float64(x * y))
end
function code(x, y)
	return fma(x, Float64(1.0 - y), y)
end
code[x_, y_] := N[(N[(x + y), $MachinePrecision] - N[(x * y), $MachinePrecision]), $MachinePrecision]
code[x_, y_] := N[(x * N[(1.0 - y), $MachinePrecision] + y), $MachinePrecision]
\left(x + y\right) - x \cdot y
\mathsf{fma}\left(x, 1 - y, y\right)

Error

Derivation

  1. Initial program 0.0

    \[\left(x + y\right) - x \cdot y \]
  2. Simplified0.0

    \[\leadsto \color{blue}{\mathsf{fma}\left(x, 1 - y, y\right)} \]
    Proof
    (fma.f64 x (-.f64 1 y) y): 0 points increase in error, 0 points decrease in error
    (fma.f64 x (Rewrite<= unsub-neg_binary64 (+.f64 1 (neg.f64 y))) y): 0 points increase in error, 0 points decrease in error
    (fma.f64 x (Rewrite<= +-commutative_binary64 (+.f64 (neg.f64 y) 1)) y): 0 points increase in error, 0 points decrease in error
    (Rewrite<= fma-def_binary64 (+.f64 (*.f64 x (+.f64 (neg.f64 y) 1)) y)): 2 points increase in error, 0 points decrease in error
    (+.f64 (Rewrite<= *-commutative_binary64 (*.f64 (+.f64 (neg.f64 y) 1) x)) y): 0 points increase in error, 0 points decrease in error
    (+.f64 (Rewrite<= distribute-rgt1-in_binary64 (+.f64 x (*.f64 (neg.f64 y) x))) y): 2 points increase in error, 3 points decrease in error
    (+.f64 (+.f64 x (Rewrite<= distribute-lft-neg-in_binary64 (neg.f64 (*.f64 y x)))) y): 0 points increase in error, 0 points decrease in error
    (+.f64 (+.f64 x (neg.f64 (Rewrite<= *-commutative_binary64 (*.f64 x y)))) y): 0 points increase in error, 0 points decrease in error
    (+.f64 (+.f64 x (Rewrite<= distribute-lft-neg-out_binary64 (*.f64 (neg.f64 x) y))) y): 0 points increase in error, 0 points decrease in error
    (Rewrite=> associate-+l+_binary64 (+.f64 x (+.f64 (*.f64 (neg.f64 x) y) y))): 0 points increase in error, 0 points decrease in error
    (+.f64 x (Rewrite<= +-commutative_binary64 (+.f64 y (*.f64 (neg.f64 x) y)))): 0 points increase in error, 0 points decrease in error
    (+.f64 x (Rewrite<= cancel-sign-sub-inv_binary64 (-.f64 y (*.f64 x y)))): 0 points increase in error, 0 points decrease in error
    (Rewrite<= associate--l+_binary64 (-.f64 (+.f64 x y) (*.f64 x y))): 0 points increase in error, 0 points decrease in error
  3. Final simplification0.0

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

Alternatives

Alternative 1
Error8.0
Cost848
\[\begin{array}{l} t_0 := x \cdot \left(1 - y\right)\\ \mathbf{if}\;x \leq -1.9976601841451555 \cdot 10^{-53}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -2.6993255607761914 \cdot 10^{-77}:\\ \;\;\;\;y\\ \mathbf{elif}\;x \leq -1.328817439861793 \cdot 10^{-106}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 7.703325917439791 \cdot 10^{-7}:\\ \;\;\;\;y\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Error8.9
Cost716
\[\begin{array}{l} \mathbf{if}\;y \leq 3.586961999891287 \cdot 10^{-122}:\\ \;\;\;\;x \cdot \left(1 - y\right)\\ \mathbf{elif}\;y \leq 6.604264934648181 \cdot 10^{-101}:\\ \;\;\;\;y\\ \mathbf{elif}\;y \leq 1.214288369280016 \cdot 10^{-25}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(1 - x\right)\\ \end{array} \]
Alternative 3
Error16.3
Cost592
\[\begin{array}{l} \mathbf{if}\;y \leq -3.266139341985723:\\ \;\;\;\;x \cdot \left(-y\right)\\ \mathbf{elif}\;y \leq 3.586961999891287 \cdot 10^{-122}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 6.604264934648181 \cdot 10^{-101}:\\ \;\;\;\;y\\ \mathbf{elif}\;y \leq 1.214288369280016 \cdot 10^{-25}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y\\ \end{array} \]
Alternative 4
Error18.1
Cost460
\[\begin{array}{l} \mathbf{if}\;y \leq 3.586961999891287 \cdot 10^{-122}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 6.604264934648181 \cdot 10^{-101}:\\ \;\;\;\;y\\ \mathbf{elif}\;y \leq 1.214288369280016 \cdot 10^{-25}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y\\ \end{array} \]
Alternative 5
Error0.0
Cost448
\[\left(x + y\right) - x \cdot y \]
Alternative 6
Error36.4
Cost64
\[x \]

Error

Reproduce

herbie shell --seed 2022317 
(FPCore (x y)
  :name "Data.Colour.RGBSpace.HSL:hsl from colour-2.3.3, A"
  :precision binary64
  (- (+ x y) (* x y)))