?

Average Error: 24.85% → 0.01%
Time: 4.4s
Precision: binary64
Cost: 6720

?

\[x + \left(1 - x\right) \cdot \left(1 - y\right) \]
\[\mathsf{fma}\left(y, x + -1, 1\right) \]
(FPCore (x y) :precision binary64 (+ x (* (- 1.0 x) (- 1.0 y))))
(FPCore (x y) :precision binary64 (fma y (+ x -1.0) 1.0))
double code(double x, double y) {
	return x + ((1.0 - x) * (1.0 - y));
}
double code(double x, double y) {
	return fma(y, (x + -1.0), 1.0);
}
function code(x, y)
	return Float64(x + Float64(Float64(1.0 - x) * Float64(1.0 - y)))
end
function code(x, y)
	return fma(y, Float64(x + -1.0), 1.0)
end
code[x_, y_] := N[(x + N[(N[(1.0 - x), $MachinePrecision] * N[(1.0 - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_, y_] := N[(y * N[(x + -1.0), $MachinePrecision] + 1.0), $MachinePrecision]
x + \left(1 - x\right) \cdot \left(1 - y\right)
\mathsf{fma}\left(y, x + -1, 1\right)

Error?

Target

Original24.85%
Target0.01%
Herbie0.01%
\[y \cdot x - \left(y - 1\right) \]

Derivation?

  1. Initial program 24.85

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

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

    [Start]24.85

    \[ x + \left(1 - x\right) \cdot \left(1 - y\right) \]

    +-commutative [=>]24.85

    \[ \color{blue}{\left(1 - x\right) \cdot \left(1 - y\right) + x} \]

    sub-neg [=>]24.85

    \[ \left(1 - x\right) \cdot \color{blue}{\left(1 + \left(-y\right)\right)} + x \]

    distribute-rgt-in [=>]24.84

    \[ \color{blue}{\left(1 \cdot \left(1 - x\right) + \left(-y\right) \cdot \left(1 - x\right)\right)} + x \]

    +-commutative [=>]24.84

    \[ \color{blue}{\left(\left(-y\right) \cdot \left(1 - x\right) + 1 \cdot \left(1 - x\right)\right)} + x \]

    sub-neg [=>]24.84

    \[ \left(\left(-y\right) \cdot \left(1 - x\right) + 1 \cdot \color{blue}{\left(1 + \left(-x\right)\right)}\right) + x \]

    distribute-lft-in [=>]24.84

    \[ \left(\left(-y\right) \cdot \left(1 - x\right) + \color{blue}{\left(1 \cdot 1 + 1 \cdot \left(-x\right)\right)}\right) + x \]

    metadata-eval [=>]24.84

    \[ \left(\left(-y\right) \cdot \left(1 - x\right) + \left(\color{blue}{1} + 1 \cdot \left(-x\right)\right)\right) + x \]

    associate-+r+ [=>]24.84

    \[ \color{blue}{\left(\left(\left(-y\right) \cdot \left(1 - x\right) + 1\right) + 1 \cdot \left(-x\right)\right)} + x \]

    associate-+l+ [=>]0.01

    \[ \color{blue}{\left(\left(-y\right) \cdot \left(1 - x\right) + 1\right) + \left(1 \cdot \left(-x\right) + x\right)} \]

    neg-mul-1 [=>]0.01

    \[ \left(\left(-y\right) \cdot \left(1 - x\right) + 1\right) + \left(1 \cdot \color{blue}{\left(-1 \cdot x\right)} + x\right) \]

    associate-*r* [=>]0.01

    \[ \left(\left(-y\right) \cdot \left(1 - x\right) + 1\right) + \left(\color{blue}{\left(1 \cdot -1\right) \cdot x} + x\right) \]

    metadata-eval [=>]0.01

    \[ \left(\left(-y\right) \cdot \left(1 - x\right) + 1\right) + \left(\color{blue}{-1} \cdot x + x\right) \]

    distribute-lft1-in [=>]0.01

    \[ \left(\left(-y\right) \cdot \left(1 - x\right) + 1\right) + \color{blue}{\left(-1 + 1\right) \cdot x} \]

    metadata-eval [=>]0.01

    \[ \left(\left(-y\right) \cdot \left(1 - x\right) + 1\right) + \color{blue}{0} \cdot x \]

    metadata-eval [<=]0.01

    \[ \left(\left(-y\right) \cdot \left(1 - x\right) + 1\right) + \color{blue}{\left(0 \cdot -1\right)} \cdot x \]

    associate-*r* [<=]0.01

    \[ \left(\left(-y\right) \cdot \left(1 - x\right) + 1\right) + \color{blue}{0 \cdot \left(-1 \cdot x\right)} \]

    metadata-eval [<=]0.01

    \[ \left(\left(-y\right) \cdot \left(1 - x\right) + 1\right) + 0 \cdot \left(\color{blue}{\left(1 \cdot -1\right)} \cdot x\right) \]

    associate-*r* [<=]0.01

    \[ \left(\left(-y\right) \cdot \left(1 - x\right) + 1\right) + 0 \cdot \color{blue}{\left(1 \cdot \left(-1 \cdot x\right)\right)} \]

    neg-mul-1 [<=]0.01

    \[ \left(\left(-y\right) \cdot \left(1 - x\right) + 1\right) + 0 \cdot \left(1 \cdot \color{blue}{\left(-x\right)}\right) \]

    mul0-lft [=>]0.01

    \[ \left(\left(-y\right) \cdot \left(1 - x\right) + 1\right) + \color{blue}{0} \]
  3. Final simplification0.01

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

Alternatives

Alternative 1
Error15.53%
Cost585
\[\begin{array}{l} \mathbf{if}\;y \leq -360000000000 \lor \neg \left(y \leq 1.65 \cdot 10^{-43}\right):\\ \;\;\;\;y \cdot \left(x + -1\right)\\ \mathbf{else}:\\ \;\;\;\;1 - y\\ \end{array} \]
Alternative 2
Error43.35%
Cost456
\[\begin{array}{l} \mathbf{if}\;y \leq -2.5 \cdot 10^{-24}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;y \leq 1.55 \cdot 10^{-43}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;y \cdot x\\ \end{array} \]
Alternative 3
Error15.25%
Cost456
\[\begin{array}{l} \mathbf{if}\;x \leq -4.6 \cdot 10^{+48}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;x \leq 4 \cdot 10^{+90}:\\ \;\;\;\;1 - y\\ \mathbf{else}:\\ \;\;\;\;y \cdot x\\ \end{array} \]
Alternative 4
Error0.01%
Cost448
\[\left(1 + y \cdot x\right) - y \]
Alternative 5
Error57.1%
Cost64
\[1 \]

Error

Reproduce?

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