Average Error: 37.5 → 9.1
Time: 8.3s
Precision: binary64
Cost: 7568
\[\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z} \]
\[\begin{array}{l} \mathbf{if}\;z \cdot z \leq 5 \cdot 10^{-25}:\\ \;\;\;\;\mathsf{hypot}\left(y, x\right)\\ \mathbf{elif}\;z \cdot z \leq 10^{+57}:\\ \;\;\;\;\mathsf{hypot}\left(z, x\right)\\ \mathbf{elif}\;z \cdot z \leq 10^{+105}:\\ \;\;\;\;\mathsf{hypot}\left(z, y\right)\\ \mathbf{elif}\;z \cdot z \leq 10^{+291}:\\ \;\;\;\;\mathsf{hypot}\left(z, x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{hypot}\left(z, y\right)\\ \end{array} \]
(FPCore (x y z) :precision binary64 (sqrt (+ (+ (* x x) (* y y)) (* z z))))
(FPCore (x y z)
 :precision binary64
 (if (<= (* z z) 5e-25)
   (hypot y x)
   (if (<= (* z z) 1e+57)
     (hypot z x)
     (if (<= (* z z) 1e+105)
       (hypot z y)
       (if (<= (* z z) 1e+291) (hypot z x) (hypot z y))))))
double code(double x, double y, double z) {
	return sqrt((((x * x) + (y * y)) + (z * z)));
}
double code(double x, double y, double z) {
	double tmp;
	if ((z * z) <= 5e-25) {
		tmp = hypot(y, x);
	} else if ((z * z) <= 1e+57) {
		tmp = hypot(z, x);
	} else if ((z * z) <= 1e+105) {
		tmp = hypot(z, y);
	} else if ((z * z) <= 1e+291) {
		tmp = hypot(z, x);
	} else {
		tmp = hypot(z, y);
	}
	return tmp;
}
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) {
	double tmp;
	if ((z * z) <= 5e-25) {
		tmp = Math.hypot(y, x);
	} else if ((z * z) <= 1e+57) {
		tmp = Math.hypot(z, x);
	} else if ((z * z) <= 1e+105) {
		tmp = Math.hypot(z, y);
	} else if ((z * z) <= 1e+291) {
		tmp = Math.hypot(z, x);
	} else {
		tmp = Math.hypot(z, y);
	}
	return tmp;
}
def code(x, y, z):
	return math.sqrt((((x * x) + (y * y)) + (z * z)))
def code(x, y, z):
	tmp = 0
	if (z * z) <= 5e-25:
		tmp = math.hypot(y, x)
	elif (z * z) <= 1e+57:
		tmp = math.hypot(z, x)
	elif (z * z) <= 1e+105:
		tmp = math.hypot(z, y)
	elif (z * z) <= 1e+291:
		tmp = math.hypot(z, x)
	else:
		tmp = math.hypot(z, y)
	return tmp
function code(x, y, z)
	return sqrt(Float64(Float64(Float64(x * x) + Float64(y * y)) + Float64(z * z)))
end
function code(x, y, z)
	tmp = 0.0
	if (Float64(z * z) <= 5e-25)
		tmp = hypot(y, x);
	elseif (Float64(z * z) <= 1e+57)
		tmp = hypot(z, x);
	elseif (Float64(z * z) <= 1e+105)
		tmp = hypot(z, y);
	elseif (Float64(z * z) <= 1e+291)
		tmp = hypot(z, x);
	else
		tmp = hypot(z, y);
	end
	return tmp
end
function tmp = code(x, y, z)
	tmp = sqrt((((x * x) + (y * y)) + (z * z)));
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if ((z * z) <= 5e-25)
		tmp = hypot(y, x);
	elseif ((z * z) <= 1e+57)
		tmp = hypot(z, x);
	elseif ((z * z) <= 1e+105)
		tmp = hypot(z, y);
	elseif ((z * z) <= 1e+291)
		tmp = hypot(z, x);
	else
		tmp = hypot(z, y);
	end
	tmp_2 = tmp;
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_] := If[LessEqual[N[(z * z), $MachinePrecision], 5e-25], N[Sqrt[y ^ 2 + x ^ 2], $MachinePrecision], If[LessEqual[N[(z * z), $MachinePrecision], 1e+57], N[Sqrt[z ^ 2 + x ^ 2], $MachinePrecision], If[LessEqual[N[(z * z), $MachinePrecision], 1e+105], N[Sqrt[z ^ 2 + y ^ 2], $MachinePrecision], If[LessEqual[N[(z * z), $MachinePrecision], 1e+291], N[Sqrt[z ^ 2 + x ^ 2], $MachinePrecision], N[Sqrt[z ^ 2 + y ^ 2], $MachinePrecision]]]]]
\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}
\begin{array}{l}
\mathbf{if}\;z \cdot z \leq 5 \cdot 10^{-25}:\\
\;\;\;\;\mathsf{hypot}\left(y, x\right)\\

\mathbf{elif}\;z \cdot z \leq 10^{+57}:\\
\;\;\;\;\mathsf{hypot}\left(z, x\right)\\

\mathbf{elif}\;z \cdot z \leq 10^{+105}:\\
\;\;\;\;\mathsf{hypot}\left(z, y\right)\\

\mathbf{elif}\;z \cdot z \leq 10^{+291}:\\
\;\;\;\;\mathsf{hypot}\left(z, x\right)\\

