
(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 4 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 (- 1.0 (/ x y))))
double code(double x, double y) {
return fabs((1.0 - (x / y)));
}
real(8) function code(x, y)
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]
\begin{array}{l}
\\
\left|1 - \frac{x}{y}\right|
\end{array}
Initial program 100.0%
Applied egg-rr0
(FPCore (x y)
:precision binary64
(let* ((t_0 (- 1.0 (/ x y))))
(if (<= x -1.8e+168)
t_0
(if (<= x -5.5e+114) (/ x y) (if (<= x 8.5e+245) t_0 (/ x y))))))
double code(double x, double y) {
double t_0 = 1.0 - (x / y);
double tmp;
if (x <= -1.8e+168) {
tmp = t_0;
} else if (x <= -5.5e+114) {
tmp = x / y;
} else if (x <= 8.5e+245) {
tmp = t_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) :: t_0
real(8) :: tmp
t_0 = 1.0d0 - (x / y)
if (x <= (-1.8d+168)) then
tmp = t_0
else if (x <= (-5.5d+114)) then
tmp = x / y
else if (x <= 8.5d+245) then
tmp = t_0
else
tmp = x / y
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = 1.0 - (x / y);
double tmp;
if (x <= -1.8e+168) {
tmp = t_0;
} else if (x <= -5.5e+114) {
tmp = x / y;
} else if (x <= 8.5e+245) {
tmp = t_0;
} else {
tmp = x / y;
}
return tmp;
}
def code(x, y): t_0 = 1.0 - (x / y) tmp = 0 if x <= -1.8e+168: tmp = t_0 elif x <= -5.5e+114: tmp = x / y elif x <= 8.5e+245: tmp = t_0 else: tmp = x / y return tmp
function code(x, y) t_0 = Float64(1.0 - Float64(x / y)) tmp = 0.0 if (x <= -1.8e+168) tmp = t_0; elseif (x <= -5.5e+114) tmp = Float64(x / y); elseif (x <= 8.5e+245) tmp = t_0; else tmp = Float64(x / y); end return tmp end
function tmp_2 = code(x, y) t_0 = 1.0 - (x / y); tmp = 0.0; if (x <= -1.8e+168) tmp = t_0; elseif (x <= -5.5e+114) tmp = x / y; elseif (x <= 8.5e+245) tmp = t_0; else tmp = x / y; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(1.0 - N[(x / y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -1.8e+168], t$95$0, If[LessEqual[x, -5.5e+114], N[(x / y), $MachinePrecision], If[LessEqual[x, 8.5e+245], t$95$0, N[(x / y), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 1 - \frac{x}{y}\\
\mathbf{if}\;x \leq -1.8 \cdot 10^{+168}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq -5.5 \cdot 10^{+114}:\\
\;\;\;\;\frac{x}{y}\\
\mathbf{elif}\;x \leq 8.5 \cdot 10^{+245}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{y}\\
\end{array}
\end{array}
if x < -1.8e168 or -5.5000000000000001e114 < x < 8.49999999999999971e245Initial program 100.0%
Applied egg-rr0
Applied egg-rr0
Applied egg-rr0
if -1.8e168 < x < -5.5000000000000001e114 or 8.49999999999999971e245 < x Initial program 100.0%
Applied egg-rr0
Applied egg-rr0
Applied egg-rr0
Taylor expanded in y around 0 0
Simplified0
(FPCore (x y) :precision binary64 (if (<= x -7e+37) (/ x y) (if (<= x 2e+186) 1.0 (/ x y))))
double code(double x, double y) {
double tmp;
if (x <= -7e+37) {
tmp = x / y;
} else if (x <= 2e+186) {
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 (x <= (-7d+37)) then
tmp = x / y
else if (x <= 2d+186) 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 (x <= -7e+37) {
tmp = x / y;
} else if (x <= 2e+186) {
tmp = 1.0;
} else {
tmp = x / y;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -7e+37: tmp = x / y elif x <= 2e+186: tmp = 1.0 else: tmp = x / y return tmp
function code(x, y) tmp = 0.0 if (x <= -7e+37) tmp = Float64(x / y); elseif (x <= 2e+186) tmp = 1.0; else tmp = Float64(x / y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -7e+37) tmp = x / y; elseif (x <= 2e+186) tmp = 1.0; else tmp = x / y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -7e+37], N[(x / y), $MachinePrecision], If[LessEqual[x, 2e+186], 1.0, N[(x / y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -7 \cdot 10^{+37}:\\
\;\;\;\;\frac{x}{y}\\
\mathbf{elif}\;x \leq 2 \cdot 10^{+186}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{y}\\
\end{array}
\end{array}
if x < -7e37 or 1.99999999999999996e186 < x Initial program 99.9%
Applied egg-rr0
Applied egg-rr0
Applied egg-rr0
Taylor expanded in y around 0 0
Simplified0
if -7e37 < x < 1.99999999999999996e186Initial program 100.0%
Applied egg-rr0
Taylor expanded in x around 0 0
Simplified0
Applied egg-rr0
(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%
Applied egg-rr0
Taylor expanded in x around 0 0
Simplified0
Applied egg-rr0
herbie shell --seed 2024110
(FPCore (x y)
:name "Numeric.LinearAlgebra.Util:formatSparse from hmatrix-0.16.1.5"
:precision binary64
(/ (fabs (- x y)) (fabs y)))