Data.Array.Repa.Algorithms.Pixel:doubleRmsOfRGB8 from repa-algorithms-3.4.0.1

Percentage Accurate: 44.9% → 99.4%
Time: 6.8s
Alternatives: 8
Speedup: 0.6×

Specification

?
\[\begin{array}{l} \\ \sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (sqrt (/ (+ (+ (* x x) (* y y)) (* z z)) 3.0)))
double code(double x, double y, double z) {
	return sqrt(((((x * x) + (y * y)) + (z * z)) / 3.0));
}
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)) / 3.0d0))
end function
public static double code(double x, double y, double z) {
	return Math.sqrt(((((x * x) + (y * y)) + (z * z)) / 3.0));
}
def code(x, y, z):
	return math.sqrt(((((x * x) + (y * y)) + (z * z)) / 3.0))
function code(x, y, z)
	return sqrt(Float64(Float64(Float64(Float64(x * x) + Float64(y * y)) + Float64(z * z)) / 3.0))
end
function tmp = code(x, y, z)
	tmp = sqrt(((((x * x) + (y * y)) + (z * z)) / 3.0));
end
code[x_, y_, z_] := N[Sqrt[N[(N[(N[(N[(x * x), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision] + N[(z * z), $MachinePrecision]), $MachinePrecision] / 3.0), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}

\\
\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}
\end{array}

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 8 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 44.9% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (sqrt (/ (+ (+ (* x x) (* y y)) (* z z)) 3.0)))
double code(double x, double y, double z) {
	return sqrt(((((x * x) + (y * y)) + (z * z)) / 3.0));
}
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)) / 3.0d0))
end function
public static double code(double x, double y, double z) {
	return Math.sqrt(((((x * x) + (y * y)) + (z * z)) / 3.0));
}
def code(x, y, z):
	return math.sqrt(((((x * x) + (y * y)) + (z * z)) / 3.0))
function code(x, y, z)
	return sqrt(Float64(Float64(Float64(Float64(x * x) + Float64(y * y)) + Float64(z * z)) / 3.0))
end
function tmp = code(x, y, z)
	tmp = sqrt(((((x * x) + (y * y)) + (z * z)) / 3.0));
end
code[x_, y_, z_] := N[Sqrt[N[(N[(N[(N[(x * x), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision] + N[(z * z), $MachinePrecision]), $MachinePrecision] / 3.0), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}

\\
\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}
\end{array}

Alternative 1: 99.4% accurate, 0.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \mathsf{hypot}\left(x, \mathsf{hypot}\left(z, y\right)\right)\\ \sqrt{t_0} \cdot \sqrt{t_0 \cdot 0.3333333333333333} \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (hypot x (hypot z y))))
   (* (sqrt t_0) (sqrt (* t_0 0.3333333333333333)))))
double code(double x, double y, double z) {
	double t_0 = hypot(x, hypot(z, y));
	return sqrt(t_0) * sqrt((t_0 * 0.3333333333333333));
}
public static double code(double x, double y, double z) {
	double t_0 = Math.hypot(x, Math.hypot(z, y));
	return Math.sqrt(t_0) * Math.sqrt((t_0 * 0.3333333333333333));
}
def code(x, y, z):
	t_0 = math.hypot(x, math.hypot(z, y))
	return math.sqrt(t_0) * math.sqrt((t_0 * 0.3333333333333333))
function code(x, y, z)
	t_0 = hypot(x, hypot(z, y))
	return Float64(sqrt(t_0) * sqrt(Float64(t_0 * 0.3333333333333333)))
end
function tmp = code(x, y, z)
	t_0 = hypot(x, hypot(z, y));
	tmp = sqrt(t_0) * sqrt((t_0 * 0.3333333333333333));
