
(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.6e-145) (* (fabs (- y x)) 0.5) (* 0.5 (+ x y))))
double code(double x, double y) {
double tmp;
if (y <= -1.6e-145) {
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.6d-145)) 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.6e-145) {
tmp = Math.abs((y - x)) * 0.5;
} else {
tmp = 0.5 * (x + y);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.6e-145: 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.6e-145) 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.6e-145) tmp = abs((y - x)) * 0.5; else tmp = 0.5 * (x + y); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.6e-145], 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.6 \cdot 10^{-145}:\\
\;\;\;\;\left|y - x\right| \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(x + y\right)\\
\end{array}
\end{array}
if y < -1.60000000000000004e-145Initial program 100.0%
Taylor expanded in x around 0 68.1%
if -1.60000000000000004e-145 < y Initial program 99.9%
Taylor expanded in x around inf 89.4%
Taylor expanded in x around 0 99.9%
+-commutative99.9%
fma-define99.9%
rem-square-sqrt68.1%
fabs-sqr68.1%
rem-square-sqrt74.2%
fma-undefine74.2%
+-commutative74.2%
sub-neg74.2%
distribute-lft-in74.2%
distribute-rgt-neg-in74.2%
distribute-lft-neg-in74.2%
metadata-eval74.2%
+-commutative74.2%
associate-+r+74.2%
distribute-rgt1-in74.2%
metadata-eval74.2%
distribute-lft-out74.2%
+-commutative74.2%
Simplified74.2%
Final simplification71.7%
(FPCore (x y) :precision binary64 (if (<= y 1.22e-49) (* x 0.5) (* y 0.5)))
double code(double x, double y) {
double tmp;
if (y <= 1.22e-49) {
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.22d-49) 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.22e-49) {
tmp = x * 0.5;
} else {
tmp = y * 0.5;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 1.22e-49: tmp = x * 0.5 else: tmp = y * 0.5 return tmp
function code(x, y) tmp = 0.0 if (y <= 1.22e-49) 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.22e-49) tmp = x * 0.5; else tmp = y * 0.5; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 1.22e-49], N[(x * 0.5), $MachinePrecision], N[(y * 0.5), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.22 \cdot 10^{-49}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;y \cdot 0.5\\
\end{array}
\end{array}
if y < 1.2199999999999999e-49Initial program 99.9%
+-commutative99.9%
div-inv99.9%
fma-define99.9%
add-sqr-sqrt29.6%
fabs-sqr29.6%
add-sqr-sqrt35.8%
fma-define35.8%
div-inv35.8%
add-sqr-sqrt29.6%
fabs-sqr29.6%
add-sqr-sqrt99.9%
add-cube-cbrt98.1%
associate-/l*98.1%
fma-define98.1%
Applied egg-rr35.1%
fma-undefine35.1%
+-commutative35.1%
associate-*r/35.1%
unpow235.1%
rem-3cbrt-lft35.8%
Simplified35.8%
Taylor expanded in x around inf 33.0%
if 1.2199999999999999e-49 < y Initial program 99.9%
+-commutative99.9%
div-inv99.9%
fma-define99.9%
add-sqr-sqrt88.6%
fabs-sqr88.6%
add-sqr-sqrt91.2%
fma-define91.2%
div-inv91.2%
add-sqr-sqrt88.6%
fabs-sqr88.6%
add-sqr-sqrt99.9%
add-cube-cbrt98.0%
associate-/l*98.0%
fma-define98.0%
Applied egg-rr89.3%
fma-undefine89.3%
+-commutative89.3%
associate-*r/89.3%
unpow289.3%
rem-3cbrt-lft91.2%
Simplified91.2%
Taylor expanded in x around 0 77.8%
Final simplification46.1%
(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%
Taylor expanded in x around inf 86.8%
Taylor expanded in x around 0 99.9%
+-commutative99.9%
fma-define99.9%
rem-square-sqrt46.9%
fabs-sqr46.9%
rem-square-sqrt52.1%
fma-undefine52.1%
+-commutative52.1%
sub-neg52.1%
distribute-lft-in52.1%
distribute-rgt-neg-in52.1%
distribute-lft-neg-in52.1%
metadata-eval52.1%
+-commutative52.1%
associate-+r+52.1%
distribute-rgt1-in52.1%
metadata-eval52.1%
distribute-lft-out52.1%
+-commutative52.1%
Simplified52.1%
Final simplification52.1%
(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-sqrt46.9%
fabs-sqr46.9%
add-sqr-sqrt52.1%
fma-define52.1%
div-inv52.1%
add-sqr-sqrt46.9%
fabs-sqr46.9%
add-sqr-sqrt99.9%
add-cube-cbrt98.1%
associate-/l*98.1%
fma-define98.1%
Applied egg-rr51.0%
fma-undefine51.0%
+-commutative51.0%
associate-*r/51.0%
unpow251.0%
rem-3cbrt-lft52.1%
Simplified52.1%
Taylor expanded in x around inf 27.6%
Final simplification27.6%
(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.9%
herbie shell --seed 2024091
(FPCore (x y)
:name "Graphics.Rendering.Chart.Plot.AreaSpots:renderSpotLegend from Chart-1.5.3"
:precision binary64
(+ x (/ (fabs (- y x)) 2.0)))