
(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 -8400000.0) (not (<= x 1.6e-73))) (fabs (/ x y)) 1.0))
double code(double x, double y) {
double tmp;
if ((x <= -8400000.0) || !(x <= 1.6e-73)) {
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 <= (-8400000.0d0)) .or. (.not. (x <= 1.6d-73))) 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 <= -8400000.0) || !(x <= 1.6e-73)) {
tmp = Math.abs((x / y));
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -8400000.0) or not (x <= 1.6e-73): tmp = math.fabs((x / y)) else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if ((x <= -8400000.0) || !(x <= 1.6e-73)) tmp = abs(Float64(x / y)); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -8400000.0) || ~((x <= 1.6e-73))) tmp = abs((x / y)); else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -8400000.0], N[Not[LessEqual[x, 1.6e-73]], $MachinePrecision]], N[Abs[N[(x / y), $MachinePrecision]], $MachinePrecision], 1.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -8400000 \lor \neg \left(x \leq 1.6 \cdot 10^{-73}\right):\\
\;\;\;\;\left|\frac{x}{y}\right|\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if x < -8.4e6 or 1.59999999999999993e-73 < x Initial program 100.0%
Taylor expanded in x around -inf 100.0%
Simplified100.0%
Taylor expanded in x around inf 78.5%
if -8.4e6 < x < 1.59999999999999993e-73Initial program 100.0%
Taylor expanded in x around -inf 100.0%
Simplified100.0%
Taylor expanded in x around inf 18.9%
Applied egg-rr36.1%
*-inverses82.0%
Simplified82.0%
Final simplification79.8%
(FPCore (x y)
:precision binary64
(let* ((t_0 (/ (- x y) y)))
(if (<= y -2.8e+18)
1.0
(if (<= y -1.55e-54)
t_0
(if (<= y -5e-157)
(* (+ x -1.0) (+ x -1.0))
(if (<= y 2.4e-12) t_0 1.0))))))
double code(double x, double y) {
double t_0 = (x - y) / y;
double tmp;
if (y <= -2.8e+18) {
tmp = 1.0;
} else if (y <= -1.55e-54) {
tmp = t_0;
} else if (y <= -5e-157) {
tmp = (x + -1.0) * (x + -1.0);
} else if (y <= 2.4e-12) {
tmp = t_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) :: t_0
real(8) :: tmp
t_0 = (x - y) / y
if (y <= (-2.8d+18)) then
tmp = 1.0d0
else if (y <= (-1.55d-54)) then
tmp = t_0
else if (y <= (-5d-157)) then
tmp = (x + (-1.0d0)) * (x + (-1.0d0))
else if (y <= 2.4d-12) then
tmp = t_0
else
tmp = 1.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = (x - y) / y;
double tmp;
if (y <= -2.8e+18) {
tmp = 1.0;
} else if (y <= -1.55e-54) {
tmp = t_0;
} else if (y <= -5e-157) {
tmp = (x + -1.0) * (x + -1.0);
} else if (y <= 2.4e-12) {
tmp = t_0;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): t_0 = (x - y) / y tmp = 0 if y <= -2.8e+18: tmp = 1.0 elif y <= -1.55e-54: tmp = t_0 elif y <= -5e-157: tmp = (x + -1.0) * (x + -1.0) elif y <= 2.4e-12: tmp = t_0 else: tmp = 1.0 return tmp
function code(x, y) t_0 = Float64(Float64(x - y) / y) tmp = 0.0 if (y <= -2.8e+18) tmp = 1.0; elseif (y <= -1.55e-54) tmp = t_0; elseif (y <= -5e-157) tmp = Float64(Float64(x + -1.0) * Float64(x + -1.0)); elseif (y <= 2.4e-12) tmp = t_0; else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) t_0 = (x - y) / y; tmp = 0.0; if (y <= -2.8e+18) tmp = 1.0; elseif (y <= -1.55e-54) tmp = t_0; elseif (y <= -5e-157) tmp = (x + -1.0) * (x + -1.0); elseif (y <= 2.4e-12) tmp = t_0; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(N[(x - y), $MachinePrecision] / y), $MachinePrecision]}, If[LessEqual[y, -2.8e+18], 1.0, If[LessEqual[y, -1.55e-54], t$95$0, If[LessEqual[y, -5e-157], N[(N[(x + -1.0), $MachinePrecision] * N[(x + -1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 2.4e-12], t$95$0, 1.0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x - y}{y}\\
\mathbf{if}\;y \leq -2.8 \cdot 10^{+18}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq -1.55 \cdot 10^{-54}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq -5 \cdot 10^{-157}:\\
\;\;\;\;\left(x + -1\right) \cdot \left(x + -1\right)\\
\mathbf{elif}\;y \leq 2.4 \cdot 10^{-12}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -2.8e18 or 2.39999999999999987e-12 < y Initial program 100.0%
Taylor expanded in x around -inf 100.0%
Simplified100.0%
Taylor expanded in x around inf 28.5%
Applied egg-rr35.3%
*-inverses74.3%
Simplified74.3%
if -2.8e18 < y < -1.55000000000000002e-54 or -5.0000000000000002e-157 < y < 2.39999999999999987e-12Initial program 100.0%
Taylor expanded in x around -inf 100.0%
Simplified100.0%
metadata-eval100.0%
*-inverses100.0%
sub-neg100.0%
sub-div100.0%
add-sqr-sqrt46.2%
fabs-sqr46.2%
add-sqr-sqrt46.8%
Applied egg-rr46.8%
if -1.55000000000000002e-54 < y < -5.0000000000000002e-157Initial program 100.0%
Taylor expanded in x around -inf 100.0%
Simplified100.0%
metadata-eval100.0%
*-inverses100.0%
sub-neg100.0%
sub-div100.0%
add-sqr-sqrt14.2%
fabs-sqr14.2%
add-sqr-sqrt15.1%
Applied egg-rr15.1%
Applied egg-rr73.8%
(FPCore (x y) :precision binary64 (if (<= y -1.4e-142) 1.0 (if (<= y 2e-12) (/ (- x y) y) 1.0)))
double code(double x, double y) {
double tmp;
if (y <= -1.4e-142) {
tmp = 1.0;
} else if (y <= 2e-12) {
tmp = (x - y) / 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 (y <= (-1.4d-142)) then
tmp = 1.0d0
else if (y <= 2d-12) then
tmp = (x - y) / y
else
tmp = 1.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -1.4e-142) {
tmp = 1.0;
} else if (y <= 2e-12) {
tmp = (x - y) / y;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.4e-142: tmp = 1.0 elif y <= 2e-12: tmp = (x - y) / y else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -1.4e-142) tmp = 1.0; elseif (y <= 2e-12) tmp = Float64(Float64(x - y) / y); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -1.4e-142) tmp = 1.0; elseif (y <= 2e-12) tmp = (x - y) / y; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.4e-142], 1.0, If[LessEqual[y, 2e-12], N[(N[(x - y), $MachinePrecision] / y), $MachinePrecision], 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.4 \cdot 10^{-142}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 2 \cdot 10^{-12}:\\
\;\;\;\;\frac{x - y}{y}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -1.40000000000000002e-142 or 1.99999999999999996e-12 < y Initial program 100.0%
Taylor expanded in x around -inf 100.0%
Simplified100.0%
Taylor expanded in x around inf 34.7%
Applied egg-rr32.6%
*-inverses67.9%
Simplified67.9%
if -1.40000000000000002e-142 < y < 1.99999999999999996e-12Initial program 100.0%
Taylor expanded in x around -inf 100.0%
Simplified100.0%
metadata-eval100.0%
*-inverses100.0%
sub-neg100.0%
sub-div100.0%
add-sqr-sqrt43.9%
fabs-sqr43.9%
add-sqr-sqrt44.3%
Applied egg-rr44.3%
(FPCore (x y) :precision binary64 (if (<= y -1.45e-142) 1.0 (if (<= y 4e-12) (/ x y) 1.0)))
double code(double x, double y) {
double tmp;
if (y <= -1.45e-142) {
tmp = 1.0;
} else if (y <= 4e-12) {
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 (y <= (-1.45d-142)) then
tmp = 1.0d0
else if (y <= 4d-12) 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 (y <= -1.45e-142) {
tmp = 1.0;
} else if (y <= 4e-12) {
tmp = x / y;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.45e-142: tmp = 1.0 elif y <= 4e-12: tmp = x / y else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -1.45e-142) tmp = 1.0; elseif (y <= 4e-12) tmp = Float64(x / y); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -1.45e-142) tmp = 1.0; elseif (y <= 4e-12) tmp = x / y; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.45e-142], 1.0, If[LessEqual[y, 4e-12], N[(x / y), $MachinePrecision], 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.45 \cdot 10^{-142}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 4 \cdot 10^{-12}:\\
\;\;\;\;\frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -1.44999999999999995e-142 or 3.99999999999999992e-12 < y Initial program 100.0%
Taylor expanded in x around -inf 100.0%
Simplified100.0%
Taylor expanded in x around inf 34.7%
Applied egg-rr32.6%
*-inverses67.9%
Simplified67.9%
if -1.44999999999999995e-142 < y < 3.99999999999999992e-12Initial program 100.0%
div-inv99.7%
add-sqr-sqrt49.8%
fabs-sqr49.8%
add-sqr-sqrt50.2%
*-commutative50.2%
add-sqr-sqrt26.1%
fabs-sqr26.1%
add-sqr-sqrt44.2%
Applied egg-rr44.2%
Taylor expanded in x around inf 44.0%
Taylor expanded in y around 0 44.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%
Taylor expanded in x around -inf 100.0%
Simplified100.0%
Taylor expanded in x around inf 56.4%
Applied egg-rr21.8%
*-inverses46.1%
Simplified46.1%
herbie shell --seed 2024181
(FPCore (x y)
:name "Numeric.LinearAlgebra.Util:formatSparse from hmatrix-0.16.1.5"
:precision binary64
(/ (fabs (- x y)) (fabs y)))