
(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%
(FPCore (x y) :precision binary64 (if (<= y -1.95e-67) (* (fabs (- y x)) 0.5) (* 0.5 (+ x y))))
double code(double x, double y) {
double tmp;
if (y <= -1.95e-67) {
tmp = fabs((y - x)) * 0.5;
} else {
tmp = 0.5 * (x + y);
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= (-1.95d-67)) then
tmp = abs((y - x)) * 0.5d0
else
tmp = 0.5d0 * (x + y)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -1.95e-67) {
tmp = Math.abs((y - x)) * 0.5;
} else {
tmp = 0.5 * (x + y);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.95e-67: tmp = math.fabs((y - x)) * 0.5 else: tmp = 0.5 * (x + y) return tmp
function code(x, y) tmp = 0.0 if (y <= -1.95e-67) tmp = Float64(abs(Float64(y - x)) * 0.5); else tmp = Float64(0.5 * Float64(x + y)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -1.95e-67) tmp = abs((y - x)) * 0.5; else tmp = 0.5 * (x + y); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.95e-67], N[(N[Abs[N[(y - x), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision], N[(0.5 * N[(x + y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.95 \cdot 10^{-67}:\\
\;\;\;\;\left|y - x\right| \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(x + y\right)\\
\end{array}
\end{array}
if y < -1.9499999999999999e-67Initial program 99.9%
Taylor expanded in x around 0 72.2%
if -1.9499999999999999e-67 < y Initial program 99.9%
+-commutative99.9%
div-inv99.9%
fma-define99.9%
add-sqr-sqrt63.9%
fabs-sqr63.9%
add-sqr-sqrt70.0%
fma-define70.0%
div-inv70.0%
add-sqr-sqrt63.9%
fabs-sqr63.9%
add-sqr-sqrt99.9%
add-cube-cbrt98.3%
associate-/l*98.3%
fma-define98.3%
Applied egg-rr68.8%
fma-undefine68.8%
+-commutative68.8%
associate-*r/68.8%
unpow268.8%
rem-3cbrt-lft70.0%
Simplified70.0%
Taylor expanded in x around 0 70.1%
distribute-lft-out70.1%
Simplified70.1%
Final simplification70.7%
(FPCore (x y) :precision binary64 (if (or (<= y 1.65e-77) (and (not (<= y 4.8e-56)) (<= y 1200000.0))) (* x 0.5) (* y 0.5)))
double code(double x, double y) {
double tmp;
if ((y <= 1.65e-77) || (!(y <= 4.8e-56) && (y <= 1200000.0))) {
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-77) .or. (.not. (y <= 4.8d-56)) .and. (y <= 1200000.0d0)) 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-77) || (!(y <= 4.8e-56) && (y <= 1200000.0))) {
tmp = x * 0.5;
} else {
tmp = y * 0.5;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= 1.65e-77) or (not (y <= 4.8e-56) and (y <= 1200000.0)): tmp = x * 0.5 else: tmp = y * 0.5 return tmp
function code(x, y) tmp = 0.0 if ((y <= 1.65e-77) || (!(y <= 4.8e-56) && (y <= 1200000.0))) 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-77) || (~((y <= 4.8e-56)) && (y <= 1200000.0))) tmp = x * 0.5; else tmp = y * 0.5; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, 1.65e-77], And[N[Not[LessEqual[y, 4.8e-56]], $MachinePrecision], LessEqual[y, 1200000.0]]], N[(x * 0.5), $MachinePrecision], N[(y * 0.5), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.65 \cdot 10^{-77} \lor \neg \left(y \leq 4.8 \cdot 10^{-56}\right) \land y \leq 1200000:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;y \cdot 0.5\\
\end{array}
\end{array}
if y < 1.64999999999999996e-77 or 4.80000000000000001e-56 < y < 1.2e6Initial program 99.9%
+-commutative99.9%
div-inv99.9%
fma-define99.9%
add-sqr-sqrt32.4%
fabs-sqr32.4%
add-sqr-sqrt38.8%
fma-define38.8%
div-inv38.8%
add-sqr-sqrt32.4%
fabs-sqr32.4%
add-sqr-sqrt99.9%
add-cube-cbrt98.3%
associate-/l*98.3%
fma-define98.4%
Applied egg-rr38.2%
fma-undefine38.2%
+-commutative38.2%
associate-*r/38.2%
unpow238.2%
rem-3cbrt-lft38.8%
Simplified38.8%
Taylor expanded in x around inf 36.4%
if 1.64999999999999996e-77 < y < 4.80000000000000001e-56 or 1.2e6 < y Initial program 99.9%
+-commutative99.9%
div-inv99.9%
fma-define99.9%
add-sqr-sqrt88.2%
fabs-sqr88.2%
add-sqr-sqrt90.8%
fma-define90.8%
div-inv90.8%
add-sqr-sqrt88.2%
fabs-sqr88.2%
add-sqr-sqrt99.9%
add-cube-cbrt97.9%
associate-/l*97.9%
fma-define97.9%
Applied egg-rr89.0%
fma-undefine89.0%
+-commutative89.0%
associate-*r/89.0%
unpow289.0%
rem-3cbrt-lft90.8%
Simplified90.8%
Taylor expanded in x around 0 79.6%
Final simplification48.5%
(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-define99.9%
add-sqr-sqrt48.1%
fabs-sqr48.1%
add-sqr-sqrt53.4%
fma-define53.4%
div-inv53.4%
add-sqr-sqrt48.1%
fabs-sqr48.1%
add-sqr-sqrt99.9%
add-cube-cbrt98.2%
associate-/l*98.2%
fma-define98.2%
Applied egg-rr52.5%
fma-undefine52.5%
+-commutative52.5%
associate-*r/52.5%
unpow252.5%
rem-3cbrt-lft53.4%
Simplified53.4%
Taylor expanded in x around 0 53.4%
distribute-lft-out53.4%
Simplified53.4%
(FPCore (x y) :precision binary64 (* x 0.5))
double code(double x, double y) {
return x * 0.5;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x * 0.5d0
end function
public static double code(double x, double y) {
return x * 0.5;
}
def code(x, y): return x * 0.5
function code(x, y) return Float64(x * 0.5) end
function tmp = code(x, y) tmp = x * 0.5; end
code[x_, y_] := N[(x * 0.5), $MachinePrecision]
\begin{array}{l}
\\
x \cdot 0.5
\end{array}
Initial program 99.9%
+-commutative99.9%
div-inv99.9%
fma-define99.9%
add-sqr-sqrt48.1%
fabs-sqr48.1%
add-sqr-sqrt53.4%
fma-define53.4%
div-inv53.4%
add-sqr-sqrt48.1%
fabs-sqr48.1%
add-sqr-sqrt99.9%
add-cube-cbrt98.2%
associate-/l*98.2%
fma-define98.2%
Applied egg-rr52.5%
fma-undefine52.5%
+-commutative52.5%
associate-*r/52.5%
unpow252.5%
rem-3cbrt-lft53.4%
Simplified53.4%
Taylor expanded in x around inf 29.9%
Final simplification29.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.5%
herbie shell --seed 2024100
(FPCore (x y)
:name "Graphics.Rendering.Chart.Plot.AreaSpots:renderSpotLegend from Chart-1.5.3"
:precision binary64
(+ x (/ (fabs (- y x)) 2.0)))