
(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));
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
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]
\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 (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));
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
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]
\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}
(FPCore (x y z) :precision binary64 (* (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;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
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]
\mathsf{max}\left(\left|y\right|, \mathsf{max}\left(\left|x\right|, \left|z\right|\right)\right) \cdot 0.5773502691896257
Initial program 45.0%
Taylor expanded in z around inf
lower-*.f64N/A
lower-sqrt.f6418.2%
Applied rewrites18.2%
Evaluated real constant18.2%
(FPCore (x y z) :precision binary64 (* (fabs x) 0.5773502691896257))
double code(double x, double y, double z) {
return fabs(x) * 0.5773502691896257;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
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]
\left|x\right| \cdot 0.5773502691896257
Initial program 45.0%
Taylor expanded in x around inf
lower-*.f64N/A
lower-sqrt.f6418.2%
Applied rewrites18.2%
Evaluated real constant18.2%
(FPCore (x y z) :precision binary64 (* (fmin (fmin x y) z) -0.5773502691896257))
double code(double x, double y, double z) {
return fmin(fmin(x, y), z) * -0.5773502691896257;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
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 = fmin(fmin(x, y), z) * (-0.5773502691896257d0)
end function
public static double code(double x, double y, double z) {
return fmin(fmin(x, y), z) * -0.5773502691896257;
}
def code(x, y, z): return fmin(fmin(x, y), z) * -0.5773502691896257
function code(x, y, z) return Float64(fmin(fmin(x, y), z) * -0.5773502691896257) end
function tmp = code(x, y, z) tmp = min(min(x, y), z) * -0.5773502691896257; end
code[x_, y_, z_] := N[(N[Min[N[Min[x, y], $MachinePrecision], z], $MachinePrecision] * -0.5773502691896257), $MachinePrecision]
\mathsf{min}\left(\mathsf{min}\left(x, y\right), z\right) \cdot -0.5773502691896257
Initial program 45.0%
Taylor expanded in x around -inf
lower-*.f64N/A
lower-*.f64N/A
lower-sqrt.f6418.8%
Applied rewrites18.8%
Evaluated real constant18.8%
lift-*.f64N/A
mul-1-negN/A
lift-*.f64N/A
distribute-rgt-neg-inN/A
lower-*.f64N/A
metadata-eval18.8%
Applied rewrites18.8%
herbie shell --seed 2025258
(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)))