\mathbf{else}:\\
\;\;\;\;\mathsf{hypot}\left(z, y\right)\\


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original37.5
Target25.7
Herbie9.1
\[\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. Split input into 3 regimes
  2. if (*.f64 z z) < 4.99999999999999962e-25

    1. Initial program 30.0

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

      \[\leadsto \color{blue}{\sqrt{{y}^{2} + {x}^{2}}} \]
    3. Simplified34.1

      \[\leadsto \color{blue}{\sqrt{\mathsf{fma}\left(x, x, y \cdot y\right)}} \]
      Proof
    4. Applied egg-rr5.0

      \[\leadsto \color{blue}{\sqrt{\mathsf{hypot}\left(x, y\right)} \cdot \sqrt{\mathsf{hypot}\left(x, y\right)}} \]
    5. Simplified4.6

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

    if 4.99999999999999962e-25 < (*.f64 z z) < 1.00000000000000005e57 or 9.9999999999999994e104 < (*.f64 z z) < 9.9999999999999996e290

    1. Initial program 26.9

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

      \[\leadsto \sqrt{\color{blue}{{x}^{2}} + z \cdot z} \]
    3. Simplified31.9

      \[\leadsto \sqrt{\color{blue}{x \cdot x} + z \cdot z} \]
      Proof
    4. Applied egg-rr18.8

      \[\leadsto \color{blue}{\sqrt{\mathsf{hypot}\left(x, z\right)} \cdot \sqrt{\mathsf{hypot}\left(x, z\right)}} \]
    5. Simplified18.5

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

    if 1.00000000000000005e57 < (*.f64 z z) < 9.9999999999999994e104 or 9.9999999999999996e290 < (*.f64 z z)

    1. Initial program 57.2

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

      \[\leadsto \sqrt{\color{blue}{{y}^{2}} + z \cdot z} \]
    3. Simplified58.4

      \[\leadsto \sqrt{\color{blue}{y \cdot y} + z \cdot z} \]
      Proof
    4. Applied egg-rr10.4

      \[\leadsto \color{blue}{\sqrt{\mathsf{hypot}\left(y, z\right)} \cdot \sqrt{\mathsf{hypot}\left(y, z\right)}} \]
    5. Simplified10.0

      \[\leadsto \color{blue}{\mathsf{hypot}\left(z, y\right)} \]
      Proof
  3. Recombined 3 regimes into one program.

Alternatives

Alternative 1
Error13.6
Cost7056
\[\begin{array}{l} \mathbf{if}\;z \leq -1.45 \cdot 10^{+168}:\\ \;\;\;\;-z\\ \mathbf{elif}\;z \leq -2.75 \cdot 10^{+73}:\\ \;\;\;\;\mathsf{hypot}\left(y, x\right)\\ \mathbf{elif}\;z \leq -4.8 \cdot 10^{+15}:\\ \;\;\;\;-z\\ \mathbf{elif}\;z \leq 1.65 \cdot 10^{+134}:\\ \;\;\;\;\mathsf{hypot}\left(y, x\right)\\ \mathbf{else}:\\ \;\;\;\;z\\ \end{array} \]
Alternative 2
Error8.5
Cost6792
\[\begin{array}{l} \mathbf{if}\;y \leq -4.9 \cdot 10^{+93}:\\ \;\;\;\;\mathsf{hypot}\left(y, x\right)\\ \mathbf{elif}\;y \leq 1.55 \cdot 10^{+52}:\\ \;\;\;\;\mathsf{hypot}\left(z, x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{hypot}\left(y, x\right)\\ \end{array} \]
Alternative 3
Error37.6
Cost1580
\[\begin{array}{l} \mathbf{if}\;z \leq -2.95 \cdot 10^{-8}:\\ \;\;\;\;-z\\ \mathbf{elif}\;z \leq -3 \cdot 10^{-82}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq -2.5 \cdot 10^{-108}:\\ \;\;\;\;y\\ \mathbf{elif}\;z \leq -1.05 \cdot 10^{-203}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq -1.16 \cdot 10^{-272}:\\ \;\;\;\;y\\ \mathbf{elif}\;z \leq 8 \cdot 10^{-203}:\\ \;\;\;\;-x\\ \mathbf{elif}\;z \leq 1.35 \cdot 10^{-137}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 4.8 \cdot 10^{-46}:\\ \;\;\;\;-y\\ \mathbf{elif}\;z \leq 3.9 \cdot 10^{-36}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 1.1 \cdot 10^{+30}:\\ \;\;\;\;-x\\ \mathbf{elif}\;z \leq 1.4 \cdot 10^{+58}:\\ \;\;\;\;-y\\ \mathbf{else}:\\ \;\;\;\;z\\ \end{array} \]
Alternative 4
Error36.7
Cost592
\[\begin{array}{l} \mathbf{if}\;x \leq -1.8:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \leq -7.2 \cdot 10^{-192}:\\ \;\;\;\;-y\\ \mathbf{elif}\;x \leq 9.4 \cdot 10^{-180}:\\ \;\;\;\;y\\ \mathbf{elif}\;x \leq 1.2 \cdot 10^{-80}:\\ \;\;\;\;z\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 5
Error36.5
Cost460
\[\begin{array}{l} \mathbf{if}\;x \leq -9.2 \cdot 10^{-31}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \leq 10^{-179}:\\ \;\;\;\;y\\ \mathbf{elif}\;x \leq 1.6 \cdot 10^{-78}:\\ \;\;\;\;z\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 6
Error44.2
Cost328
\[\begin{array}{l} \mathbf{if}\;x \leq 7.8 \cdot 10^{-180}:\\ \;\;\;\;y\\ \mathbf{elif}\;x \leq 3.4 \cdot 10^{-74}:\\ \;\;\;\;z\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 7
Error44.2
Cost196
\[\begin{array}{l} \mathbf{if}\;x \leq 5.6 \cdot 10^{-57}:\\ \;\;\;\;y\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 8
Error52.0
Cost64
\[x \]

Error

Reproduce

herbie shell --seed 2023010 
(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))))