
(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 6 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
lower-/.f64N/A
lift--.f64N/A
sub-negN/A
+-commutativeN/A
distribute-neg-inN/A
remove-double-negN/A
sub-negN/A
lower--.f64100.0
Applied rewrites100.0%
Final simplification100.0%
(FPCore (x y) :precision binary64 (if (<= (fabs (/ (- x y) y)) 2.0) 1.0 (/ x y)))
double code(double x, double y) {
double tmp;
if (fabs(((x - y) / y)) <= 2.0) {
tmp = 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)) <= 2.0d0) then
tmp = 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)) <= 2.0) {
tmp = 1.0;
} else {
tmp = x / y;
}
return tmp;
}
def code(x, y): tmp = 0 if math.fabs(((x - y) / y)) <= 2.0: tmp = 1.0 else: tmp = x / y return tmp
function code(x, y) tmp = 0.0 if (abs(Float64(Float64(x - y) / y)) <= 2.0) tmp = 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)) <= 2.0) tmp = 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], 2.0], 1.0, N[(x / y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left|\frac{x - y}{y}\right| \leq 2:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{y}\\
\end{array}
\end{array}
if (/.f64 (fabs.f64 (-.f64 x y)) (fabs.f64 y)) < 2Initial program 100.0%
lift-/.f64N/A
lift-fabs.f64N/A
fabs-fabs-revN/A
lift-fabs.f64N/A
lift-fabs.f64N/A
fabs-fabs-revN/A
lift-fabs.f64N/A
div-fabsN/A
frac-2negN/A
div-invN/A
fabs-mulN/A
neg-fabsN/A
lift-fabs.f64N/A
fabs-fabs-revN/A
rem-sqrt-square-revN/A
sqrt-prodN/A
rem-square-sqrtN/A
lower-*.f64N/A
lower-fabs.f64N/A
neg-mul-1N/A
lift-fabs.f64N/A
rem-sqrt-square-revN/A
sqrt-prodN/A
rem-square-sqrtN/A
Applied rewrites42.8%
Taylor expanded in x around inf
fabs-divN/A
metadata-evalN/A
associate-*r/N/A
*-rgt-identityN/A
lower-/.f64N/A
lower-fabs.f643.5
Applied rewrites3.5%
Applied rewrites3.6%
Taylor expanded in x around 0
Applied rewrites98.4%
if 2 < (/.f64 (fabs.f64 (-.f64 x y)) (fabs.f64 y)) Initial program 100.0%
lift-/.f64N/A
lift-fabs.f64N/A
fabs-fabs-revN/A
lift-fabs.f64N/A
lift-fabs.f64N/A
fabs-fabs-revN/A
lift-fabs.f64N/A
div-fabsN/A
frac-2negN/A
div-invN/A
fabs-mulN/A
neg-fabsN/A
lift-fabs.f64N/A
fabs-fabs-revN/A
rem-sqrt-square-revN/A
sqrt-prodN/A
rem-square-sqrtN/A
lower-*.f64N/A
lower-fabs.f64N/A
neg-mul-1N/A
lift-fabs.f64N/A
rem-sqrt-square-revN/A
sqrt-prodN/A
rem-square-sqrtN/A
Applied rewrites51.7%
Taylor expanded in x around inf
fabs-divN/A
metadata-evalN/A
associate-*r/N/A
*-rgt-identityN/A
lower-/.f64N/A
lower-fabs.f6450.3
Applied rewrites50.3%
Applied rewrites51.0%
Final simplification74.3%
(FPCore (x y) :precision binary64 (if (<= x -7.5e+199) (- (/ x y) 1.0) (if (<= x 5.8e+48) (- 1.0 (/ x y)) (/ x (fabs y)))))
double code(double x, double y) {
double tmp;
if (x <= -7.5e+199) {
tmp = (x / y) - 1.0;
} else if (x <= 5.8e+48) {
tmp = 1.0 - (x / y);
} else {
tmp = x / fabs(y);
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= (-7.5d+199)) then
tmp = (x / y) - 1.0d0
else if (x <= 5.8d+48) then
tmp = 1.0d0 - (x / y)
else
tmp = x / abs(y)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -7.5e+199) {
tmp = (x / y) - 1.0;
} else if (x <= 5.8e+48) {
tmp = 1.0 - (x / y);
} else {
tmp = x / Math.abs(y);
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -7.5e+199: tmp = (x / y) - 1.0 elif x <= 5.8e+48: tmp = 1.0 - (x / y) else: tmp = x / math.fabs(y) return tmp
function code(x, y) tmp = 0.0 if (x <= -7.5e+199) tmp = Float64(Float64(x / y) - 1.0); elseif (x <= 5.8e+48) tmp = Float64(1.0 - Float64(x / y)); else tmp = Float64(x / abs(y)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -7.5e+199) tmp = (x / y) - 1.0; elseif (x <= 5.8e+48) tmp = 1.0 - (x / y); else tmp = x / abs(y); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -7.5e+199], N[(N[(x / y), $MachinePrecision] - 1.0), $MachinePrecision], If[LessEqual[x, 5.8e+48], N[(1.0 - N[(x / y), $MachinePrecision]), $MachinePrecision], N[(x / N[Abs[y], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -7.5 \cdot 10^{+199}:\\
\;\;\;\;\frac{x}{y} - 1\\
\mathbf{elif}\;x \leq 5.8 \cdot 10^{+48}:\\
\;\;\;\;1 - \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{\left|y\right|}\\
\end{array}
\end{array}
if x < -7.49999999999999977e199Initial program 100.0%
lift-/.f64N/A
lift-fabs.f64N/A
rem-sqrt-square-revN/A
sqrt-prodN/A
rem-square-sqrtN/A
lift--.f64N/A
lift-fabs.f64N/A
rem-sqrt-square-revN/A
sqrt-prodN/A
rem-square-sqrtN/A
div-subN/A
*-inversesN/A
lower--.f64N/A
lower-/.f6469.7
Applied rewrites69.7%
if -7.49999999999999977e199 < x < 5.7999999999999998e48Initial program 100.0%
lift-/.f64N/A
lift-fabs.f64N/A
neg-fabsN/A
lift-fabs.f64N/A
div-fabsN/A
lower-fabs.f64N/A
lower-/.f64N/A
lift--.f64N/A
sub-negN/A
+-commutativeN/A
distribute-neg-inN/A
remove-double-negN/A
sub-negN/A
lower--.f64100.0
Applied rewrites100.0%
lift-fabs.f64N/A
rem-sqrt-square-revN/A
sqrt-prodN/A
rem-square-sqrt84.6
lift-/.f64N/A
lift--.f64N/A
div-subN/A
*-inversesN/A
lift-/.f64N/A
lower--.f6484.6
Applied rewrites84.6%
if 5.7999999999999998e48 < x Initial program 100.0%
lift-/.f64N/A
lift-fabs.f64N/A
fabs-fabs-revN/A
lift-fabs.f64N/A
lift-fabs.f64N/A
fabs-fabs-revN/A
lift-fabs.f64N/A
div-fabsN/A
frac-2negN/A
div-invN/A
fabs-mulN/A
neg-fabsN/A
lift-fabs.f64N/A
fabs-fabs-revN/A
rem-sqrt-square-revN/A
sqrt-prodN/A
rem-square-sqrtN/A
lower-*.f64N/A
lower-fabs.f64N/A
neg-mul-1N/A
lift-fabs.f64N/A
rem-sqrt-square-revN/A
sqrt-prodN/A
rem-square-sqrtN/A
Applied rewrites91.3%
Taylor expanded in x around inf
fabs-divN/A
metadata-evalN/A
associate-*r/N/A
*-rgt-identityN/A
lower-/.f64N/A
lower-fabs.f6487.4
Applied rewrites87.4%
(FPCore (x y) :precision binary64 (if (<= x -7.5e+199) (/ x y) (if (<= x 5.8e+48) (- 1.0 (/ x y)) (/ x (fabs y)))))
double code(double x, double y) {
double tmp;
if (x <= -7.5e+199) {
tmp = x / y;
} else if (x <= 5.8e+48) {
tmp = 1.0 - (x / y);
} else {
tmp = x / fabs(y);
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= (-7.5d+199)) then
tmp = x / y
else if (x <= 5.8d+48) then
tmp = 1.0d0 - (x / y)
else
tmp = x / abs(y)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -7.5e+199) {
tmp = x / y;
} else if (x <= 5.8e+48) {
tmp = 1.0 - (x / y);
} else {
tmp = x / Math.abs(y);
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -7.5e+199: tmp = x / y elif x <= 5.8e+48: tmp = 1.0 - (x / y) else: tmp = x / math.fabs(y) return tmp
function code(x, y) tmp = 0.0 if (x <= -7.5e+199) tmp = Float64(x / y); elseif (x <= 5.8e+48) tmp = Float64(1.0 - Float64(x / y)); else tmp = Float64(x / abs(y)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -7.5e+199) tmp = x / y; elseif (x <= 5.8e+48) tmp = 1.0 - (x / y); else tmp = x / abs(y); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -7.5e+199], N[(x / y), $MachinePrecision], If[LessEqual[x, 5.8e+48], N[(1.0 - N[(x / y), $MachinePrecision]), $MachinePrecision], N[(x / N[Abs[y], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -7.5 \cdot 10^{+199}:\\
\;\;\;\;\frac{x}{y}\\
\mathbf{elif}\;x \leq 5.8 \cdot 10^{+48}:\\
\;\;\;\;1 - \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{\left|y\right|}\\
\end{array}
\end{array}
if x < -7.49999999999999977e199Initial program 100.0%
lift-/.f64N/A
lift-fabs.f64N/A
fabs-fabs-revN/A
lift-fabs.f64N/A
lift-fabs.f64N/A
fabs-fabs-revN/A
lift-fabs.f64N/A
div-fabsN/A
frac-2negN/A
div-invN/A
fabs-mulN/A
neg-fabsN/A
lift-fabs.f64N/A
fabs-fabs-revN/A
rem-sqrt-square-revN/A
sqrt-prodN/A
rem-square-sqrtN/A
lower-*.f64N/A
lower-fabs.f64N/A
neg-mul-1N/A
lift-fabs.f64N/A
rem-sqrt-square-revN/A
sqrt-prodN/A
rem-square-sqrtN/A
Applied rewrites4.9%
Taylor expanded in x around inf
fabs-divN/A
metadata-evalN/A
associate-*r/N/A
*-rgt-identityN/A
lower-/.f64N/A
lower-fabs.f640.6
Applied rewrites0.6%
Applied rewrites67.0%
if -7.49999999999999977e199 < x < 5.7999999999999998e48Initial program 100.0%
lift-/.f64N/A
lift-fabs.f64N/A
neg-fabsN/A
lift-fabs.f64N/A
div-fabsN/A
lower-fabs.f64N/A
lower-/.f64N/A
lift--.f64N/A
sub-negN/A
+-commutativeN/A
distribute-neg-inN/A
remove-double-negN/A
sub-negN/A
lower--.f64100.0
Applied rewrites100.0%
lift-fabs.f64N/A
rem-sqrt-square-revN/A
sqrt-prodN/A
rem-square-sqrt84.6
lift-/.f64N/A
lift--.f64N/A
div-subN/A
*-inversesN/A
lift-/.f64N/A
lower--.f6484.6
Applied rewrites84.6%
if 5.7999999999999998e48 < x Initial program 100.0%
lift-/.f64N/A
lift-fabs.f64N/A
fabs-fabs-revN/A
lift-fabs.f64N/A
lift-fabs.f64N/A
fabs-fabs-revN/A
lift-fabs.f64N/A
div-fabsN/A
frac-2negN/A
div-invN/A
fabs-mulN/A
neg-fabsN/A
lift-fabs.f64N/A
fabs-fabs-revN/A
rem-sqrt-square-revN/A
sqrt-prodN/A
rem-square-sqrtN/A
lower-*.f64N/A
lower-fabs.f64N/A
neg-mul-1N/A
lift-fabs.f64N/A
rem-sqrt-square-revN/A
sqrt-prodN/A
rem-square-sqrtN/A
Applied rewrites91.3%
Taylor expanded in x around inf
fabs-divN/A
metadata-evalN/A
associate-*r/N/A
*-rgt-identityN/A
lower-/.f64N/A
lower-fabs.f6487.4
Applied rewrites87.4%
(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
fabs-fabs-revN/A
lift-fabs.f64N/A
lift-fabs.f64N/A
fabs-fabs-revN/A
lift-fabs.f64N/A
div-fabsN/A
frac-2negN/A
div-invN/A
fabs-mulN/A
neg-fabsN/A
lift-fabs.f64N/A
fabs-fabs-revN/A
rem-sqrt-square-revN/A
sqrt-prodN/A
rem-square-sqrtN/A
lower-*.f64N/A
lower-fabs.f64N/A
neg-mul-1N/A
lift-fabs.f64N/A
rem-sqrt-square-revN/A
sqrt-prodN/A
rem-square-sqrtN/A
Applied rewrites47.3%
Taylor expanded in x around inf
fabs-divN/A
metadata-evalN/A
associate-*r/N/A
*-rgt-identityN/A
lower-/.f64N/A
lower-fabs.f6427.2
Applied rewrites27.2%
Applied rewrites27.6%
Taylor expanded in x around 0
Applied rewrites51.1%
(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
rem-sqrt-square-revN/A
sqrt-prodN/A
rem-square-sqrtN/A
lift--.f64N/A
lift-fabs.f64N/A
rem-sqrt-square-revN/A
sqrt-prodN/A
rem-square-sqrtN/A
div-subN/A
*-inversesN/A
lower--.f64N/A
lower-/.f6427.5
Applied rewrites27.5%
Taylor expanded in x around 0
Applied rewrites1.3%
herbie shell --seed 2024298
(FPCore (x y)
:name "Numeric.LinearAlgebra.Util:formatSparse from hmatrix-0.16.1.5"
:precision binary64
(/ (fabs (- x y)) (fabs y)))