?

Average Error: 38.1 → 11.7
Time: 17.5s
Precision: binary64
Cost: 7760

?

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

\mathbf{elif}\;x \leq -1.7 \cdot 10^{+16}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;x \leq -2.8 \cdot 10^{-35}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;x \leq -1.9 \cdot 10^{-64}:\\
\;\;\;\;t_1\\

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original38.1
Target19.5
Herbie11.7
\[\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} \]

Derivation?

  1. Split input into 3 regimes
  2. if x < -1.3000000000000001e134

    1. Initial program 59.2

      \[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}} \]
    2. Applied egg-rr64.0

      \[\leadsto \color{blue}{\frac{1}{\sqrt{\frac{x \cdot x + \left(y \cdot y + z \cdot z\right)}{3}}} \cdot \sqrt{\frac{x \cdot x + \left(y \cdot y + z \cdot z\right)}{3} \cdot \frac{x \cdot x + \left(y \cdot y + z \cdot z\right)}{3}}} \]
    3. Taylor expanded in x around -inf 9.9

      \[\leadsto \color{blue}{-0.3333333333333333 \cdot \frac{x}{\sqrt{0.3333333333333333}}} \]
    4. Simplified9.9

      \[\leadsto \color{blue}{\frac{x}{\sqrt{0.3333333333333333}} \cdot -0.3333333333333333} \]
      Proof

      [Start]9.9

      \[ -0.3333333333333333 \cdot \frac{x}{\sqrt{0.3333333333333333}} \]

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

      \[ \color{blue}{\frac{x}{\sqrt{0.3333333333333333}} \cdot -0.3333333333333333} \]

    if -1.3000000000000001e134 < x < -1.7e16 or -2.8e-35 < x < -1.9000000000000001e-64

    1. Initial program 18.1

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

    if -1.7e16 < x < -2.8e-35 or -1.9000000000000001e-64 < x

    1. Initial program 30.1

      \[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}} \]
    2. Applied egg-rr45.1

      \[\leadsto \color{blue}{\frac{1}{\sqrt{\frac{x \cdot x + \left(y \cdot y + z \cdot z\right)}{3}}} \cdot \sqrt{\frac{x \cdot x + \left(y \cdot y + z \cdot z\right)}{3} \cdot \frac{x \cdot x + \left(y \cdot y + z \cdot z\right)}{3}}} \]
    3. Taylor expanded in z around inf 9.9

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -1.3 \cdot 10^{+134}:\\ \;\;\;\;\frac{x}{\sqrt{0.3333333333333333}} \cdot -0.3333333333333333\\ \mathbf{elif}\;x \leq -1.7 \cdot 10^{+16}:\\ \;\;\;\;\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\\ \mathbf{elif}\;x \leq -2.8 \cdot 10^{-35}:\\ \;\;\;\;0.3333333333333333 \cdot \frac{z}{\sqrt{0.3333333333333333}}\\ \mathbf{elif}\;x \leq -1.9 \cdot 10^{-64}:\\ \;\;\;\;\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\\ \mathbf{else}:\\ \;\;\;\;0.3333333333333333 \cdot \frac{z}{\sqrt{0.3333333333333333}}\\ \end{array} \]

Alternatives

Alternative 1
Error14.0
Cost7380
\[\begin{array}{l} t_0 := 0.3333333333333333 \cdot \frac{z}{\sqrt{0.3333333333333333}}\\ t_1 := \sqrt{0.3333333333333333} \cdot \left(-x\right)\\ \mathbf{if}\;x \leq -4.1 \cdot 10^{+89}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -6.4 \cdot 10^{+61}:\\ \;\;\;\;z \cdot \sqrt{0.3333333333333333}\\ \mathbf{elif}\;x \leq -7 \cdot 10^{+15}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -1.2 \cdot 10^{-39}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -3.05 \cdot 10^{-61}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Error14.0
Cost7380
\[\begin{array}{l} t_0 := \sqrt{0.3333333333333333} \cdot \left(-x\right)\\ t_1 := 0.3333333333333333 \cdot \frac{z}{\sqrt{0.3333333333333333}}\\ \mathbf{if}\;x \leq -3.7 \cdot 10^{+89}:\\ \;\;\;\;\frac{x}{\sqrt{0.3333333333333333}} \cdot -0.3333333333333333\\ \mathbf{elif}\;x \leq -5.1 \cdot 10^{+61}:\\ \;\;\;\;z \cdot \sqrt{0.3333333333333333}\\ \mathbf{elif}\;x \leq -2.1 \cdot 10^{+16}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -1.95 \cdot 10^{-42}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -2.65 \cdot 10^{-61}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 3
Error14.0
Cost7316
\[\begin{array}{l} t_0 := \sqrt{0.3333333333333333} \cdot \left(-x\right)\\ t_1 := z \cdot \sqrt{0.3333333333333333}\\ \mathbf{if}\;x \leq -3.5 \cdot 10^{+89}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -4.2 \cdot 10^{+61}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -2.5 \cdot 10^{+16}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -1.95 \cdot 10^{-42}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -8.8 \cdot 10^{-64}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 4
Error31.1
Cost6592
\[z \cdot \sqrt{0.3333333333333333} \]

Error

Reproduce?

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