
(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 -1.16e-184) (* 0.5 (+ x y)) (* (fabs (- y x)) 0.5)))
double code(double x, double y) {
double tmp;
if (x <= -1.16e-184) {
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 <= (-1.16d-184)) 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 <= -1.16e-184) {
tmp = 0.5 * (x + y);
} else {
tmp = Math.abs((y - x)) * 0.5;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -1.16e-184: tmp = 0.5 * (x + y) else: tmp = math.fabs((y - x)) * 0.5 return tmp
function code(x, y) tmp = 0.0 if (x <= -1.16e-184) 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 <= -1.16e-184) tmp = 0.5 * (x + y); else tmp = abs((y - x)) * 0.5; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -1.16e-184], 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 -1.16 \cdot 10^{-184}:\\
\;\;\;\;0.5 \cdot \left(x + y\right)\\
\mathbf{else}:\\
\;\;\;\;\left|y - x\right| \cdot 0.5\\
\end{array}
\end{array}
if x < -1.15999999999999998e-184Initial program 100.0%
Taylor expanded in x around inf 97.9%
Taylor expanded in x around 0 100.0%
+-commutative100.0%
fma-define100.0%
rem-square-sqrt87.1%
fabs-sqr87.1%
rem-square-sqrt88.0%
fma-undefine88.0%
+-commutative88.0%
sub-neg88.0%
distribute-lft-in88.0%
distribute-rgt-neg-in88.0%
distribute-lft-neg-in88.0%
metadata-eval88.0%
+-commutative88.0%
associate-+r+88.0%
distribute-rgt1-in88.0%
metadata-eval88.0%
distribute-lft-out88.0%
+-commutative88.0%
Simplified88.0%
if -1.15999999999999998e-184 < x Initial program 99.9%
Taylor expanded in x around 0 64.4%
Final simplification72.8%
(FPCore (x y) :precision binary64 (if (or (<= y 1.15e-111) (and (not (<= y 3.6e-41)) (<= y 5.4e-17))) (* x 0.5) (* y 0.5)))
double code(double x, double y) {
double tmp;
if ((y <= 1.15e-111) || (!(y <= 3.6e-41) && (y <= 5.4e-17))) {
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.15d-111) .or. (.not. (y <= 3.6d-41)) .and. (y <= 5.4d-17)) 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.15e-111) || (!(y <= 3.6e-41) && (y <= 5.4e-17))) {
tmp = x * 0.5;
} else {
tmp = y * 0.5;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= 1.15e-111) or (not (y <= 3.6e-41) and (y <= 5.4e-17)): tmp = x * 0.5 else: tmp = y * 0.5 return tmp
function code(x, y) tmp = 0.0 if ((y <= 1.15e-111) || (!(y <= 3.6e-41) && (y <= 5.4e-17))) 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.15e-111) || (~((y <= 3.6e-41)) && (y <= 5.4e-17))) tmp = x * 0.5; else tmp = y * 0.5; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, 1.15e-111], And[N[Not[LessEqual[y, 3.6e-41]], $MachinePrecision], LessEqual[y, 5.4e-17]]], N[(x * 0.5), $MachinePrecision], N[(y * 0.5), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.15 \cdot 10^{-111} \lor \neg \left(y \leq 3.6 \cdot 10^{-41}\right) \land y \leq 5.4 \cdot 10^{-17}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;y \cdot 0.5\\
\end{array}
\end{array}
if y < 1.15e-111 or 3.6e-41 < y < 5.4000000000000002e-17Initial program 99.9%
+-commutative99.9%
div-inv99.9%
fma-define99.9%
add-sqr-sqrt32.3%
fabs-sqr32.3%
add-sqr-sqrt38.8%
fma-define38.8%
div-inv38.8%
add-sqr-sqrt32.3%
fabs-sqr32.3%
add-sqr-sqrt99.9%
add-cube-cbrt98.3%
associate-/l*98.3%
fma-define98.3%
Applied egg-rr38.1%
fma-undefine38.1%
+-commutative38.1%
associate-*r/38.1%
unpow238.1%
rem-3cbrt-lft38.8%
Simplified38.8%
Taylor expanded in x around inf 36.2%
if 1.15e-111 < y < 3.6e-41 or 5.4000000000000002e-17 < y Initial program 99.9%
+-commutative99.9%
div-inv99.9%
fma-define99.9%
add-sqr-sqrt86.9%
fabs-sqr86.9%
add-sqr-sqrt89.8%
fma-define89.8%
div-inv89.8%
add-sqr-sqrt86.9%
fabs-sqr86.9%
add-sqr-sqrt99.9%
add-cube-cbrt97.9%
associate-/l*97.9%
fma-define97.9%
Applied egg-rr87.9%
fma-undefine87.9%
+-commutative87.9%
associate-*r/87.9%
unpow287.9%
rem-3cbrt-lft89.8%
Simplified89.8%
Taylor expanded in x around 0 73.8%
Final simplification48.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 88.5%
Taylor expanded in x around 0 99.9%
+-commutative99.9%
fma-define99.9%
rem-square-sqrt49.6%
fabs-sqr49.6%
rem-square-sqrt54.9%
fma-undefine54.9%
+-commutative54.9%
sub-neg54.9%
distribute-lft-in54.9%
distribute-rgt-neg-in54.9%
distribute-lft-neg-in54.9%
metadata-eval54.9%
+-commutative54.9%
associate-+r+54.9%
distribute-rgt1-in54.9%
metadata-eval54.9%
distribute-lft-out54.9%
+-commutative54.9%
Simplified54.9%
Final simplification54.9%
(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-sqrt49.6%
fabs-sqr49.6%
add-sqr-sqrt54.9%
fma-define54.9%
div-inv54.9%
add-sqr-sqrt49.6%
fabs-sqr49.6%
add-sqr-sqrt99.9%
add-cube-cbrt98.2%
associate-/l*98.2%
fma-define98.2%
Applied egg-rr53.9%
fma-undefine53.8%
+-commutative53.8%
associate-*r/53.8%
unpow253.8%
rem-3cbrt-lft54.9%
Simplified54.9%
Taylor expanded in x around inf 30.5%
Final simplification30.5%
(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 2024067
(FPCore (x y)
:name "Graphics.Rendering.Chart.Plot.AreaSpots:renderSpotLegend from Chart-1.5.3"
:precision binary64
(+ x (/ (fabs (- y x)) 2.0)))