
(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 (<= x -3e-87) (* 0.5 (+ x y)) (* (fabs (- y x)) 0.5)))
double code(double x, double y) {
double tmp;
if (x <= -3e-87) {
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 <= (-3d-87)) 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 <= -3e-87) {
tmp = 0.5 * (x + y);
} else {
tmp = Math.abs((y - x)) * 0.5;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -3e-87: tmp = 0.5 * (x + y) else: tmp = math.fabs((y - x)) * 0.5 return tmp
function code(x, y) tmp = 0.0 if (x <= -3e-87) 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 <= -3e-87) tmp = 0.5 * (x + y); else tmp = abs((y - x)) * 0.5; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -3e-87], 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 \cdot 10^{-87}:\\
\;\;\;\;0.5 \cdot \left(x + y\right)\\
\mathbf{else}:\\
\;\;\;\;\left|y - x\right| \cdot 0.5\\
\end{array}
\end{array}
if x < -3.00000000000000016e-87Initial program 100.0%
Taylor expanded in x around inf 97.7%
Taylor expanded in x around 0 100.0%
+-commutative100.0%
fma-define100.0%
rem-square-sqrt84.4%
fabs-sqr84.4%
rem-square-sqrt85.1%
fma-undefine85.1%
+-commutative85.1%
sub-neg85.1%
distribute-lft-in85.1%
distribute-rgt-neg-in85.1%
distribute-lft-neg-in85.1%
metadata-eval85.1%
+-commutative85.1%
associate-+r+85.1%
distribute-rgt1-in85.1%
metadata-eval85.1%
distribute-lft-out85.1%
+-commutative85.1%
Simplified85.1%
if -3.00000000000000016e-87 < x Initial program 99.9%
Taylor expanded in x around 0 64.5%
Final simplification70.9%
(FPCore (x y) :precision binary64 (if (<= y 2.4e+28) (* x 0.5) (* y 0.5)))
double code(double x, double y) {
double tmp;
if (y <= 2.4e+28) {
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 <= 2.4d+28) 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 <= 2.4e+28) {
tmp = x * 0.5;
} else {
tmp = y * 0.5;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 2.4e+28: tmp = x * 0.5 else: tmp = y * 0.5 return tmp
function code(x, y) tmp = 0.0 if (y <= 2.4e+28) 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 <= 2.4e+28) tmp = x * 0.5; else tmp = y * 0.5; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 2.4e+28], N[(x * 0.5), $MachinePrecision], N[(y * 0.5), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 2.4 \cdot 10^{+28}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;y \cdot 0.5\\
\end{array}
\end{array}
if y < 2.39999999999999981e28Initial program 99.9%
+-commutative99.9%
div-inv99.9%
fma-define99.9%
add-sqr-sqrt34.2%
fabs-sqr34.2%
add-sqr-sqrt40.2%
fma-define40.2%
div-inv40.2%
add-sqr-sqrt34.2%
fabs-sqr34.2%
add-sqr-sqrt99.9%
add-cube-cbrt98.1%
associate-/l*98.1%
fma-define98.2%
Applied egg-rr39.6%
fma-undefine39.6%
+-commutative39.6%
associate-*r/39.6%
unpow239.6%
rem-3cbrt-lft40.2%
Simplified40.2%
Taylor expanded in x around inf 34.6%
if 2.39999999999999981e28 < y Initial program 99.9%
+-commutative99.9%
div-inv99.9%
fma-define99.9%
add-sqr-sqrt88.0%
fabs-sqr88.0%
add-sqr-sqrt90.7%
fma-define90.7%
div-inv90.7%
add-sqr-sqrt88.0%
fabs-sqr88.0%
add-sqr-sqrt99.9%
add-cube-cbrt98.3%
associate-/l*98.3%
fma-define98.3%
Applied egg-rr89.1%
fma-undefine89.1%
+-commutative89.1%
associate-*r/89.1%
unpow289.1%
rem-3cbrt-lft90.7%
Simplified90.7%
Taylor expanded in x around 0 78.2%
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%
Taylor expanded in x around inf 90.7%
Taylor expanded in x around 0 99.9%
+-commutative99.9%
fma-define99.9%
rem-square-sqrt45.3%
fabs-sqr45.3%
rem-square-sqrt50.7%
fma-undefine50.7%
+-commutative50.7%
sub-neg50.7%
distribute-lft-in50.7%
distribute-rgt-neg-in50.7%
distribute-lft-neg-in50.7%
metadata-eval50.7%
+-commutative50.7%
associate-+r+50.7%
distribute-rgt1-in50.7%
metadata-eval50.7%
distribute-lft-out50.7%
+-commutative50.7%
Simplified50.7%
Final simplification50.7%
(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-sqrt45.3%
fabs-sqr45.3%
add-sqr-sqrt50.7%
fma-define50.7%
div-inv50.7%
add-sqr-sqrt45.3%
fabs-sqr45.3%
add-sqr-sqrt99.9%
add-cube-cbrt98.2%
associate-/l*98.2%
fma-define98.2%
Applied egg-rr49.8%
fma-undefine49.8%
+-commutative49.8%
associate-*r/49.8%
unpow249.8%
rem-3cbrt-lft50.7%
Simplified50.7%
Taylor expanded in x around inf 30.6%
Final simplification30.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 11.5%
herbie shell --seed 2024086
(FPCore (x y)
:name "Graphics.Rendering.Chart.Plot.AreaSpots:renderSpotLegend from Chart-1.5.3"
:precision binary64
(+ x (/ (fabs (- y x)) 2.0)))