Average Error: 0.0 → 0
Time: 2.0s
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.0

    \[x - y \cdot y \]
  2. Simplified0

    \[\leadsto \color{blue}{\mathsf{fma}\left(y, -y, x\right)} \]
    Proof
    (fma.f64 y (neg.f64 y) x): 0 points increase in error, 0 points decrease in error
    (Rewrite<= fma-def_binary64 (+.f64 (*.f64 y (neg.f64 y)) x)): 1 points increase in error, 0 points decrease in error
    (+.f64 (Rewrite<= *-commutative_binary64 (*.f64 (neg.f64 y) y)) x): 0 points increase in error, 0 points decrease in error
    (Rewrite<= +-commutative_binary64 (+.f64 x (*.f64 (neg.f64 y) y))): 0 points increase in error, 0 points decrease in error
    (Rewrite<= cancel-sign-sub-inv_binary64 (-.f64 x (*.f64 y y))): 0 points increase in error, 0 points decrease in error
  3. Final simplification0

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

Alternatives

Alternative 1
Error11.0
Cost520
\[\begin{array}{l} t_0 := y \cdot \left(-y\right)\\ \mathbf{if}\;y \leq -4.390169387380253 \cdot 10^{-12}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 1.4298932302469947 \cdot 10^{+27}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Error0.0
Cost320
\[x - y \cdot y \]
Alternative 3
Error21.1
Cost64
\[x \]

Error

Reproduce

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