
(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 5 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%
neg-fabsN/A
div-fabsN/A
fabs-lowering-fabs.f64N/A
sub-negN/A
+-commutativeN/A
distribute-neg-inN/A
remove-double-negN/A
sub-negN/A
div-subN/A
*-inversesN/A
--lowering--.f64N/A
/-lowering-/.f64100.0%
Applied egg-rr100.0%
(FPCore (x y) :precision binary64 (if (<= x -1.5e+77) (- 0.0 (/ x y)) (if (<= x 2.1e+59) 1.0 (/ 1.0 (/ -1.0 (/ x y))))))
double code(double x, double y) {
double tmp;
if (x <= -1.5e+77) {
tmp = 0.0 - (x / y);
} else if (x <= 2.1e+59) {
tmp = 1.0;
} else {
tmp = 1.0 / (-1.0 / (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 <= (-1.5d+77)) then
tmp = 0.0d0 - (x / y)
else if (x <= 2.1d+59) then
tmp = 1.0d0
else
tmp = 1.0d0 / ((-1.0d0) / (x / y))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -1.5e+77) {
tmp = 0.0 - (x / y);
} else if (x <= 2.1e+59) {
tmp = 1.0;
} else {
tmp = 1.0 / (-1.0 / (x / y));
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -1.5e+77: tmp = 0.0 - (x / y) elif x <= 2.1e+59: tmp = 1.0 else: tmp = 1.0 / (-1.0 / (x / y)) return tmp
function code(x, y) tmp = 0.0 if (x <= -1.5e+77) tmp = Float64(0.0 - Float64(x / y)); elseif (x <= 2.1e+59) tmp = 1.0; else tmp = Float64(1.0 / Float64(-1.0 / Float64(x / y))); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -1.5e+77) tmp = 0.0 - (x / y); elseif (x <= 2.1e+59) tmp = 1.0; else tmp = 1.0 / (-1.0 / (x / y)); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -1.5e+77], N[(0.0 - N[(x / y), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 2.1e+59], 1.0, N[(1.0 / N[(-1.0 / N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.5 \cdot 10^{+77}:\\
\;\;\;\;0 - \frac{x}{y}\\
\mathbf{elif}\;x \leq 2.1 \cdot 10^{+59}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{-1}{\frac{x}{y}}}\\
\end{array}
\end{array}
if x < -1.4999999999999999e77Initial program 100.0%
div-fabsN/A
div-invN/A
flip--N/A
clear-numN/A
frac-timesN/A
metadata-evalN/A
fabs-divN/A
metadata-evalN/A
/-lowering-/.f64N/A
fabs-lowering-fabs.f64N/A
*-lowering-*.f64N/A
clear-numN/A
flip--N/A
/-lowering-/.f64N/A
--lowering--.f6499.6%
Applied egg-rr99.6%
Taylor expanded in x around inf
/-lowering-/.f6490.0%
Simplified90.0%
inv-powN/A
sqr-powN/A
pow-prod-downN/A
remove-double-negN/A
remove-double-negN/A
sqr-negN/A
pow-prod-downN/A
sqr-powN/A
inv-powN/A
distribute-frac-neg2N/A
neg-lowering-neg.f64N/A
inv-powN/A
sqr-powN/A
pow-prod-downN/A
sqr-absN/A
pow2N/A
pow-powN/A
metadata-evalN/A
metadata-evalN/A
inv-powN/A
Applied egg-rr56.9%
if -1.4999999999999999e77 < x < 2.09999999999999984e59Initial program 100.0%
neg-fabsN/A
div-fabsN/A
fabs-lowering-fabs.f64N/A
sub-negN/A
+-commutativeN/A
distribute-neg-inN/A
remove-double-negN/A
sub-negN/A
div-subN/A
*-inversesN/A
--lowering--.f64N/A
/-lowering-/.f64100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0
Simplified73.4%
metadata-eval73.4%
Applied egg-rr73.4%
if 2.09999999999999984e59 < x Initial program 100.0%
div-fabsN/A
div-invN/A
flip--N/A
clear-numN/A
frac-timesN/A
metadata-evalN/A
fabs-divN/A
metadata-evalN/A
/-lowering-/.f64N/A
fabs-lowering-fabs.f64N/A
*-lowering-*.f64N/A
clear-numN/A
flip--N/A
/-lowering-/.f64N/A
--lowering--.f6499.7%
Applied egg-rr99.7%
Taylor expanded in x around inf
/-lowering-/.f6488.5%
Simplified88.5%
remove-double-divN/A
frac-2negN/A
metadata-evalN/A
distribute-frac-neg2N/A
inv-powN/A
sqr-powN/A
pow-prod-downN/A
sqr-negN/A
remove-double-negN/A
remove-double-negN/A
pow-prod-downN/A
sqr-powN/A
inv-powN/A
/-lowering-/.f64N/A
inv-powN/A
sqr-powN/A
pow-prod-downN/A
Applied egg-rr48.3%
Final simplification65.8%
(FPCore (x y) :precision binary64 (let* ((t_0 (- 0.0 (/ x y)))) (if (<= x -7.5e+78) t_0 (if (<= x 4e+62) 1.0 t_0))))
double code(double x, double y) {
double t_0 = 0.0 - (x / y);
double tmp;
if (x <= -7.5e+78) {
tmp = t_0;
} else if (x <= 4e+62) {
tmp = 1.0;
} else {
tmp = t_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 = 0.0d0 - (x / y)
if (x <= (-7.5d+78)) then
tmp = t_0
else if (x <= 4d+62) then
tmp = 1.0d0
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = 0.0 - (x / y);
double tmp;
if (x <= -7.5e+78) {
tmp = t_0;
} else if (x <= 4e+62) {
tmp = 1.0;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y): t_0 = 0.0 - (x / y) tmp = 0 if x <= -7.5e+78: tmp = t_0 elif x <= 4e+62: tmp = 1.0 else: tmp = t_0 return tmp
function code(x, y) t_0 = Float64(0.0 - Float64(x / y)) tmp = 0.0 if (x <= -7.5e+78) tmp = t_0; elseif (x <= 4e+62) tmp = 1.0; else tmp = t_0; end return tmp end
function tmp_2 = code(x, y) t_0 = 0.0 - (x / y); tmp = 0.0; if (x <= -7.5e+78) tmp = t_0; elseif (x <= 4e+62) tmp = 1.0; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(0.0 - N[(x / y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -7.5e+78], t$95$0, If[LessEqual[x, 4e+62], 1.0, t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 0 - \frac{x}{y}\\
\mathbf{if}\;x \leq -7.5 \cdot 10^{+78}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 4 \cdot 10^{+62}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -7.49999999999999934e78 or 4.00000000000000014e62 < x Initial program 100.0%
div-fabsN/A
div-invN/A
flip--N/A
clear-numN/A
frac-timesN/A
metadata-evalN/A
fabs-divN/A
metadata-evalN/A
/-lowering-/.f64N/A
fabs-lowering-fabs.f64N/A
*-lowering-*.f64N/A
clear-numN/A
flip--N/A
/-lowering-/.f64N/A
--lowering--.f6499.7%
Applied egg-rr99.7%
Taylor expanded in x around inf
/-lowering-/.f6489.1%
Simplified89.1%
inv-powN/A
sqr-powN/A
pow-prod-downN/A
remove-double-negN/A
remove-double-negN/A
sqr-negN/A
pow-prod-downN/A
sqr-powN/A
inv-powN/A
distribute-frac-neg2N/A
neg-lowering-neg.f64N/A
inv-powN/A
sqr-powN/A
pow-prod-downN/A
sqr-absN/A
pow2N/A
pow-powN/A
metadata-evalN/A
metadata-evalN/A
inv-powN/A
Applied egg-rr52.0%
if -7.49999999999999934e78 < x < 4.00000000000000014e62Initial program 100.0%
neg-fabsN/A
div-fabsN/A
fabs-lowering-fabs.f64N/A
sub-negN/A
+-commutativeN/A
distribute-neg-inN/A
remove-double-negN/A
sub-negN/A
div-subN/A
*-inversesN/A
--lowering--.f64N/A
/-lowering-/.f64100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0
Simplified73.4%
metadata-eval73.4%
Applied egg-rr73.4%
Final simplification65.8%
(FPCore (x y) :precision binary64 (if (<= x -7.5e+131) (/ x y) (if (<= x 4.1e+106) 1.0 (/ x y))))
double code(double x, double y) {
double tmp;
if (x <= -7.5e+131) {
tmp = x / y;
} else if (x <= 4.1e+106) {
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 <= (-7.5d+131)) then
tmp = x / y
else if (x <= 4.1d+106) 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 <= -7.5e+131) {
tmp = x / y;
} else if (x <= 4.1e+106) {
tmp = 1.0;
} else {
tmp = x / y;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -7.5e+131: tmp = x / y elif x <= 4.1e+106: tmp = 1.0 else: tmp = x / y return tmp
function code(x, y) tmp = 0.0 if (x <= -7.5e+131) tmp = Float64(x / y); elseif (x <= 4.1e+106) tmp = 1.0; else tmp = Float64(x / y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -7.5e+131) tmp = x / y; elseif (x <= 4.1e+106) tmp = 1.0; else tmp = x / y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -7.5e+131], N[(x / y), $MachinePrecision], If[LessEqual[x, 4.1e+106], 1.0, N[(x / y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -7.5 \cdot 10^{+131}:\\
\;\;\;\;\frac{x}{y}\\
\mathbf{elif}\;x \leq 4.1 \cdot 10^{+106}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{y}\\
\end{array}
\end{array}
if x < -7.4999999999999995e131 or 4.1000000000000002e106 < x Initial program 100.0%
div-fabsN/A
div-invN/A
flip--N/A
clear-numN/A
frac-timesN/A
metadata-evalN/A
fabs-divN/A
metadata-evalN/A
/-lowering-/.f64N/A
fabs-lowering-fabs.f64N/A
*-lowering-*.f64N/A
clear-numN/A
flip--N/A
/-lowering-/.f64N/A
--lowering--.f6499.6%
Applied egg-rr99.6%
Taylor expanded in x around inf
/-lowering-/.f6492.9%
Simplified92.9%
inv-powN/A
sqr-powN/A
pow-prod-downN/A
sqr-absN/A
pow2N/A
pow-powN/A
metadata-evalN/A
metadata-evalN/A
inv-powN/A
*-commutativeN/A
un-div-invN/A
clear-numN/A
/-lowering-/.f6444.2%
Applied egg-rr44.2%
if -7.4999999999999995e131 < x < 4.1000000000000002e106Initial program 100.0%
neg-fabsN/A
div-fabsN/A
fabs-lowering-fabs.f64N/A
sub-negN/A
+-commutativeN/A
distribute-neg-inN/A
remove-double-negN/A
sub-negN/A
div-subN/A
*-inversesN/A
--lowering--.f64N/A
/-lowering-/.f64100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0
Simplified68.5%
metadata-eval68.5%
Applied egg-rr68.5%
(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%
neg-fabsN/A
div-fabsN/A
fabs-lowering-fabs.f64N/A
sub-negN/A
+-commutativeN/A
distribute-neg-inN/A
remove-double-negN/A
sub-negN/A
div-subN/A
*-inversesN/A
--lowering--.f64N/A
/-lowering-/.f64100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0
Simplified52.3%
metadata-eval52.3%
Applied egg-rr52.3%
herbie shell --seed 2024161
(FPCore (x y)
:name "Numeric.LinearAlgebra.Util:formatSparse from hmatrix-0.16.1.5"
:precision binary64
(/ (fabs (- x y)) (fabs y)))