
(FPCore (x y z) :precision binary64 :pre TRUE (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)
use fmin_fmax_functions
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]
f(x, y, z): x in [-inf, +inf], y in [-inf, +inf], z in [-inf, +inf] code: THEORY BEGIN f(x, y, z: real): real = sqrt(((((x * x) + (y * y)) + (z * z)) / (3))) END code
\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}
Herbie found 3 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 :pre TRUE (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)
use fmin_fmax_functions
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]
f(x, y, z): x in [-inf, +inf], y in [-inf, +inf], z in [-inf, +inf] code: THEORY BEGIN f(x, y, z: real): real = sqrt(((((x * x) + (y * y)) + (z * z)) / (3))) END code
\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}
(FPCore (x y z) :precision binary64 :pre TRUE (* (fmax (fabs y) (fmax (fabs x) (fabs z))) 0.5773502691896257))
double code(double x, double y, double z) {
return fmax(fabs(y), fmax(fabs(x), fabs(z))) * 0.5773502691896257;
}
real(8) function code(x, y, z)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = fmax(abs(y), fmax(abs(x), abs(z))) * 0.5773502691896257d0
end function
public static double code(double x, double y, double z) {
return fmax(Math.abs(y), fmax(Math.abs(x), Math.abs(z))) * 0.5773502691896257;
}
def code(x, y, z): return fmax(math.fabs(y), fmax(math.fabs(x), math.fabs(z))) * 0.5773502691896257
function code(x, y, z) return Float64(fmax(abs(y), fmax(abs(x), abs(z))) * 0.5773502691896257) end
function tmp = code(x, y, z) tmp = max(abs(y), max(abs(x), abs(z))) * 0.5773502691896257; end
code[x_, y_, z_] := N[(N[Max[N[Abs[y], $MachinePrecision], N[Max[N[Abs[x], $MachinePrecision], N[Abs[z], $MachinePrecision]], $MachinePrecision]], $MachinePrecision] * 0.5773502691896257), $MachinePrecision]
f(x, y, z): x in [-inf, +inf], y in [-inf, +inf], z in [-inf, +inf] code: THEORY BEGIN f(x, y, z: real): real = LET tmp_1 = IF ((abs(x)) > (abs(z))) THEN (abs(x)) ELSE (abs(z)) ENDIF IN LET tmp_2 = IF ((abs(x)) > (abs(z))) THEN (abs(x)) ELSE (abs(z)) ENDIF IN LET tmp = IF ((abs(y)) > tmp_1) THEN (abs(y)) ELSE tmp_2 ENDIF IN tmp * (577350269189625731058868041145615279674530029296875e-51) END code
\mathsf{max}\left(\left|y\right|, \mathsf{max}\left(\left|x\right|, \left|z\right|\right)\right) \cdot 0.5773502691896257
Initial program 44.9%
Taylor expanded in z around inf
Applied rewrites18.1%
Evaluated real constant18.1%
(FPCore (x y z) :precision binary64 :pre TRUE (* (fmax (fabs x) (fabs y)) 0.5773502691896257))
double code(double x, double y, double z) {
return fmax(fabs(x), fabs(y)) * 0.5773502691896257;
}
real(8) function code(x, y, z)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = fmax(abs(x), abs(y)) * 0.5773502691896257d0
end function
public static double code(double x, double y, double z) {
return fmax(Math.abs(x), Math.abs(y)) * 0.5773502691896257;
}
def code(x, y, z): return fmax(math.fabs(x), math.fabs(y)) * 0.5773502691896257
function code(x, y, z) return Float64(fmax(abs(x), abs(y)) * 0.5773502691896257) end
function tmp = code(x, y, z) tmp = max(abs(x), abs(y)) * 0.5773502691896257; end
code[x_, y_, z_] := N[(N[Max[N[Abs[x], $MachinePrecision], N[Abs[y], $MachinePrecision]], $MachinePrecision] * 0.5773502691896257), $MachinePrecision]
f(x, y, z): x in [-inf, +inf], y in [-inf, +inf], z in [-inf, +inf] code: THEORY BEGIN f(x, y, z: real): real = LET tmp = IF ((abs(x)) > (abs(y))) THEN (abs(x)) ELSE (abs(y)) ENDIF IN tmp * (577350269189625731058868041145615279674530029296875e-51) END code
\mathsf{max}\left(\left|x\right|, \left|y\right|\right) \cdot 0.5773502691896257
Initial program 44.9%
Taylor expanded in y around inf
Applied rewrites18.9%
Evaluated real constant18.9%
(FPCore (x y z) :precision binary64 :pre TRUE (* (fabs x) 0.5773502691896257))
double code(double x, double y, double z) {
return fabs(x) * 0.5773502691896257;
}
real(8) function code(x, y, z)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = abs(x) * 0.5773502691896257d0
end function
public static double code(double x, double y, double z) {
return Math.abs(x) * 0.5773502691896257;
}
def code(x, y, z): return math.fabs(x) * 0.5773502691896257
function code(x, y, z) return Float64(abs(x) * 0.5773502691896257) end
function tmp = code(x, y, z) tmp = abs(x) * 0.5773502691896257; end
code[x_, y_, z_] := N[(N[Abs[x], $MachinePrecision] * 0.5773502691896257), $MachinePrecision]
f(x, y, z): x in [-inf, +inf], y in [-inf, +inf], z in [-inf, +inf] code: THEORY BEGIN f(x, y, z: real): real = (abs(x)) * (577350269189625731058868041145615279674530029296875e-51) END code
\left|x\right| \cdot 0.5773502691896257
Initial program 44.9%
Taylor expanded in x around inf
Applied rewrites18.6%
Evaluated real constant18.6%
herbie shell --seed 2026092
(FPCore (x y z)
:name "Data.Array.Repa.Algorithms.Pixel:doubleRmsOfRGB8 from repa-algorithms-3.4.0.1"
:precision binary64
(sqrt (/ (+ (+ (* x x) (* y y)) (* z z)) 3.0)))