?

Average Error: 16.5 → 0.0
Time: 3.5s
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.5
Target0.0
Herbie0.0
\[y \cdot x - \left(y - 1\right) \]

Derivation?

  1. Initial program 16.5

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

    [Start]16.5

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

    *-commutative [=>]16.5

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

    sub-neg [=>]16.5

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

    distribute-rgt-in [=>]16.5

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

    associate-+r+ [=>]16.5

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

    +-commutative [=>]16.5

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

    *-lft-identity [=>]16.5

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

    associate-+r+ [=>]8.7

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

    associate-+r- [=>]8.7

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

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

Alternatives

Alternative 1
Error18.8
Cost720
\[\begin{array}{l} \mathbf{if}\;y \leq -2.25 \cdot 10^{+41}:\\ \;\;\;\;-y\\ \mathbf{elif}\;y \leq -4.2 \cdot 10^{-30}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;y \leq 1.05 \cdot 10^{-18}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \leq 4.7 \cdot 10^{+69}:\\ \;\;\;\;x \cdot y\\ \mathbf{else}:\\ \;\;\;\;-y\\ \end{array} \]
Alternative 2
Error11.7
Cost720
\[\begin{array}{l} \mathbf{if}\;x \leq -2.25 \cdot 10^{+148}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \leq 195:\\ \;\;\;\;1 - y\\ \mathbf{elif}\;x \leq 6.5 \cdot 10^{+107}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \leq 8.2 \cdot 10^{+187}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;x \cdot y\\ \end{array} \]
Alternative 3
Error11.8
Cost720
\[\begin{array}{l} \mathbf{if}\;x \leq -4 \cdot 10^{+149}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \leq 7.5 \cdot 10^{-19}:\\ \;\;\;\;1 - y\\ \mathbf{elif}\;x \leq 6.8 \cdot 10^{+107}:\\ \;\;\;\;y \cdot \left(x + -1\right)\\ \mathbf{elif}\;x \leq 8.5 \cdot 10^{+186}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;x \cdot y\\ \end{array} \]
Alternative 4
Error0.0
Cost448
\[\left(1 + x \cdot y\right) - y \]
Alternative 5
Error19.1
Cost392
\[\begin{array}{l} \mathbf{if}\;y \leq -1:\\ \;\;\;\;-y\\ \mathbf{elif}\;y \leq 0.000205:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;-y\\ \end{array} \]
Alternative 6
Error36.2
Cost64
\[1 \]

Error

Reproduce?

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