Average Error: 37.4 → 0.4
Time: 7.3s
Precision: binary64
Cost: 6528
\[ \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

Target

Original37.4
Target18.6
Herbie0.4
\[\begin{array}{l} \mathbf{if}\;z < -6.396479394109776 \cdot 10^{+136}:\\ \;\;\;\;-z\\ \mathbf{elif}\;z < 7.320293694404182 \cdot 10^{+117}:\\ \;\;\;\;\sqrt{\left(z \cdot z + x \cdot x\right) + y \cdot y}\\ \mathbf{else}:\\ \;\;\;\;z\\ \end{array} \]

Derivation

  1. Initial program 37.4

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

    \[\leadsto \color{blue}{\sqrt{\mathsf{fma}\left(x, x, \mathsf{fma}\left(y, y, z \cdot z\right)\right)}} \]
    Proof
    (sqrt.f64 (fma.f64 x x (fma.f64 y y (*.f64 z z)))): 0 points increase in error, 0 points decrease in error
    (sqrt.f64 (fma.f64 x x (Rewrite<= fma-def_binary64 (+.f64 (*.f64 y y) (*.f64 z z))))): 0 points increase in error, 0 points decrease in error
    (sqrt.f64 (Rewrite<= fma-def_binary64 (+.f64 (*.f64 x x) (+.f64 (*.f64 y y) (*.f64 z z))))): 1 points increase in error, 0 points decrease in error
    (sqrt.f64 (Rewrite<= associate-+l+_binary64 (+.f64 (+.f64 (*.f64 x x) (*.f64 y y)) (*.f64 z z)))): 0 points increase in error, 0 points decrease in error
  3. Taylor expanded in y around 0 37.5

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

    \[\leadsto \color{blue}{\mathsf{hypot}\left(z, x\right)} \]
    Proof
    (hypot.f64 z x): 0 points increase in error, 0 points decrease in error
    (Rewrite<= hypot-def_binary64 (sqrt.f64 (+.f64 (*.f64 z z) (*.f64 x x)))): 149 points increase in error, 0 points decrease in error
    (sqrt.f64 (+.f64 (Rewrite<= unpow2_binary64 (pow.f64 z 2)) (*.f64 x x))): 0 points increase in error, 0 points decrease in error
    (sqrt.f64 (+.f64 (pow.f64 z 2) (Rewrite<= unpow2_binary64 (pow.f64 x 2)))): 0 points increase in error, 0 points decrease in error
  5. Final simplification0.4

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

Alternatives

Alternative 1
Error13.0
Cost1092
\[\begin{array}{l} \mathbf{if}\;x \leq -1.0928096931712628 \cdot 10^{+70}:\\ \;\;\;\;-0.5 \cdot \left(\frac{y}{\frac{x}{y}} + \frac{z}{\frac{x}{z}}\right) - x\\ \mathbf{elif}\;x \leq -5.349477531016157 \cdot 10^{+32}:\\ \;\;\;\;z\\ \mathbf{elif}\;x \leq -2.994381464941496 \cdot 10^{-28}:\\ \;\;\;\;-x\\ \mathbf{else}:\\ \;\;\;\;z\\ \end{array} \]
Alternative 2
Error13.1
Cost708
\[\begin{array}{l} \mathbf{if}\;x \leq -1.0928096931712628 \cdot 10^{+70}:\\ \;\;\;\;z \cdot \left(-0.5 \cdot \frac{z}{x}\right) - x\\ \mathbf{elif}\;x \leq -5.349477531016157 \cdot 10^{+32}:\\ \;\;\;\;z\\ \mathbf{elif}\;x \leq -2.994381464941496 \cdot 10^{-28}:\\ \;\;\;\;-x\\ \mathbf{else}:\\ \;\;\;\;z\\ \end{array} \]
Alternative 3
Error12.9
Cost708
\[\begin{array}{l} \mathbf{if}\;x \leq -1.0928096931712628 \cdot 10^{+70}:\\ \;\;\;\;-0.5 \cdot \left(y \cdot \frac{y}{x}\right) - x\\ \mathbf{elif}\;x \leq -5.349477531016157 \cdot 10^{+32}:\\ \;\;\;\;z\\ \mathbf{elif}\;x \leq -2.994381464941496 \cdot 10^{-28}:\\ \;\;\;\;-x\\ \mathbf{else}:\\ \;\;\;\;z\\ \end{array} \]
Alternative 4
Error13.0
Cost524
\[\begin{array}{l} \mathbf{if}\;x \leq -1.0928096931712628 \cdot 10^{+70}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \leq -5.349477531016157 \cdot 10^{+32}:\\ \;\;\;\;z\\ \mathbf{elif}\;x \leq -2.994381464941496 \cdot 10^{-28}:\\ \;\;\;\;-x\\ \mathbf{else}:\\ \;\;\;\;z\\ \end{array} \]
Alternative 5
Error30.6
Cost64
\[z \]

Error

Reproduce

herbie shell --seed 2022316 
(FPCore (x y z)
  :name "FRP.Yampa.Vector3:vector3Rho from Yampa-0.10.2"
  :precision binary64

  :herbie-target
  (if (< z -6.396479394109776e+136) (- z) (if (< z 7.320293694404182e+117) (sqrt (+ (+ (* z z) (* x x)) (* y y))) z))

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