?

Average Accuracy: 99.9% → 99.9%
Time: 11.4s
Precision: binary64
Cost: 6784

?

\[x \cdot \left(1 - x \cdot y\right) \]
\[\mathsf{fma}\left(x \cdot y, -x, x\right) \]
(FPCore (x y) :precision binary64 (* x (- 1.0 (* x y))))
(FPCore (x y) :precision binary64 (fma (* x y) (- x) x))
double code(double x, double y) {
	return x * (1.0 - (x * y));
}
double code(double x, double y) {
	return fma((x * y), -x, x);
}
function code(x, y)
	return Float64(x * Float64(1.0 - Float64(x * y)))
end
function code(x, y)
	return fma(Float64(x * y), Float64(-x), x)
end
code[x_, y_] := N[(x * N[(1.0 - N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_, y_] := N[(N[(x * y), $MachinePrecision] * (-x) + x), $MachinePrecision]
x \cdot \left(1 - x \cdot y\right)
\mathsf{fma}\left(x \cdot y, -x, x\right)

Error?

Derivation?

  1. Initial program 99.9%

    \[x \cdot \left(1 - x \cdot y\right) \]
  2. Simplified99.9%

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

    [Start]99.9

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

    sub-neg [=>]99.9

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

    distribute-lft-in [=>]99.9

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

    +-commutative [=>]99.9

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

    distribute-lft-neg-in [=>]99.9

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

    *-commutative [=>]99.9

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

    associate-*r* [=>]99.9

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

    *-rgt-identity [=>]99.9

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

    fma-def [=>]99.9

    \[ \color{blue}{\mathsf{fma}\left(x \cdot y, -x, x\right)} \]
  3. Final simplification99.9%

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

Alternatives

Alternative 1
Accuracy76.3%
Cost649
\[\begin{array}{l} \mathbf{if}\;y \leq -2.3 \cdot 10^{+181} \lor \neg \left(y \leq 1.3 \cdot 10^{+112}\right):\\ \;\;\;\;\left(x \cdot y\right) \cdot \left(-x\right)\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 2
Accuracy99.9%
Cost448
\[x \cdot \left(1 - x \cdot y\right) \]
Alternative 3
Accuracy99.9%
Cost448
\[x - x \cdot \left(x \cdot y\right) \]
Alternative 4
Accuracy65.9%
Cost64
\[x \]

Error

Reproduce?

herbie shell --seed 2023135 
(FPCore (x y)
  :name "Numeric.SpecFunctions:log1p from math-functions-0.1.5.2, A"
  :precision binary64
  (* x (- 1.0 (* x y))))