?

Average Error: 16.4 → 0.0
Time: 3.0s
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

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

Derivation?

  1. Initial program 16.4

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

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

    [Start]16.4

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

    +-commutative [=>]16.4

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

    sub-neg [=>]16.4

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

    distribute-rgt-in [=>]16.4

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

    +-commutative [=>]16.4

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

    sub-neg [=>]16.4

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

    distribute-lft-in [=>]16.4

    \[ \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 [=>]16.4

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

    associate-+r+ [=>]16.4

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

    associate-+l+ [=>]0.0

    \[ \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.0

    \[ \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.0

    \[ \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.0

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

    distribute-lft1-in [=>]0.0

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

    metadata-eval [=>]0.0

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

    metadata-eval [<=]0.0

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

    associate-*r* [<=]0.0

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

    metadata-eval [<=]0.0

    \[ \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.0

    \[ \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.0

    \[ \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.0

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

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

Alternatives

Alternative 1
Error20.3
Cost720
\[\begin{array}{l} \mathbf{if}\;y \leq -4.9 \cdot 10^{+141}:\\ \;\;\;\;-y\\ \mathbf{elif}\;y \leq -4 \cdot 10^{-104}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;y \leq 3.8 \cdot 10^{-14}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \leq 2.6 \cdot 10^{+27}:\\ \;\;\;\;y \cdot x\\ \mathbf{else}:\\ \;\;\;\;-y\\ \end{array} \]
Alternative 2
Error9.7
Cost585
\[\begin{array}{l} \mathbf{if}\;x \leq -0.38 \lor \neg \left(x \leq 1.55 \cdot 10^{+22}\right):\\ \;\;\;\;y \cdot \left(x + -1\right)\\ \mathbf{else}:\\ \;\;\;\;1 - y\\ \end{array} \]
Alternative 3
Error9.6
Cost456
\[\begin{array}{l} \mathbf{if}\;x \leq -1.6 \cdot 10^{+43}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;x \leq 1.6 \cdot 10^{+22}:\\ \;\;\;\;1 - y\\ \mathbf{else}:\\ \;\;\;\;y \cdot x\\ \end{array} \]
Alternative 4
Error0.0
Cost448
\[\left(1 + y \cdot x\right) - y \]
Alternative 5
Error18.9
Cost392
\[\begin{array}{l} \mathbf{if}\;y \leq -1:\\ \;\;\;\;-y\\ \mathbf{elif}\;y \leq 1:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;-y\\ \end{array} \]
Alternative 6
Error36.6
Cost64
\[1 \]

Error

Reproduce?

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