
(FPCore (x y) :precision binary64 :pre TRUE (/ (fabs (- x y)) (fabs y)))
double code(double x, double y) {
return fabs((x - y)) / fabs(y);
}
real(8) function code(x, y)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
code = abs((x - y)) / abs(y)
end function
public static double code(double x, double y) {
return Math.abs((x - y)) / Math.abs(y);
}
def code(x, y): return math.fabs((x - y)) / math.fabs(y)
function code(x, y) return Float64(abs(Float64(x - y)) / abs(y)) end
function tmp = code(x, y) tmp = abs((x - y)) / abs(y); end
code[x_, y_] := N[(N[Abs[N[(x - y), $MachinePrecision]], $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 = (abs((x - y))) / (abs(y)) END code
\frac{\left|x - y\right|}{\left|y\right|}
Herbie found 3 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 :pre TRUE (/ (fabs (- x y)) (fabs y)))
double code(double x, double y) {
return fabs((x - y)) / fabs(y);
}
real(8) function code(x, y)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
code = abs((x - y)) / abs(y)
end function
public static double code(double x, double y) {
return Math.abs((x - y)) / Math.abs(y);
}
def code(x, y): return math.fabs((x - y)) / math.fabs(y)
function code(x, y) return Float64(abs(Float64(x - y)) / abs(y)) end
function tmp = code(x, y) tmp = abs((x - y)) / abs(y); end
code[x_, y_] := N[(N[Abs[N[(x - y), $MachinePrecision]], $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 = (abs((x - y))) / (abs(y)) END code
\frac{\left|x - y\right|}{\left|y\right|}
(FPCore (x y) :precision binary64 :pre TRUE (fabs (+ -1.0 (/ x y))))
double code(double x, double y) {
return fabs((-1.0 + (x / y)));
}
real(8) function code(x, y)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
code = abs(((-1.0d0) + (x / y)))
end function
public static double code(double x, double y) {
return Math.abs((-1.0 + (x / y)));
}
def code(x, y): return math.fabs((-1.0 + (x / y)))
function code(x, y) return abs(Float64(-1.0 + Float64(x / y))) end
function tmp = code(x, y) tmp = abs((-1.0 + (x / y))); end
code[x_, y_] := N[Abs[N[(-1.0 + N[(x / y), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
f(x, y): x in [-inf, +inf], y in [-inf, +inf] code: THEORY BEGIN f(x, y: real): real = abs(((-1) + (x / y))) END code
\left|-1 + \frac{x}{y}\right|
Initial program 100.0%
Applied rewrites100.0%
Applied rewrites100.0%
(FPCore (x y) :precision binary64 :pre TRUE (fabs (/ (- x y) y)))
double code(double x, double y) {
return fabs(((x - y) / y));
}
real(8) function code(x, y)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
code = abs(((x - y) / y))
end function
public static double code(double x, double y) {
return Math.abs(((x - y) / y));
}
def code(x, y): return math.fabs(((x - y) / y))
function code(x, y) return abs(Float64(Float64(x - y) / y)) end
function tmp = code(x, y) tmp = abs(((x - y) / y)); end
code[x_, y_] := N[Abs[N[(N[(x - y), $MachinePrecision] / y), $MachinePrecision]], $MachinePrecision]
f(x, y): x in [-inf, +inf], y in [-inf, +inf] code: THEORY BEGIN f(x, y: real): real = abs(((x - y) / y)) END code
\left|\frac{x - y}{y}\right|
Initial program 100.0%
Applied rewrites100.0%
(FPCore (x y) :precision binary64 :pre TRUE 1.0)
double code(double x, double y) {
return 1.0;
}
real(8) function code(x, y)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 1.0d0
end function
public static double code(double x, double y) {
return 1.0;
}
def code(x, y): return 1.0
function code(x, y) return 1.0 end
function tmp = code(x, y) tmp = 1.0; end
code[x_, y_] := 1.0
f(x, y): x in [-inf, +inf], y in [-inf, +inf] code: THEORY BEGIN f(x, y: real): real = 1 END code
1
Initial program 100.0%
Applied rewrites100.0%
Taylor expanded in x around 0
Applied rewrites52.6%
herbie shell --seed 2026092
(FPCore (x y)
:name "Numeric.LinearAlgebra.Util:formatSparse from hmatrix-0.16.1.5"
:precision binary64
(/ (fabs (- x y)) (fabs y)))