
(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 (+ 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}
Initial program 99.9%
Final simplification99.9%
(FPCore (x y) :precision binary64 (if (<= x -3.1e-170) (* 0.5 (+ x y)) (* (fabs (- y x)) 0.5)))
double code(double x, double y) {
double tmp;
if (x <= -3.1e-170) {
tmp = 0.5 * (x + y);
} else {
tmp = fabs((y - x)) * 0.5;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= (-3.1d-170)) then
tmp = 0.5d0 * (x + y)
else
tmp = abs((y - x)) * 0.5d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -3.1e-170) {
tmp = 0.5 * (x + y);
} else {
tmp = Math.abs((y - x)) * 0.5;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -3.1e-170: tmp = 0.5 * (x + y) else: tmp = math.fabs((y - x)) * 0.5 return tmp
function code(x, y) tmp = 0.0 if (x <= -3.1e-170) tmp = Float64(0.5 * Float64(x + y)); else tmp = Float64(abs(Float64(y - x)) * 0.5); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -3.1e-170) tmp = 0.5 * (x + y); else tmp = abs((y - x)) * 0.5; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -3.1e-170], N[(0.5 * N[(x + y), $MachinePrecision]), $MachinePrecision], N[(N[Abs[N[(y - x), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.1 \cdot 10^{-170}:\\
\;\;\;\;0.5 \cdot \left(x + y\right)\\
\mathbf{else}:\\
\;\;\;\;\left|y - x\right| \cdot 0.5\\
\end{array}
\end{array}
if x < -3.09999999999999986e-170Initial program 100.0%
+-commutative100.0%
div-inv100.0%
fma-def100.0%
add-sqr-sqrt89.2%
fabs-sqr89.2%
add-sqr-sqrt90.0%
fma-def90.0%
add-sqr-sqrt89.2%
fabs-sqr89.2%
add-sqr-sqrt100.0%
add-sqr-sqrt99.2%
associate-*l*99.2%
fma-def99.2%
Applied egg-rr89.2%
Taylor expanded in y around 0 0.0%
+-commutative0.0%
associate-+l+0.0%
*-commutative0.0%
associate-*r*0.0%
unpow20.0%
rem-square-sqrt90.0%
metadata-eval90.0%
distribute-lft1-in90.0%
metadata-eval90.0%
distribute-lft-in90.0%
+-commutative90.0%
Simplified90.0%
if -3.09999999999999986e-170 < x Initial program 99.9%
Taylor expanded in x around 0 67.6%
Final simplification76.3%
(FPCore (x y) :precision binary64 (if (<= y 6.2e-210) x (* y 0.5)))
double code(double x, double y) {
double tmp;
if (y <= 6.2e-210) {
tmp = x;
} else {
tmp = y * 0.5;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= 6.2d-210) then
tmp = x
else
tmp = y * 0.5d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 6.2e-210) {
tmp = x;
} else {
tmp = y * 0.5;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 6.2e-210: tmp = x else: tmp = y * 0.5 return tmp
function code(x, y) tmp = 0.0 if (y <= 6.2e-210) tmp = x; else tmp = Float64(y * 0.5); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 6.2e-210) tmp = x; else tmp = y * 0.5; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 6.2e-210], x, N[(y * 0.5), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 6.2 \cdot 10^{-210}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot 0.5\\
\end{array}
\end{array}
if y < 6.19999999999999973e-210Initial program 99.9%
Taylor expanded in x around inf 12.8%
if 6.19999999999999973e-210 < y Initial program 100.0%
+-commutative100.0%
div-inv100.0%
fma-def100.0%
add-sqr-sqrt84.8%
fabs-sqr84.8%
add-sqr-sqrt88.0%
fma-def88.0%
add-sqr-sqrt84.8%
fabs-sqr84.8%
add-sqr-sqrt100.0%
add-sqr-sqrt99.4%
associate-*l*99.4%
fma-def99.4%
Applied egg-rr84.8%
Taylor expanded in x around 0 58.7%
Final simplification32.5%
(FPCore (x y) :precision binary64 (if (<= y 1.65e-112) (* x 0.5) (* y 0.5)))
double code(double x, double y) {
double tmp;
if (y <= 1.65e-112) {
tmp = x * 0.5;
} else {
tmp = y * 0.5;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= 1.65d-112) then
tmp = x * 0.5d0
else
tmp = y * 0.5d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 1.65e-112) {
tmp = x * 0.5;
} else {
tmp = y * 0.5;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 1.65e-112: tmp = x * 0.5 else: tmp = y * 0.5 return tmp
function code(x, y) tmp = 0.0 if (y <= 1.65e-112) tmp = Float64(x * 0.5); else tmp = Float64(y * 0.5); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 1.65e-112) tmp = x * 0.5; else tmp = y * 0.5; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 1.65e-112], N[(x * 0.5), $MachinePrecision], N[(y * 0.5), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.65 \cdot 10^{-112}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;y \cdot 0.5\\
\end{array}
\end{array}
if y < 1.65e-112Initial program 99.9%
+-commutative99.9%
div-inv99.9%
fma-def99.9%
add-sqr-sqrt36.2%
fabs-sqr36.2%
add-sqr-sqrt41.9%
fma-def41.9%
add-sqr-sqrt36.2%
fabs-sqr36.2%
add-sqr-sqrt99.9%
add-sqr-sqrt99.3%
associate-*l*99.3%
fma-def99.4%
Applied egg-rr36.2%
Taylor expanded in y around 0 0.0%
*-commutative0.0%
associate-*r*0.0%
unpow20.0%
rem-square-sqrt38.9%
metadata-eval38.9%
distribute-rgt1-in38.9%
metadata-eval38.9%
*-commutative38.9%
Simplified38.9%
if 1.65e-112 < y Initial program 100.0%
+-commutative100.0%
div-inv100.0%
fma-def100.0%
add-sqr-sqrt88.1%
fabs-sqr88.1%
add-sqr-sqrt90.7%
fma-def90.7%
add-sqr-sqrt88.1%
fabs-sqr88.1%
add-sqr-sqrt100.0%
add-sqr-sqrt99.3%
associate-*l*99.3%
fma-def99.3%
Applied egg-rr88.1%
Taylor expanded in x around 0 67.5%
Final simplification48.9%
(FPCore (x y) :precision binary64 (* 0.5 (+ x y)))
double code(double x, double y) {
return 0.5 * (x + y);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 0.5d0 * (x + y)
end function
public static double code(double x, double y) {
return 0.5 * (x + y);
}
def code(x, y): return 0.5 * (x + y)
function code(x, y) return Float64(0.5 * Float64(x + y)) end
function tmp = code(x, y) tmp = 0.5 * (x + y); end
code[x_, y_] := N[(0.5 * N[(x + y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.5 \cdot \left(x + y\right)
\end{array}
Initial program 99.9%
+-commutative99.9%
div-inv99.9%
fma-def99.9%
add-sqr-sqrt54.3%
fabs-sqr54.3%
add-sqr-sqrt58.9%
fma-def58.9%
add-sqr-sqrt54.3%
fabs-sqr54.3%
add-sqr-sqrt99.9%
add-sqr-sqrt99.3%
associate-*l*99.3%
fma-def99.4%
Applied egg-rr54.3%
Taylor expanded in y around 0 0.0%
+-commutative0.0%
associate-+l+0.0%
*-commutative0.0%
associate-*r*0.0%
unpow20.0%
rem-square-sqrt58.9%
metadata-eval58.9%
distribute-lft1-in58.9%
metadata-eval58.9%
distribute-lft-in58.9%
+-commutative58.9%
Simplified58.9%
Final simplification58.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 11.6%
Final simplification11.6%
herbie shell --seed 2023271
(FPCore (x y)
:name "Graphics.Rendering.Chart.Plot.AreaSpots:renderSpotLegend from Chart-1.5.3"
:precision binary64
(+ x (/ (fabs (- y x)) 2.0)))