?

Average Error: 37.7 → 14.5
Time: 7.6s
Precision: binary64
Cost: 7624

?

\[ \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 \cdot z \leq 2 \cdot 10^{-103}:\\ \;\;\;\;-x\\ \mathbf{elif}\;z \cdot z \leq 10^{+163}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\ \mathbf{elif}\;z \cdot z \leq 4 \cdot 10^{+284}:\\ \;\;\;\;-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 z) 2e-103)
   (- x)
   (if (<= (* z z) 1e+163)
     (sqrt (+ (+ (* x x) (* y y)) (* z z)))
     (if (<= (* z z) 4e+284) (- 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 * z) <= 2e-103) {
		tmp = -x;
	} else if ((z * z) <= 1e+163) {
		tmp = sqrt((((x * x) + (y * y)) + (z * z)));
	} else if ((z * z) <= 4e+284) {
		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 * z) <= 2d-103) then
        tmp = -x
    else if ((z * z) <= 1d+163) then
        tmp = sqrt((((x * x) + (y * y)) + (z * z)))
    else if ((z * z) <= 4d+284) 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 * z) <= 2e-103) {
		tmp = -x;
	} else if ((z * z) <= 1e+163) {
		tmp = Math.sqrt((((x * x) + (y * y)) + (z * z)));
	} else if ((z * z) <= 4e+284) {
		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 * z) <= 2e-103:
		tmp = -x
	elif (z * z) <= 1e+163:
		tmp = math.sqrt((((x * x) + (y * y)) + (z * z)))
	elif (z * z) <= 4e+284:
		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 (Float64(z * z) <= 2e-103)
		tmp = Float64(-x);
	elseif (Float64(z * z) <= 1e+163)
		tmp = sqrt(Float64(Float64(Float64(x * x) + Float64(y * y)) + Float64(z * z)));
	elseif (Float64(z * z) <= 4e+284)
		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 * z) <= 2e-103)
		tmp = -x;
	elseif ((z * z) <= 1e+163)
		tmp = sqrt((((x * x) + (y * y)) + (z * z)));
	elseif ((z * z) <= 4e+284)
		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[N[(z * z), $MachinePrecision], 2e-103], (-x), If[LessEqual[N[(z * z), $MachinePrecision], 1e+163], N[Sqrt[N[(N[(N[(x * x), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision] + N[(z * z), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], If[LessEqual[N[(z * z), $MachinePrecision], 4e+284], (-x), z]]]
\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}
\begin{array}{l}
\mathbf{if}\;z \cdot z \leq 2 \cdot 10^{-103}:\\
\;\;\;\;-x\\

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

\mathbf{elif}\;z \cdot z \leq 4 \cdot 10^{+284}:\\
\;\;\;\;-x\\

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


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original37.7
Target19.2
Herbie14.5
\[\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) < 1.99999999999999992e-103 or 9.9999999999999994e162 < (*.f64 z z) < 4.00000000000000032e284

    1. Initial program 26.4

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

      \[\leadsto \color{blue}{-1 \cdot x} \]
    3. Simplified15.8

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

      [Start]15.8

      \[ -1 \cdot x \]

      rational.json-simplify-2 [=>]15.8

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

      rational.json-simplify-9 [=>]15.8

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

    if 1.99999999999999992e-103 < (*.f64 z z) < 9.9999999999999994e162

    1. Initial program 21.5

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

    if 4.00000000000000032e284 < (*.f64 z z)

    1. Initial program 61.2

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \cdot z \leq 2 \cdot 10^{-103}:\\ \;\;\;\;-x\\ \mathbf{elif}\;z \cdot z \leq 10^{+163}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\ \mathbf{elif}\;z \cdot z \leq 4 \cdot 10^{+284}:\\ \;\;\;\;-x\\ \mathbf{else}:\\ \;\;\;\;z\\ \end{array} \]

Alternatives

Alternative 1
Error14.4
Cost524
\[\begin{array}{l} \mathbf{if}\;z \leq 7.2 \cdot 10^{-29}:\\ \;\;\;\;-x\\ \mathbf{elif}\;z \leq 3.1 \cdot 10^{+85}:\\ \;\;\;\;z\\ \mathbf{elif}\;z \leq 7.8 \cdot 10^{+126}:\\ \;\;\;\;-x\\ \mathbf{else}:\\ \;\;\;\;z\\ \end{array} \]
Alternative 2
Error30.7
Cost64
\[z \]

Error

Reproduce?

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