?

Average Error: 38.4 → 12.4
Time: 2.1s
Precision: binary64
Cost: 7368

?

\[ \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} \]
\[\begin{array}{l} \mathbf{if}\;z \leq 1.9 \cdot 10^{-32}:\\ \;\;\;\;-x\\ \mathbf{elif}\;z \leq 7200000000000:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\ \mathbf{elif}\;z \leq 1.8 \cdot 10^{+38}:\\ \;\;\;\;-x\\ \mathbf{else}:\\ \;\;\;\;z\\ \end{array} \]
(FPCore (x y z) :precision binary64 (sqrt (+ (+ (* x x) (* y y)) (* z z))))
(FPCore (x y z)
 :precision binary64
 (if (<= z 1.9e-32)
   (- x)
   (if (<= z 7200000000000.0)
     (sqrt (+ (+ (* x x) (* y y)) (* z z)))
     (if (<= z 1.8e+38) (- x) z))))
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 <= 1.9e-32) {
		tmp = -x;
	} else if (z <= 7200000000000.0) {
		tmp = sqrt((((x * x) + (y * y)) + (z * z)));
	} else if (z <= 1.8e+38) {
		tmp = -x;
	} else {
		tmp = z;
	}
	return tmp;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = sqrt((((x * x) + (y * y)) + (z * z)))
end function
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: tmp
    if (z <= 1.9d-32) then
        tmp = -x
    else if (z <= 7200000000000.0d0) then
        tmp = sqrt((((x * x) + (y * y)) + (z * z)))
    else if (z <= 1.8d+38) then
        tmp = -x
    else
        tmp = z
    end if
    code = tmp
end function
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 <= 1.9e-32) {
		tmp = -x;
	} else if (z <= 7200000000000.0) {
		tmp = Math.sqrt((((x * x) + (y * y)) + (z * z)));
	} else if (z <= 1.8e+38) {
		tmp = -x;
	} else {
		tmp = z;
	}
	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 <= 1.9e-32:
		tmp = -x
	elif z <= 7200000000000.0:
		tmp = math.sqrt((((x * x) + (y * y)) + (z * z)))
	elif z <= 1.8e+38:
		tmp = -x
	else:
		tmp = z
	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 (z <= 1.9e-32)
		tmp = Float64(-x);
	elseif (z <= 7200000000000.0)
		tmp = sqrt(Float64(Float64(Float64(x * x) + Float64(y * y)) + Float64(z * z)));
	elseif (z <= 1.8e+38)
		tmp = Float64(-x);
	else
		tmp = z;
	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 <= 1.9e-32)
		tmp = -x;
	elseif (z <= 7200000000000.0)
		tmp = sqrt((((x * x) + (y * y)) + (z * z)));
	elseif (z <= 1.8e+38)
		tmp = -x;
	else
		tmp = z;
	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[z, 1.9e-32], (-x), If[LessEqual[z, 7200000000000.0], N[Sqrt[N[(N[(N[(x * x), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision] + N[(z * z), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], If[LessEqual[z, 1.8e+38], (-x), z]]]
\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}
\begin{array}{l}
\mathbf{if}\;z \leq 1.9 \cdot 10^{-32}:\\
\;\;\;\;-x\\

\mathbf{elif}\;z \leq 7200000000000:\\
\;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\

\mathbf{elif}\;z \leq 1.8 \cdot 10^{+38}:\\
\;\;\;\;-x\\

\mathbf{else}:\\
\;\;\;\;z\\


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original38.4
Target19.9
Herbie12.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. Split input into 3 regimes
  2. if z < 1.90000000000000004e-32 or 7.2e12 < z < 1.79999999999999985e38

    1. Initial program 29.9

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

      \[\leadsto \color{blue}{-1 \cdot x} \]
    3. Simplified9.4

      \[\leadsto \color{blue}{-x} \]
      Proof

      [Start]9.4

      \[ -1 \cdot x \]

      rational_best_oopsla_all_46_json_45_simplify-74 [=>]9.4

      \[ \color{blue}{x \cdot -1} \]

      rational_best_oopsla_all_46_json_45_simplify-94 [<=]9.4

      \[ \color{blue}{-x} \]

    if 1.90000000000000004e-32 < z < 7.2e12

    1. Initial program 19.8

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

    if 1.79999999999999985e38 < z

    1. Initial program 47.2

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

      \[\leadsto \color{blue}{z} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification12.4

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq 1.9 \cdot 10^{-32}:\\ \;\;\;\;-x\\ \mathbf{elif}\;z \leq 7200000000000:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\ \mathbf{elif}\;z \leq 1.8 \cdot 10^{+38}:\\ \;\;\;\;-x\\ \mathbf{else}:\\ \;\;\;\;z\\ \end{array} \]

Alternatives

Alternative 1
Error13.2
Cost524
\[\begin{array}{l} \mathbf{if}\;z \leq 3.15 \cdot 10^{-24}:\\ \;\;\;\;-x\\ \mathbf{elif}\;z \leq 44000000000:\\ \;\;\;\;z\\ \mathbf{elif}\;z \leq 1.7 \cdot 10^{+38}:\\ \;\;\;\;-x\\ \mathbf{else}:\\ \;\;\;\;z\\ \end{array} \]
Alternative 2
Error31.4
Cost64
\[z \]

Error

Reproduce?

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