?

Average Error: 37.9 → 11.8
Time: 3.3s
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 6.6 \cdot 10^{-29}:\\ \;\;\;\;-x\\ \mathbf{elif}\;z \leq 4.05 \cdot 10^{+49}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\ \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 6.6e-29)
   (- x)
   (if (<= z 4.05e+49) (sqrt (+ (+ (* x x) (* y y)) (* z z))) 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 <= 6.6e-29) {
		tmp = -x;
	} else if (z <= 4.05e+49) {
		tmp = sqrt((((x * x) + (y * y)) + (z * z)));
	} 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 <= 6.6d-29) then
        tmp = -x
    else if (z <= 4.05d+49) then
        tmp = sqrt((((x * x) + (y * y)) + (z * z)))
    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 <= 6.6e-29) {
		tmp = -x;
	} else if (z <= 4.05e+49) {
		tmp = Math.sqrt((((x * x) + (y * y)) + (z * z)));
	} 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 <= 6.6e-29:
		tmp = -x
	elif z <= 4.05e+49:
		tmp = math.sqrt((((x * x) + (y * y)) + (z * z)))
	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 <= 6.6e-29)
		tmp = Float64(-x);
	elseif (z <= 4.05e+49)
		tmp = sqrt(Float64(Float64(Float64(x * x) + Float64(y * y)) + Float64(z * z)));
	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 <= 6.6e-29)
		tmp = -x;
	elseif (z <= 4.05e+49)
		tmp = sqrt((((x * x) + (y * y)) + (z * z)));
	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, 6.6e-29], (-x), If[LessEqual[z, 4.05e+49], N[Sqrt[N[(N[(N[(x * x), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision] + N[(z * z), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], z]]
\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}
\begin{array}{l}
\mathbf{if}\;z \leq 6.6 \cdot 10^{-29}:\\
\;\;\;\;-x\\

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

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


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original37.9
Target19.5
Herbie11.8
\[\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 < 6.60000000000000055e-29

    1. Initial program 29.8

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

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

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

      [Start]7.9

      \[ -1 \cdot x \]

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

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

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

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

    if 6.60000000000000055e-29 < z < 4.04999999999999989e49

    1. Initial program 18.3

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

    if 4.04999999999999989e49 < z

    1. Initial program 48.4

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq 6.6 \cdot 10^{-29}:\\ \;\;\;\;-x\\ \mathbf{elif}\;z \leq 4.05 \cdot 10^{+49}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\ \mathbf{else}:\\ \;\;\;\;z\\ \end{array} \]

Alternatives

Alternative 1
Error12.8
Cost260
\[\begin{array}{l} \mathbf{if}\;x \leq -3.4 \cdot 10^{+58}:\\ \;\;\;\;-x\\ \mathbf{else}:\\ \;\;\;\;z\\ \end{array} \]
Alternative 2
Error31.5
Cost64
\[z \]

Error

Reproduce?

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