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

Percentage Accurate: 44.7% → 99.4%
Time: 6.4s
Alternatives: 11
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 11 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.7% 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.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 44.7%

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

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

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

      \[\leadsto \sqrt{\color{blue}{x \cdot x + \left(y \cdot y + z \cdot z\right)}} \cdot \frac{1}{\sqrt{3}} \]
    4. add-sqr-sqrt44.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-def59.7%

      \[\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-def60.2%

      \[\leadsto \frac{\mathsf{hypot}\left(x, \color{blue}{\sqrt{y \cdot y + z \cdot z}}\right)}{\sqrt{3}} \]
    4. +-commutative60.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 2: 64.5% accurate, 0.5× speedup?

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

\\
\begin{array}{l}
t_0 := \sqrt{0.3333333333333333} \cdot \mathsf{hypot}\left(y, x\right)\\
\mathbf{if}\;z \cdot z \leq 5 \cdot 10^{-21}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;z \cdot z \leq 5 \cdot 10^{+177}:\\
\;\;\;\;\sqrt{\frac{z \cdot z + x \cdot x}{3}}\\

\mathbf{elif}\;z \cdot z \leq 10^{+224}:\\
\;\;\;\;t_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (*.f64 z z) < 4.99999999999999973e-21 or 5.0000000000000003e177 < (*.f64 z z) < 9.9999999999999997e223

    1. Initial program 56.4%

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

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

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

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

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

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

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

    if 4.99999999999999973e-21 < (*.f64 z z) < 5.0000000000000003e177

    1. Initial program 55.0%

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

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

        \[\leadsto \sqrt{\frac{\color{blue}{x \cdot x} + z \cdot z}{3}} \]
    4. Simplified34.4%

      \[\leadsto \sqrt{\frac{\color{blue}{x \cdot x} + z \cdot z}{3}} \]

    if 9.9999999999999997e223 < (*.f64 z z)

    1. Initial program 17.1%

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

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

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

Alternative 3: 67.4% accurate, 0.6× speedup?

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

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

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

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

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

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

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

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

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

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

Alternative 4: 67.4% accurate, 0.6× speedup?

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

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

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

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

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

      \[\leadsto \sqrt{\color{blue}{x \cdot x + \left(y \cdot y + z \cdot z\right)}} \cdot \frac{1}{\sqrt{3}} \]
    4. add-sqr-sqrt44.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-def59.7%

      \[\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-def60.2%

      \[\leadsto \frac{\mathsf{hypot}\left(x, \color{blue}{\sqrt{y \cdot y + z \cdot z}}\right)}{\sqrt{3}} \]
    4. +-commutative60.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. Taylor expanded in y around 0 29.4%

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

      \[\leadsto \color{blue}{\frac{\sqrt{{z}^{2} + {x}^{2}} \cdot 1}{\sqrt{3}}} \]
    2. unpow229.6%

      \[\leadsto \frac{\sqrt{\color{blue}{z \cdot z} + {x}^{2}} \cdot 1}{\sqrt{3}} \]
    3. unpow229.6%

      \[\leadsto \frac{\sqrt{z \cdot z + \color{blue}{x \cdot x}} \cdot 1}{\sqrt{3}} \]
    4. +-commutative29.6%

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

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

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

      \[\leadsto \frac{\color{blue}{\sqrt{x \cdot x + z \cdot z}}}{\sqrt{3}} \]
    8. +-commutative29.6%

      \[\leadsto \frac{\sqrt{\color{blue}{z \cdot z + x \cdot x}}}{\sqrt{3}} \]
    9. hypot-def69.1%

      \[\leadsto \frac{\color{blue}{\mathsf{hypot}\left(z, x\right)}}{\sqrt{3}} \]
  8. Simplified69.1%

    \[\leadsto \color{blue}{\frac{\mathsf{hypot}\left(z, x\right)}{\sqrt{3}}} \]
  9. Final simplification69.1%

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

Alternative 5: 31.3% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
t_0 := x \cdot \left(-\sqrt{0.3333333333333333}\right)\\
\mathbf{if}\;z \cdot z \leq 5 \cdot 10^{-21}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;z \cdot z \leq 5 \cdot 10^{+177}:\\
\;\;\;\;\sqrt{\frac{z \cdot z + x \cdot x}{3}}\\

\mathbf{elif}\;z \cdot z \leq 10^{+224}:\\
\;\;\;\;t_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (*.f64 z z) < 4.99999999999999973e-21 or 5.0000000000000003e177 < (*.f64 z z) < 9.9999999999999997e223

    1. Initial program 56.4%

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

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

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

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

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

    if 4.99999999999999973e-21 < (*.f64 z z) < 5.0000000000000003e177

    1. Initial program 55.0%

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

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

        \[\leadsto \sqrt{\frac{\color{blue}{x \cdot x} + z \cdot z}{3}} \]
    4. Simplified34.4%

      \[\leadsto \sqrt{\frac{\color{blue}{x \cdot x} + z \cdot z}{3}} \]

    if 9.9999999999999997e223 < (*.f64 z z)

    1. Initial program 17.1%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \cdot z \leq 5 \cdot 10^{-21}:\\ \;\;\;\;x \cdot \left(-\sqrt{0.3333333333333333}\right)\\ \mathbf{elif}\;z \cdot z \leq 5 \cdot 10^{+177}:\\ \;\;\;\;\sqrt{\frac{z \cdot z + x \cdot x}{3}}\\ \mathbf{elif}\;z \cdot z \leq 10^{+224}:\\ \;\;\;\;x \cdot \left(-\sqrt{0.3333333333333333}\right)\\ \mathbf{else}:\\ \;\;\;\;z \cdot \sqrt{0.3333333333333333}\\ \end{array} \]

Alternative 6: 28.1% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
t_0 := x \cdot \left(-\sqrt{0.3333333333333333}\right)\\
\mathbf{if}\;z \leq 2050000:\\
\;\;\;\;t_0\\

\mathbf{elif}\;z \leq 7.4 \cdot 10^{+22}:\\
\;\;\;\;\frac{z}{\sqrt{3}}\\

\mathbf{elif}\;z \leq 2.1 \cdot 10^{+113}:\\
\;\;\;\;t_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if z < 2.05e6 or 7.3999999999999996e22 < z < 2.0999999999999999e113

    1. Initial program 48.6%

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

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

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

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

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

    if 2.05e6 < z < 7.3999999999999996e22

    1. Initial program 77.1%

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

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

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

        \[\leadsto \sqrt{\color{blue}{x \cdot x + \left(y \cdot y + z \cdot z\right)}} \cdot \frac{1}{\sqrt{3}} \]
      4. add-sqr-sqrt76.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-def98.8%

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

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

      \[\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/100.0%

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{z}{\sqrt{3}}} \]

    if 2.0999999999999999e113 < z

    1. Initial program 17.6%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq 2050000:\\ \;\;\;\;x \cdot \left(-\sqrt{0.3333333333333333}\right)\\ \mathbf{elif}\;z \leq 7.4 \cdot 10^{+22}:\\ \;\;\;\;\frac{z}{\sqrt{3}}\\ \mathbf{elif}\;z \leq 2.1 \cdot 10^{+113}:\\ \;\;\;\;x \cdot \left(-\sqrt{0.3333333333333333}\right)\\ \mathbf{else}:\\ \;\;\;\;z \cdot \sqrt{0.3333333333333333}\\ \end{array} \]