end
code[x_, y_, z_] := Block[{t$95$0 = N[Sqrt[x ^ 2 + N[Sqrt[z ^ 2 + y ^ 2], $MachinePrecision] ^ 2], $MachinePrecision]}, N[(N[Sqrt[t$95$0], $MachinePrecision] * N[Sqrt[N[(t$95$0 * 0.3333333333333333), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \mathsf{hypot}\left(x, \mathsf{hypot}\left(z, y\right)\right)\\
\sqrt{t_0} \cdot \sqrt{t_0 \cdot 0.3333333333333333}
\end{array}
\end{array}
Derivation
  1. Initial program 47.2%

    \[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}} \]
  2. Step-by-step derivation
    1. sqrt-div47.0%

      \[\leadsto \color{blue}{\frac{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}}{\sqrt{3}}} \]
    2. div-inv46.7%

      \[\leadsto \color{blue}{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z} \cdot \frac{1}{\sqrt{3}}} \]
    3. associate-+l+46.7%

      \[\leadsto \sqrt{\color{blue}{x \cdot x + \left(y \cdot y + z \cdot z\right)}} \cdot \frac{1}{\sqrt{3}} \]
    4. add-sqr-sqrt46.7%

      \[\leadsto \sqrt{x \cdot x + \color{blue}{\sqrt{y \cdot y + z \cdot z} \cdot \sqrt{y \cdot y + z \cdot z}}} \cdot \frac{1}{\sqrt{3}} \]
    5. hypot-def58.8%

      \[\leadsto \color{blue}{\mathsf{hypot}\left(x, \sqrt{y \cdot y + z \cdot z}\right)} \cdot \frac{1}{\sqrt{3}} \]
    6. hypot-def98.6%

      \[\leadsto \mathsf{hypot}\left(x, \color{blue}{\mathsf{hypot}\left(y, z\right)}\right) \cdot \frac{1}{\sqrt{3}} \]
  3. Applied egg-rr98.6%

    \[\leadsto \color{blue}{\mathsf{hypot}\left(x, \mathsf{hypot}\left(y, z\right)\right) \cdot \frac{1}{\sqrt{3}}} \]
  4. Step-by-step derivation
    1. associate-*r/99.4%

      \[\leadsto \color{blue}{\frac{\mathsf{hypot}\left(x, \mathsf{hypot}\left(y, z\right)\right) \cdot 1}{\sqrt{3}}} \]
    2. *-rgt-identity99.4%

      \[\leadsto \frac{\color{blue}{\mathsf{hypot}\left(x, \mathsf{hypot}\left(y, z\right)\right)}}{\sqrt{3}} \]
    3. hypot-def59.2%

      \[\leadsto \frac{\mathsf{hypot}\left(x, \color{blue}{\sqrt{y \cdot y + z \cdot z}}\right)}{\sqrt{3}} \]
    4. +-commutative59.2%

      \[\leadsto \frac{\mathsf{hypot}\left(x, \sqrt{\color{blue}{z \cdot z + y \cdot y}}\right)}{\sqrt{3}} \]
    5. hypot-def99.4%

      \[\leadsto \frac{\mathsf{hypot}\left(x, \color{blue}{\mathsf{hypot}\left(z, y\right)}\right)}{\sqrt{3}} \]
  5. Simplified99.4%

    \[\leadsto \color{blue}{\frac{\mathsf{hypot}\left(x, \mathsf{hypot}\left(z, y\right)\right)}{\sqrt{3}}} \]
  6. Step-by-step derivation
    1. div-inv98.6%

      \[\leadsto \color{blue}{\mathsf{hypot}\left(x, \mathsf{hypot}\left(z, y\right)\right) \cdot \frac{1}{\sqrt{3}}} \]
    2. add-sqr-sqrt98.6%

      \[\leadsto \color{blue}{\left(\sqrt{\mathsf{hypot}\left(x, \mathsf{hypot}\left(z, y\right)\right)} \cdot \sqrt{\mathsf{hypot}\left(x, \mathsf{hypot}\left(z, y\right)\right)}\right)} \cdot \frac{1}{\sqrt{3}} \]
    3. associate-*l*98.6%

      \[\leadsto \color{blue}{\sqrt{\mathsf{hypot}\left(x, \mathsf{hypot}\left(z, y\right)\right)} \cdot \left(\sqrt{\mathsf{hypot}\left(x, \mathsf{hypot}\left(z, y\right)\right)} \cdot \frac{1}{\sqrt{3}}\right)} \]
    4. pow1/298.6%

      \[\leadsto \sqrt{\mathsf{hypot}\left(x, \mathsf{hypot}\left(z, y\right)\right)} \cdot \left(\sqrt{\mathsf{hypot}\left(x, \mathsf{hypot}\left(z, y\right)\right)} \cdot \frac{1}{\color{blue}{{3}^{0.5}}}\right) \]
    5. pow-flip99.1%

      \[\leadsto \sqrt{\mathsf{hypot}\left(x, \mathsf{hypot}\left(z, y\right)\right)} \cdot \left(\sqrt{\mathsf{hypot}\left(x, \mathsf{hypot}\left(z, y\right)\right)} \cdot \color{blue}{{3}^{\left(-0.5\right)}}\right) \]
    6. metadata-eval99.1%

      \[\leadsto \sqrt{\mathsf{hypot}\left(x, \mathsf{hypot}\left(z, y\right)\right)} \cdot \left(\sqrt{\mathsf{hypot}\left(x, \mathsf{hypot}\left(z, y\right)\right)} \cdot {3}^{\color{blue}{-0.5}}\right) \]
  7. Applied egg-rr99.1%

    \[\leadsto \color{blue}{\sqrt{\mathsf{hypot}\left(x, \mathsf{hypot}\left(z, y\right)\right)} \cdot \left(\sqrt{\mathsf{hypot}\left(x, \mathsf{hypot}\left(z, y\right)\right)} \cdot {3}^{-0.5}\right)} \]
  8. Step-by-step derivation
    1. add-sqr-sqrt98.8%

      \[\leadsto \sqrt{\mathsf{hypot}\left(x, \mathsf{hypot}\left(z, y\right)\right)} \cdot \color{blue}{\left(\sqrt{\sqrt{\mathsf{hypot}\left(x, \mathsf{hypot}\left(z, y\right)\right)} \cdot {3}^{-0.5}} \cdot \sqrt{\sqrt{\mathsf{hypot}\left(x, \mathsf{hypot}\left(z, y\right)\right)} \cdot {3}^{-0.5}}\right)} \]
    2. sqrt-unprod99.1%

      \[\leadsto \sqrt{\mathsf{hypot}\left(x, \mathsf{hypot}\left(z, y\right)\right)} \cdot \color{blue}{\sqrt{\left(\sqrt{\mathsf{hypot}\left(x, \mathsf{hypot}\left(z, y\right)\right)} \cdot {3}^{-0.5}\right) \cdot \left(\sqrt{\mathsf{hypot}\left(x, \mathsf{hypot}\left(z, y\right)\right)} \cdot {3}^{-0.5}\right)}} \]
    3. swap-sqr99.1%

      \[\leadsto \sqrt{\mathsf{hypot}\left(x, \mathsf{hypot}\left(z, y\right)\right)} \cdot \sqrt{\color{blue}{\left(\sqrt{\mathsf{hypot}\left(x, \mathsf{hypot}\left(z, y\right)\right)} \cdot \sqrt{\mathsf{hypot}\left(x, \mathsf{hypot}\left(z, y\right)\right)}\right) \cdot \left({3}^{-0.5} \cdot {3}^{-0.5}\right)}} \]
    4. add-sqr-sqrt99.4%

      \[\leadsto \sqrt{\mathsf{hypot}\left(x, \mathsf{hypot}\left(z, y\right)\right)} \cdot \sqrt{\color{blue}{\mathsf{hypot}\left(x, \mathsf{hypot}\left(z, y\right)\right)} \cdot \left({3}^{-0.5} \cdot {3}^{-0.5}\right)} \]
    5. pow-prod-up99.4%

      \[\leadsto \sqrt{\mathsf{hypot}\left(x, \mathsf{hypot}\left(z, y\right)\right)} \cdot \sqrt{\mathsf{hypot}\left(x, \mathsf{hypot}\left(z, y\right)\right) \cdot \color{blue}{{3}^{\left(-0.5 + -0.5\right)}}} \]
    6. metadata-eval99.4%

      \[\leadsto \sqrt{\mathsf{hypot}\left(x, \mathsf{hypot}\left(z, y\right)\right)} \cdot \sqrt{\mathsf{hypot}\left(x, \mathsf{hypot}\left(z, y\right)\right) \cdot {3}^{\color{blue}{-1}}} \]
    7. metadata-eval99.4%

      \[\leadsto \sqrt{\mathsf{hypot}\left(x, \mathsf{hypot}\left(z, y\right)\right)} \cdot \sqrt{\mathsf{hypot}\left(x, \mathsf{hypot}\left(z, y\right)\right) \cdot \color{blue}{0.3333333333333333}} \]
  9. Applied egg-rr99.4%

    \[\leadsto \sqrt{\mathsf{hypot}\left(x, \mathsf{hypot}\left(z, y\right)\right)} \cdot \color{blue}{\sqrt{\mathsf{hypot}\left(x, \mathsf{hypot}\left(z, y\right)\right) \cdot 0.3333333333333333}} \]
  10. Final simplification99.4%

    \[\leadsto \sqrt{\mathsf{hypot}\left(x, \mathsf{hypot}\left(z, y\right)\right)} \cdot \sqrt{\mathsf{hypot}\left(x, \mathsf{hypot}\left(z, y\right)\right) \cdot 0.3333333333333333} \]

Alternative 2: 99.4% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \frac{\mathsf{hypot}\left(x, \mathsf{hypot}\left(z, y\right)\right)}{\sqrt{3}} \end{array} \]
(FPCore (x y z) :precision binary64 (/ (hypot x (hypot z y)) (sqrt 3.0)))
double code(double x, double y, double z) {
	return hypot(x, hypot(z, y)) / sqrt(3.0);
}
public static double code(double x, double y, double z) {
	return Math.hypot(x, Math.hypot(z, y)) / Math.sqrt(3.0);
}
def code(x, y, z):
	return math.hypot(x, math.hypot(z, y)) / math.sqrt(3.0)
function code(x, y, z)
	return Float64(hypot(x, hypot(z, y)) / sqrt(3.0))
end
function tmp = code(x, y, z)
	tmp = hypot(x, hypot(z, y)) / sqrt(3.0);
end
code[x_, y_, z_] := N[(N[Sqrt[x ^ 2 + N[Sqrt[z ^ 2 + y ^ 2], $MachinePrecision] ^ 2], $MachinePrecision] / N[Sqrt[3.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{\mathsf{hypot}\left(x, \mathsf{hypot}\left(z, y\right)\right)}{\sqrt{3}}
\end{array}
Derivation
  1. Initial program 47.2%

    \[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}} \]
  2. Step-by-step derivation
    1. sqrt-div47.0%

      \[\leadsto \color{blue}{\frac{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}}{\sqrt{3}}} \]
    2. div-inv46.7%

      \[\leadsto \color{blue}{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z} \cdot \frac{1}{\sqrt{3}}} \]
    3. associate-+l+46.7%

      \[\leadsto \sqrt{\color{blue}{x \cdot x + \left(y \cdot y + z \cdot z\right)}} \cdot \frac{1}{\sqrt{3}} \]
    4. add-sqr-sqrt46.7%

      \[\leadsto \sqrt{x \cdot x + \color{blue}{\sqrt{y \cdot y + z \cdot z} \cdot \sqrt{y \cdot y + z \cdot z}}} \cdot \frac{1}{\sqrt{3}} \]
    5. hypot-def58.8%

      \[\leadsto \color{blue}{\mathsf{hypot}\left(x, \sqrt{y \cdot y + z \cdot z}\right)} \cdot \frac{1}{\sqrt{3}} \]
    6. hypot-def98.6%

      \[\leadsto \mathsf{hypot}\left(x, \color{blue}{\mathsf{hypot}\left(y, z\right)}\right) \cdot \frac{1}{\sqrt{3}} \]
  3. Applied egg-rr98.6%

    \[\leadsto \color{blue}{\mathsf{hypot}\left(x, \mathsf{hypot}\left(y, z\right)\right) \cdot \frac{1}{\sqrt{3}}} \]
  4. Step-by-step derivation
    1. associate-*r/99.4%

      \[\leadsto \color{blue}{\frac{\mathsf{hypot}\left(x, \mathsf{hypot}\left(y, z\right)\right) \cdot 1}{\sqrt{3}}} \]
    2. *-rgt-identity99.4%

      \[\leadsto \frac{\color{blue}{\mathsf{hypot}\left(x, \mathsf{hypot}\left(y, z\right)\right)}}{\sqrt{3}} \]
    3. hypot-def59.2%

      \[\leadsto \frac{\mathsf{hypot}\left(x, \color{blue}{\sqrt{y \cdot y + z \cdot z}}\right)}{\sqrt{3}} \]
    4. +-commutative59.2%

      \[\leadsto \frac{\mathsf{hypot}\left(x, \sqrt{\color{blue}{z \cdot z + y \cdot y}}\right)}{\sqrt{3}} \]
    5. hypot-def99.4%

      \[\leadsto \frac{\mathsf{hypot}\left(x, \color{blue}{\mathsf{hypot}\left(z, y\right)}\right)}{\sqrt{3}} \]
  5. Simplified99.4%

    \[\leadsto \color{blue}{\frac{\mathsf{hypot}\left(x, \mathsf{hypot}\left(z, y\right)\right)}{\sqrt{3}}} \]
  6. Final simplification99.4%

    \[\leadsto \frac{\mathsf{hypot}\left(x, \mathsf{hypot}\left(z, y\right)\right)}{\sqrt{3}} \]

Alternative 3: 32.5% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -1.16 \cdot 10^{+154}:\\ \;\;\;\;\sqrt{0.3333333333333333} \cdot \mathsf{hypot}\left(y, x\right)\\ \mathbf{elif}\;x \leq -3.8 \cdot 10^{+30}:\\ \;\;\;\;\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\\ \mathbf{else}:\\ \;\;\;\;z \cdot \sqrt{0.3333333333333333}\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= x -1.16e+154)
   (* (sqrt 0.3333333333333333) (hypot y x))
   (if (<= x -3.8e+30)
     (sqrt (/ (+ (+ (* x x) (* y y)) (* z z)) 3.0))
     (* z (sqrt 0.3333333333333333)))))
