
(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 (<= y -7.5e-26) 1.0 (if (<= y 1.8e+33) (fabs (/ x y)) 1.0)))
double code(double x, double y) {
double tmp;
if (y <= -7.5e-26) {
tmp = 1.0;
} else if (y <= 1.8e+33) {
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 (y <= (-7.5d-26)) then
tmp = 1.0d0
else if (y <= 1.8d+33) 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 (y <= -7.5e-26) {
tmp = 1.0;
} else if (y <= 1.8e+33) {
tmp = Math.abs((x / y));
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -7.5e-26: tmp = 1.0 elif y <= 1.8e+33: tmp = math.fabs((x / y)) else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -7.5e-26) tmp = 1.0; elseif (y <= 1.8e+33) tmp = abs(Float64(x / y)); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -7.5e-26) tmp = 1.0; elseif (y <= 1.8e+33) tmp = abs((x / y)); else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -7.5e-26], 1.0, If[LessEqual[y, 1.8e+33], N[Abs[N[(x / y), $MachinePrecision]], $MachinePrecision], 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -7.5 \cdot 10^{-26}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 1.8 \cdot 10^{+33}:\\
\;\;\;\;\left|\frac{x}{y}\right|\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -7.4999999999999994e-26 or 1.8000000000000001e33 < y Initial program 100.0%
Taylor expanded in x around -inf 100.0%
Simplified100.0%
Taylor expanded in x around 0 78.9%
Applied egg-rr78.9%
if -7.4999999999999994e-26 < y < 1.8000000000000001e33Initial program 100.0%
Taylor expanded in x around -inf 100.0%
Simplified100.0%
Taylor expanded in x around inf 79.5%
(FPCore (x y)
:precision binary64
(if (<= y -900000000.0)
1.0
(if (<= y -4.2e-218)
(* (+ x -1.0) (+ x (+ x -1.0)))
(if (<= y 3.6e-69) (/ x y) 1.0))))
double code(double x, double y) {
double tmp;
if (y <= -900000000.0) {
tmp = 1.0;
} else if (y <= -4.2e-218) {
tmp = (x + -1.0) * (x + (x + -1.0));
} else if (y <= 3.6e-69) {
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 <= (-900000000.0d0)) then
tmp = 1.0d0
else if (y <= (-4.2d-218)) then
tmp = (x + (-1.0d0)) * (x + (x + (-1.0d0)))
else if (y <= 3.6d-69) 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 <= -900000000.0) {
tmp = 1.0;
} else if (y <= -4.2e-218) {
tmp = (x + -1.0) * (x + (x + -1.0));
} else if (y <= 3.6e-69) {
tmp = x / y;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -900000000.0: tmp = 1.0 elif y <= -4.2e-218: tmp = (x + -1.0) * (x + (x + -1.0)) elif y <= 3.6e-69: tmp = x / y else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -900000000.0) tmp = 1.0; elseif (y <= -4.2e-218) tmp = Float64(Float64(x + -1.0) * Float64(x + Float64(x + -1.0))); elseif (y <= 3.6e-69) tmp = Float64(x / y); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -900000000.0) tmp = 1.0; elseif (y <= -4.2e-218) tmp = (x + -1.0) * (x + (x + -1.0)); elseif (y <= 3.6e-69) tmp = x / y; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -900000000.0], 1.0, If[LessEqual[y, -4.2e-218], N[(N[(x + -1.0), $MachinePrecision] * N[(x + N[(x + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 3.6e-69], N[(x / y), $MachinePrecision], 1.0]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -900000000:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq -4.2 \cdot 10^{-218}:\\
\;\;\;\;\left(x + -1\right) \cdot \left(x + \left(x + -1\right)\right)\\
\mathbf{elif}\;y \leq 3.6 \cdot 10^{-69}:\\
\;\;\;\;\frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -9e8 or 3.60000000000000018e-69 < y Initial program 100.0%
Taylor expanded in x around -inf 100.0%
Simplified100.0%
Taylor expanded in x around 0 75.1%
Applied egg-rr75.1%
if -9e8 < y < -4.19999999999999988e-218Initial 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-sqrt31.7%
fabs-sqr31.7%
add-sqr-sqrt32.6%
Applied egg-rr32.6%
Applied egg-rr57.6%
if -4.19999999999999988e-218 < y < 3.60000000000000018e-69Initial program 100.0%
div-inv99.7%
add-sqr-sqrt35.6%
fabs-sqr35.6%
add-sqr-sqrt36.2%
*-commutative36.2%
add-sqr-sqrt24.0%
fabs-sqr24.0%
add-sqr-sqrt46.5%
Applied egg-rr46.5%
Taylor expanded in x around inf 47.0%
Taylor expanded in y around 0 47.1%
Final simplification64.8%
(FPCore (x y) :precision binary64 (if (<= y -3.1e-143) 1.0 (if (<= y 2.2e-67) (/ x y) 1.0)))
double code(double x, double y) {
double tmp;
if (y <= -3.1e-143) {
tmp = 1.0;
} else if (y <= 2.2e-67) {
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 <= (-3.1d-143)) then
tmp = 1.0d0
else if (y <= 2.2d-67) 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 <= -3.1e-143) {
tmp = 1.0;
} else if (y <= 2.2e-67) {
tmp = x / y;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -3.1e-143: tmp = 1.0 elif y <= 2.2e-67: tmp = x / y else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -3.1e-143) tmp = 1.0; elseif (y <= 2.2e-67) tmp = Float64(x / y); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -3.1e-143) tmp = 1.0; elseif (y <= 2.2e-67) tmp = x / y; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -3.1e-143], 1.0, If[LessEqual[y, 2.2e-67], N[(x / y), $MachinePrecision], 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.1 \cdot 10^{-143}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 2.2 \cdot 10^{-67}:\\
\;\;\;\;\frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -3.10000000000000007e-143 or 2.2000000000000001e-67 < y Initial program 100.0%
Taylor expanded in x around -inf 100.0%
Simplified100.0%
Taylor expanded in x around 0 71.9%
Applied egg-rr71.9%
if -3.10000000000000007e-143 < y < 2.2000000000000001e-67Initial program 99.9%
div-inv99.7%
add-sqr-sqrt41.1%
fabs-sqr41.1%
add-sqr-sqrt41.7%
*-commutative41.7%
add-sqr-sqrt18.5%
fabs-sqr18.5%
add-sqr-sqrt45.1%
Applied egg-rr45.1%
Taylor expanded in x around inf 45.6%
Taylor expanded in y around 0 45.8%
(FPCore (x y) :precision binary64 (if (<= x -2.4e+161) (* x x) 1.0))
double code(double x, double y) {
double tmp;
if (x <= -2.4e+161) {
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 <= (-2.4d+161)) 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 <= -2.4e+161) {
tmp = x * x;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -2.4e+161: tmp = x * x else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (x <= -2.4e+161) tmp = Float64(x * x); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -2.4e+161) tmp = x * x; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -2.4e+161], N[(x * x), $MachinePrecision], 1.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.4 \cdot 10^{+161}:\\
\;\;\;\;x \cdot x\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if x < -2.3999999999999999e161Initial program 100.0%
add-log-exp61.2%
*-un-lft-identity61.2%
log-prod61.2%
metadata-eval61.2%
add-log-exp100.0%
add-sqr-sqrt11.1%
fabs-sqr11.1%
add-sqr-sqrt0.0%
fabs-sqr0.0%
add-sqr-sqrt0.2%
add-sqr-sqrt52.2%
Applied egg-rr52.2%
Taylor expanded in x around inf 51.1%
Applied egg-rr50.4%
if -2.3999999999999999e161 < x Initial program 100.0%
Taylor expanded in x around -inf 100.0%
Simplified100.0%
Taylor expanded in x around 0 57.9%
Applied egg-rr57.9%
(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 0 53.4%
Applied egg-rr53.4%
herbie shell --seed 2024165
(FPCore (x y)
:name "Numeric.LinearAlgebra.Util:formatSparse from hmatrix-0.16.1.5"
:precision binary64
(/ (fabs (- x y)) (fabs y)))