?

Average Error: 25.79% → 0.01%
Time: 3.4s
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

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

Derivation?

  1. Initial program 25.79

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

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

    [Start]25.79

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

    *-commutative [=>]25.79

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

    sub-neg [=>]25.79

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

    distribute-rgt-in [=>]25.79

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

    associate-+r+ [=>]25.79

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

    +-commutative [=>]25.79

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

    *-lft-identity [=>]25.79

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

    associate-+r+ [=>]13.6

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

    associate-+r- [=>]13.6

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

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

Alternatives

Alternative 1
Error35.61%
Cost984
\[\begin{array}{l} \mathbf{if}\;y \leq -5.1 \cdot 10^{+135}:\\ \;\;\;\;-y\\ \mathbf{elif}\;y \leq -3.2 \cdot 10^{+62}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;y \leq -2.05 \cdot 10^{+23}:\\ \;\;\;\;-y\\ \mathbf{elif}\;y \leq -4.5 \cdot 10^{-118}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;y \leq 1.92 \cdot 10^{-103}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \leq 2.5 \cdot 10^{+195}:\\ \;\;\;\;x \cdot y\\ \mathbf{else}:\\ \;\;\;\;-y\\ \end{array} \]
Alternative 2
Error15.31%
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -5.2 \cdot 10^{+36}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \leq 1.9 \cdot 10^{-17}:\\ \;\;\;\;1 - y\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(x + -1\right)\\ \end{array} \]
Alternative 3
Error15.02%
Cost456
\[\begin{array}{l} \mathbf{if}\;x \leq -1.3 \cdot 10^{+38}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \leq 10000000:\\ \;\;\;\;1 - y\\ \mathbf{else}:\\ \;\;\;\;x \cdot y\\ \end{array} \]
Alternative 4
Error0.01%
Cost448
\[\left(1 + x \cdot y\right) - y \]
Alternative 5
Error30.1%
Cost392
\[\begin{array}{l} \mathbf{if}\;y \leq -24000:\\ \;\;\;\;-y\\ \mathbf{elif}\;y \leq 1:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;-y\\ \end{array} \]
Alternative 6
Error56.29%
Cost64
\[1 \]

Error

Reproduce?

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