
(FPCore (x y z) :precision binary64 :pre TRUE (sqrt (+ (+ (* x x) (* y y)) (* z z))))
double code(double x, double y, double z) {
return sqrt((((x * x) + (y * y)) + (z * z)));
}
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)))
end function
public static double code(double x, double y, double z) {
return Math.sqrt((((x * x) + (y * y)) + (z * z)));
}
def code(x, y, z): return math.sqrt((((x * x) + (y * y)) + (z * z)))
function code(x, y, z) return sqrt(Float64(Float64(Float64(x * x) + Float64(y * y)) + Float64(z * z))) end
function tmp = code(x, y, z) tmp = sqrt((((x * x) + (y * y)) + (z * z))); end
code[x_, y_, z_] := N[Sqrt[N[(N[(N[(x * x), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision] + N[(z * z), $MachinePrecision]), $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))) END code
\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}
Herbie found 2 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 :pre TRUE (sqrt (+ (+ (* x x) (* y y)) (* z z))))
double code(double x, double y, double z) {
return sqrt((((x * x) + (y * y)) + (z * z)));
}
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)))
end function
public static double code(double x, double y, double z) {
return Math.sqrt((((x * x) + (y * y)) + (z * z)));
}
def code(x, y, z): return math.sqrt((((x * x) + (y * y)) + (z * z)))
function code(x, y, z) return sqrt(Float64(Float64(Float64(x * x) + Float64(y * y)) + Float64(z * z))) end
function tmp = code(x, y, z) tmp = sqrt((((x * x) + (y * y)) + (z * z))); end
code[x_, y_, z_] := N[Sqrt[N[(N[(N[(x * x), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision] + N[(z * z), $MachinePrecision]), $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))) END code
\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}
(FPCore (x y z) :precision binary64 :pre TRUE (fmax (fabs y) (fmax (fabs x) (fabs z))))
double code(double x, double y, double z) {
return fmax(fabs(y), fmax(fabs(x), fabs(z)));
}
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)))
end function
public static double code(double x, double y, double z) {
return fmax(Math.abs(y), fmax(Math.abs(x), Math.abs(z)));
}
def code(x, y, z): return fmax(math.fabs(y), fmax(math.fabs(x), math.fabs(z)))
function code(x, y, z) return fmax(abs(y), fmax(abs(x), abs(z))) end
function tmp = code(x, y, z) tmp = max(abs(y), max(abs(x), abs(z))); end
code[x_, y_, z_] := N[Max[N[Abs[y], $MachinePrecision], N[Max[N[Abs[x], $MachinePrecision], N[Abs[z], $MachinePrecision]], $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 = 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 END code
\mathsf{max}\left(\left|y\right|, \mathsf{max}\left(\left|x\right|, \left|z\right|\right)\right)
Initial program 45.0%
Taylor expanded in x around -inf
Applied rewrites18.9%
Applied rewrites18.9%
Taylor expanded in undef-var around zero
Applied rewrites2.3%
Taylor expanded in z around inf
Applied rewrites18.2%
(FPCore (x y z) :precision binary64 :pre TRUE (fmax (fabs x) (fabs y)))
double code(double x, double y, double z) {
return fmax(fabs(x), fabs(y));
}
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))
end function
public static double code(double x, double y, double z) {
return fmax(Math.abs(x), Math.abs(y));
}
def code(x, y, z): return fmax(math.fabs(x), math.fabs(y))
function code(x, y, z) return fmax(abs(x), abs(y)) end
function tmp = code(x, y, z) tmp = max(abs(x), abs(y)); end
code[x_, y_, z_] := N[Max[N[Abs[x], $MachinePrecision], N[Abs[y], $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 = LET tmp = IF ((abs(x)) > (abs(y))) THEN (abs(x)) ELSE (abs(y)) ENDIF IN tmp END code
\mathsf{max}\left(\left|x\right|, \left|y\right|\right)
Initial program 45.0%
Taylor expanded in x around -inf
Applied rewrites18.9%
Applied rewrites18.9%
Taylor expanded in undef-var around zero
Applied rewrites2.3%
Taylor expanded in y around inf
Applied rewrites19.0%
herbie shell --seed 2026092
(FPCore (x y z)
:name "FRP.Yampa.Vector3:vector3Rho from Yampa-0.10.2"
:precision binary64
(sqrt (+ (+ (* x x) (* y y)) (* z z))))