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

Error

Target

Original16.3
Target0.0
Herbie0.0
\[y \cdot x - \left(y - 1\right) \]

Derivation

  1. Initial program 16.3

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

    \[\leadsto \color{blue}{\mathsf{fma}\left(x, y, 1\right) - y} \]
    Proof
    (-.f64 (fma.f64 x y 1) y): 0 points increase in error, 0 points decrease in error
    (-.f64 (Rewrite<= fma-def_binary64 (+.f64 (*.f64 x y) 1)) y): 13 points increase in error, 28 points decrease in error
    (-.f64 (+.f64 (Rewrite=> *-commutative_binary64 (*.f64 y x)) 1) y): 0 points increase in error, 13 points decrease in error
    (-.f64 (+.f64 (*.f64 y (Rewrite<= *-lft-identity_binary64 (*.f64 1 x))) 1) y): 13 points increase in error, 0 points decrease in error
    (-.f64 (+.f64 (*.f64 y (*.f64 (Rewrite<= metadata-eval (*.f64 -1 -1)) x)) 1) y): 0 points increase in error, 13 points decrease in error
    (-.f64 (+.f64 (*.f64 y (Rewrite<= associate-*r*_binary64 (*.f64 -1 (*.f64 -1 x)))) 1) y): 0 points increase in error, 13 points decrease in error
    (-.f64 (+.f64 (*.f64 y (*.f64 -1 (*.f64 (Rewrite<= metadata-eval (*.f64 1 -1)) x))) 1) y): 38 points increase in error, 0 points decrease in error
    (-.f64 (+.f64 (*.f64 y (*.f64 -1 (Rewrite<= associate-*r*_binary64 (*.f64 1 (*.f64 -1 x))))) 1) y): 0 points increase in error, 38 points decrease in error
    (-.f64 (+.f64 (*.f64 y (*.f64 -1 (*.f64 1 (Rewrite<= neg-mul-1_binary64 (neg.f64 x))))) 1) y): 0 points increase in error, 0 points decrease in error
    (-.f64 (+.f64 (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 y -1) (*.f64 1 (neg.f64 x)))) 1) y): 7 points increase in error, 0 points decrease in error
    (-.f64 (+.f64 (*.f64 (Rewrite<= *-commutative_binary64 (*.f64 -1 y)) (*.f64 1 (neg.f64 x))) 1) y): 0 points increase in error, 7 points decrease in error
    (-.f64 (+.f64 (*.f64 (Rewrite<= neg-mul-1_binary64 (neg.f64 y)) (*.f64 1 (neg.f64 x))) 1) y): 0 points increase in error, 0 points decrease in error
    (-.f64 (+.f64 (*.f64 (neg.f64 y) (Rewrite=> distribute-rgt-neg-out_binary64 (neg.f64 (*.f64 1 x)))) 1) y): 0 points increase in error, 0 points decrease in error
    (-.f64 (+.f64 (*.f64 (neg.f64 y) (neg.f64 (Rewrite=> *-lft-identity_binary64 x))) 1) y): 13 points increase in error, 0 points decrease in error
    (-.f64 (Rewrite<= +-commutative_binary64 (+.f64 1 (*.f64 (neg.f64 y) (neg.f64 x)))) y): 0 points increase in error, 13 points decrease in error
    (-.f64 (+.f64 (Rewrite<= metadata-eval (+.f64 1 0)) (*.f64 (neg.f64 y) (neg.f64 x))) y): 13 points increase in error, 0 points decrease in error
    (-.f64 (Rewrite<= associate-+r+_binary64 (+.f64 1 (+.f64 0 (*.f64 (neg.f64 y) (neg.f64 x))))) y): 0 points increase in error, 13 points decrease in error
    (-.f64 (+.f64 1 (+.f64 (Rewrite<= mul0-lft_binary64 (*.f64 0 (*.f64 1 (neg.f64 x)))) (*.f64 (neg.f64 y) (neg.f64 x)))) y): 0 points increase in error, 0 points decrease in error
    (-.f64 (+.f64 1 (+.f64 (*.f64 0 (*.f64 1 (Rewrite=> neg-mul-1_binary64 (*.f64 -1 x)))) (*.f64 (neg.f64 y) (neg.f64 x)))) y): 0 points increase in error, 0 points decrease in error
    (-.f64 (+.f64 1 (+.f64 (*.f64 0 (Rewrite=> associate-*r*_binary64 (*.f64 (*.f64 1 -1) x))) (*.f64 (neg.f64 y) (neg.f64 x)))) y): 0 points increase in error, 0 points decrease in error
    (-.f64 (+.f64 1 (+.f64 (*.f64 0 (*.f64 (Rewrite=> metadata-eval -1) x)) (*.f64 (neg.f64 y) (neg.f64 x)))) y): 0 points increase in error, 0 points decrease in error
    (-.f64 (+.f64 1 (+.f64 (Rewrite=> associate-*r*_binary64 (*.f64 (*.f64 0 -1) x)) (*.f64 (neg.f64 y) (neg.f64 x)))) y): 0 points increase in error, 0 points decrease in error
    (-.f64 (+.f64 1 (+.f64 (*.f64 (Rewrite=> metadata-eval 0) x) (*.f64 (neg.f64 y) (neg.f64 x)))) y): 0 points increase in error, 0 points decrease in error
    (-.f64 (+.f64 1 (+.f64 (*.f64 (Rewrite<= metadata-eval (+.f64 -1 1)) x) (*.f64 (neg.f64 y) (neg.f64 x)))) y): 13 points increase in error, 0 points decrease in error
    (-.f64 (+.f64 1 (+.f64 (Rewrite<= distribute-rgt1-in_binary64 (+.f64 x (*.f64 -1 x))) (*.f64 (neg.f64 y) (neg.f64 x)))) y): 0 points increase in error, 13 points decrease in error
    (-.f64 (+.f64 1 (+.f64 (+.f64 x (*.f64 (Rewrite<= metadata-eval (*.f64 1 -1)) x)) (*.f64 (neg.f64 y) (neg.f64 x)))) y): 13 points increase in error, 0 points decrease in error
    (-.f64 (+.f64 1 (+.f64 (+.f64 x (Rewrite<= associate-*r*_binary64 (*.f64 1 (*.f64 -1 x)))) (*.f64 (neg.f64 y) (neg.f64 x)))) y): 0 points increase in error, 13 points decrease in error
    (-.f64 (+.f64 1 (+.f64 (+.f64 x (*.f64 1 (Rewrite<= neg-mul-1_binary64 (neg.f64 x)))) (*.f64 (neg.f64 y) (neg.f64 x)))) y): 0 points increase in error, 0 points decrease in error
    (-.f64 (+.f64 1 (Rewrite<= associate-+r+_binary64 (+.f64 x (+.f64 (*.f64 1 (neg.f64 x)) (*.f64 (neg.f64 y) (neg.f64 x)))))) y): 7 points increase in error, 0 points decrease in error
    (-.f64 (+.f64 1 (+.f64 x (Rewrite<= distribute-rgt-in_binary64 (*.f64 (neg.f64 x) (+.f64 1 (neg.f64 y)))))) y): 13 points increase in error, 0 points decrease in error
    (-.f64 (+.f64 1 (+.f64 x (*.f64 (neg.f64 x) (Rewrite<= sub-neg_binary64 (-.f64 1 y))))) y): 0 points increase in error, 13 points decrease in error
    (-.f64 (+.f64 1 (Rewrite<= +-commutative_binary64 (+.f64 (*.f64 (neg.f64 x) (-.f64 1 y)) x))) y): 0 points increase in error, 0 points decrease in error
    (-.f64 (Rewrite=> +-commutative_binary64 (+.f64 (+.f64 (*.f64 (neg.f64 x) (-.f64 1 y)) x) 1)) y): 13 points increase in error, 0 points decrease in error
    (Rewrite<= associate-+r-_binary64 (+.f64 (+.f64 (*.f64 (neg.f64 x) (-.f64 1 y)) x) (-.f64 1 y))): 0 points increase in error, 13 points decrease in error
    (Rewrite<= associate-+r+_binary64 (+.f64 (*.f64 (neg.f64 x) (-.f64 1 y)) (+.f64 x (-.f64 1 y)))): 13 points increase in error, 0 points decrease in error
    (+.f64 (*.f64 (neg.f64 x) (-.f64 1 y)) (+.f64 x (Rewrite<= *-lft-identity_binary64 (*.f64 1 (-.f64 1 y))))): 0 points increase in error, 13 points decrease in error
    (Rewrite<= +-commutative_binary64 (+.f64 (+.f64 x (*.f64 1 (-.f64 1 y))) (*.f64 (neg.f64 x) (-.f64 1 y)))): 0 points increase in error, 0 points decrease in error
    (Rewrite<= associate-+r+_binary64 (+.f64 x (+.f64 (*.f64 1 (-.f64 1 y)) (*.f64 (neg.f64 x) (-.f64 1 y))))): 0 points increase in error, 0 points decrease in error
    (+.f64 x (Rewrite<= distribute-rgt-in_binary64 (*.f64 (-.f64 1 y) (+.f64 1 (neg.f64 x))))): 0 points increase in error, 0 points decrease in error
    (+.f64 x (*.f64 (-.f64 1 y) (Rewrite<= sub-neg_binary64 (-.f64 1 x)))): 0 points increase in error, 0 points decrease in error
    (+.f64 x (Rewrite<= *-commutative_binary64 (*.f64 (-.f64 1 x) (-.f64 1 y)))): 0 points increase in error, 0 points decrease in error
  3. Final simplification0.0

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