Alternative 7: 28.1% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;z \leq 2600000:\\
\;\;\;\;x \cdot \left(-\sqrt{0.3333333333333333}\right)\\

\mathbf{elif}\;z \leq 8 \cdot 10^{+22}:\\
\;\;\;\;\frac{z}{\sqrt{3}}\\

\mathbf{elif}\;z \leq 2.3 \cdot 10^{+112}:\\
\;\;\;\;\frac{-x}{\sqrt{3}}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if z < 2.6e6

    1. Initial program 49.3%

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

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

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

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

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

    if 2.6e6 < z < 8e22

    1. Initial program 77.1%

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

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

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

        \[\leadsto \sqrt{\color{blue}{x \cdot x + \left(y \cdot y + z \cdot z\right)}} \cdot \frac{1}{\sqrt{3}} \]
      4. add-sqr-sqrt76.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-def98.8%

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

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

      \[\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/100.0%

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{z}{\sqrt{3}}} \]

    if 8e22 < z < 2.3e112

    1. Initial program 42.2%

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

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

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

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

        \[\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-def68.3%

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

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

      \[\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-def68.9%

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

        \[\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 35.0%

      \[\leadsto \color{blue}{-1 \cdot \frac{x}{\sqrt{3}}} \]
    7. Step-by-step derivation
      1. mul-1-neg35.0%

        \[\leadsto \color{blue}{-\frac{x}{\sqrt{3}}} \]
      2. distribute-neg-frac35.0%

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

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

    if 2.3e112 < z

    1. Initial program 17.6%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq 2600000:\\ \;\;\;\;x \cdot \left(-\sqrt{0.3333333333333333}\right)\\ \mathbf{elif}\;z \leq 8 \cdot 10^{+22}:\\ \;\;\;\;\frac{z}{\sqrt{3}}\\ \mathbf{elif}\;z \leq 2.3 \cdot 10^{+112}:\\ \;\;\;\;\frac{-x}{\sqrt{3}}\\ \mathbf{else}:\\ \;\;\;\;z \cdot \sqrt{0.3333333333333333}\\ \end{array} \]

Alternative 8: 28.1% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;z \leq 2050000:\\
\;\;\;\;x \cdot \left(-\sqrt{0.3333333333333333}\right)\\

\mathbf{elif}\;z \leq 2.6 \cdot 10^{+23}:\\
\;\;\;\;\sqrt{\frac{z}{\frac{3}{z}}}\\

\mathbf{elif}\;z \leq 3.6 \cdot 10^{+112}:\\
\;\;\;\;\frac{-x}{\sqrt{3}}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if z < 2.05e6

    1. Initial program 49.3%

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

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

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

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

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

    if 2.05e6 < z < 2.59999999999999992e23

    1. Initial program 77.1%

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

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

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

        \[\leadsto \sqrt{\color{blue}{x \cdot x + \left(y \cdot y + z \cdot z\right)}} \cdot \frac{1}{\sqrt{3}} \]
      4. add-sqr-sqrt76.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-def98.8%

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

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

      \[\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/100.0%

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{z}{\sqrt{3}}} \]
    7. Step-by-step derivation
      1. add-sqr-sqrt51.4%

        \[\leadsto \color{blue}{\sqrt{\frac{z}{\sqrt{3}}} \cdot \sqrt{\frac{z}{\sqrt{3}}}} \]
      2. sqrt-unprod52.2%

        \[\leadsto \color{blue}{\sqrt{\frac{z}{\sqrt{3}} \cdot \frac{z}{\sqrt{3}}}} \]
      3. frac-times52.2%

        \[\leadsto \sqrt{\color{blue}{\frac{z \cdot z}{\sqrt{3} \cdot \sqrt{3}}}} \]
      4. add-sqr-sqrt52.2%

        \[\leadsto \sqrt{\frac{z \cdot z}{\color{blue}{3}}} \]
    8. Applied egg-rr52.2%

      \[\leadsto \color{blue}{\sqrt{\frac{z \cdot z}{3}}} \]
    9. Step-by-step derivation
      1. associate-/l*52.2%

        \[\leadsto \sqrt{\color{blue}{\frac{z}{\frac{3}{z}}}} \]
    10. Simplified52.2%

      \[\leadsto \color{blue}{\sqrt{\frac{z}{\frac{3}{z}}}} \]

    if 2.59999999999999992e23 < z < 3.6e112

    1. Initial program 42.2%

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

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

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

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

        \[\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-def68.3%

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

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

      \[\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-def68.9%

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

        \[\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 35.0%

      \[\leadsto \color{blue}{-1 \cdot \frac{x}{\sqrt{3}}} \]
    7. Step-by-step derivation
      1. mul-1-neg35.0%

        \[\leadsto \color{blue}{-\frac{x}{\sqrt{3}}} \]
      2. distribute-neg-frac35.0%

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

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

    if 3.6e112 < z

    1. Initial program 17.6%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq 2050000:\\ \;\;\;\;x \cdot \left(-\sqrt{0.3333333333333333}\right)\\ \mathbf{elif}\;z \leq 2.6 \cdot 10^{+23}:\\ \;\;\;\;\sqrt{\frac{z}{\frac{3}{z}}}\\ \mathbf{elif}\;z \leq 3.6 \cdot 10^{+112}:\\ \;\;\;\;\frac{-x}{\sqrt{3}}\\ \mathbf{else}:\\ \;\;\;\;z \cdot \sqrt{0.3333333333333333}\\ \end{array} \]

Alternative 9: 28.1% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;z \leq 1700000:\\
\;\;\;\;x \cdot \left(-\sqrt{0.3333333333333333}\right)\\

\mathbf{elif}\;z \leq 9.6 \cdot 10^{+22}:\\
\;\;\;\;\sqrt{\frac{z \cdot z}{3}}\\

\mathbf{elif}\;z \leq 7.2 \cdot 10^{+111}:\\
\;\;\;\;\frac{-x}{\sqrt{3}}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if z < 1.7e6

    1. Initial program 49.3%

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

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

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

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

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

    if 1.7e6 < z < 9.6e22

    1. Initial program 77.1%

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

      \[\leadsto \sqrt{\frac{\color{blue}{{z}^{2}}}{3}} \]
    3. Step-by-step derivation
      1. unpow252.2%

        \[\leadsto \sqrt{\frac{\color{blue}{z \cdot z}}{3}} \]
    4. Simplified52.2%

      \[\leadsto \sqrt{\frac{\color{blue}{z \cdot z}}{3}} \]

    if 9.6e22 < z < 7.2000000000000004e111

    1. Initial program 42.2%

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

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

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

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

        \[\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-def68.3%

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

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

      \[\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-def68.9%

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

        \[\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 35.0%

      \[\leadsto \color{blue}{-1 \cdot \frac{x}{\sqrt{3}}} \]
    7. Step-by-step derivation
      1. mul-1-neg35.0%

        \[\leadsto \color{blue}{-\frac{x}{\sqrt{3}}} \]
      2. distribute-neg-frac35.0%

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

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

    if 7.2000000000000004e111 < z

    1. Initial program 17.6%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq 1700000:\\ \;\;\;\;x \cdot \left(-\sqrt{0.3333333333333333}\right)\\ \mathbf{elif}\;z \leq 9.6 \cdot 10^{+22}:\\ \;\;\;\;\sqrt{\frac{z \cdot z}{3}}\\ \mathbf{elif}\;z \leq 7.2 \cdot 10^{+111}:\\ \;\;\;\;\frac{-x}{\sqrt{3}}\\ \mathbf{else}:\\ \;\;\;\;z \cdot \sqrt{0.3333333333333333}\\ \end{array} \]

Alternative 10: 18.7% 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 44.7%

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

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

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

Alternative 11: 18.7% accurate, 1.1× speedup?

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

\\
\frac{z}{\sqrt{3}}
\end{array}
Derivation
  1. Initial program 44.7%

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

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

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

      \[\leadsto \sqrt{\color{blue}{x \cdot x + \left(y \cdot y + z \cdot z\right)}} \cdot \frac{1}{\sqrt{3}} \]
    4. add-sqr-sqrt44.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-def59.7%

      \[\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-def60.2%

      \[\leadsto \frac{\mathsf{hypot}\left(x, \color{blue}{\sqrt{y \cdot y + z \cdot z}}\right)}{\sqrt{3}} \]
    4. +-commutative60.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. Taylor expanded in z around inf 18.2%

    \[\leadsto \color{blue}{\frac{z}{\sqrt{3}}} \]
  7. Final simplification18.2%

    \[\leadsto \frac{z}{\sqrt{3}} \]

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 2023171 
(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)))