
(FPCore (x y) :precision binary64 (+ x (/ (fabs (- y x)) 2.0)))
double code(double x, double y) {
return x + (fabs((y - x)) / 2.0);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x + (abs((y - x)) / 2.0d0)
end function
public static double code(double x, double y) {
return x + (Math.abs((y - x)) / 2.0);
}
def code(x, y): return x + (math.fabs((y - x)) / 2.0)
function code(x, y) return Float64(x + Float64(abs(Float64(y - x)) / 2.0)) end
function tmp = code(x, y) tmp = x + (abs((y - x)) / 2.0); end
code[x_, y_] := N[(x + N[(N[Abs[N[(y - x), $MachinePrecision]], $MachinePrecision] / 2.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \frac{\left|y - x\right|}{2}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (+ x (/ (fabs (- y x)) 2.0)))
double code(double x, double y) {
return x + (fabs((y - x)) / 2.0);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x + (abs((y - x)) / 2.0d0)
end function
public static double code(double x, double y) {
return x + (Math.abs((y - x)) / 2.0);
}
def code(x, y): return x + (math.fabs((y - x)) / 2.0)
function code(x, y) return Float64(x + Float64(abs(Float64(y - x)) / 2.0)) end
function tmp = code(x, y) tmp = x + (abs((y - x)) / 2.0); end
code[x_, y_] := N[(x + N[(N[Abs[N[(y - x), $MachinePrecision]], $MachinePrecision] / 2.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \frac{\left|y - x\right|}{2}
\end{array}
(FPCore (x y) :precision binary64 (fma (+ y x) (* (/ (fabs (- y x)) (+ y x)) 0.5) x))
double code(double x, double y) {
return fma((y + x), ((fabs((y - x)) / (y + x)) * 0.5), x);
}
function code(x, y) return fma(Float64(y + x), Float64(Float64(abs(Float64(y - x)) / Float64(y + x)) * 0.5), x) end
code[x_, y_] := N[(N[(y + x), $MachinePrecision] * N[(N[(N[Abs[N[(y - x), $MachinePrecision]], $MachinePrecision] / N[(y + x), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision] + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y + x, \frac{\left|y - x\right|}{y + x} \cdot 0.5, x\right)
\end{array}
Initial program 99.9%
+-commutativeN/A
div-invN/A
accelerator-lowering-fma.f64N/A
fabs-lowering-fabs.f64N/A
--lowering--.f64N/A
metadata-eval99.9
Applied egg-rr99.9%
flip--N/A
difference-of-squaresN/A
associate-*r/N/A
un-div-invN/A
metadata-evalN/A
div-invN/A
Applied egg-rr99.9%
(FPCore (x y) :precision binary64 (if (<= (+ x (/ (fabs (- y x)) 2.0)) 1.5e-281) (fma 0.5 (fabs x) x) (fma (fabs y) 0.5 x)))
double code(double x, double y) {
double tmp;
if ((x + (fabs((y - x)) / 2.0)) <= 1.5e-281) {
tmp = fma(0.5, fabs(x), x);
} else {
tmp = fma(fabs(y), 0.5, x);
}
return tmp;
}
function code(x, y) tmp = 0.0 if (Float64(x + Float64(abs(Float64(y - x)) / 2.0)) <= 1.5e-281) tmp = fma(0.5, abs(x), x); else tmp = fma(abs(y), 0.5, x); end return tmp end
code[x_, y_] := If[LessEqual[N[(x + N[(N[Abs[N[(y - x), $MachinePrecision]], $MachinePrecision] / 2.0), $MachinePrecision]), $MachinePrecision], 1.5e-281], N[(0.5 * N[Abs[x], $MachinePrecision] + x), $MachinePrecision], N[(N[Abs[y], $MachinePrecision] * 0.5 + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x + \frac{\left|y - x\right|}{2} \leq 1.5 \cdot 10^{-281}:\\
\;\;\;\;\mathsf{fma}\left(0.5, \left|x\right|, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\left|y\right|, 0.5, x\right)\\
\end{array}
\end{array}
if (+.f64 x (/.f64 (fabs.f64 (-.f64 y x)) #s(literal 2 binary64))) < 1.49999999999999987e-281Initial program 100.0%
+-commutativeN/A
div-invN/A
accelerator-lowering-fma.f64N/A
fabs-lowering-fabs.f64N/A
--lowering--.f64N/A
metadata-eval100.0
Applied egg-rr100.0%
Taylor expanded in x around inf
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
accelerator-lowering-fma.f64N/A
associate-*r/N/A
*-commutativeN/A
sub-negN/A
mul-1-negN/A
associate-/l*N/A
*-lowering-*.f64N/A
mul-1-negN/A
sub-negN/A
fabs-subN/A
sub-negN/A
mul-1-negN/A
fabs-lowering-fabs.f64N/A
mul-1-negN/A
sub-negN/A
--lowering--.f64N/A
/-lowering-/.f6499.7
Simplified99.7%
Taylor expanded in x around inf
Simplified96.1%
Taylor expanded in x around 0
+-commutativeN/A
accelerator-lowering-fma.f64N/A
fabs-lowering-fabs.f6496.3
Simplified96.3%
if 1.49999999999999987e-281 < (+.f64 x (/.f64 (fabs.f64 (-.f64 y x)) #s(literal 2 binary64))) Initial program 99.9%
+-commutativeN/A
div-invN/A
accelerator-lowering-fma.f64N/A
fabs-lowering-fabs.f64N/A
--lowering--.f64N/A
metadata-eval99.9
Applied egg-rr99.9%
Taylor expanded in y around inf
Simplified71.7%
(FPCore (x y) :precision binary64 (if (<= (+ x (/ (fabs (- y x)) 2.0)) 1.5e-281) x (* 0.5 (fabs y))))
double code(double x, double y) {
double tmp;
if ((x + (fabs((y - x)) / 2.0)) <= 1.5e-281) {
tmp = x;
} else {
tmp = 0.5 * fabs(y);
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((x + (abs((y - x)) / 2.0d0)) <= 1.5d-281) then
tmp = x
else
tmp = 0.5d0 * abs(y)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x + (Math.abs((y - x)) / 2.0)) <= 1.5e-281) {
tmp = x;
} else {
tmp = 0.5 * Math.abs(y);
}
return tmp;
}
def code(x, y): tmp = 0 if (x + (math.fabs((y - x)) / 2.0)) <= 1.5e-281: tmp = x else: tmp = 0.5 * math.fabs(y) return tmp
function code(x, y) tmp = 0.0 if (Float64(x + Float64(abs(Float64(y - x)) / 2.0)) <= 1.5e-281) tmp = x; else tmp = Float64(0.5 * abs(y)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x + (abs((y - x)) / 2.0)) <= 1.5e-281) tmp = x; else tmp = 0.5 * abs(y); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[N[(x + N[(N[Abs[N[(y - x), $MachinePrecision]], $MachinePrecision] / 2.0), $MachinePrecision]), $MachinePrecision], 1.5e-281], x, N[(0.5 * N[Abs[y], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x + \frac{\left|y - x\right|}{2} \leq 1.5 \cdot 10^{-281}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left|y\right|\\
\end{array}
\end{array}
if (+.f64 x (/.f64 (fabs.f64 (-.f64 y x)) #s(literal 2 binary64))) < 1.49999999999999987e-281Initial program 100.0%
Taylor expanded in x around inf
Simplified18.8%
if 1.49999999999999987e-281 < (+.f64 x (/.f64 (fabs.f64 (-.f64 y x)) #s(literal 2 binary64))) Initial program 99.9%
+-commutativeN/A
div-invN/A
accelerator-lowering-fma.f64N/A
fabs-lowering-fabs.f64N/A
--lowering--.f64N/A
metadata-eval99.9
Applied egg-rr99.9%
Taylor expanded in y around inf
Simplified71.7%
Taylor expanded in x around 0
*-lowering-*.f64N/A
fabs-lowering-fabs.f6466.7
Simplified66.7%
(FPCore (x y) :precision binary64 (let* ((t_0 (* 0.5 (fabs y)))) (if (<= y -790000000.0) t_0 (if (<= y 1.85e+47) (fma 0.5 (fabs x) x) t_0))))
double code(double x, double y) {
double t_0 = 0.5 * fabs(y);
double tmp;
if (y <= -790000000.0) {
tmp = t_0;
} else if (y <= 1.85e+47) {
tmp = fma(0.5, fabs(x), x);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y) t_0 = Float64(0.5 * abs(y)) tmp = 0.0 if (y <= -790000000.0) tmp = t_0; elseif (y <= 1.85e+47) tmp = fma(0.5, abs(x), x); else tmp = t_0; end return tmp end
code[x_, y_] := Block[{t$95$0 = N[(0.5 * N[Abs[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -790000000.0], t$95$0, If[LessEqual[y, 1.85e+47], N[(0.5 * N[Abs[x], $MachinePrecision] + x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 0.5 \cdot \left|y\right|\\
\mathbf{if}\;y \leq -790000000:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 1.85 \cdot 10^{+47}:\\
\;\;\;\;\mathsf{fma}\left(0.5, \left|x\right|, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -7.9e8 or 1.8500000000000002e47 < y Initial program 99.9%
+-commutativeN/A
div-invN/A
accelerator-lowering-fma.f64N/A
fabs-lowering-fabs.f64N/A
--lowering--.f64N/A
metadata-eval99.9
Applied egg-rr99.9%
Taylor expanded in y around inf
Simplified80.3%
Taylor expanded in x around 0
*-lowering-*.f64N/A
fabs-lowering-fabs.f6476.7
Simplified76.7%
if -7.9e8 < y < 1.8500000000000002e47Initial program 99.9%
+-commutativeN/A
div-invN/A
accelerator-lowering-fma.f64N/A
fabs-lowering-fabs.f64N/A
--lowering--.f64N/A
metadata-eval99.9
Applied egg-rr99.9%
Taylor expanded in x around inf
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
accelerator-lowering-fma.f64N/A
associate-*r/N/A
*-commutativeN/A
sub-negN/A
mul-1-negN/A
associate-/l*N/A
*-lowering-*.f64N/A
mul-1-negN/A
sub-negN/A
fabs-subN/A
sub-negN/A
mul-1-negN/A
fabs-lowering-fabs.f64N/A
mul-1-negN/A
sub-negN/A
--lowering--.f64N/A
/-lowering-/.f6499.7
Simplified99.7%
Taylor expanded in x around inf
Simplified76.7%
Taylor expanded in x around 0
+-commutativeN/A
accelerator-lowering-fma.f64N/A
fabs-lowering-fabs.f6476.8
Simplified76.8%
(FPCore (x y) :precision binary64 (fma (fabs (- y x)) 0.5 x))
double code(double x, double y) {
return fma(fabs((y - x)), 0.5, x);
}
function code(x, y) return fma(abs(Float64(y - x)), 0.5, x) end
code[x_, y_] := N[(N[Abs[N[(y - x), $MachinePrecision]], $MachinePrecision] * 0.5 + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\left|y - x\right|, 0.5, x\right)
\end{array}
Initial program 99.9%
+-commutativeN/A
div-invN/A
accelerator-lowering-fma.f64N/A
fabs-lowering-fabs.f64N/A
--lowering--.f64N/A
metadata-eval99.9
Applied egg-rr99.9%
(FPCore (x y) :precision binary64 x)
double code(double x, double y) {
return x;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x
end function
public static double code(double x, double y) {
return x;
}
def code(x, y): return x
function code(x, y) return x end
function tmp = code(x, y) tmp = x; end
code[x_, y_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 99.9%
Taylor expanded in x around inf
Simplified11.5%
herbie shell --seed 2024199
(FPCore (x y)
:name "Graphics.Rendering.Chart.Plot.AreaSpots:renderSpotLegend from Chart-1.5.3"
:precision binary64
(+ x (/ (fabs (- y x)) 2.0)))