?

Average Error: 7.3 → 1.0
Time: 7.9s
Precision: binary64
Cost: 6528

?

\[\left(\left(-10 \leq x \land x \leq 10\right) \land \left(-10 \leq y \land y \leq 10\right)\right) \land \left(-10 \leq z \land z \leq 10\right)\]
\[ \begin{array}{c}[x, y, z] = \mathsf{sort}([x, y, z])\\ \end{array} \]
\[\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z} \]
\[\mathsf{hypot}\left(z, x\right) \]
(FPCore (x y z) :precision binary64 (sqrt (+ (+ (* x x) (* y y)) (* z z))))
(FPCore (x y z) :precision binary64 (hypot z x))
double code(double x, double y, double z) {
	return sqrt((((x * x) + (y * y)) + (z * z)));
}
double code(double x, double y, double z) {
	return hypot(z, x);
}
public static double code(double x, double y, double z) {
	return Math.sqrt((((x * x) + (y * y)) + (z * z)));
}
public static double code(double x, double y, double z) {
	return Math.hypot(z, x);
}
def code(x, y, z):
	return math.sqrt((((x * x) + (y * y)) + (z * z)))
def code(x, y, z):
	return math.hypot(z, x)
function code(x, y, z)
	return sqrt(Float64(Float64(Float64(x * x) + Float64(y * y)) + Float64(z * z)))
end
function code(x, y, z)
	return hypot(z, x)
end
function tmp = code(x, y, z)
	tmp = sqrt((((x * x) + (y * y)) + (z * z)));
end
function tmp = code(x, y, z)
	tmp = hypot(z, x);
end
code[x_, y_, z_] := N[Sqrt[N[(N[(N[(x * x), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision] + N[(z * z), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
code[x_, y_, z_] := N[Sqrt[z ^ 2 + x ^ 2], $MachinePrecision]
\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}
\mathsf{hypot}\left(z, x\right)

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation?

  1. Initial program 7.3

    \[\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z} \]
  2. Simplified7.3

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

    [Start]7.3

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

    associate-+l+ [=>]7.3

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

    fma-def [=>]7.3

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

    fma-def [=>]7.3

    \[ \sqrt{\mathsf{fma}\left(x, x, \color{blue}{\mathsf{fma}\left(y, y, z \cdot z\right)}\right)} \]
  3. Taylor expanded in y around 0 8.1

    \[\leadsto \color{blue}{\sqrt{{z}^{2} + {x}^{2}}} \]
  4. Simplified1.0

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

    [Start]8.1

    \[ \sqrt{{z}^{2} + {x}^{2}} \]

    unpow2 [=>]8.1

    \[ \sqrt{\color{blue}{z \cdot z} + {x}^{2}} \]

    unpow2 [=>]8.1

    \[ \sqrt{z \cdot z + \color{blue}{x \cdot x}} \]

    hypot-def [=>]1.0

    \[ \color{blue}{\mathsf{hypot}\left(z, x\right)} \]
  5. Final simplification1.0

    \[\leadsto \mathsf{hypot}\left(z, x\right) \]

Alternatives

Alternative 1
Error12.3
Cost6660
\[\begin{array}{l} \mathbf{if}\;z \leq 6.2 \cdot 10^{-141}:\\ \;\;\;\;\mathsf{hypot}\left(y, x\right)\\ \mathbf{else}:\\ \;\;\;\;z + 0.5 \cdot \frac{y \cdot y}{z}\\ \end{array} \]
Alternative 2
Error12.9
Cost708
\[\begin{array}{l} \mathbf{if}\;z \leq 7.8 \cdot 10^{-141}:\\ \;\;\;\;-x\\ \mathbf{else}:\\ \;\;\;\;z + 0.5 \cdot \frac{y \cdot y}{z}\\ \end{array} \]
Alternative 3
Error12.7
Cost708
\[\begin{array}{l} \mathbf{if}\;z \leq 2 \cdot 10^{-140}:\\ \;\;\;\;\frac{y \cdot y}{x} \cdot -0.5 - x\\ \mathbf{else}:\\ \;\;\;\;z + 0.5 \cdot \frac{y \cdot y}{z}\\ \end{array} \]
Alternative 4
Error13.1
Cost260
\[\begin{array}{l} \mathbf{if}\;z \leq 1.2 \cdot 10^{-141}:\\ \;\;\;\;-x\\ \mathbf{else}:\\ \;\;\;\;z\\ \end{array} \]
Alternative 5
Error30.9
Cost64
\[z \]

Error

Reproduce?

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