
(FPCore (x y) :precision binary64 (/ (fabs (- x y)) (fabs y)))
double code(double x, double y) {
return fabs((x - y)) / fabs(y);
}
real(8) function code(x, y)
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]
\begin{array}{l}
\\
\frac{\left|x - y\right|}{\left|y\right|}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 5 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (/ (fabs (- x y)) (fabs y)))
double code(double x, double y) {
return fabs((x - y)) / fabs(y);
}
real(8) function code(x, y)
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]
\begin{array}{l}
\\
\frac{\left|x - y\right|}{\left|y\right|}
\end{array}
(FPCore (x y) :precision binary64 (fabs (/ (- x y) y)))
double code(double x, double y) {
return fabs(((x - y) / y));
}
real(8) function code(x, y)
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]
\begin{array}{l}
\\
\left|\frac{x - y}{y}\right|
\end{array}
Initial program 100.0%
lift-/.f64N/A
lift-fabs.f64N/A
neg-fabsN/A
lift-fabs.f64N/A
div-fabsN/A
lower-fabs.f64N/A
neg-sub0N/A
lift--.f64N/A
associate--r-N/A
neg-sub0N/A
+-commutativeN/A
sub-negN/A
lower-/.f64N/A
lower--.f64100.0
Applied rewrites100.0%
Final simplification100.0%
(FPCore (x y) :precision binary64 (let* ((t_0 (fabs (/ (- x y) y)))) (if (or (<= t_0 2e+117) (not (<= t_0 5e+273))) (- 1.0 (/ x y)) (/ x y))))
double code(double x, double y) {
double t_0 = fabs(((x - y) / y));
double tmp;
if ((t_0 <= 2e+117) || !(t_0 <= 5e+273)) {
tmp = 1.0 - (x / y);
} else {
tmp = x / y;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: t_0
real(8) :: tmp
t_0 = abs(((x - y) / y))
if ((t_0 <= 2d+117) .or. (.not. (t_0 <= 5d+273))) then
tmp = 1.0d0 - (x / y)
else
tmp = x / y
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = Math.abs(((x - y) / y));
double tmp;
if ((t_0 <= 2e+117) || !(t_0 <= 5e+273)) {
tmp = 1.0 - (x / y);
} else {
tmp = x / y;
}
return tmp;
}
def code(x, y): t_0 = math.fabs(((x - y) / y)) tmp = 0 if (t_0 <= 2e+117) or not (t_0 <= 5e+273): tmp = 1.0 - (x / y) else: tmp = x / y return tmp
function code(x, y) t_0 = abs(Float64(Float64(x - y) / y)) tmp = 0.0 if ((t_0 <= 2e+117) || !(t_0 <= 5e+273)) tmp = Float64(1.0 - Float64(x / y)); else tmp = Float64(x / y); end return tmp end
function tmp_2 = code(x, y) t_0 = abs(((x - y) / y)); tmp = 0.0; if ((t_0 <= 2e+117) || ~((t_0 <= 5e+273))) tmp = 1.0 - (x / y); else tmp = x / y; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[Abs[N[(N[(x - y), $MachinePrecision] / y), $MachinePrecision]], $MachinePrecision]}, If[Or[LessEqual[t$95$0, 2e+117], N[Not[LessEqual[t$95$0, 5e+273]], $MachinePrecision]], N[(1.0 - N[(x / y), $MachinePrecision]), $MachinePrecision], N[(x / y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left|\frac{x - y}{y}\right|\\
\mathbf{if}\;t\_0 \leq 2 \cdot 10^{+117} \lor \neg \left(t\_0 \leq 5 \cdot 10^{+273}\right):\\
\;\;\;\;1 - \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{y}\\
\end{array}
\end{array}
if (/.f64 (fabs.f64 (-.f64 x y)) (fabs.f64 y)) < 2.0000000000000001e117 or 4.99999999999999961e273 < (/.f64 (fabs.f64 (-.f64 x y)) (fabs.f64 y)) Initial program 100.0%
lift-/.f64N/A
lift-fabs.f64N/A
neg-fabsN/A
lift-fabs.f64N/A
div-fabsN/A
lower-fabs.f64N/A
neg-sub0N/A
lift--.f64N/A
associate--r-N/A
neg-sub0N/A
+-commutativeN/A
sub-negN/A
lower-/.f64N/A
lower--.f64100.0
Applied rewrites100.0%
lift-fabs.f64N/A
lift-/.f64N/A
clear-numN/A
inv-powN/A
sqr-powN/A
fabs-sqrN/A
sqr-powN/A
inv-powN/A
clear-numN/A
lift--.f64N/A
div-subN/A
*-inversesN/A
metadata-evalN/A
lower--.f64N/A
metadata-evalN/A
lower-/.f6486.8
Applied rewrites86.8%
if 2.0000000000000001e117 < (/.f64 (fabs.f64 (-.f64 x y)) (fabs.f64 y)) < 4.99999999999999961e273Initial program 100.0%
lift-/.f64N/A
lift-fabs.f64N/A
neg-fabsN/A
lift-fabs.f64N/A
div-fabsN/A
lower-fabs.f64N/A
neg-sub0N/A
lift--.f64N/A
associate--r-N/A
neg-sub0N/A
+-commutativeN/A
sub-negN/A
lower-/.f64N/A
lower--.f64100.0
Applied rewrites100.0%
lift-fabs.f64N/A
lift-/.f64N/A
clear-numN/A
inv-powN/A
sqr-powN/A
fabs-sqrN/A
sqr-powN/A
inv-powN/A
frac-2negN/A
clear-numN/A
div-invN/A
inv-powN/A
sqr-powN/A
pow-prod-downN/A
sqr-negN/A
pow-prod-downN/A
sqr-powN/A
inv-powN/A
div-invN/A
lift--.f64N/A
flip--N/A
distribute-neg-frac2N/A
Applied rewrites58.5%
Taylor expanded in x around 0
Applied rewrites1.0%
Taylor expanded in x around inf
lower-/.f6458.5
Applied rewrites58.5%
Final simplification80.2%
(FPCore (x y) :precision binary64 (if (<= (fabs (/ (- x y) y)) 1e+26) (fabs 1.0) (/ x y)))
double code(double x, double y) {
double tmp;
if (fabs(((x - y) / y)) <= 1e+26) {
tmp = fabs(1.0);
} else {
tmp = x / y;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (abs(((x - y) / y)) <= 1d+26) then
tmp = abs(1.0d0)
else
tmp = x / y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (Math.abs(((x - y) / y)) <= 1e+26) {
tmp = Math.abs(1.0);
} else {
tmp = x / y;
}
return tmp;
}
def code(x, y): tmp = 0 if math.fabs(((x - y) / y)) <= 1e+26: tmp = math.fabs(1.0) else: tmp = x / y return tmp
function code(x, y) tmp = 0.0 if (abs(Float64(Float64(x - y) / y)) <= 1e+26) tmp = abs(1.0); else tmp = Float64(x / y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (abs(((x - y) / y)) <= 1e+26) tmp = abs(1.0); else tmp = x / y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[N[Abs[N[(N[(x - y), $MachinePrecision] / y), $MachinePrecision]], $MachinePrecision], 1e+26], N[Abs[1.0], $MachinePrecision], N[(x / y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left|\frac{x - y}{y}\right| \leq 10^{+26}:\\
\;\;\;\;\left|1\right|\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{y}\\
\end{array}
\end{array}
if (/.f64 (fabs.f64 (-.f64 x y)) (fabs.f64 y)) < 1.00000000000000005e26Initial program 100.0%
lift-/.f64N/A
lift-fabs.f64N/A
neg-fabsN/A
lift-fabs.f64N/A
div-fabsN/A
lower-fabs.f64N/A
neg-sub0N/A
lift--.f64N/A
associate--r-N/A
neg-sub0N/A
+-commutativeN/A
sub-negN/A
lower-/.f64N/A
lower--.f64100.0
Applied rewrites100.0%
Taylor expanded in x around 0
Applied rewrites94.5%
if 1.00000000000000005e26 < (/.f64 (fabs.f64 (-.f64 x y)) (fabs.f64 y)) Initial program 100.0%
lift-/.f64N/A
lift-fabs.f64N/A
neg-fabsN/A
lift-fabs.f64N/A
div-fabsN/A
lower-fabs.f64N/A
neg-sub0N/A
lift--.f64N/A
associate--r-N/A
neg-sub0N/A
+-commutativeN/A
sub-negN/A
lower-/.f64N/A
lower--.f64100.0
Applied rewrites100.0%
lift-fabs.f64N/A
lift-/.f64N/A
clear-numN/A
inv-powN/A
sqr-powN/A
fabs-sqrN/A
sqr-powN/A
inv-powN/A
frac-2negN/A
clear-numN/A
div-invN/A
inv-powN/A
sqr-powN/A
pow-prod-downN/A
sqr-negN/A
pow-prod-downN/A
sqr-powN/A
inv-powN/A
div-invN/A
lift--.f64N/A
flip--N/A
distribute-neg-frac2N/A
Applied rewrites48.3%
Taylor expanded in x around 0
Applied rewrites1.0%
Taylor expanded in x around inf
lower-/.f6448.3
Applied rewrites48.3%
Final simplification71.9%
(FPCore (x y) :precision binary64 (fabs 1.0))
double code(double x, double y) {
return fabs(1.0);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = abs(1.0d0)
end function
public static double code(double x, double y) {
return Math.abs(1.0);
}
def code(x, y): return math.fabs(1.0)
function code(x, y) return abs(1.0) end
function tmp = code(x, y) tmp = abs(1.0); end
code[x_, y_] := N[Abs[1.0], $MachinePrecision]
\begin{array}{l}
\\
\left|1\right|
\end{array}
Initial program 100.0%
lift-/.f64N/A
lift-fabs.f64N/A
neg-fabsN/A
lift-fabs.f64N/A
div-fabsN/A
lower-fabs.f64N/A
neg-sub0N/A
lift--.f64N/A
associate--r-N/A
neg-sub0N/A
+-commutativeN/A
sub-negN/A
lower-/.f64N/A
lower--.f64100.0
Applied rewrites100.0%
Taylor expanded in x around 0
Applied rewrites50.7%
(FPCore (x y) :precision binary64 -1.0)
double code(double x, double y) {
return -1.0;
}
real(8) function code(x, y)
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
\begin{array}{l}
\\
-1
\end{array}
Initial program 100.0%
lift-/.f64N/A
lift-fabs.f64N/A
neg-fabsN/A
lift-fabs.f64N/A
div-fabsN/A
lower-fabs.f64N/A
neg-sub0N/A
lift--.f64N/A
associate--r-N/A
neg-sub0N/A
+-commutativeN/A
sub-negN/A
lower-/.f64N/A
lower--.f64100.0
Applied rewrites100.0%
lift-fabs.f64N/A
lift-/.f64N/A
clear-numN/A
inv-powN/A
sqr-powN/A
fabs-sqrN/A
sqr-powN/A
inv-powN/A
frac-2negN/A
clear-numN/A
div-invN/A
inv-powN/A
sqr-powN/A
pow-prod-downN/A
sqr-negN/A
pow-prod-downN/A
sqr-powN/A
inv-powN/A
div-invN/A
lift--.f64N/A
flip--N/A
distribute-neg-frac2N/A
Applied rewrites24.8%
Taylor expanded in x around 0
Applied rewrites1.3%
herbie shell --seed 2024313
(FPCore (x y)
:name "Numeric.LinearAlgebra.Util:formatSparse from hmatrix-0.16.1.5"
:precision binary64
(/ (fabs (- x y)) (fabs y)))