
(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:
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(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}
(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}
Initial program 46.9%
sqrt-div46.7%
div-inv46.4%
associate-+l+46.4%
add-sqr-sqrt46.4%
hypot-def59.0%
hypot-def98.6%
Applied egg-rr98.6%
associate-*r/99.3%
*-rgt-identity99.3%
hypot-def59.4%
unpow259.4%
+-commutative59.4%
unpow259.4%
unpow259.4%
unpow259.4%
hypot-def99.3%
Simplified99.3%
Final simplification99.3%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (sqrt 0.3333333333333333) (hypot y x))))
(if (<= z 4.1e-70)
t_0
(if (<= z 1.26e+148)
(sqrt (/ (+ (* x x) (* z z)) 3.0))
(if (<= z 2.3e+163) 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 <= 4.1e-70) {
tmp = t_0;
} else if (z <= 1.26e+148) {
tmp = sqrt((((x * x) + (z * z)) / 3.0));
} else if (z <= 2.3e+163) {
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 <= 4.1e-70) {
tmp = t_0;
} else if (z <= 1.26e+148) {
tmp = Math.sqrt((((x * x) + (z * z)) / 3.0));
} else if (z <= 2.3e+163) {
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 <= 4.1e-70: tmp = t_0 elif z <= 1.26e+148: tmp = math.sqrt((((x * x) + (z * z)) / 3.0)) elif z <= 2.3e+163: 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 (z <= 4.1e-70) tmp = t_0; elseif (z <= 1.26e+148) tmp = sqrt(Float64(Float64(Float64(x * x) + Float64(z * z)) / 3.0)); elseif (z <= 2.3e+163) 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 <= 4.1e-70) tmp = t_0; elseif (z <= 1.26e+148) tmp = sqrt((((x * x) + (z * z)) / 3.0)); elseif (z <= 2.3e+163) 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[z, 4.1e-70], t$95$0, If[LessEqual[z, 1.26e+148], N[Sqrt[N[(N[(N[(x * x), $MachinePrecision] + N[(z * z), $MachinePrecision]), $MachinePrecision] / 3.0), $MachinePrecision]], $MachinePrecision], If[LessEqual[z, 2.3e+163], 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 \leq 4.1 \cdot 10^{-70}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq 1.26 \cdot 10^{+148}:\\
\;\;\;\;\sqrt{\frac{x \cdot x + z \cdot z}{3}}\\
\mathbf{elif}\;z \leq 2.3 \cdot 10^{+163}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;z \cdot \sqrt{0.3333333333333333}\\
\end{array}
\end{array}
if z < 4.09999999999999977e-70 or 1.25999999999999997e148 < z < 2.30000000000000002e163Initial program 49.5%
Taylor expanded in z around 0 37.7%
*-commutative37.7%
unpow237.7%
unpow237.7%
hypot-def72.7%
Simplified72.7%
if 4.09999999999999977e-70 < z < 1.25999999999999997e148Initial program 63.9%
Taylor expanded in x around inf 46.7%
unpow246.7%
Simplified46.7%
if 2.30000000000000002e163 < z Initial program 7.1%
Taylor expanded in z around inf 84.4%
Final simplification69.7%
(FPCore (x y z) :precision binary64 (* (sqrt 0.3333333333333333) (hypot z x)))
double code(double x, double y, double z) {
return sqrt(0.3333333333333333) * hypot(z, x);
}
public static double code(double x, double y, double z) {
return Math.sqrt(0.3333333333333333) * Math.hypot(z, x);
}
def code(x, y, z): return math.sqrt(0.3333333333333333) * math.hypot(z, x)
function code(x, y, z) return Float64(sqrt(0.3333333333333333) * hypot(z, x)) end
function tmp = code(x, y, z) tmp = sqrt(0.3333333333333333) * hypot(z, x); end
code[x_, y_, z_] := N[(N[Sqrt[0.3333333333333333], $MachinePrecision] * N[Sqrt[z ^ 2 + x ^ 2], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt{0.3333333333333333} \cdot \mathsf{hypot}\left(z, x\right)
\end{array}
Initial program 46.9%
Taylor expanded in y around 0 32.7%
*-commutative32.7%
unpow232.7%
unpow232.7%
hypot-def70.3%
Simplified70.3%
Final simplification70.3%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (sqrt 0.3333333333333333) (- x))))
(if (<= z 2.15e-71)
t_0
(if (<= z 7.8e+147)
(sqrt (/ (+ (* x x) (* z z)) 3.0))
(if (<= z 3.5e+163) t_0 (* z (sqrt 0.3333333333333333)))))))
double code(double x, double y, double z) {
double t_0 = sqrt(0.3333333333333333) * -x;
double tmp;
if (z <= 2.15e-71) {
tmp = t_0;
} else if (z <= 7.8e+147) {
tmp = sqrt((((x * x) + (z * z)) / 3.0));
} else if (z <= 3.5e+163) {
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 = sqrt(0.3333333333333333d0) * -x
if (z <= 2.15d-71) then
tmp = t_0
else if (z <= 7.8d+147) then
tmp = sqrt((((x * x) + (z * z)) / 3.0d0))
else if (z <= 3.5d+163) 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 = Math.sqrt(0.3333333333333333) * -x;
double tmp;
if (z <= 2.15e-71) {
tmp = t_0;
} else if (z <= 7.8e+147) {
tmp = Math.sqrt((((x * x) + (z * z)) / 3.0));
} else if (z <= 3.5e+163) {
tmp = t_0;
} else {
tmp = z * Math.sqrt(0.3333333333333333);
}
return tmp;
}
def code(x, y, z): t_0 = math.sqrt(0.3333333333333333) * -x tmp = 0 if z <= 2.15e-71: tmp = t_0 elif z <= 7.8e+147: tmp = math.sqrt((((x * x) + (z * z)) / 3.0)) elif z <= 3.5e+163: tmp = t_0 else: tmp = z * math.sqrt(0.3333333333333333) return tmp
function code(x, y, z) t_0 = Float64(sqrt(0.3333333333333333) * Float64(-x)) tmp = 0.0 if (z <= 2.15e-71) tmp = t_0; elseif (z <= 7.8e+147) tmp = sqrt(Float64(Float64(Float64(x * x) + Float64(z * z)) / 3.0)); elseif (z <= 3.5e+163) 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) * -x; tmp = 0.0; if (z <= 2.15e-71) tmp = t_0; elseif (z <= 7.8e+147) tmp = sqrt((((x * x) + (z * z)) / 3.0)); elseif (z <= 3.5e+163) 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] * (-x)), $MachinePrecision]}, If[LessEqual[z, 2.15e-71], t$95$0, If[LessEqual[z, 7.8e+147], N[Sqrt[N[(N[(N[(x * x), $MachinePrecision] + N[(z * z), $MachinePrecision]), $MachinePrecision] / 3.0), $MachinePrecision]], $MachinePrecision], If[LessEqual[z, 3.5e+163], t$95$0, N[(z * N[Sqrt[0.3333333333333333], $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{0.3333333333333333} \cdot \left(-x\right)\\
\mathbf{if}\;z \leq 2.15 \cdot 10^{-71}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq 7.8 \cdot 10^{+147}:\\
\;\;\;\;\sqrt{\frac{x \cdot x + z \cdot z}{3}}\\
\mathbf{elif}\;z \leq 3.5 \cdot 10^{+163}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;z \cdot \sqrt{0.3333333333333333}\\
\end{array}
\end{array}
if z < 2.1499999999999998e-71 or 7.80000000000000033e147 < z < 3.5000000000000003e163Initial program 49.5%
Taylor expanded in x around -inf 20.8%
mul-1-neg20.8%
distribute-rgt-neg-in20.8%
Simplified20.8%
if 2.1499999999999998e-71 < z < 7.80000000000000033e147Initial program 63.9%
Taylor expanded in x around inf 46.7%
unpow246.7%
Simplified46.7%
if 3.5000000000000003e163 < z Initial program 7.1%
Taylor expanded in z around inf 84.4%
Final simplification32.9%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (sqrt 0.3333333333333333) (- x))))
(if (<= z 2.1e-16)
t_0
(if (<= z 1.15e+148)
(/ z (sqrt 3.0))
(if (<= z 6.2e+162) t_0 (* z (sqrt 0.3333333333333333)))))))
double code(double x, double y, double z) {
double t_0 = sqrt(0.3333333333333333) * -x;
double tmp;
if (z <= 2.1e-16) {
tmp = t_0;
} else if (z <= 1.15e+148) {
tmp = z / sqrt(3.0);
} else if (z <= 6.2e+162) {
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 = sqrt(0.3333333333333333d0) * -x
if (z <= 2.1d-16) then
tmp = t_0
else if (z <= 1.15d+148) then
tmp = z / sqrt(3.0d0)
else if (z <= 6.2d+162) 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 = Math.sqrt(0.3333333333333333) * -x;
double tmp;
if (z <= 2.1e-16) {
tmp = t_0;
} else if (z <= 1.15e+148) {
tmp = z / Math.sqrt(3.0);
} else if (z <= 6.2e+162) {
tmp = t_0;
} else {
tmp = z * Math.sqrt(0.3333333333333333);
}
return tmp;
}
def code(x, y, z): t_0 = math.sqrt(0.3333333333333333) * -x tmp = 0 if z <= 2.1e-16: tmp = t_0 elif z <= 1.15e+148: tmp = z / math.sqrt(3.0) elif z <= 6.2e+162: tmp = t_0 else: tmp = z * math.sqrt(0.3333333333333333) return tmp
function code(x, y, z) t_0 = Float64(sqrt(0.3333333333333333) * Float64(-x)) tmp = 0.0 if (z <= 2.1e-16) tmp = t_0; elseif (z <= 1.15e+148) tmp = Float64(z / sqrt(3.0)); elseif (z <= 6.2e+162) 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) * -x; tmp = 0.0; if (z <= 2.1e-16) tmp = t_0; elseif (z <= 1.15e+148) tmp = z / sqrt(3.0); elseif (z <= 6.2e+162) 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] * (-x)), $MachinePrecision]}, If[LessEqual[z, 2.1e-16], t$95$0, If[LessEqual[z, 1.15e+148], N[(z / N[Sqrt[3.0], $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 6.2e+162], t$95$0, N[(z * N[Sqrt[0.3333333333333333], $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{0.3333333333333333} \cdot \left(-x\right)\\
\mathbf{if}\;z \leq 2.1 \cdot 10^{-16}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq 1.15 \cdot 10^{+148}:\\
\;\;\;\;\frac{z}{\sqrt{3}}\\
\mathbf{elif}\;z \leq 6.2 \cdot 10^{+162}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;z \cdot \sqrt{0.3333333333333333}\\
\end{array}
\end{array}
if z < 2.1000000000000001e-16 or 1.15e148 < z < 6.1999999999999999e162Initial program 50.2%
Taylor expanded in x around -inf 20.6%
mul-1-neg20.6%
distribute-rgt-neg-in20.6%
Simplified20.6%
if 2.1000000000000001e-16 < z < 1.15e148Initial program 63.6%
sqrt-div63.5%
div-inv63.0%
associate-+l+63.0%
add-sqr-sqrt63.0%
hypot-def80.8%
hypot-def98.6%
Applied egg-rr98.6%
associate-*r/99.5%
*-rgt-identity99.5%
hypot-def81.4%
unpow281.4%
+-commutative81.4%
unpow281.4%
unpow281.4%
unpow281.4%
hypot-def99.5%
Simplified99.5%
Taylor expanded in z around inf 52.6%
if 6.1999999999999999e162 < z Initial program 7.1%
Taylor expanded in z around inf 84.4%
Final simplification32.8%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (sqrt 0.3333333333333333) (- x))))
(if (<= z 1.8e-14)
t_0
(if (<= z 1.26e+148)
(sqrt (* z (* z 0.3333333333333333)))
(if (<= z 6.2e+162) t_0 (* z (sqrt 0.3333333333333333)))))))
double code(double x, double y, double z) {
double t_0 = sqrt(0.3333333333333333) * -x;
double tmp;
if (z <= 1.8e-14) {
tmp = t_0;
} else if (z <= 1.26e+148) {
tmp = sqrt((z * (z * 0.3333333333333333)));
} else if (z <= 6.2e+162) {
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 = sqrt(0.3333333333333333d0) * -x
if (z <= 1.8d-14) then
tmp = t_0
else if (z <= 1.26d+148) then
tmp = sqrt((z * (z * 0.3333333333333333d0)))
else if (z <= 6.2d+162) 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 = Math.sqrt(0.3333333333333333) * -x;
double tmp;
if (z <= 1.8e-14) {
tmp = t_0;
} else if (z <= 1.26e+148) {
tmp = Math.sqrt((z * (z * 0.3333333333333333)));
} else if (z <= 6.2e+162) {
tmp = t_0;
} else {
tmp = z * Math.sqrt(0.3333333333333333);
}
return tmp;
}
def code(x, y, z): t_0 = math.sqrt(0.3333333333333333) * -x tmp = 0 if z <= 1.8e-14: tmp = t_0 elif z <= 1.26e+148: tmp = math.sqrt((z * (z * 0.3333333333333333))) elif z <= 6.2e+162: tmp = t_0 else: tmp = z * math.sqrt(0.3333333333333333) return tmp
function code(x, y, z) t_0 = Float64(sqrt(0.3333333333333333) * Float64(-x)) tmp = 0.0 if (z <= 1.8e-14) tmp = t_0; elseif (z <= 1.26e+148) tmp = sqrt(Float64(z * Float64(z * 0.3333333333333333))); elseif (z <= 6.2e+162) 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) * -x; tmp = 0.0; if (z <= 1.8e-14) tmp = t_0; elseif (z <= 1.26e+148) tmp = sqrt((z * (z * 0.3333333333333333))); elseif (z <= 6.2e+162) 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] * (-x)), $MachinePrecision]}, If[LessEqual[z, 1.8e-14], t$95$0, If[LessEqual[z, 1.26e+148], N[Sqrt[N[(z * N[(z * 0.3333333333333333), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], If[LessEqual[z, 6.2e+162], t$95$0, N[(z * N[Sqrt[0.3333333333333333], $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{0.3333333333333333} \cdot \left(-x\right)\\
\mathbf{if}\;z \leq 1.8 \cdot 10^{-14}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq 1.26 \cdot 10^{+148}:\\
\;\;\;\;\sqrt{z \cdot \left(z \cdot 0.3333333333333333\right)}\\
\mathbf{elif}\;z \leq 6.2 \cdot 10^{+162}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;z \cdot \sqrt{0.3333333333333333}\\
\end{array}
\end{array}
if z < 1.7999999999999999e-14 or 1.25999999999999997e148 < z < 6.1999999999999999e162Initial program 50.2%
Taylor expanded in x around -inf 20.6%
mul-1-neg20.6%
distribute-rgt-neg-in20.6%
Simplified20.6%
if 1.7999999999999999e-14 < z < 1.25999999999999997e148Initial program 63.6%
Taylor expanded in z around inf 52.8%
*-commutative52.8%
unpow252.8%
associate-*l*52.7%
Simplified52.7%
if 6.1999999999999999e162 < z Initial program 7.1%
Taylor expanded in z around inf 84.4%
Final simplification32.8%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (sqrt 0.3333333333333333) (- x))))
(if (<= z 1.8e-14)
t_0
(if (<= z 1.26e+148)
(sqrt (* 0.3333333333333333 (* z z)))
(if (<= z 8.2e+162) t_0 (* z (sqrt 0.3333333333333333)))))))
double code(double x, double y, double z) {
double t_0 = sqrt(0.3333333333333333) * -x;
double tmp;
if (z <= 1.8e-14) {
tmp = t_0;
} else if (z <= 1.26e+148) {
tmp = sqrt((0.3333333333333333 * (z * z)));
} else if (z <= 8.2e+162) {
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 = sqrt(0.3333333333333333d0) * -x
if (z <= 1.8d-14) then
tmp = t_0
else if (z <= 1.26d+148) then
tmp = sqrt((0.3333333333333333d0 * (z * z)))
else if (z <= 8.2d+162) 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 = Math.sqrt(0.3333333333333333) * -x;
double tmp;
if (z <= 1.8e-14) {
tmp = t_0;
} else if (z <= 1.26e+148) {
tmp = Math.sqrt((0.3333333333333333 * (z * z)));
} else if (z <= 8.2e+162) {
tmp = t_0;
} else {
tmp = z * Math.sqrt(0.3333333333333333);
}
return tmp;
}
def code(x, y, z): t_0 = math.sqrt(0.3333333333333333) * -x tmp = 0 if z <= 1.8e-14: tmp = t_0 elif z <= 1.26e+148: tmp = math.sqrt((0.3333333333333333 * (z * z))) elif z <= 8.2e+162: tmp = t_0 else: tmp = z * math.sqrt(0.3333333333333333) return tmp
function code(x, y, z) t_0 = Float64(sqrt(0.3333333333333333) * Float64(-x)) tmp = 0.0 if (z <= 1.8e-14) tmp = t_0; elseif (z <= 1.26e+148) tmp = sqrt(Float64(0.3333333333333333 * Float64(z * z))); elseif (z <= 8.2e+162) 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) * -x; tmp = 0.0; if (z <= 1.8e-14) tmp = t_0; elseif (z <= 1.26e+148) tmp = sqrt((0.3333333333333333 * (z * z))); elseif (z <= 8.2e+162) 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] * (-x)), $MachinePrecision]}, If[LessEqual[z, 1.8e-14], t$95$0, If[LessEqual[z, 1.26e+148], N[Sqrt[N[(0.3333333333333333 * N[(z * z), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], If[LessEqual[z, 8.2e+162], t$95$0, N[(z * N[Sqrt[0.3333333333333333], $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{0.3333333333333333} \cdot \left(-x\right)\\
\mathbf{if}\;z \leq 1.8 \cdot 10^{-14}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq 1.26 \cdot 10^{+148}:\\
\;\;\;\;\sqrt{0.3333333333333333 \cdot \left(z \cdot z\right)}\\
\mathbf{elif}\;z \leq 8.2 \cdot 10^{+162}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;z \cdot \sqrt{0.3333333333333333}\\
\end{array}
\end{array}
if z < 1.7999999999999999e-14 or 1.25999999999999997e148 < z < 8.1999999999999998e162Initial program 50.2%
Taylor expanded in x around -inf 20.6%
mul-1-neg20.6%
distribute-rgt-neg-in20.6%
Simplified20.6%
if 1.7999999999999999e-14 < z < 1.25999999999999997e148Initial program 63.6%
Taylor expanded in z around inf 52.8%
*-commutative52.8%
unpow252.8%
Simplified52.8%
if 8.1999999999999998e162 < z Initial program 7.1%
Taylor expanded in z around inf 84.4%
Final simplification32.8%
(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}
Initial program 46.9%
Taylor expanded in z around inf 19.4%
Final simplification19.4%
(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}
herbie shell --seed 2023195
(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)))