?

Average Accuracy: 74.9% → 100.0%
Time: 2.8s
Precision: binary64
Cost: 6720

?

\[x + \left(1 - x\right) \cdot \left(1 - y\right) \]
\[\mathsf{fma}\left(x, y, 1 - y\right) \]
(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 fma(x, y, 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[(x * y + N[(1.0 - y), $MachinePrecision]), $MachinePrecision]
x + \left(1 - x\right) \cdot \left(1 - y\right)
\mathsf{fma}\left(x, y, 1 - y\right)

Error?

Target

Original74.9%
Target100.0%
Herbie100.0%
\[y \cdot x - \left(y - 1\right) \]

Derivation?

  1. Initial program 74.9%

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

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

    [Start]74.9

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

    sub-neg [=>]74.9

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

    distribute-rgt-in [=>]75.0

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

    *-lft-identity [=>]75.0

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

    associate-+r+ [=>]87.3

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

    +-commutative [=>]87.3

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

    sub-neg [=>]87.3

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

    associate-+l+ [=>]100.0

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

    neg-mul-1 [=>]100.0

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

    distribute-lft1-in [=>]100.0

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

    metadata-eval [=>]100.0

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

    metadata-eval [<=]100.0

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

    associate-*r* [<=]100.0

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

    neg-mul-1 [<=]100.0

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

    mul0-lft [=>]100.0

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

    metadata-eval [=>]100.0

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

    sub-neg [=>]100.0

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

    distribute-rgt-in [=>]100.0

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

    *-lft-identity [=>]100.0

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

    associate-+r+ [=>]100.0

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

    sub-neg [<=]100.0

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

    +-commutative [=>]100.0

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

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

Alternatives

Alternative 1
Accuracy71.1%
Cost720
\[\begin{array}{l} \mathbf{if}\;y \leq -5.3 \cdot 10^{+22}:\\ \;\;\;\;-y\\ \mathbf{elif}\;y \leq -3.2 \cdot 10^{-30}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;y \leq 10^{-35}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \leq 2.3 \cdot 10^{+51}:\\ \;\;\;\;x \cdot y\\ \mathbf{else}:\\ \;\;\;\;-y\\ \end{array} \]
Alternative 2
Accuracy83.8%
Cost457
\[\begin{array}{l} \mathbf{if}\;x \leq -5.2 \cdot 10^{+73} \lor \neg \left(x \leq 5 \cdot 10^{+112}\right):\\ \;\;\;\;x \cdot y\\ \mathbf{else}:\\ \;\;\;\;1 - y\\ \end{array} \]
Alternative 3
Accuracy100.0%
Cost448
\[\left(1 + x \cdot y\right) - y \]
Alternative 4
Accuracy70.3%
Cost392
\[\begin{array}{l} \mathbf{if}\;y \leq -1:\\ \;\;\;\;-y\\ \mathbf{elif}\;y \leq 4.2 \cdot 10^{+14}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;-y\\ \end{array} \]
Alternative 5
Accuracy43.9%
Cost64
\[1 \]

Error

Reproduce?

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