
(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 5 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 (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 (if (<= (+ x (/ (fabs (- y x)) 2.0)) -2e-219) (* x 0.75) (* 0.5 (fabs y))))
double code(double x, double y) {
double tmp;
if ((x + (fabs((y - x)) / 2.0)) <= -2e-219) {
tmp = x * 0.75;
} 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)) <= (-2d-219)) then
tmp = x * 0.75d0
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)) <= -2e-219) {
tmp = x * 0.75;
} else {
tmp = 0.5 * Math.abs(y);
}
return tmp;
}
def code(x, y): tmp = 0 if (x + (math.fabs((y - x)) / 2.0)) <= -2e-219: tmp = x * 0.75 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)) <= -2e-219) tmp = Float64(x * 0.75); 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)) <= -2e-219) tmp = x * 0.75; 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], -2e-219], N[(x * 0.75), $MachinePrecision], N[(0.5 * N[Abs[y], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x + \frac{\left|y - x\right|}{2} \leq -2 \cdot 10^{-219}:\\
\;\;\;\;x \cdot 0.75\\
\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))) < -2.0000000000000001e-219Initial program 100.0%
flip-+N/A
/-lowering-/.f64N/A
Applied egg-rr49.9%
Taylor expanded in x around inf
*-commutativeN/A
*-lowering-*.f6420.0
Simplified20.0%
if -2.0000000000000001e-219 < (+.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
Simplified68.2%
Taylor expanded in x around 0
*-lowering-*.f64N/A
fabs-lowering-fabs.f6462.5
Simplified62.5%
(FPCore (x y) :precision binary64 (let* ((t_0 (fma (fabs y) 0.5 x))) (if (<= y -0.0014) t_0 (if (<= y 3.8e-24) (fma (fabs x) 0.5 x) t_0))))
double code(double x, double y) {
double t_0 = fma(fabs(y), 0.5, x);
double tmp;
if (y <= -0.0014) {
tmp = t_0;
} else if (y <= 3.8e-24) {
tmp = fma(fabs(x), 0.5, x);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y) t_0 = fma(abs(y), 0.5, x) tmp = 0.0 if (y <= -0.0014) tmp = t_0; elseif (y <= 3.8e-24) tmp = fma(abs(x), 0.5, x); else tmp = t_0; end return tmp end
code[x_, y_] := Block[{t$95$0 = N[(N[Abs[y], $MachinePrecision] * 0.5 + x), $MachinePrecision]}, If[LessEqual[y, -0.0014], t$95$0, If[LessEqual[y, 3.8e-24], N[(N[Abs[x], $MachinePrecision] * 0.5 + x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(\left|y\right|, 0.5, x\right)\\
\mathbf{if}\;y \leq -0.0014:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 3.8 \cdot 10^{-24}:\\
\;\;\;\;\mathsf{fma}\left(\left|x\right|, 0.5, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -0.00139999999999999999 or 3.80000000000000026e-24 < 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
Simplified78.8%
if -0.00139999999999999999 < y < 3.80000000000000026e-24Initial 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 0
mul-1-negN/A
neg-lowering-neg.f6483.9
Simplified83.9%
fabs-negN/A
fabs-lowering-fabs.f6483.9
Applied egg-rr83.9%
(FPCore (x y) :precision binary64 (let* ((t_0 (* 0.5 (fabs y)))) (if (<= y -1.25) t_0 (if (<= y 8.5e-11) (fma (fabs x) 0.5 x) t_0))))
double code(double x, double y) {
double t_0 = 0.5 * fabs(y);
double tmp;
if (y <= -1.25) {
tmp = t_0;
} else if (y <= 8.5e-11) {
tmp = fma(fabs(x), 0.5, x);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y) t_0 = Float64(0.5 * abs(y)) tmp = 0.0 if (y <= -1.25) tmp = t_0; elseif (y <= 8.5e-11) tmp = fma(abs(x), 0.5, 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, -1.25], t$95$0, If[LessEqual[y, 8.5e-11], N[(N[Abs[x], $MachinePrecision] * 0.5 + x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 0.5 \cdot \left|y\right|\\
\mathbf{if}\;y \leq -1.25:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 8.5 \cdot 10^{-11}:\\
\;\;\;\;\mathsf{fma}\left(\left|x\right|, 0.5, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -1.25 or 8.50000000000000037e-11 < 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
Simplified79.4%
Taylor expanded in x around 0
*-lowering-*.f64N/A
fabs-lowering-fabs.f6475.6
Simplified75.6%
if -1.25 < y < 8.50000000000000037e-11Initial 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 0
mul-1-negN/A
neg-lowering-neg.f6482.9
Simplified82.9%
fabs-negN/A
fabs-lowering-fabs.f6482.9
Applied egg-rr82.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
Simplified12.1%
herbie shell --seed 2024198
(FPCore (x y)
:name "Graphics.Rendering.Chart.Plot.AreaSpots:renderSpotLegend from Chart-1.5.3"
:precision binary64
(+ x (/ (fabs (- y x)) 2.0)))