
(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) -1.0)))
double code(double x, double y) {
return fabs(((x / y) + -1.0));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = abs(((x / y) + (-1.0d0)))
end function
public static double code(double x, double y) {
return Math.abs(((x / y) + -1.0));
}
def code(x, y): return math.fabs(((x / y) + -1.0))
function code(x, y) return abs(Float64(Float64(x / y) + -1.0)) end
function tmp = code(x, y) tmp = abs(((x / y) + -1.0)); end
code[x_, y_] := N[Abs[N[(N[(x / y), $MachinePrecision] + -1.0), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\left|\frac{x}{y} + -1\right|
\end{array}
Initial program 100.0%
Taylor expanded in x around -inf 100.0%
Simplified100.0%
(FPCore (x y) :precision binary64 (if (or (<= x -1.8e+52) (not (<= x 82.0))) (fabs (/ x y)) 1.0))
double code(double x, double y) {
double tmp;
if ((x <= -1.8e+52) || !(x <= 82.0)) {
tmp = fabs((x / y));
} else {
tmp = 1.0;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((x <= (-1.8d+52)) .or. (.not. (x <= 82.0d0))) then
tmp = abs((x / y))
else
tmp = 1.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x <= -1.8e+52) || !(x <= 82.0)) {
tmp = Math.abs((x / y));
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -1.8e+52) or not (x <= 82.0): tmp = math.fabs((x / y)) else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if ((x <= -1.8e+52) || !(x <= 82.0)) tmp = abs(Float64(x / y)); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -1.8e+52) || ~((x <= 82.0))) tmp = abs((x / y)); else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -1.8e+52], N[Not[LessEqual[x, 82.0]], $MachinePrecision]], N[Abs[N[(x / y), $MachinePrecision]], $MachinePrecision], 1.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.8 \cdot 10^{+52} \lor \neg \left(x \leq 82\right):\\
\;\;\;\;\left|\frac{x}{y}\right|\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if x < -1.8e52 or 82 < x Initial program 100.0%
Taylor expanded in x around -inf 100.0%
Simplified100.0%
Taylor expanded in x around inf 83.4%
if -1.8e52 < x < 82Initial program 100.0%
Taylor expanded in x around -inf 100.0%
Simplified100.0%
Taylor expanded in x around inf 27.6%
Applied egg-rr74.5%
*-inverses74.5%
Simplified74.5%
Final simplification78.9%
(FPCore (x y) :precision binary64 (if (<= x -7.2e+183) (* x x) (if (or (<= x -8e+80) (not (<= x 1.85e+135))) (+ (/ x y) -1.0) 1.0)))
double code(double x, double y) {
double tmp;
if (x <= -7.2e+183) {
tmp = x * x;
} else if ((x <= -8e+80) || !(x <= 1.85e+135)) {
tmp = (x / y) + -1.0;
} else {
tmp = 1.0;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= (-7.2d+183)) then
tmp = x * x
else if ((x <= (-8d+80)) .or. (.not. (x <= 1.85d+135))) then
tmp = (x / y) + (-1.0d0)
else
tmp = 1.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -7.2e+183) {
tmp = x * x;
} else if ((x <= -8e+80) || !(x <= 1.85e+135)) {
tmp = (x / y) + -1.0;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -7.2e+183: tmp = x * x elif (x <= -8e+80) or not (x <= 1.85e+135): tmp = (x / y) + -1.0 else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (x <= -7.2e+183) tmp = Float64(x * x); elseif ((x <= -8e+80) || !(x <= 1.85e+135)) tmp = Float64(Float64(x / y) + -1.0); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -7.2e+183) tmp = x * x; elseif ((x <= -8e+80) || ~((x <= 1.85e+135))) tmp = (x / y) + -1.0; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -7.2e+183], N[(x * x), $MachinePrecision], If[Or[LessEqual[x, -8e+80], N[Not[LessEqual[x, 1.85e+135]], $MachinePrecision]], N[(N[(x / y), $MachinePrecision] + -1.0), $MachinePrecision], 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -7.2 \cdot 10^{+183}:\\
\;\;\;\;x \cdot x\\
\mathbf{elif}\;x \leq -8 \cdot 10^{+80} \lor \neg \left(x \leq 1.85 \cdot 10^{+135}\right):\\
\;\;\;\;\frac{x}{y} + -1\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if x < -7.20000000000000046e183Initial program 100.0%
Taylor expanded in x around -inf 100.0%
Simplified100.0%
Taylor expanded in x around inf 100.0%
Applied egg-rr67.4%
if -7.20000000000000046e183 < x < -8e80 or 1.84999999999999999e135 < x Initial program 100.0%
add-sqr-sqrt60.6%
fabs-sqr60.6%
add-sqr-sqrt35.2%
fabs-sqr35.2%
add-sqr-sqrt35.5%
add-sqr-sqrt54.5%
div-sub54.5%
Applied egg-rr54.5%
Taylor expanded in y around 0 54.5%
if -8e80 < x < 1.84999999999999999e135Initial program 100.0%
Taylor expanded in x around -inf 100.0%
Simplified100.0%
Taylor expanded in x around inf 35.0%
Applied egg-rr67.5%
*-inverses67.5%
Simplified67.5%
Final simplification64.5%
(FPCore (x y) :precision binary64 (if (<= x -1.3e+184) (* x x) (if (or (<= x -1.5e+103) (not (<= x 8.5e+132))) (/ x y) 1.0)))
double code(double x, double y) {
double tmp;
if (x <= -1.3e+184) {
tmp = x * x;
} else if ((x <= -1.5e+103) || !(x <= 8.5e+132)) {
tmp = x / y;
} else {
tmp = 1.0;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= (-1.3d+184)) then
tmp = x * x
else if ((x <= (-1.5d+103)) .or. (.not. (x <= 8.5d+132))) then
tmp = x / y
else
tmp = 1.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -1.3e+184) {
tmp = x * x;
} else if ((x <= -1.5e+103) || !(x <= 8.5e+132)) {
tmp = x / y;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -1.3e+184: tmp = x * x elif (x <= -1.5e+103) or not (x <= 8.5e+132): tmp = x / y else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (x <= -1.3e+184) tmp = Float64(x * x); elseif ((x <= -1.5e+103) || !(x <= 8.5e+132)) tmp = Float64(x / y); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -1.3e+184) tmp = x * x; elseif ((x <= -1.5e+103) || ~((x <= 8.5e+132))) tmp = x / y; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -1.3e+184], N[(x * x), $MachinePrecision], If[Or[LessEqual[x, -1.5e+103], N[Not[LessEqual[x, 8.5e+132]], $MachinePrecision]], N[(x / y), $MachinePrecision], 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.3 \cdot 10^{+184}:\\
\;\;\;\;x \cdot x\\
\mathbf{elif}\;x \leq -1.5 \cdot 10^{+103} \lor \neg \left(x \leq 8.5 \cdot 10^{+132}\right):\\
\;\;\;\;\frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if x < -1.29999999999999997e184Initial program 100.0%
Taylor expanded in x around -inf 100.0%
Simplified100.0%
Taylor expanded in x around inf 100.0%
Applied egg-rr67.4%
if -1.29999999999999997e184 < x < -1.5e103 or 8.49999999999999969e132 < x Initial program 100.0%
div-inv99.7%
add-sqr-sqrt65.6%
fabs-sqr65.6%
add-sqr-sqrt66.1%
*-commutative66.1%
add-sqr-sqrt39.6%
fabs-sqr39.6%
add-sqr-sqrt56.7%
Applied egg-rr56.7%
Taylor expanded in x around inf 56.0%
Taylor expanded in y around 0 56.2%
if -1.5e103 < x < 8.49999999999999969e132Initial program 100.0%
Taylor expanded in x around -inf 100.0%
Simplified100.0%
Taylor expanded in x around inf 36.3%
Applied egg-rr65.9%
*-inverses65.9%
Simplified65.9%
Final simplification64.1%
(FPCore (x y) :precision binary64 (if (or (<= x -1.02e+161) (not (<= x 2.05e+136))) (* x x) 1.0))
double code(double x, double y) {
double tmp;
if ((x <= -1.02e+161) || !(x <= 2.05e+136)) {
tmp = x * x;
} else {
tmp = 1.0;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((x <= (-1.02d+161)) .or. (.not. (x <= 2.05d+136))) then
tmp = x * x
else
tmp = 1.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x <= -1.02e+161) || !(x <= 2.05e+136)) {
tmp = x * x;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -1.02e+161) or not (x <= 2.05e+136): tmp = x * x else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if ((x <= -1.02e+161) || !(x <= 2.05e+136)) tmp = Float64(x * x); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -1.02e+161) || ~((x <= 2.05e+136))) tmp = x * x; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -1.02e+161], N[Not[LessEqual[x, 2.05e+136]], $MachinePrecision]], N[(x * x), $MachinePrecision], 1.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.02 \cdot 10^{+161} \lor \neg \left(x \leq 2.05 \cdot 10^{+136}\right):\\
\;\;\;\;x \cdot x\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if x < -1.02e161 or 2.0499999999999999e136 < x Initial program 100.0%
Taylor expanded in x around -inf 100.0%
Simplified100.0%
Taylor expanded in x around inf 93.0%
Applied egg-rr52.0%
if -1.02e161 < x < 2.0499999999999999e136Initial program 100.0%
Taylor expanded in x around -inf 100.0%
Simplified100.0%
Taylor expanded in x around inf 40.0%
Applied egg-rr62.4%
*-inverses62.4%
Simplified62.4%
Final simplification59.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%
Taylor expanded in x around -inf 100.0%
Simplified100.0%
Taylor expanded in x around inf 55.1%
Applied egg-rr47.1%
*-inverses47.1%
Simplified47.1%
herbie shell --seed 2024139
(FPCore (x y)
:name "Numeric.LinearAlgebra.Util:formatSparse from hmatrix-0.16.1.5"
:precision binary64
(/ (fabs (- x y)) (fabs y)))