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

Percentage Accurate: 44.5% → 99.4%
Time: 6.1s
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.5% 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(y, z\right)\right)}{\sqrt{3}} \end{array} \]
(FPCore (x y z) :precision binary64 (/ (hypot x (hypot y z)) (sqrt 3.0)))
double code(double x, double y, double z) {
	return hypot(x, hypot(y, z)) / sqrt(3.0);
}
public static double code(double x, double y, double z) {
	return Math.hypot(x, Math.hypot(y, z)) / Math.sqrt(3.0);
}
def code(x, y, z):
	return math.hypot(x, math.hypot(y, z)) / math.sqrt(3.0)
function code(x, y, z)
	return Float64(hypot(x, hypot(y, z)) / sqrt(3.0))
end
function tmp = code(x, y, z)
	tmp = hypot(x, hypot(y, z)) / sqrt(3.0);
end
code[x_, y_, z_] := N[(N[Sqrt[x ^ 2 + N[Sqrt[y ^ 2 + z ^ 2], $MachinePrecision] ^ 2], $MachinePrecision] / N[Sqrt[3.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

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

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

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

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

      \[\leadsto \sqrt{\color{blue}{\left(-1 \cdot -1\right)} \cdot \frac{\left(y \cdot y + x \cdot x\right) + z \cdot z}{3}} \]
    4. associate-*r/48.7%

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

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

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

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

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

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

      \[\leadsto \sqrt{\color{blue}{\left(x \cdot x + \left(z \cdot z + y \cdot y\right)\right)} \cdot \frac{-1 \cdot -1}{3}} \]
    11. fma-def48.6%

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

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

      \[\leadsto \sqrt{\mathsf{fma}\left(x, x, \color{blue}{\mathsf{fma}\left(y, y, z \cdot z\right)}\right) \cdot \frac{-1 \cdot -1}{3}} \]
    14. metadata-eval48.6%

      \[\leadsto \sqrt{\mathsf{fma}\left(x, x, \mathsf{fma}\left(y, y, z \cdot z\right)\right) \cdot \frac{\color{blue}{1}}{3}} \]
    15. metadata-eval48.6%

      \[\leadsto \sqrt{\mathsf{fma}\left(x, x, \mathsf{fma}\left(y, y, z \cdot z\right)\right) \cdot \color{blue}{0.3333333333333333}} \]
  3. Simplified48.6%

    \[\leadsto \color{blue}{\sqrt{\mathsf{fma}\left(x, x, \mathsf{fma}\left(y, y, z \cdot z\right)\right) \cdot 0.3333333333333333}} \]
  4. Step-by-step derivation
    1. fma-udef48.6%

      \[\leadsto \sqrt{\color{blue}{\left(x \cdot x + \mathsf{fma}\left(y, y, z \cdot z\right)\right)} \cdot 0.3333333333333333} \]
    2. fma-udef48.6%

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

      \[\leadsto \sqrt{\color{blue}{\left(\left(x \cdot x + y \cdot y\right) + z \cdot z\right)} \cdot 0.3333333333333333} \]
    4. metadata-eval48.6%

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

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

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

      \[\leadsto \frac{\sqrt{\color{blue}{x \cdot x + \left(y \cdot y + z \cdot z\right)}}}{\sqrt{3}} \]
    8. fma-udef48.6%

      \[\leadsto \frac{\sqrt{x \cdot x + \color{blue}{\mathsf{fma}\left(y, y, z \cdot z\right)}}}{\sqrt{3}} \]
    9. add-sqr-sqrt48.6%

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

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

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

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

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

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

Alternative 2: 99.4% accurate, 0.4× speedup?

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

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

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

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

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

      \[\leadsto \sqrt{\color{blue}{\left(-1 \cdot -1\right)} \cdot \frac{\left(y \cdot y + x \cdot x\right) + z \cdot z}{3}} \]
    4. associate-*r/48.7%

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

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

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

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

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

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

      \[\leadsto \sqrt{\color{blue}{\left(x \cdot x + \left(z \cdot z + y \cdot y\right)\right)} \cdot \frac{-1 \cdot -1}{3}} \]
    11. fma-def48.6%

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

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

      \[\leadsto \sqrt{\mathsf{fma}\left(x, x, \color{blue}{\mathsf{fma}\left(y, y, z \cdot z\right)}\right) \cdot \frac{-1 \cdot -1}{3}} \]
    14. metadata-eval48.6%

      \[\leadsto \sqrt{\mathsf{fma}\left(x, x, \mathsf{fma}\left(y, y, z \cdot z\right)\right) \cdot \frac{\color{blue}{1}}{3}} \]
    15. metadata-eval48.6%

      \[\leadsto \sqrt{\mathsf{fma}\left(x, x, \mathsf{fma}\left(y, y, z \cdot z\right)\right) \cdot \color{blue}{0.3333333333333333}} \]
  3. Simplified48.6%

    \[\leadsto \color{blue}{\sqrt{\mathsf{fma}\left(x, x, \mathsf{fma}\left(y, y, z \cdot z\right)\right) \cdot 0.3333333333333333}} \]
  4. Step-by-step derivation
    1. sqrt-prod48.5%

      \[\leadsto \color{blue}{\sqrt{\mathsf{fma}\left(x, x, \mathsf{fma}\left(y, y, z \cdot z\right)\right)} \cdot \sqrt{0.3333333333333333}} \]
    2. fma-udef48.5%

      \[\leadsto \sqrt{\color{blue}{x \cdot x + \mathsf{fma}\left(y, y, z \cdot z\right)}} \cdot \sqrt{0.3333333333333333} \]
    3. add-sqr-sqrt48.5%

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

      \[\leadsto \color{blue}{\mathsf{hypot}\left(x, \sqrt{\mathsf{fma}\left(y, y, z \cdot z\right)}\right)} \cdot \sqrt{0.3333333333333333} \]
    5. fma-udef60.9%

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

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

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

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

Alternative 3: 68.4% accurate, 0.6× speedup?

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

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

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

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

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

      \[\leadsto \sqrt{\color{blue}{\left(-1 \cdot -1\right)} \cdot \frac{\left(y \cdot y + x \cdot x\right) + z \cdot z}{3}} \]
    4. associate-*r/48.7%

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

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

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

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

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

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

      \[\leadsto \sqrt{\color{blue}{\left(x \cdot x + \left(z \cdot z + y \cdot y\right)\right)} \cdot \frac{-1 \cdot -1}{3}} \]
    11. fma-def48.6%

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

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

      \[\leadsto \sqrt{\mathsf{fma}\left(x, x, \color{blue}{\mathsf{fma}\left(y, y, z \cdot z\right)}\right) \cdot \frac{-1 \cdot -1}{3}} \]
    14. metadata-eval48.6%

      \[\leadsto \sqrt{\mathsf{fma}\left(x, x, \mathsf{fma}\left(y, y, z \cdot z\right)\right) \cdot \frac{\color{blue}{1}}{3}} \]
    15. metadata-eval48.6%

      \[\leadsto \sqrt{\mathsf{fma}\left(x, x, \mathsf{fma}\left(y, y, z \cdot z\right)\right) \cdot \color{blue}{0.3333333333333333}} \]
  3. Simplified48.6%

    \[\leadsto \color{blue}{\sqrt{\mathsf{fma}\left(x, x, \mathsf{fma}\left(y, y, z \cdot z\right)\right) \cdot 0.3333333333333333}} \]
  4. Step-by-step derivation
    1. sqrt-prod48.5%

      \[\leadsto \color{blue}{\sqrt{\mathsf{fma}\left(x, x, \mathsf{fma}\left(y, y, z \cdot z\right)\right)} \cdot \sqrt{0.3333333333333333}} \]
    2. fma-udef48.5%

      \[\leadsto \sqrt{\color{blue}{x \cdot x + \mathsf{fma}\left(y, y, z \cdot z\right)}} \cdot \sqrt{0.3333333333333333} \]
    3. add-sqr-sqrt48.5%

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

      \[\leadsto \color{blue}{\mathsf{hypot}\left(x, \sqrt{\mathsf{fma}\left(y, y, z \cdot z\right)}\right)} \cdot \sqrt{0.3333333333333333} \]
    5. fma-udef60.9%

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

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

    \[\leadsto \color{blue}{\mathsf{hypot}\left(x, \mathsf{hypot}\left(y, z\right)\right) \cdot \sqrt{0.3333333333333333}} \]
  6. Taylor expanded in x around 0 33.0%

    \[\leadsto \color{blue}{\sqrt{0.3333333333333333} \cdot \sqrt{{y}^{2} + {z}^{2}}} \]
  7. Step-by-step derivation
    1. +-commutative33.0%

      \[\leadsto \sqrt{0.3333333333333333} \cdot \sqrt{\color{blue}{{z}^{2} + {y}^{2}}} \]
    2. unpow233.0%

      \[\leadsto \sqrt{0.3333333333333333} \cdot \sqrt{\color{blue}{z \cdot z} + {y}^{2}} \]
    3. unpow233.0%

      \[\leadsto \sqrt{0.3333333333333333} \cdot \sqrt{z \cdot z + \color{blue}{y \cdot y}} \]
    4. hypot-def67.2%

      \[\leadsto \sqrt{0.3333333333333333} \cdot \color{blue}{\mathsf{hypot}\left(z, y\right)} \]
  8. Simplified67.2%

    \[\leadsto \color{blue}{\sqrt{0.3333333333333333} \cdot \mathsf{hypot}\left(z, y\right)} \]
  9. Final simplification67.2%

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

Alternative 4: 68.4% accurate, 0.6× speedup?

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

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

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

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

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

      \[\leadsto \sqrt{\color{blue}{\left(-1 \cdot -1\right)} \cdot \frac{\left(y \cdot y + x \cdot x\right) + z \cdot z}{3}} \]
    4. associate-*r/48.7%

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

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

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

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

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

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

      \[\leadsto \sqrt{\color{blue}{\left(x \cdot x + \left(z \cdot z + y \cdot y\right)\right)} \cdot \frac{-1 \cdot -1}{3}} \]
    11. fma-def48.6%

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

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

      \[\leadsto \sqrt{\mathsf{fma}\left(x, x, \color{blue}{\mathsf{fma}\left(y, y, z \cdot z\right)}\right) \cdot \frac{-1 \cdot -1}{3}} \]
    14. metadata-eval48.6%

      \[\leadsto \sqrt{\mathsf{fma}\left(x, x, \mathsf{fma}\left(y, y, z \cdot z\right)\right) \cdot \frac{\color{blue}{1}}{3}} \]
    15. metadata-eval48.6%

      \[\leadsto \sqrt{\mathsf{fma}\left(x, x, \mathsf{fma}\left(y, y, z \cdot z\right)\right) \cdot \color{blue}{0.3333333333333333}} \]
  3. Simplified48.6%

    \[\leadsto \color{blue}{\sqrt{\mathsf{fma}\left(x, x, \mathsf{fma}\left(y, y, z \cdot z\right)\right) \cdot 0.3333333333333333}} \]
  4. Step-by-step derivation
    1. fma-udef48.6%

      \[\leadsto \sqrt{\color{blue}{\left(x \cdot x + \mathsf{fma}\left(y, y, z \cdot z\right)\right)} \cdot 0.3333333333333333} \]
    2. fma-udef48.6%

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

      \[\leadsto \sqrt{\color{blue}{\left(\left(x \cdot x + y \cdot y\right) + z \cdot z\right)} \cdot 0.3333333333333333} \]
    4. metadata-eval48.6%

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

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

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

      \[\leadsto \frac{\sqrt{\color{blue}{x \cdot x + \left(y \cdot y + z \cdot z\right)}}}{\sqrt{3}} \]
    8. fma-udef48.6%

      \[\leadsto \frac{\sqrt{x \cdot x + \color{blue}{\mathsf{fma}\left(y, y, z \cdot z\right)}}}{\sqrt{3}} \]
    9. add-sqr-sqrt48.6%

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{1 \cdot \sqrt{{y}^{2} + {z}^{2}}}{\sqrt{3}}} \]
    2. *-lft-identity33.1%

      \[\leadsto \frac{\color{blue}{\sqrt{{y}^{2} + {z}^{2}}}}{\sqrt{3}} \]
    3. +-commutative33.1%

      \[\leadsto \frac{\sqrt{\color{blue}{{z}^{2} + {y}^{2}}}}{\sqrt{3}} \]
    4. unpow233.1%

      \[\leadsto \frac{\sqrt{\color{blue}{z \cdot z} + {y}^{2}}}{\sqrt{3}} \]
    5. unpow233.1%

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

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

    \[\leadsto \color{blue}{\frac{\mathsf{hypot}\left(z, y\right)}{\sqrt{3}}} \]
  9. Final simplification67.2%

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

Alternative 5: 18.6% 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 48.7%

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

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

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

      \[\leadsto \sqrt{\color{blue}{\left(-1 \cdot -1\right)} \cdot \frac{\left(y \cdot y + x \cdot x\right) + z \cdot z}{3}} \]
    4. associate-*r/48.7%

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

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

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

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

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

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

      \[\leadsto \sqrt{\color{blue}{\left(x \cdot x + \left(z \cdot z + y \cdot y\right)\right)} \cdot \frac{-1 \cdot -1}{3}} \]
    11. fma-def48.6%

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

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

      \[\leadsto \sqrt{\mathsf{fma}\left(x, x, \color{blue}{\mathsf{fma}\left(y, y, z \cdot z\right)}\right) \cdot \frac{-1 \cdot -1}{3}} \]
    14. metadata-eval48.6%

      \[\leadsto \sqrt{\mathsf{fma}\left(x, x, \mathsf{fma}\left(y, y, z \cdot z\right)\right) \cdot \frac{\color{blue}{1}}{3}} \]
    15. metadata-eval48.6%

      \[\leadsto \sqrt{\mathsf{fma}\left(x, x, \mathsf{fma}\left(y, y, z \cdot z\right)\right) \cdot \color{blue}{0.3333333333333333}} \]
  3. Simplified48.6%

    \[\leadsto \color{blue}{\sqrt{\mathsf{fma}\left(x, x, \mathsf{fma}\left(y, y, z \cdot z\right)\right) \cdot 0.3333333333333333}} \]
  4. Taylor expanded in z around inf 18.9%

    \[\leadsto \color{blue}{z \cdot \sqrt{0.3333333333333333}} \]
  5. Step-by-step derivation
    1. *-commutative18.9%

      \[\leadsto \color{blue}{\sqrt{0.3333333333333333} \cdot z} \]
  6. Simplified18.9%

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

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

Alternative 6: 18.6% 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 48.7%

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

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

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

      \[\leadsto \sqrt{\color{blue}{\left(-1 \cdot -1\right)} \cdot \frac{\left(y \cdot y + x \cdot x\right) + z \cdot z}{3}} \]
    4. associate-*r/48.7%

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

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

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

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

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

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

      \[\leadsto \sqrt{\color{blue}{\left(x \cdot x + \left(z \cdot z + y \cdot y\right)\right)} \cdot \frac{-1 \cdot -1}{3}} \]
    11. fma-def48.6%

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

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

      \[\leadsto \sqrt{\mathsf{fma}\left(x, x, \color{blue}{\mathsf{fma}\left(y, y, z \cdot z\right)}\right) \cdot \frac{-1 \cdot -1}{3}} \]
    14. metadata-eval48.6%

      \[\leadsto \sqrt{\mathsf{fma}\left(x, x, \mathsf{fma}\left(y, y, z \cdot z\right)\right) \cdot \frac{\color{blue}{1}}{3}} \]
    15. metadata-eval48.6%

      \[\leadsto \sqrt{\mathsf{fma}\left(x, x, \mathsf{fma}\left(y, y, z \cdot z\right)\right) \cdot \color{blue}{0.3333333333333333}} \]
  3. Simplified48.6%

    \[\leadsto \color{blue}{\sqrt{\mathsf{fma}\left(x, x, \mathsf{fma}\left(y, y, z \cdot z\right)\right) \cdot 0.3333333333333333}} \]
  4. Step-by-step derivation
    1. fma-udef48.6%

      \[\leadsto \sqrt{\color{blue}{\left(x \cdot x + \mathsf{fma}\left(y, y, z \cdot z\right)\right)} \cdot 0.3333333333333333} \]
    2. fma-udef48.6%

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

      \[\leadsto \sqrt{\color{blue}{\left(\left(x \cdot x + y \cdot y\right) + z \cdot z\right)} \cdot 0.3333333333333333} \]
    4. metadata-eval48.6%

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

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

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

      \[\leadsto \frac{\sqrt{\color{blue}{x \cdot x + \left(y \cdot y + z \cdot z\right)}}}{\sqrt{3}} \]
    8. fma-udef48.6%

      \[\leadsto \frac{\sqrt{x \cdot x + \color{blue}{\mathsf{fma}\left(y, y, z \cdot z\right)}}}{\sqrt{3}} \]
    9. add-sqr-sqrt48.6%

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

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

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

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

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

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

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

Alternative 7: 5.4% accurate, 28.3× speedup?

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

\\
z \cdot \left(--0.3333333333333333\right)
\end{array}
Derivation
  1. Initial program 48.7%

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

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

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

      \[\leadsto \sqrt{\color{blue}{\left(-1 \cdot -1\right)} \cdot \frac{\left(y \cdot y + x \cdot x\right) + z \cdot z}{3}} \]
    4. associate-*r/48.7%

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

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

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

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

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

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

      \[\leadsto \sqrt{\color{blue}{\left(x \cdot x + \left(z \cdot z + y \cdot y\right)\right)} \cdot \frac{-1 \cdot -1}{3}} \]
    11. fma-def48.6%

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

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

      \[\leadsto \sqrt{\mathsf{fma}\left(x, x, \color{blue}{\mathsf{fma}\left(y, y, z \cdot z\right)}\right) \cdot \frac{-1 \cdot -1}{3}} \]
    14. metadata-eval48.6%

      \[\leadsto \sqrt{\mathsf{fma}\left(x, x, \mathsf{fma}\left(y, y, z \cdot z\right)\right) \cdot \frac{\color{blue}{1}}{3}} \]
    15. metadata-eval48.6%

      \[\leadsto \sqrt{\mathsf{fma}\left(x, x, \mathsf{fma}\left(y, y, z \cdot z\right)\right) \cdot \color{blue}{0.3333333333333333}} \]
  3. Simplified48.6%

    \[\leadsto \color{blue}{\sqrt{\mathsf{fma}\left(x, x, \mathsf{fma}\left(y, y, z \cdot z\right)\right) \cdot 0.3333333333333333}} \]
  4. Step-by-step derivation
    1. fma-udef48.6%

      \[\leadsto \sqrt{\color{blue}{\left(x \cdot x + \mathsf{fma}\left(y, y, z \cdot z\right)\right)} \cdot 0.3333333333333333} \]
    2. fma-udef48.6%

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

      \[\leadsto \sqrt{\color{blue}{\left(\left(x \cdot x + y \cdot y\right) + z \cdot z\right)} \cdot 0.3333333333333333} \]
    4. metadata-eval48.6%

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

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

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

      \[\leadsto \frac{\sqrt{\color{blue}{x \cdot x + \left(y \cdot y + z \cdot z\right)}}}{\sqrt{3}} \]
    8. fma-udef48.6%

      \[\leadsto \frac{\sqrt{x \cdot x + \color{blue}{\mathsf{fma}\left(y, y, z \cdot z\right)}}}{\sqrt{3}} \]
    9. add-sqr-sqrt48.6%

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{-z}{-\sqrt{3}}} \]
    2. div-inv18.8%

      \[\leadsto \color{blue}{\left(-z\right) \cdot \frac{1}{-\sqrt{3}}} \]
    3. *-commutative18.8%

      \[\leadsto \color{blue}{\frac{1}{-\sqrt{3}} \cdot \left(-z\right)} \]
    4. *-un-lft-identity18.8%

      \[\leadsto \frac{1}{-\color{blue}{1 \cdot \sqrt{3}}} \cdot \left(-z\right) \]
    5. distribute-lft-neg-in18.8%

      \[\leadsto \frac{1}{\color{blue}{\left(-1\right) \cdot \sqrt{3}}} \cdot \left(-z\right) \]
    6. associate-/r*18.8%

      \[\leadsto \color{blue}{\frac{\frac{1}{-1}}{\sqrt{3}}} \cdot \left(-z\right) \]
    7. metadata-eval18.8%

      \[\leadsto \frac{\frac{1}{\color{blue}{-1}}}{\sqrt{3}} \cdot \left(-z\right) \]
    8. metadata-eval18.8%

      \[\leadsto \frac{\color{blue}{-1}}{\sqrt{3}} \cdot \left(-z\right) \]
  8. Applied egg-rr18.8%

    \[\leadsto \color{blue}{\frac{-1}{\sqrt{3}} \cdot \left(-z\right)} \]
  9. Applied egg-rr5.6%

    \[\leadsto \color{blue}{-0.3333333333333333} \cdot \left(-z\right) \]
  10. Final simplification5.6%

    \[\leadsto z \cdot \left(--0.3333333333333333\right) \]

