Average Error: 0.0 → 0.0
Time: 2.0s
Precision: binary64
Cost: 6784
\[\left(x + y\right) \cdot \left(x - y\right) \]
\[\mathsf{fma}\left(x, x, -y \cdot y\right) \]
(FPCore (x y) :precision binary64 (* (+ x y) (- x y)))
(FPCore (x y) :precision binary64 (fma x x (- (* y y))))
double code(double x, double y) {
	return (x + y) * (x - y);
}
double code(double x, double y) {
	return fma(x, x, -(y * y));
}
function code(x, y)
	return Float64(Float64(x + y) * Float64(x - y))
end
function code(x, y)
	return fma(x, x, Float64(-Float64(y * y)))
end
code[x_, y_] := N[(N[(x + y), $MachinePrecision] * N[(x - y), $MachinePrecision]), $MachinePrecision]
code[x_, y_] := N[(x * x + (-N[(y * y), $MachinePrecision])), $MachinePrecision]
\left(x + y\right) \cdot \left(x - y\right)
\mathsf{fma}\left(x, x, -y \cdot y\right)

Error

Derivation

  1. Initial program 0.0

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

    \[\leadsto \color{blue}{\mathsf{fma}\left(x, x, y \cdot \left(-y\right)\right)} \]
    Proof
    (fma.f64 x x (*.f64 y (neg.f64 y))): 0 points increase in error, 0 points decrease in error
    (fma.f64 x x (Rewrite=> distribute-rgt-neg-out_binary64 (neg.f64 (*.f64 y y)))): 0 points increase in error, 0 points decrease in error
    (Rewrite<= fma-neg_binary64 (-.f64 (*.f64 x x) (*.f64 y y))): 1 points increase in error, 0 points decrease in error
    (Rewrite=> difference-of-squares_binary64 (*.f64 (+.f64 x y) (-.f64 x y))): 1 points increase in error, 0 points decrease in error
  3. Final simplification0.0

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

Alternatives

Alternative 1
Error14.0
Cost520
\[\begin{array}{l} t_0 := -y \cdot y\\ \mathbf{if}\;y \leq -1.16 \cdot 10^{+22}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 2.65 \cdot 10^{-53}:\\ \;\;\;\;x \cdot x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Error0.0
Cost448
\[\left(x + y\right) \cdot \left(x - y\right) \]
Alternative 3
Error0.0
Cost448
\[x \cdot x - y \cdot y \]
Alternative 4
Error27.8
Cost192
\[x \cdot x \]

Error

Reproduce

herbie shell --seed 2022325 
(FPCore (x y)
  :name "Examples.Basics.BasicTests:f1 from sbv-4.4"
  :precision binary64
  (* (+ x y) (- x y)))