
(FPCore (x y) :precision binary64 :pre TRUE (sqrt (+ (* x x) (* y y))))
double code(double x, double y) {
return sqrt(((x * x) + (y * y)));
}
real(8) function code(x, y)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
code = sqrt(((x * x) + (y * y)))
end function
public static double code(double x, double y) {
return Math.sqrt(((x * x) + (y * y)));
}
def code(x, y): return math.sqrt(((x * x) + (y * y)))
function code(x, y) return sqrt(Float64(Float64(x * x) + Float64(y * y))) end
function tmp = code(x, y) tmp = sqrt(((x * x) + (y * y))); end
code[x_, y_] := N[Sqrt[N[(N[(x * x), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
f(x, y): x in [-inf, +inf], y in [-inf, +inf] code: THEORY BEGIN f(x, y: real): real = sqrt(((x * x) + (y * y))) END code
\sqrt{x \cdot x + y \cdot y}
Herbie found 2 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 :pre TRUE (sqrt (+ (* x x) (* y y))))
double code(double x, double y) {
return sqrt(((x * x) + (y * y)));
}
real(8) function code(x, y)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
code = sqrt(((x * x) + (y * y)))
end function
public static double code(double x, double y) {
return Math.sqrt(((x * x) + (y * y)));
}
def code(x, y): return math.sqrt(((x * x) + (y * y)))
function code(x, y) return sqrt(Float64(Float64(x * x) + Float64(y * y))) end
function tmp = code(x, y) tmp = sqrt(((x * x) + (y * y))); end
code[x_, y_] := N[Sqrt[N[(N[(x * x), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
f(x, y): x in [-inf, +inf], y in [-inf, +inf] code: THEORY BEGIN f(x, y: real): real = sqrt(((x * x) + (y * y))) END code
\sqrt{x \cdot x + y \cdot y}
(FPCore (x y) :precision binary64 :pre TRUE (hypot x y))
double code(double x, double y) {
return hypot(x, y);
}
public static double code(double x, double y) {
return Math.hypot(x, y);
}
def code(x, y): return math.hypot(x, y)
function code(x, y) return hypot(x, y) end
function tmp = code(x, y) tmp = hypot(x, y); end
code[x_, y_] := N[Sqrt[x ^ 2 + y ^ 2], $MachinePrecision]
f(x, y): x in [-inf, +inf], y in [-inf, +inf] code: THEORY BEGIN f(x, y: real): real = sqrt(((x ^ (2)) + (y ^ (2)))) END code
\mathsf{hypot}\left(x, y\right)
Initial program 54.4%
Applied rewrites100.0%
(FPCore (x y) :precision binary64 :pre TRUE (fmax (fabs x) (fabs y)))
double code(double x, double y) {
return fmax(fabs(x), fabs(y));
}
real(8) function code(x, y)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
code = fmax(abs(x), abs(y))
end function
public static double code(double x, double y) {
return fmax(Math.abs(x), Math.abs(y));
}
def code(x, y): return fmax(math.fabs(x), math.fabs(y))
function code(x, y) return fmax(abs(x), abs(y)) end
function tmp = code(x, y) tmp = max(abs(x), abs(y)); end
code[x_, y_] := N[Max[N[Abs[x], $MachinePrecision], N[Abs[y], $MachinePrecision]], $MachinePrecision]
f(x, y): x in [-inf, +inf], y in [-inf, +inf] code: THEORY BEGIN f(x, y: 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 54.4%
Taylor expanded in x around -inf
Applied rewrites27.4%
Applied rewrites27.4%
Taylor expanded in undef-var around zero
Applied rewrites2.7%
Taylor expanded in y around inf
Applied rewrites27.4%
herbie shell --seed 2026092
(FPCore (x y)
:name "Data.Octree.Internal:octantDistance from Octree-0.5.4.2"
:precision binary64
(sqrt (+ (* x x) (* y y))))