?

Average Error: 0.01% → 0%
Time: 1.5s
Precision: binary64
Cost: 6656

?

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

Error?

Derivation?

  1. Initial program 0.01

    \[x - y \cdot y \]
  2. Taylor expanded in x around 0 0.01

    \[\leadsto \color{blue}{-1 \cdot {y}^{2} + x} \]
  3. Simplified0

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

    [Start]0.01

    \[ -1 \cdot {y}^{2} + x \]

    mul-1-neg [=>]0.01

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

    unpow2 [=>]0.01

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

    distribute-rgt-neg-out [<=]0.01

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

    fma-def [=>]0

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

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

Alternatives

Alternative 1
Error16.88%
Cost786
\[\begin{array}{l} \mathbf{if}\;y \leq -1.05 \cdot 10^{-12} \lor \neg \left(y \leq 2.9 \cdot 10^{-29} \lor \neg \left(y \leq 1.75 \cdot 10^{-15}\right) \land y \leq 7.5 \cdot 10^{+40}\right):\\ \;\;\;\;y \cdot \left(-y\right)\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 2
Error0.01%
Cost320
\[x - y \cdot y \]
Alternative 3
Error32.72%
Cost64
\[x \]

Error

Reproduce?

herbie shell --seed 2023090 
(FPCore (x y)
  :name "Graphics.Rasterific.Shading:$sradialGradientWithFocusShader from Rasterific-0.6.1"
  :precision binary64
  (- x (* y y)))