?

Average Error: 24.81% → 0.01%
Time: 4.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

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

Derivation?

  1. Initial program 24.81

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

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

    +-commutative [=>]24.81

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

    sub-neg [=>]24.81

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

    distribute-rgt-in [=>]24.79

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

    +-commutative [=>]24.79

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

    sub-neg [=>]24.79

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

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

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

    associate-+r+ [=>]24.79

    \[ \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.82%
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -4.2 \cdot 10^{+111}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;x \leq 0.09:\\ \;\;\;\;1 - y\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(x + -1\right)\\ \end{array} \]
Alternative 2
Error16.17%
Cost456
\[\begin{array}{l} \mathbf{if}\;x \leq -1.8 \cdot 10^{+112}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;x \leq 18.5:\\ \;\;\;\;1 - y\\ \mathbf{else}:\\ \;\;\;\;y \cdot x\\ \end{array} \]
Alternative 3
Error0.01%
Cost448
\[\left(1 + y \cdot x\right) - y \]
Alternative 4
Error30.1%
Cost392
\[\begin{array}{l} \mathbf{if}\;y \leq -1:\\ \;\;\;\;-y\\ \mathbf{elif}\;y \leq 1:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;-y\\ \end{array} \]
Alternative 5
Error56.51%
Cost64
\[1 \]

Error

Reproduce?

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