Average Error: 16.2 → 0.0
Time: 1.5s
Precision: binary64
\[x + \left(1 - x\right) \cdot \left(1 - y\right) \]
\[\mathsf{fma}\left(y, x, 1 - y\right) \]
(FPCore (x y) :precision binary64 (+ x (* (- 1.0 x) (- 1.0 y))))
(FPCore (x y) :precision binary64 (fma y x (- 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(y, x, (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 fma(y, x, Float64(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[(y * x + N[(1.0 - y), $MachinePrecision]), $MachinePrecision]
x + \left(1 - x\right) \cdot \left(1 - y\right)
\mathsf{fma}\left(y, x, 1 - y\right)

Error

Bits error versus x

Bits error versus y

Target

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

Derivation

  1. Initial program 16.2

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

    \[\leadsto \color{blue}{\mathsf{fma}\left(x, y, 1\right) - y} \]
  3. Taylor expanded in x around 0 0.0

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

    \[\leadsto \color{blue}{\mathsf{fma}\left(y, x, 1 - y\right)} \]
  5. Final simplification0.0

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

Reproduce

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