Alternative 8: 2.3% accurate, 113.0× speedup?

\[\begin{array}{l} \\ 0 \end{array} \]
(FPCore (x y z) :precision binary64 0.0)
double code(double x, double y, double z) {
	return 0.0;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = 0.0d0
end function
public static double code(double x, double y, double z) {
	return 0.0;
}
def code(x, y, z):
	return 0.0
function code(x, y, z)
	return 0.0
end
function tmp = code(x, y, z)
	tmp = 0.0;
end
code[x_, y_, z_] := 0.0
\begin{array}{l}

\\
0
\end{array}
Derivation
  1. Initial program 48.7%

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

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

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

      \[\leadsto \sqrt{\color{blue}{\left(-1 \cdot -1\right)} \cdot \frac{\left(y \cdot y + x \cdot x\right) + z \cdot z}{3}} \]
    4. associate-*r/48.7%

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

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

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

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

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

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

      \[\leadsto \sqrt{\color{blue}{\left(x \cdot x + \left(z \cdot z + y \cdot y\right)\right)} \cdot \frac{-1 \cdot -1}{3}} \]
    11. fma-def48.6%

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

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

      \[\leadsto \sqrt{\mathsf{fma}\left(x, x, \color{blue}{\mathsf{fma}\left(y, y, z \cdot z\right)}\right) \cdot \frac{-1 \cdot -1}{3}} \]
    14. metadata-eval48.6%

      \[\leadsto \sqrt{\mathsf{fma}\left(x, x, \mathsf{fma}\left(y, y, z \cdot z\right)\right) \cdot \frac{\color{blue}{1}}{3}} \]
    15. metadata-eval48.6%

      \[\leadsto \sqrt{\mathsf{fma}\left(x, x, \mathsf{fma}\left(y, y, z \cdot z\right)\right) \cdot \color{blue}{0.3333333333333333}} \]
  3. Simplified48.6%

    \[\leadsto \color{blue}{\sqrt{\mathsf{fma}\left(x, x, \mathsf{fma}\left(y, y, z \cdot z\right)\right) \cdot 0.3333333333333333}} \]
  4. Step-by-step derivation
    1. fma-udef48.6%

      \[\leadsto \sqrt{\color{blue}{\left(x \cdot x + \mathsf{fma}\left(y, y, z \cdot z\right)\right)} \cdot 0.3333333333333333} \]
    2. fma-udef48.6%

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

      \[\leadsto \sqrt{\color{blue}{\left(\left(x \cdot x + y \cdot y\right) + z \cdot z\right)} \cdot 0.3333333333333333} \]
    4. metadata-eval48.6%

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

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

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

      \[\leadsto \frac{\sqrt{\color{blue}{x \cdot x + \left(y \cdot y + z \cdot z\right)}}}{\sqrt{3}} \]
    8. fma-udef48.6%

      \[\leadsto \frac{\sqrt{x \cdot x + \color{blue}{\mathsf{fma}\left(y, y, z \cdot z\right)}}}{\sqrt{3}} \]
    9. add-sqr-sqrt48.6%

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{-z}{-\sqrt{3}}} \]
    2. div-inv18.8%

      \[\leadsto \color{blue}{\left(-z\right) \cdot \frac{1}{-\sqrt{3}}} \]
    3. *-commutative18.8%

      \[\leadsto \color{blue}{\frac{1}{-\sqrt{3}} \cdot \left(-z\right)} \]
    4. *-un-lft-identity18.8%

      \[\leadsto \frac{1}{-\color{blue}{1 \cdot \sqrt{3}}} \cdot \left(-z\right) \]
    5. distribute-lft-neg-in18.8%

      \[\leadsto \frac{1}{\color{blue}{\left(-1\right) \cdot \sqrt{3}}} \cdot \left(-z\right) \]
    6. associate-/r*18.8%

      \[\leadsto \color{blue}{\frac{\frac{1}{-1}}{\sqrt{3}}} \cdot \left(-z\right) \]
    7. metadata-eval18.8%

      \[\leadsto \frac{\frac{1}{\color{blue}{-1}}}{\sqrt{3}} \cdot \left(-z\right) \]
    8. metadata-eval18.8%

      \[\leadsto \frac{\color{blue}{-1}}{\sqrt{3}} \cdot \left(-z\right) \]
  8. Applied egg-rr18.8%

    \[\leadsto \color{blue}{\frac{-1}{\sqrt{3}} \cdot \left(-z\right)} \]
  9. Applied egg-rr2.4%

    \[\leadsto \color{blue}{0} \]
  10. Final simplification2.4%

    \[\leadsto 0 \]

Developer target: 62.3% 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 2023301 
(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)))