?

Average Error: 38.4 → 13.1
Time: 5.9s
Precision: binary64
Cost: 8144

?

\[ \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}\;x \cdot x \leq 5 \cdot 10^{-58}:\\ \;\;\;\;z\\ \mathbf{elif}\;x \cdot x \leq 2 \cdot 10^{-38}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \cdot x \leq 6 \cdot 10^{+63}:\\ \;\;\;\;z\\ \mathbf{elif}\;x \cdot x \leq 5 \cdot 10^{+91}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\ \mathbf{elif}\;x \cdot x \leq 5 \cdot 10^{+104}:\\ \;\;\;\;z\\ \mathbf{else}:\\ \;\;\;\;-x\\ \end{array} \]
(FPCore (x y z) :precision binary64 (sqrt (+ (+ (* x x) (* y y)) (* z z))))
(FPCore (x y z)
 :precision binary64
 (if (<= (* x x) 5e-58)
   z
   (if (<= (* x x) 2e-38)
     (- x)
     (if (<= (* x x) 6e+63)
       z
       (if (<= (* x x) 5e+91)
         (sqrt (+ (+ (* x x) (* y y)) (* z z)))
         (if (<= (* x x) 5e+104) 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) {
	double tmp;
	if ((x * x) <= 5e-58) {
		tmp = z;
	} else if ((x * x) <= 2e-38) {
		tmp = -x;
	} else if ((x * x) <= 6e+63) {
		tmp = z;
	} else if ((x * x) <= 5e+91) {
		tmp = sqrt((((x * x) + (y * y)) + (z * z)));
	} else if ((x * x) <= 5e+104) {
		tmp = z;
	} else {
		tmp = -x;
	}
	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 ((x * x) <= 5d-58) then
        tmp = z
    else if ((x * x) <= 2d-38) then
        tmp = -x
    else if ((x * x) <= 6d+63) then
        tmp = z
    else if ((x * x) <= 5d+91) then
        tmp = sqrt((((x * x) + (y * y)) + (z * z)))
    else if ((x * x) <= 5d+104) then
        tmp = z
    else
        tmp = -x
    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 ((x * x) <= 5e-58) {
		tmp = z;
	} else if ((x * x) <= 2e-38) {
		tmp = -x;
	} else if ((x * x) <= 6e+63) {
		tmp = z;
	} else if ((x * x) <= 5e+91) {
		tmp = Math.sqrt((((x * x) + (y * y)) + (z * z)));
	} else if ((x * x) <= 5e+104) {
		tmp = z;
	} else {
		tmp = -x;
	}
	return tmp;
}
def code(x, y, z):
	return math.sqrt((((x * x) + (y * y)) + (z * z)))
def code(x, y, z):
	tmp = 0
	if (x * x) <= 5e-58:
		tmp = z
	elif (x * x) <= 2e-38:
		tmp = -x
	elif (x * x) <= 6e+63:
		tmp = z
	elif (x * x) <= 5e+91:
		tmp = math.sqrt((((x * x) + (y * y)) + (z * z)))
	elif (x * x) <= 5e+104:
		tmp = z
	else:
		tmp = -x
	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(x * x) <= 5e-58)
		tmp = z;
	elseif (Float64(x * x) <= 2e-38)
		tmp = Float64(-x);
	elseif (Float64(x * x) <= 6e+63)
		tmp = z;
	elseif (Float64(x * x) <= 5e+91)
		tmp = sqrt(Float64(Float64(Float64(x * x) + Float64(y * y)) + Float64(z * z)));
	elseif (Float64(x * x) <= 5e+104)
		tmp = z;
	else
		tmp = Float64(-x);
	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 ((x * x) <= 5e-58)
		tmp = z;
	elseif ((x * x) <= 2e-38)
		tmp = -x;
	elseif ((x * x) <= 6e+63)
		tmp = z;
	elseif ((x * x) <= 5e+91)
		tmp = sqrt((((x * x) + (y * y)) + (z * z)));
	elseif ((x * x) <= 5e+104)
		tmp = z;
	else
		tmp = -x;
	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[(x * x), $MachinePrecision], 5e-58], z, If[LessEqual[N[(x * x), $MachinePrecision], 2e-38], (-x), If[LessEqual[N[(x * x), $MachinePrecision], 6e+63], z, If[LessEqual[N[(x * x), $MachinePrecision], 5e+91], N[Sqrt[N[(N[(N[(x * x), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision] + N[(z * z), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], If[LessEqual[N[(x * x), $MachinePrecision], 5e+104], z, (-x)]]]]]
\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}
\begin{array}{l}
\mathbf{if}\;x \cdot x \leq 5 \cdot 10^{-58}:\\
\;\;\;\;z\\

\mathbf{elif}\;x \cdot x \leq 2 \cdot 10^{-38}:\\
\;\;\;\;-x\\

\mathbf{elif}\;x \cdot x \leq 6 \cdot 10^{+63}:\\
\;\;\;\;z\\

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

\mathbf{elif}\;x \cdot x \leq 5 \cdot 10^{+104}:\\
\;\;\;\;z\\

\mathbf{else}:\\
\;\;\;\;-x\\


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original38.4
Target20.3
Herbie13.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 x x) < 4.99999999999999977e-58 or 1.9999999999999999e-38 < (*.f64 x x) < 5.99999999999999998e63 or 5.0000000000000002e91 < (*.f64 x x) < 4.9999999999999997e104

    1. Initial program 27.1

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

      \[\leadsto \color{blue}{z} \]

    if 4.99999999999999977e-58 < (*.f64 x x) < 1.9999999999999999e-38 or 4.9999999999999997e104 < (*.f64 x x)

    1. Initial program 48.5

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

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

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

      [Start]14.1

      \[ -1 \cdot x \]

      rational_best-simplify-2 [=>]14.1

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

      rational_best-simplify-12 [=>]14.1

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

    if 5.99999999999999998e63 < (*.f64 x x) < 5.0000000000000002e91

    1. Initial program 18.7

      \[\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification13.1

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \cdot x \leq 5 \cdot 10^{-58}:\\ \;\;\;\;z\\ \mathbf{elif}\;x \cdot x \leq 2 \cdot 10^{-38}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \cdot x \leq 6 \cdot 10^{+63}:\\ \;\;\;\;z\\ \mathbf{elif}\;x \cdot x \leq 5 \cdot 10^{+91}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\ \mathbf{elif}\;x \cdot x \leq 5 \cdot 10^{+104}:\\ \;\;\;\;z\\ \mathbf{else}:\\ \;\;\;\;-x\\ \end{array} \]

Alternatives

Alternative 1
Error12.6
Cost524
\[\begin{array}{l} \mathbf{if}\;x \leq -8.5 \cdot 10^{+31}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \leq -1.3 \cdot 10^{-19}:\\ \;\;\;\;z\\ \mathbf{elif}\;x \leq -1.3 \cdot 10^{-28}:\\ \;\;\;\;-x\\ \mathbf{else}:\\ \;\;\;\;z\\ \end{array} \]
Alternative 2
Error31.7
Cost64
\[z \]

Error

Reproduce?

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