Alternatives

Alternative 1
Error11.1
Cost720
\[\begin{array}{l} \mathbf{if}\;x \leq -9 \cdot 10^{+150}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \leq 1.6 \cdot 10^{+28}:\\ \;\;\;\;1 - y\\ \mathbf{elif}\;x \leq 8.5 \cdot 10^{+76}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \leq 1.35 \cdot 10^{+106}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;x \cdot y\\ \end{array} \]
Alternative 2
Error11.2
Cost720
\[\begin{array}{l} \mathbf{if}\;x \leq -6.5 \cdot 10^{+152}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \leq 8.5 \cdot 10^{-7}:\\ \;\;\;\;1 - y\\ \mathbf{elif}\;x \leq 1.9 \cdot 10^{+66}:\\ \;\;\;\;y \cdot \left(x + -1\right)\\ \mathbf{elif}\;x \leq 5.4 \cdot 10^{+107}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;x \cdot y\\ \end{array} \]
Alternative 3
Error19.4
Cost524
\[\begin{array}{l} \mathbf{if}\;y \leq -3.4 \cdot 10^{+61}:\\ \;\;\;\;-y\\ \mathbf{elif}\;y \leq -6.8 \cdot 10^{-11}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;y \leq 1:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;-y\\ \end{array} \]
Alternative 4
Error0.0
Cost448
\[\left(1 + x \cdot y\right) - y \]
Alternative 5
Error19.5
Cost392
\[\begin{array}{l} \mathbf{if}\;y \leq -3.2:\\ \;\;\;\;-y\\ \mathbf{elif}\;y \leq 1:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;-y\\ \end{array} \]
Alternative 6
Error36.7
Cost64
\[1 \]

Error

Reproduce

herbie shell --seed 2022343 
(FPCore (x y)
  :name "Graphics.Rendering.Chart.Plot.Vectors:renderPlotVectors from Chart-1.5.3"
  :precision binary64

  :herbie-target
  (- (* y x) (- y 1.0))

  (+ x (* (- 1.0 x) (- 1.0 y))))