?

Average Error: 0.0 → 0.0
Time: 6.1s
Precision: binary64
Cost: 13248

?

\[\left(\left(-1000 \leq x \land x \leq 1000\right) \land \left(-1000 \leq y \land y \leq 1000\right)\right) \land \left(-1000 \leq z \land z \leq 1000\right)\]
\[ \begin{array}{c}[x, y, z] = \mathsf{sort}([x, y, z])\\ \end{array} \]
\[\left(x \cdot x + y \cdot y\right) + z \cdot z \]
\[\mathsf{fma}\left(x, x, \mathsf{fma}\left(y, y, z \cdot z\right)\right) \]
(FPCore (x y z) :precision binary64 (+ (+ (* x x) (* y y)) (* z z)))
(FPCore (x y z) :precision binary64 (fma x x (fma y y (* z z))))
double code(double x, double y, double z) {
	return ((x * x) + (y * y)) + (z * z);
}
double code(double x, double y, double z) {
	return fma(x, x, fma(y, y, (z * z)));
}
function code(x, y, z)
	return Float64(Float64(Float64(x * x) + Float64(y * y)) + Float64(z * z))
end
function code(x, y, z)
	return fma(x, x, fma(y, y, Float64(z * z)))
end
code[x_, y_, z_] := N[(N[(N[(x * x), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision] + N[(z * z), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_] := N[(x * x + N[(y * y + N[(z * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\left(x \cdot x + y \cdot y\right) + z \cdot z
\mathsf{fma}\left(x, x, \mathsf{fma}\left(y, y, z \cdot z\right)\right)

Error?

Derivation?

  1. Initial program 0.0

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

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

    [Start]0.0

    \[ \left(x \cdot x + y \cdot y\right) + z \cdot z \]

    associate-+l+ [=>]0.0

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

    fma-def [=>]0.0

    \[ \color{blue}{\mathsf{fma}\left(x, x, y \cdot y + z \cdot z\right)} \]

    fma-def [=>]0.0

    \[ \mathsf{fma}\left(x, x, \color{blue}{\mathsf{fma}\left(y, y, z \cdot z\right)}\right) \]
  3. Final simplification0.0

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

Alternatives

Alternative 1
Error0.0
Cost6976
\[z \cdot z + \mathsf{fma}\left(x, x, y \cdot y\right) \]
Alternative 2
Error9.2
Cost845
\[\begin{array}{l} \mathbf{if}\;z \leq 3.7 \cdot 10^{-152} \lor \neg \left(z \leq 8.4 \cdot 10^{-141}\right) \land z \leq 1.8 \cdot 10^{-109}:\\ \;\;\;\;y \cdot y + x \cdot x\\ \mathbf{else}:\\ \;\;\;\;z \cdot z + y \cdot y\\ \end{array} \]
Alternative 3
Error0.0
Cost704
\[z \cdot z + \left(y \cdot y + x \cdot x\right) \]
Alternative 4
Error9.2
Cost580
\[\begin{array}{l} \mathbf{if}\;x \leq -2.65 \cdot 10^{-129}:\\ \;\;\;\;y \cdot y + x \cdot x\\ \mathbf{else}:\\ \;\;\;\;z \cdot z\\ \end{array} \]
Alternative 5
Error9.6
Cost324
\[\begin{array}{l} \mathbf{if}\;x \leq -2.7 \cdot 10^{-129}:\\ \;\;\;\;x \cdot x\\ \mathbf{else}:\\ \;\;\;\;z \cdot z\\ \end{array} \]
Alternative 6
Error27.7
Cost192
\[x \cdot x \]

Error

Reproduce?

herbie shell --seed 1 
(FPCore (x y z)
  :name "x*x+y*y+z*z"
  :precision binary64
  :pre (and (and (and (<= -1000.0 x) (<= x 1000.0)) (and (<= -1000.0 y) (<= y 1000.0))) (and (<= -1000.0 z) (<= z 1000.0)))
  (+ (+ (* x x) (* y y)) (* z z)))