?

Average Accuracy: 40.8% → 99.3%
Time: 3.4s
Precision: binary64
Cost: 6528

?

\[ \begin{array}{c}[x, y, z] = \mathsf{sort}([x, y, z])\\ \end{array} \]
\[\sqrt{x \cdot x + \left(y \cdot y + z \cdot z\right)} \]
\[\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(x * x) + Float64(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[(x * x), $MachinePrecision] + N[(N[(y * y), $MachinePrecision] + N[(z * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
code[x_, y_, z_] := N[Sqrt[z ^ 2 + x ^ 2], $MachinePrecision]
\sqrt{x \cdot x + \left(y \cdot y + z \cdot z\right)}
\mathsf{hypot}\left(z, x\right)

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original40.8%
Target100.0%
Herbie99.3%
\[\mathsf{hypot}\left(x, \mathsf{hypot}\left(y, z\right)\right) \]

Derivation?

  1. Initial program 40.8%

    \[\sqrt{x \cdot x + \left(y \cdot y + z \cdot z\right)} \]
  2. Taylor expanded in y around 0 40.4%

    \[\leadsto \color{blue}{\sqrt{{z}^{2} + {x}^{2}}} \]
  3. Simplified99.3%

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

    [Start]40.4

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

    unpow2 [=>]40.4

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

    unpow2 [=>]40.4

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

    hypot-def [=>]99.3

    \[ \color{blue}{\mathsf{hypot}\left(z, x\right)} \]
  4. Final simplification99.3%

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

Alternatives

Alternative 1
Accuracy79.8%
Cost6924
\[\begin{array}{l} \mathbf{if}\;z \leq 1.7 \cdot 10^{-21}:\\ \;\;\;\;\mathsf{hypot}\left(y, x\right)\\ \mathbf{elif}\;z \leq 10000000:\\ \;\;\;\;z\\ \mathbf{elif}\;z \leq 8.2 \cdot 10^{+34}:\\ \;\;\;\;\mathsf{hypot}\left(y, x\right)\\ \mathbf{else}:\\ \;\;\;\;z\\ \end{array} \]
Alternative 2
Accuracy79.4%
Cost524
\[\begin{array}{l} \mathbf{if}\;z \leq 1.7 \cdot 10^{-21}:\\ \;\;\;\;-x\\ \mathbf{elif}\;z \leq 11000000:\\ \;\;\;\;z\\ \mathbf{elif}\;z \leq 7.5 \cdot 10^{+34}:\\ \;\;\;\;-x\\ \mathbf{else}:\\ \;\;\;\;z\\ \end{array} \]
Alternative 3
Accuracy52.4%
Cost64
\[z \]

Error

Reproduce?

herbie shell --seed 2023137 
(FPCore (x y z)
  :name "bug366 (missed optimization)"
  :precision binary64

  :herbie-target
  (hypot x (hypot y z))

  (sqrt (+ (* x x) (+ (* y y) (* z z)))))