
(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 (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%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
div-invN/A
lower-fma.f64N/A
lift-fabs.f64N/A
neg-fabsN/A
lower-fabs.f64N/A
lift--.f64N/A
sub-negN/A
+-commutativeN/A
distribute-neg-inN/A
remove-double-negN/A
sub-negN/A
lower--.f64N/A
metadata-eval99.9
Applied rewrites99.9%
Final simplification99.9%
(FPCore (x y) :precision binary64 (if (<= y 1.75e-218) (fma 1.5 x (* -0.5 y)) (fma (fabs (- y)) 0.5 x)))
double code(double x, double y) {
double tmp;
if (y <= 1.75e-218) {
tmp = fma(1.5, x, (-0.5 * y));
} else {
tmp = fma(fabs(-y), 0.5, x);
}
return tmp;
}
function code(x, y) tmp = 0.0 if (y <= 1.75e-218) tmp = fma(1.5, x, Float64(-0.5 * y)); else tmp = fma(abs(Float64(-y)), 0.5, x); end return tmp end
code[x_, y_] := If[LessEqual[y, 1.75e-218], N[(1.5 * x + N[(-0.5 * y), $MachinePrecision]), $MachinePrecision], N[(N[Abs[(-y)], $MachinePrecision] * 0.5 + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.75 \cdot 10^{-218}:\\
\;\;\;\;\mathsf{fma}\left(1.5, x, -0.5 \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\left|-y\right|, 0.5, x\right)\\
\end{array}
\end{array}
if y < 1.75e-218Initial program 99.9%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
div-invN/A
lower-fma.f64N/A
lift-fabs.f64N/A
neg-fabsN/A
lower-fabs.f64N/A
lift--.f64N/A
sub-negN/A
+-commutativeN/A
distribute-neg-inN/A
remove-double-negN/A
sub-negN/A
lower--.f64N/A
metadata-eval99.9
Applied rewrites99.9%
lift-fma.f64N/A
*-commutativeN/A
lift-*.f64N/A
rem-square-sqrtN/A
sqrt-unprodN/A
lift-*.f64N/A
*-commutativeN/A
associate-*l*N/A
sqrt-prodN/A
unpow1/2N/A
lower-fma.f64N/A
Applied rewrites73.7%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f64N/A
lower-*.f6478.7
Applied rewrites78.7%
if 1.75e-218 < y Initial program 99.9%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
div-invN/A
lower-fma.f64N/A
lift-fabs.f64N/A
neg-fabsN/A
lower-fabs.f64N/A
lift--.f64N/A
sub-negN/A
+-commutativeN/A
distribute-neg-inN/A
remove-double-negN/A
sub-negN/A
lower--.f64N/A
metadata-eval99.9
Applied rewrites99.9%
Taylor expanded in x around 0
mul-1-negN/A
lower-neg.f6469.1
Applied rewrites69.1%
(FPCore (x y) :precision binary64 (if (<= y 1.75e-218) (fma (- x y) 0.5 x) (fma (fabs (- y)) 0.5 x)))
double code(double x, double y) {
double tmp;
if (y <= 1.75e-218) {
tmp = fma((x - y), 0.5, x);
} else {
tmp = fma(fabs(-y), 0.5, x);
}
return tmp;
}
function code(x, y) tmp = 0.0 if (y <= 1.75e-218) tmp = fma(Float64(x - y), 0.5, x); else tmp = fma(abs(Float64(-y)), 0.5, x); end return tmp end
code[x_, y_] := If[LessEqual[y, 1.75e-218], N[(N[(x - y), $MachinePrecision] * 0.5 + x), $MachinePrecision], N[(N[Abs[(-y)], $MachinePrecision] * 0.5 + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.75 \cdot 10^{-218}:\\
\;\;\;\;\mathsf{fma}\left(x - y, 0.5, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\left|-y\right|, 0.5, x\right)\\
\end{array}
\end{array}
if y < 1.75e-218Initial program 99.9%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
div-invN/A
lower-fma.f64N/A
lift-fabs.f64N/A
neg-fabsN/A
lower-fabs.f64N/A
lift--.f64N/A
sub-negN/A
+-commutativeN/A
distribute-neg-inN/A
remove-double-negN/A
sub-negN/A
lower--.f64N/A
metadata-eval99.9
Applied rewrites99.9%
lift-fabs.f64N/A
unpow1N/A
sqr-powN/A
fabs-sqrN/A
sqr-powN/A
unpow178.6
Applied rewrites78.6%
if 1.75e-218 < y Initial program 99.9%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
div-invN/A
lower-fma.f64N/A
lift-fabs.f64N/A
neg-fabsN/A
lower-fabs.f64N/A
lift--.f64N/A
sub-negN/A
+-commutativeN/A
distribute-neg-inN/A
remove-double-negN/A
sub-negN/A
lower--.f64N/A
metadata-eval99.9
Applied rewrites99.9%
Taylor expanded in x around 0
mul-1-negN/A
lower-neg.f6469.1
Applied rewrites69.1%
(FPCore (x y) :precision binary64 (if (<= y -1.04e-100) (* -0.5 y) (* 1.5 x)))
double code(double x, double y) {
double tmp;
if (y <= -1.04e-100) {
tmp = -0.5 * y;
} else {
tmp = 1.5 * x;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= (-1.04d-100)) then
tmp = (-0.5d0) * y
else
tmp = 1.5d0 * x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -1.04e-100) {
tmp = -0.5 * y;
} else {
tmp = 1.5 * x;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.04e-100: tmp = -0.5 * y else: tmp = 1.5 * x return tmp
function code(x, y) tmp = 0.0 if (y <= -1.04e-100) tmp = Float64(-0.5 * y); else tmp = Float64(1.5 * x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -1.04e-100) tmp = -0.5 * y; else tmp = 1.5 * x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.04e-100], N[(-0.5 * y), $MachinePrecision], N[(1.5 * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.04 \cdot 10^{-100}:\\
\;\;\;\;-0.5 \cdot y\\
\mathbf{else}:\\
\;\;\;\;1.5 \cdot x\\
\end{array}
\end{array}
if y < -1.04e-100Initial program 99.9%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
div-invN/A
lower-fma.f64N/A
lift-fabs.f64N/A
neg-fabsN/A
lower-fabs.f64N/A
lift--.f64N/A
sub-negN/A
+-commutativeN/A
distribute-neg-inN/A
remove-double-negN/A
sub-negN/A
lower--.f64N/A
metadata-eval99.9
Applied rewrites99.9%
lift-fma.f64N/A
*-commutativeN/A
lift-*.f64N/A
rem-square-sqrtN/A
sqrt-unprodN/A
lift-*.f64N/A
*-commutativeN/A
associate-*l*N/A
sqrt-prodN/A
unpow1/2N/A
lower-fma.f64N/A
Applied rewrites87.7%
Taylor expanded in x around 0
lower-*.f6473.6
Applied rewrites73.6%
if -1.04e-100 < y Initial program 99.9%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
div-invN/A
lower-fma.f64N/A
lift-fabs.f64N/A
neg-fabsN/A
lower-fabs.f64N/A
lift--.f64N/A
sub-negN/A
+-commutativeN/A
distribute-neg-inN/A
remove-double-negN/A
sub-negN/A
lower--.f64N/A
metadata-eval99.9
Applied rewrites99.9%
lift-fma.f64N/A
*-commutativeN/A
lift-*.f64N/A
rem-square-sqrtN/A
sqrt-unprodN/A
lift-*.f64N/A
*-commutativeN/A
associate-*l*N/A
sqrt-prodN/A
unpow1/2N/A
lower-fma.f64N/A
Applied rewrites30.5%
Taylor expanded in x around inf
lower-*.f6435.5
Applied rewrites35.5%
(FPCore (x y) :precision binary64 (fma (- x y) 0.5 x))
double code(double x, double y) {
return fma((x - y), 0.5, x);
}
function code(x, y) return fma(Float64(x - y), 0.5, x) end
code[x_, y_] := N[(N[(x - y), $MachinePrecision] * 0.5 + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x - y, 0.5, x\right)
\end{array}
Initial program 99.9%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
div-invN/A
lower-fma.f64N/A
lift-fabs.f64N/A
neg-fabsN/A
lower-fabs.f64N/A
lift--.f64N/A
sub-negN/A
+-commutativeN/A
distribute-neg-inN/A
remove-double-negN/A
sub-negN/A
lower--.f64N/A
metadata-eval99.9
Applied rewrites99.9%
lift-fabs.f64N/A
unpow1N/A
sqr-powN/A
fabs-sqrN/A
sqr-powN/A
unpow154.3
Applied rewrites54.3%
(FPCore (x y) :precision binary64 (* -0.5 y))
double code(double x, double y) {
return -0.5 * y;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (-0.5d0) * y
end function
public static double code(double x, double y) {
return -0.5 * y;
}
def code(x, y): return -0.5 * y
function code(x, y) return Float64(-0.5 * y) end
function tmp = code(x, y) tmp = -0.5 * y; end
code[x_, y_] := N[(-0.5 * y), $MachinePrecision]
\begin{array}{l}
\\
-0.5 \cdot y
\end{array}
Initial program 99.9%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
div-invN/A
lower-fma.f64N/A
lift-fabs.f64N/A
neg-fabsN/A
lower-fabs.f64N/A
lift--.f64N/A
sub-negN/A
+-commutativeN/A
distribute-neg-inN/A
remove-double-negN/A
sub-negN/A
lower--.f64N/A
metadata-eval99.9
Applied rewrites99.9%
lift-fma.f64N/A
*-commutativeN/A
lift-*.f64N/A
rem-square-sqrtN/A
sqrt-unprodN/A
lift-*.f64N/A
*-commutativeN/A
associate-*l*N/A
sqrt-prodN/A
unpow1/2N/A
lower-fma.f64N/A
Applied rewrites49.7%
Taylor expanded in x around 0
lower-*.f6426.7
Applied rewrites26.7%
herbie shell --seed 2024296
(FPCore (x y)
:name "Graphics.Rendering.Chart.Plot.AreaSpots:renderSpotLegend from Chart-1.5.3"
:precision binary64
(+ x (/ (fabs (- y x)) 2.0)))