
(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.3e-67) (* (fabs (- y x)) 0.5) (* 0.5 (+ x y))))
double code(double x, double y) {
double tmp;
if (y <= -1.3e-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.3d-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.3e-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.3e-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.3e-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.3e-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.3e-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.3 \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.2999999999999999e-67Initial program 99.9%
Taylor expanded in x around 0 75.7%
if -1.2999999999999999e-67 < y Initial program 99.9%
+-commutative99.9%
div-inv99.9%
fma-define99.9%
add-sqr-sqrt69.8%
fabs-sqr69.8%
add-sqr-sqrt75.0%
fma-define75.0%
div-inv75.0%
add-sqr-sqrt69.8%
fabs-sqr69.8%
add-sqr-sqrt99.9%
add-cube-cbrt98.2%
associate-/l*98.2%
fma-define98.2%
Applied egg-rr73.5%
fma-undefine73.5%
+-commutative73.5%
associate-*r/73.5%
unpow273.5%
rem-3cbrt-lft75.0%
Simplified75.0%
Taylor expanded in x around 0 75.0%
+-commutative75.0%
distribute-lft-out75.0%
Simplified75.0%
Final simplification75.3%
(FPCore (x y) :precision binary64 (if (or (<= y 1.7e-182) (and (not (<= y 5.8e-130)) (<= y 6.5e-113))) (* x 0.5) (* y 0.5)))
double code(double x, double y) {
double tmp;
if ((y <= 1.7e-182) || (!(y <= 5.8e-130) && (y <= 6.5e-113))) {
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.7d-182) .or. (.not. (y <= 5.8d-130)) .and. (y <= 6.5d-113)) 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.7e-182) || (!(y <= 5.8e-130) && (y <= 6.5e-113))) {
tmp = x * 0.5;
} else {
tmp = y * 0.5;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= 1.7e-182) or (not (y <= 5.8e-130) and (y <= 6.5e-113)): tmp = x * 0.5 else: tmp = y * 0.5 return tmp
function code(x, y) tmp = 0.0 if ((y <= 1.7e-182) || (!(y <= 5.8e-130) && (y <= 6.5e-113))) 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.7e-182) || (~((y <= 5.8e-130)) && (y <= 6.5e-113))) tmp = x * 0.5; else tmp = y * 0.5; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, 1.7e-182], And[N[Not[LessEqual[y, 5.8e-130]], $MachinePrecision], LessEqual[y, 6.5e-113]]], N[(x * 0.5), $MachinePrecision], N[(y * 0.5), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.7 \cdot 10^{-182} \lor \neg \left(y \leq 5.8 \cdot 10^{-130}\right) \land y \leq 6.5 \cdot 10^{-113}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;y \cdot 0.5\\
\end{array}
\end{array}
if y < 1.69999999999999995e-182 or 5.8e-130 < y < 6.49999999999999979e-113Initial program 99.9%
+-commutative99.9%
div-inv99.9%
fma-define99.9%
add-sqr-sqrt26.7%
fabs-sqr26.7%
add-sqr-sqrt31.9%
fma-define31.9%
div-inv31.9%
add-sqr-sqrt26.7%
fabs-sqr26.7%
add-sqr-sqrt99.9%
add-cube-cbrt98.2%
associate-/l*98.2%
fma-define98.2%
Applied egg-rr31.3%
fma-undefine31.3%
+-commutative31.3%
associate-*r/31.3%
unpow231.3%
rem-3cbrt-lft31.9%
Simplified31.9%
Taylor expanded in x around inf 31.0%
if 1.69999999999999995e-182 < y < 5.8e-130 or 6.49999999999999979e-113 < y Initial program 99.9%
+-commutative99.9%
div-inv99.9%
fma-define99.9%
add-sqr-sqrt82.7%
fabs-sqr82.7%
add-sqr-sqrt86.3%
fma-define86.3%
div-inv86.3%
add-sqr-sqrt82.7%
fabs-sqr82.7%
add-sqr-sqrt99.9%
add-cube-cbrt98.1%
associate-/l*98.1%
fma-define98.1%
Applied egg-rr84.5%
fma-undefine84.5%
+-commutative84.5%
associate-*r/84.5%
unpow284.5%
rem-3cbrt-lft86.3%
Simplified86.3%
Taylor expanded in x around 0 64.6%
Final simplification43.6%
(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-sqrt47.7%
fabs-sqr47.7%
add-sqr-sqrt52.3%
fma-define52.3%
div-inv52.3%
add-sqr-sqrt47.7%
fabs-sqr47.7%
add-sqr-sqrt99.9%
add-cube-cbrt98.1%
associate-/l*98.1%
fma-define98.1%
Applied egg-rr51.2%
fma-undefine51.2%
+-commutative51.2%
associate-*r/51.2%
unpow251.2%
rem-3cbrt-lft52.3%
Simplified52.3%
Taylor expanded in x around 0 52.3%
+-commutative52.3%
distribute-lft-out52.3%
Simplified52.3%
Final simplification52.3%
(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-sqrt47.7%
fabs-sqr47.7%
add-sqr-sqrt52.3%
fma-define52.3%
div-inv52.3%
add-sqr-sqrt47.7%
fabs-sqr47.7%
add-sqr-sqrt99.9%
add-cube-cbrt98.1%
associate-/l*98.1%
fma-define98.1%
Applied egg-rr51.2%
fma-undefine51.2%
+-commutative51.2%
associate-*r/51.2%
unpow251.2%
rem-3cbrt-lft52.3%
Simplified52.3%
Taylor expanded in x around inf 28.4%
Final simplification28.4%
(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 10.6%
herbie shell --seed 2024107
(FPCore (x y)
:name "Graphics.Rendering.Chart.Plot.AreaSpots:renderSpotLegend from Chart-1.5.3"
:precision binary64
(+ x (/ (fabs (- y x)) 2.0)))