double code(double x, double y, double z) {
	double tmp;
	if (x <= -1.16e+154) {
		tmp = sqrt(0.3333333333333333) * hypot(y, x);
	} else if (x <= -3.8e+30) {
		tmp = sqrt(((((x * x) + (y * y)) + (z * z)) / 3.0));
	} else {
		tmp = z * sqrt(0.3333333333333333);
	}
	return tmp;
}
public static double code(double x, double y, double z) {
	double tmp;
	if (x <= -1.16e+154) {
		tmp = Math.sqrt(0.3333333333333333) * Math.hypot(y, x);
	} else if (x <= -3.8e+30) {
		tmp = Math.sqrt(((((x * x) + (y * y)) + (z * z)) / 3.0));
	} else {
		tmp = z * Math.sqrt(0.3333333333333333);
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if x <= -1.16e+154:
		tmp = math.sqrt(0.3333333333333333) * math.hypot(y, x)
	elif x <= -3.8e+30:
		tmp = math.sqrt(((((x * x) + (y * y)) + (z * z)) / 3.0))
	else:
		tmp = z * math.sqrt(0.3333333333333333)
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (x <= -1.16e+154)
		tmp = Float64(sqrt(0.3333333333333333) * hypot(y, x));
	elseif (x <= -3.8e+30)
		tmp = sqrt(Float64(Float64(Float64(Float64(x * x) + Float64(y * y)) + Float64(z * z)) / 3.0));
	else
		tmp = Float64(z * sqrt(0.3333333333333333));
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (x <= -1.16e+154)
		tmp = sqrt(0.3333333333333333) * hypot(y, x);
	elseif (x <= -3.8e+30)
		tmp = sqrt(((((x * x) + (y * y)) + (z * z)) / 3.0));
	else
		tmp = z * sqrt(0.3333333333333333);
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[x, -1.16e+154], N[(N[Sqrt[0.3333333333333333], $MachinePrecision] * N[Sqrt[y ^ 2 + x ^ 2], $MachinePrecision]), $MachinePrecision], If[LessEqual[x, -3.8e+30], N[Sqrt[N[(N[(N[(N[(x * x), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision] + N[(z * z), $MachinePrecision]), $MachinePrecision] / 3.0), $MachinePrecision]], $MachinePrecision], N[(z * N[Sqrt[0.3333333333333333], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.16 \cdot 10^{+154}:\\
\;\;\;\;\sqrt{0.3333333333333333} \cdot \mathsf{hypot}\left(y, x\right)\\

\mathbf{elif}\;x \leq -3.8 \cdot 10^{+30}:\\
\;\;\;\;\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\\

\mathbf{else}:\\
\;\;\;\;z \cdot \sqrt{0.3333333333333333}\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < -1.16000000000000001e154

    1. Initial program 7.3%

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

      \[\leadsto \color{blue}{\sqrt{{y}^{2} + {x}^{2}} \cdot \sqrt{0.3333333333333333}} \]
    3. Step-by-step derivation
      1. *-commutative7.3%

        \[\leadsto \color{blue}{\sqrt{0.3333333333333333} \cdot \sqrt{{y}^{2} + {x}^{2}}} \]
      2. unpow27.3%

        \[\leadsto \sqrt{0.3333333333333333} \cdot \sqrt{\color{blue}{y \cdot y} + {x}^{2}} \]
      3. unpow27.3%

        \[\leadsto \sqrt{0.3333333333333333} \cdot \sqrt{y \cdot y + \color{blue}{x \cdot x}} \]
      4. hypot-def80.7%

        \[\leadsto \sqrt{0.3333333333333333} \cdot \color{blue}{\mathsf{hypot}\left(y, x\right)} \]
    4. Simplified80.7%

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

    if -1.16000000000000001e154 < x < -3.8000000000000001e30

    1. Initial program 77.8%

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

    if -3.8000000000000001e30 < x

    1. Initial program 50.1%

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

      \[\leadsto \color{blue}{z \cdot \sqrt{0.3333333333333333}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification36.6%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -1.16 \cdot 10^{+154}:\\ \;\;\;\;\sqrt{0.3333333333333333} \cdot \mathsf{hypot}\left(y, x\right)\\ \mathbf{elif}\;x \leq -3.8 \cdot 10^{+30}:\\ \;\;\;\;\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\\ \mathbf{else}:\\ \;\;\;\;z \cdot \sqrt{0.3333333333333333}\\ \end{array} \]

Alternative 4: 67.6% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \sqrt{0.3333333333333333} \cdot \mathsf{hypot}\left(z, x\right) \end{array} \]
(FPCore (x y z) :precision binary64 (* (sqrt 0.3333333333333333) (hypot z x)))
double code(double x, double y, double z) {
	return sqrt(0.3333333333333333) * hypot(z, x);
}
public static double code(double x, double y, double z) {
	return Math.sqrt(0.3333333333333333) * Math.hypot(z, x);
}
def code(x, y, z):
	return math.sqrt(0.3333333333333333) * math.hypot(z, x)
function code(x, y, z)
	return Float64(sqrt(0.3333333333333333) * hypot(z, x))
end
function tmp = code(x, y, z)
	tmp = sqrt(0.3333333333333333) * hypot(z, x);
end
code[x_, y_, z_] := N[(N[Sqrt[0.3333333333333333], $MachinePrecision] * N[Sqrt[z ^ 2 + x ^ 2], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\sqrt{0.3333333333333333} \cdot \mathsf{hypot}\left(z, x\right)
\end{array}
Derivation
  1. Initial program 47.2%

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

    \[\leadsto \color{blue}{\sqrt{{z}^{2} + {x}^{2}} \cdot \sqrt{0.3333333333333333}} \]
  3. Step-by-step derivation
    1. *-commutative34.4%

      \[\leadsto \color{blue}{\sqrt{0.3333333333333333} \cdot \sqrt{{z}^{2} + {x}^{2}}} \]
    2. unpow234.4%

      \[\leadsto \sqrt{0.3333333333333333} \cdot \sqrt{\color{blue}{z \cdot z} + {x}^{2}} \]
    3. unpow234.4%

      \[\leadsto \sqrt{0.3333333333333333} \cdot \sqrt{z \cdot z + \color{blue}{x \cdot x}} \]
    4. hypot-def68.3%

      \[\leadsto \sqrt{0.3333333333333333} \cdot \color{blue}{\mathsf{hypot}\left(z, x\right)} \]
  4. Simplified68.3%

    \[\leadsto \color{blue}{\sqrt{0.3333333333333333} \cdot \mathsf{hypot}\left(z, x\right)} \]
  5. Final simplification68.3%

    \[\leadsto \sqrt{0.3333333333333333} \cdot \mathsf{hypot}\left(z, x\right) \]

Alternative 5: 31.2% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -1.3 \cdot 10^{+154}:\\ \;\;\;\;\frac{-x}{\sqrt{3}}\\ \mathbf{elif}\;x \leq -7.6 \cdot 10^{+30}:\\ \;\;\;\;\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\\ \mathbf{else}:\\ \;\;\;\;z \cdot \sqrt{0.3333333333333333}\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= x -1.3e+154)
   (/ (- x) (sqrt 3.0))
   (if (<= x -7.6e+30)
     (sqrt (/ (+ (+ (* x x) (* y y)) (* z z)) 3.0))
     (* z (sqrt 0.3333333333333333)))))
double code(double x, double y, double z) {
	double tmp;
	if (x <= -1.3e+154) {
		tmp = -x / sqrt(3.0);
	} else if (x <= -7.6e+30) {
		tmp = sqrt(((((x * x) + (y * y)) + (z * z)) / 3.0));
	} else {
		tmp = z * sqrt(0.3333333333333333);
	}
	return tmp;
}
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 <= (-1.3d+154)) then
        tmp = -x / sqrt(3.0d0)
    else if (x <= (-7.6d+30)) then
        tmp = sqrt(((((x * x) + (y * y)) + (z * z)) / 3.0d0))
    else
        tmp = z * sqrt(0.3333333333333333d0)
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if (x <= -1.3e+154) {
		tmp = -x / Math.sqrt(3.0);
	} else if (x <= -7.6e+30) {
		tmp = Math.sqrt(((((x * x) + (y * y)) + (z * z)) / 3.0));
	} else {
		tmp = z * Math.sqrt(0.3333333333333333);
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if x <= -1.3e+154:
		tmp = -x / math.sqrt(3.0)
	elif x <= -7.6e+30:
		tmp = math.sqrt(((((x * x) + (y * y)) + (z * z)) / 3.0))
	else:
		tmp = z * math.sqrt(0.3333333333333333)
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (x <= -1.3e+154)
		tmp = Float64(Float64(-x) / sqrt(3.0));
	elseif (x <= -7.6e+30)
		tmp = sqrt(Float64(Float64(Float64(Float64(x * x) + Float64(y * y)) + Float64(z * z)) / 3.0));
	else
		tmp = Float64(z * sqrt(0.3333333333333333));
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (x <= -1.3e+154)
		tmp = -x / sqrt(3.0);
	elseif (x <= -7.6e+30)
		tmp = sqrt(((((x * x) + (y * y)) + (z * z)) / 3.0));
	else
		tmp = z * sqrt(0.3333333333333333);
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[x, -1.3e+154], N[((-x) / N[Sqrt[3.0], $MachinePrecision]), $MachinePrecision], If[LessEqual[x, -7.6e+30], N[Sqrt[N[(N[(N[(N[(x * x), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision] + N[(z * z), $MachinePrecision]), $MachinePrecision] / 3.0), $MachinePrecision]], $MachinePrecision], N[(z * N[Sqrt[0.3333333333333333], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.3 \cdot 10^{+154}:\\
\;\;\;\;\frac{-x}{\sqrt{3}}\\

\mathbf{elif}\;x \leq -7.6 \cdot 10^{+30}:\\
\;\;\;\;\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\\

\mathbf{else}:\\
\;\;\;\;z \cdot \sqrt{0.3333333333333333}\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < -1.29999999999999994e154

    1. Initial program 7.3%

      \[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}} \]
    2. Step-by-step derivation
      1. sqrt-div7.3%

        \[\leadsto \color{blue}{\frac{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}}{\sqrt{3}}} \]
      2. div-inv7.3%

        \[\leadsto \color{blue}{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z} \cdot \frac{1}{\sqrt{3}}} \]
      3. associate-+l+7.3%

        \[\leadsto \sqrt{\color{blue}{x \cdot x + \left(y \cdot y + z \cdot z\right)}} \cdot \frac{1}{\sqrt{3}} \]
      4. add-sqr-sqrt7.3%

        \[\leadsto \sqrt{x \cdot x + \color{blue}{\sqrt{y \cdot y + z \cdot z} \cdot \sqrt{y \cdot y + z \cdot z}}} \cdot \frac{1}{\sqrt{3}} \]
      5. hypot-def60.6%

        \[\leadsto \color{blue}{\mathsf{hypot}\left(x, \sqrt{y \cdot y + z \cdot z}\right)} \cdot \frac{1}{\sqrt{3}} \]
      6. hypot-def98.5%

        \[\leadsto \mathsf{hypot}\left(x, \color{blue}{\mathsf{hypot}\left(y, z\right)}\right) \cdot \frac{1}{\sqrt{3}} \]
    3. Applied egg-rr98.5%

      \[\leadsto \color{blue}{\mathsf{hypot}\left(x, \mathsf{hypot}\left(y, z\right)\right) \cdot \frac{1}{\sqrt{3}}} \]
    4. Step-by-step derivation
      1. associate-*r/99.5%

        \[\leadsto \color{blue}{\frac{\mathsf{hypot}\left(x, \mathsf{hypot}\left(y, z\right)\right) \cdot 1}{\sqrt{3}}} \]
      2. *-rgt-identity99.5%

        \[\leadsto \frac{\color{blue}{\mathsf{hypot}\left(x, \mathsf{hypot}\left(y, z\right)\right)}}{\sqrt{3}} \]
      3. hypot-def61.2%

        \[\leadsto \frac{\mathsf{hypot}\left(x, \color{blue}{\sqrt{y \cdot y + z \cdot z}}\right)}{\sqrt{3}} \]
      4. +-commutative61.2%

        \[\leadsto \frac{\mathsf{hypot}\left(x, \sqrt{\color{blue}{z \cdot z + y \cdot y}}\right)}{\sqrt{3}} \]
      5. hypot-def99.5%

        \[\leadsto \frac{\mathsf{hypot}\left(x, \color{blue}{\mathsf{hypot}\left(z, y\right)}\right)}{\sqrt{3}} \]
    5. Simplified99.5%

      \[\leadsto \color{blue}{\frac{\mathsf{hypot}\left(x, \mathsf{hypot}\left(z, y\right)\right)}{\sqrt{3}}} \]
    6. Taylor expanded in x around -inf 80.9%

      \[\leadsto \color{blue}{-1 \cdot \frac{x}{\sqrt{3}}} \]
    7. Step-by-step derivation
      1. associate-*r/80.9%

        \[\leadsto \color{blue}{\frac{-1 \cdot x}{\sqrt{3}}} \]
      2. neg-mul-180.9%

        \[\leadsto \frac{\color{blue}{-x}}{\sqrt{3}} \]
    8. Simplified80.9%

      \[\leadsto \color{blue}{\frac{-x}{\sqrt{3}}} \]

    if -1.29999999999999994e154 < x < -7.6000000000000003e30

    1. Initial program 77.8%

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

    if -7.6000000000000003e30 < x

    1. Initial program 50.1%

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

      \[\leadsto \color{blue}{z \cdot \sqrt{0.3333333333333333}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification36.6%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -1.3 \cdot 10^{+154}:\\ \;\;\;\;\frac{-x}{\sqrt{3}}\\ \mathbf{elif}\;x \leq -7.6 \cdot 10^{+30}:\\ \;\;\;\;\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\\ \mathbf{else}:\\ \;\;\;\;z \cdot \sqrt{0.3333333333333333}\\ \end{array} \]

Alternative 6: 29.8% accurate, 1.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -3.2 \cdot 10^{+31}:\\ \;\;\;\;x \cdot \left(-\sqrt{0.3333333333333333}\right)\\ \mathbf{else}:\\ \;\;\;\;z \cdot \sqrt{0.3333333333333333}\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= x -3.2e+31)
   (* x (- (sqrt 0.3333333333333333)))
   (* z (sqrt 0.3333333333333333))))
double code(double x, double y, double z) {
	double tmp;
	if (x <= -3.2e+31) {
		tmp = x * -sqrt(0.3333333333333333);
	} else {
		tmp = z * sqrt(0.3333333333333333);
	}
	return tmp;
}
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 <= (-3.2d+31)) then
        tmp = x * -sqrt(0.3333333333333333d0)
    else
        tmp = z * sqrt(0.3333333333333333d0)
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if (x <= -3.2e+31) {
		tmp = x * -Math.sqrt(0.3333333333333333);
	} else {
		tmp = z * Math.sqrt(0.3333333333333333);
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if x <= -3.2e+31:
		tmp = x * -math.sqrt(0.3333333333333333)
	else:
		tmp = z * math.sqrt(0.3333333333333333)
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (x <= -3.2e+31)
		tmp = Float64(x * Float64(-sqrt(0.3333333333333333)));
	else
		tmp = Float64(z * sqrt(0.3333333333333333));
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (x <= -3.2e+31)
		tmp = x * -sqrt(0.3333333333333333);
	else
		tmp = z * sqrt(0.3333333333333333);
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[x, -3.2e+31], N[(x * (-N[Sqrt[0.3333333333333333], $MachinePrecision])), $MachinePrecision], N[(z * N[Sqrt[0.3333333333333333], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.2 \cdot 10^{+31}:\\
\;\;\;\;x \cdot \left(-\sqrt{0.3333333333333333}\right)\\

\mathbf{else}:\\
\;\;\;\;z \cdot \sqrt{0.3333333333333333}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -3.2000000000000001e31

    1. Initial program 35.7%

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

      \[\leadsto \color{blue}{-1 \cdot \left(\sqrt{0.3333333333333333} \cdot x\right)} \]
    3. Step-by-step derivation
      1. mul-1-neg68.8%

        \[\leadsto \color{blue}{-\sqrt{0.3333333333333333} \cdot x} \]
      2. distribute-rgt-neg-in68.8%

        \[\leadsto \color{blue}{\sqrt{0.3333333333333333} \cdot \left(-x\right)} \]
    4. Simplified68.8%

      \[\leadsto \color{blue}{\sqrt{0.3333333333333333} \cdot \left(-x\right)} \]

    if -3.2000000000000001e31 < x

    1. Initial program 50.1%

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

      \[\leadsto \color{blue}{z \cdot \sqrt{0.3333333333333333}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification34.4%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -3.2 \cdot 10^{+31}:\\ \;\;\;\;x \cdot \left(-\sqrt{0.3333333333333333}\right)\\ \mathbf{else}:\\ \;\;\;\;z \cdot \sqrt{0.3333333333333333}\\ \end{array} \]

Alternative 7: 29.8% accurate, 1.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -2.7 \cdot 10^{+31}:\\ \;\;\;\;\frac{-x}{\sqrt{3}}\\ \mathbf{else}:\\ \;\;\;\;z \cdot \sqrt{0.3333333333333333}\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= x -2.7e+31) (/ (- x) (sqrt 3.0)) (* z (sqrt 0.3333333333333333))))
double code(double x, double y, double z) {
	double tmp;
	if (x <= -2.7e+31) {
		tmp = -x / sqrt(3.0);
	} else {
		tmp = z * sqrt(0.3333333333333333);
	}
	return tmp;
}
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 <= (-2.7d+31)) then
        tmp = -x / sqrt(3.0d0)
    else
        tmp = z * sqrt(0.3333333333333333d0)
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if (x <= -2.7e+31) {
		tmp = -x / Math.sqrt(3.0);
	} else {
		tmp = z * Math.sqrt(0.3333333333333333);
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if x <= -2.7e+31:
		tmp = -x / math.sqrt(3.0)
	else:
		tmp = z * math.sqrt(0.3333333333333333)
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (x <= -2.7e+31)
		tmp = Float64(Float64(-x) / sqrt(3.0));
	else
		tmp = Float64(z * sqrt(0.3333333333333333));
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (x <= -2.7e+31)
		tmp = -x / sqrt(3.0);
	else
		tmp = z * sqrt(0.3333333333333333);
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[x, -2.7e+31], N[((-x) / N[Sqrt[3.0], $MachinePrecision]), $MachinePrecision], N[(z * N[Sqrt[0.3333333333333333], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.7 \cdot 10^{+31}:\\
\;\;\;\;\frac{-x}{\sqrt{3}}\\

\mathbf{else}:\\
\;\;\;\;z \cdot \sqrt{0.3333333333333333}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -2.69999999999999986e31

    1. Initial program 35.7%

      \[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}} \]
    2. Step-by-step derivation
      1. sqrt-div35.6%

        \[\leadsto \color{blue}{\frac{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}}{\sqrt{3}}} \]
      2. div-inv35.4%

        \[\leadsto \color{blue}{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z} \cdot \frac{1}{\sqrt{3}}} \]
      3. associate-+l+35.4%

        \[\leadsto \sqrt{\color{blue}{x \cdot x + \left(y \cdot y + z \cdot z\right)}} \cdot \frac{1}{\sqrt{3}} \]
      4. add-sqr-sqrt35.4%

        \[\leadsto \sqrt{x \cdot x + \color{blue}{\sqrt{y \cdot y + z \cdot z} \cdot \sqrt{y \cdot y + z \cdot z}}} \cdot \frac{1}{\sqrt{3}} \]
      5. hypot-def67.2%

        \[\leadsto \color{blue}{\mathsf{hypot}\left(x, \sqrt{y \cdot y + z \cdot z}\right)} \cdot \frac{1}{\sqrt{3}} \]
      6. hypot-def98.5%

        \[\leadsto \mathsf{hypot}\left(x, \color{blue}{\mathsf{hypot}\left(y, z\right)}\right) \cdot \frac{1}{\sqrt{3}} \]
    3. Applied egg-rr98.5%

      \[\leadsto \color{blue}{\mathsf{hypot}\left(x, \mathsf{hypot}\left(y, z\right)\right) \cdot \frac{1}{\sqrt{3}}} \]
    4. Step-by-step derivation
      1. associate-*r/99.4%

        \[\leadsto \color{blue}{\frac{\mathsf{hypot}\left(x, \mathsf{hypot}\left(y, z\right)\right) \cdot 1}{\sqrt{3}}} \]
      2. *-rgt-identity99.4%

        \[\leadsto \frac{\color{blue}{\mathsf{hypot}\left(x, \mathsf{hypot}\left(y, z\right)\right)}}{\sqrt{3}} \]
      3. hypot-def67.7%

        \[\leadsto \frac{\mathsf{hypot}\left(x, \color{blue}{\sqrt{y \cdot y + z \cdot z}}\right)}{\sqrt{3}} \]
      4. +-commutative67.7%

        \[\leadsto \frac{\mathsf{hypot}\left(x, \sqrt{\color{blue}{z \cdot z + y \cdot y}}\right)}{\sqrt{3}} \]
      5. hypot-def99.4%

        \[\leadsto \frac{\mathsf{hypot}\left(x, \color{blue}{\mathsf{hypot}\left(z, y\right)}\right)}{\sqrt{3}} \]
    5. Simplified99.4%

      \[\leadsto \color{blue}{\frac{\mathsf{hypot}\left(x, \mathsf{hypot}\left(z, y\right)\right)}{\sqrt{3}}} \]
    6. Taylor expanded in x around -inf 68.8%

      \[\leadsto \color{blue}{-1 \cdot \frac{x}{\sqrt{3}}} \]
    7. Step-by-step derivation
      1. associate-*r/68.8%

        \[\leadsto \color{blue}{\frac{-1 \cdot x}{\sqrt{3}}} \]
      2. neg-mul-168.8%

        \[\leadsto \frac{\color{blue}{-x}}{\sqrt{3}} \]
    8. Simplified68.8%

      \[\leadsto \color{blue}{\frac{-x}{\sqrt{3}}} \]

    if -2.69999999999999986e31 < x

    1. Initial program 50.1%

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

      \[\leadsto \color{blue}{z \cdot \sqrt{0.3333333333333333}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification34.4%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -2.7 \cdot 10^{+31}:\\ \;\;\;\;\frac{-x}{\sqrt{3}}\\ \mathbf{else}:\\ \;\;\;\;z \cdot \sqrt{0.3333333333333333}\\ \end{array} \]

Alternative 8: 17.8% accurate, 1.1× speedup?

\[\begin{array}{l} \\ z \cdot \sqrt{0.3333333333333333} \end{array} \]
(FPCore (x y z) :precision binary64 (* z (sqrt 0.3333333333333333)))
double code(double x, double y, double z) {
	return z * sqrt(0.3333333333333333);
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = z * sqrt(0.3333333333333333d0)
end function
public static double code(double x, double y, double z) {
	return z * Math.sqrt(0.3333333333333333);
}
def code(x, y, z):
	return z * math.sqrt(0.3333333333333333)
function code(x, y, z)
	return Float64(z * sqrt(0.3333333333333333))
end
function tmp = code(x, y, z)
	tmp = z * sqrt(0.3333333333333333);
end
code[x_, y_, z_] := N[(z * N[Sqrt[0.3333333333333333], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
z \cdot \sqrt{0.3333333333333333}
\end{array}
Derivation
  1. Initial program 47.2%

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

    \[\leadsto \color{blue}{z \cdot \sqrt{0.3333333333333333}} \]
  3. Final simplification21.5%

    \[\leadsto z \cdot \sqrt{0.3333333333333333} \]

Developer target: 62.1% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z < -6.396479394109776 \cdot 10^{+136}:\\ \;\;\;\;\frac{-z}{\sqrt{3}}\\ \mathbf{elif}\;z < 7.320293694404182 \cdot 10^{+117}:\\ \;\;\;\;\frac{\sqrt{\left(z \cdot z + x \cdot x\right) + y \cdot y}}{\sqrt{3}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.3333333333333333} \cdot z\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (< z -6.396479394109776e+136)
   (/ (- z) (sqrt 3.0))
   (if (< z 7.320293694404182e+117)
     (/ (sqrt (+ (+ (* z z) (* x x)) (* y y))) (sqrt 3.0))
     (* (sqrt 0.3333333333333333) z))))
double code(double x, double y, double z) {
	double tmp;
	if (z < -6.396479394109776e+136) {
		tmp = -z / sqrt(3.0);
	} else if (z < 7.320293694404182e+117) {
		tmp = sqrt((((z * z) + (x * x)) + (y * y))) / sqrt(3.0);
	} else {
		tmp = sqrt(0.3333333333333333) * 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
    real(8) :: tmp
    if (z < (-6.396479394109776d+136)) then
        tmp = -z / sqrt(3.0d0)
    else if (z < 7.320293694404182d+117) then
        tmp = sqrt((((z * z) + (x * x)) + (y * y))) / sqrt(3.0d0)
    else
        tmp = sqrt(0.3333333333333333d0) * z
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if (z < -6.396479394109776e+136) {
		tmp = -z / Math.sqrt(3.0);
	} else if (z < 7.320293694404182e+117) {
		tmp = Math.sqrt((((z * z) + (x * x)) + (y * y))) / Math.sqrt(3.0);
	} else {
		tmp = Math.sqrt(0.3333333333333333) * z;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if z < -6.396479394109776e+136:
		tmp = -z / math.sqrt(3.0)
	elif z < 7.320293694404182e+117:
		tmp = math.sqrt((((z * z) + (x * x)) + (y * y))) / math.sqrt(3.0)
	else:
		tmp = math.sqrt(0.3333333333333333) * z
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (z < -6.396479394109776e+136)
		tmp = Float64(Float64(-z) / sqrt(3.0));
	elseif (z < 7.320293694404182e+117)
		tmp = Float64(sqrt(Float64(Float64(Float64(z * z) + Float64(x * x)) + Float64(y * y))) / sqrt(3.0));
	else
		tmp = Float64(sqrt(0.3333333333333333) * z);
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (z < -6.396479394109776e+136)
		tmp = -z / sqrt(3.0);
	elseif (z < 7.320293694404182e+117)
		tmp = sqrt((((z * z) + (x * x)) + (y * y))) / sqrt(3.0);
	else
		tmp = sqrt(0.3333333333333333) * z;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[Less[z, -6.396479394109776e+136], N[((-z) / N[Sqrt[3.0], $MachinePrecision]), $MachinePrecision], If[Less[z, 7.320293694404182e+117], N[(N[Sqrt[N[(N[(N[(z * z), $MachinePrecision] + N[(x * x), $MachinePrecision]), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[3.0], $MachinePrecision]), $MachinePrecision], N[(N[Sqrt[0.3333333333333333], $MachinePrecision] * z), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;z < -6.396479394109776 \cdot 10^{+136}:\\
\;\;\;\;\frac{-z}{\sqrt{3}}\\

\mathbf{elif}\;z < 7.320293694404182 \cdot 10^{+117}:\\
\;\;\;\;\frac{\sqrt{\left(z \cdot z + x \cdot x\right) + y \cdot y}}{\sqrt{3}}\\

\mathbf{else}:\\
\;\;\;\;\sqrt{0.3333333333333333} \cdot z\\


\end{array}
\end{array}

Reproduce

?
herbie shell --seed 2023196 
(FPCore (x y z)
  :name "Data.Array.Repa.Algorithms.Pixel:doubleRmsOfRGB8 from repa-algorithms-3.4.0.1"
  :precision binary64

  :herbie-target
  (if (< z -6.396479394109776e+136) (/ (- z) (sqrt 3.0)) (if (< z 7.320293694404182e+117) (/ (sqrt (+ (+ (* z z) (* x x)) (* y y))) (sqrt 3.0)) (* (sqrt 0.3333333333333333) z)))

  (sqrt (/ (+ (+ (* x x) (* y y)) (* z z)) 3.0)))