
(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 (<= y -6.8e-135) (* (fabs (- y x)) 0.5) (/ (+ x y) 2.0)))
double code(double x, double y) {
double tmp;
if (y <= -6.8e-135) {
tmp = fabs((y - x)) * 0.5;
} else {
tmp = (x + y) / 2.0;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= (-6.8d-135)) then
tmp = abs((y - x)) * 0.5d0
else
tmp = (x + y) / 2.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -6.8e-135) {
tmp = Math.abs((y - x)) * 0.5;
} else {
tmp = (x + y) / 2.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -6.8e-135: tmp = math.fabs((y - x)) * 0.5 else: tmp = (x + y) / 2.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -6.8e-135) tmp = Float64(abs(Float64(y - x)) * 0.5); else tmp = Float64(Float64(x + y) / 2.0); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -6.8e-135) tmp = abs((y - x)) * 0.5; else tmp = (x + y) / 2.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -6.8e-135], N[(N[Abs[N[(y - x), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision], N[(N[(x + y), $MachinePrecision] / 2.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6.8 \cdot 10^{-135}:\\
\;\;\;\;\left|y - x\right| \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{x + y}{2}\\
\end{array}
\end{array}
if y < -6.79999999999999978e-135Initial program 100.0%
Taylor expanded in x around 0 64.4%
if -6.79999999999999978e-135 < y Initial program 99.9%
+-commutative99.9%
div-inv99.9%
fma-def99.9%
add-sqr-sqrt70.3%
fabs-sqr70.3%
add-sqr-sqrt75.7%
metadata-eval75.7%
Applied egg-rr75.7%
fma-udef75.7%
flip-+38.0%
pow238.0%
pow238.0%
Applied egg-rr38.0%
unpow238.0%
unpow238.0%
difference-of-squares39.7%
fma-def39.7%
associate-/l*75.7%
fma-def75.7%
+-commutative75.7%
*-commutative75.7%
sub-neg75.7%
+-commutative75.7%
distribute-lft-in75.7%
distribute-rgt-neg-in75.7%
distribute-lft-neg-in75.7%
metadata-eval75.7%
associate-+r+75.7%
distribute-rgt1-in75.7%
metadata-eval75.7%
distribute-lft-out75.7%
*-inverses75.7%
Simplified75.7%
Final simplification71.5%
(FPCore (x y) :precision binary64 (if (or (<= y 1.05e-124) (and (not (<= y 4.6e-58)) (<= y 1.15e-20))) (* x 0.5) (* y 0.5)))
double code(double x, double y) {
double tmp;
if ((y <= 1.05e-124) || (!(y <= 4.6e-58) && (y <= 1.15e-20))) {
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.05d-124) .or. (.not. (y <= 4.6d-58)) .and. (y <= 1.15d-20)) 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.05e-124) || (!(y <= 4.6e-58) && (y <= 1.15e-20))) {
tmp = x * 0.5;
} else {
tmp = y * 0.5;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= 1.05e-124) or (not (y <= 4.6e-58) and (y <= 1.15e-20)): tmp = x * 0.5 else: tmp = y * 0.5 return tmp
function code(x, y) tmp = 0.0 if ((y <= 1.05e-124) || (!(y <= 4.6e-58) && (y <= 1.15e-20))) 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.05e-124) || (~((y <= 4.6e-58)) && (y <= 1.15e-20))) tmp = x * 0.5; else tmp = y * 0.5; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, 1.05e-124], And[N[Not[LessEqual[y, 4.6e-58]], $MachinePrecision], LessEqual[y, 1.15e-20]]], N[(x * 0.5), $MachinePrecision], N[(y * 0.5), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.05 \cdot 10^{-124} \lor \neg \left(y \leq 4.6 \cdot 10^{-58}\right) \land y \leq 1.15 \cdot 10^{-20}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;y \cdot 0.5\\
\end{array}
\end{array}
if y < 1.05e-124 or 4.5999999999999998e-58 < y < 1.15e-20Initial program 99.9%
+-commutative99.9%
div-inv99.9%
fma-def99.9%
add-sqr-sqrt32.7%
fabs-sqr32.7%
add-sqr-sqrt39.1%
metadata-eval39.1%
Applied egg-rr39.1%
Taylor expanded in y around 0 36.9%
distribute-rgt1-in36.9%
metadata-eval36.9%
*-commutative36.9%
Simplified36.9%
if 1.05e-124 < y < 4.5999999999999998e-58 or 1.15e-20 < y Initial program 99.9%
+-commutative99.9%
div-inv99.9%
fma-def99.9%
add-sqr-sqrt86.0%
fabs-sqr86.0%
add-sqr-sqrt89.1%
metadata-eval89.1%
Applied egg-rr89.1%
Taylor expanded in y around inf 78.0%
Final simplification50.3%
(FPCore (x y) :precision binary64 (if (<= y 1.9e-190) x (* y 0.5)))
double code(double x, double y) {
double tmp;
if (y <= 1.9e-190) {
tmp = x;
} 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.9d-190) then
tmp = x
else
tmp = y * 0.5d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 1.9e-190) {
tmp = x;
} else {
tmp = y * 0.5;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 1.9e-190: tmp = x else: tmp = y * 0.5 return tmp
function code(x, y) tmp = 0.0 if (y <= 1.9e-190) tmp = x; else tmp = Float64(y * 0.5); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 1.9e-190) tmp = x; else tmp = y * 0.5; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 1.9e-190], x, N[(y * 0.5), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.9 \cdot 10^{-190}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot 0.5\\
\end{array}
\end{array}
if y < 1.8999999999999999e-190Initial program 99.9%
Taylor expanded in x around inf 13.0%
if 1.8999999999999999e-190 < y Initial program 99.9%
+-commutative99.9%
div-inv99.9%
fma-def99.9%
add-sqr-sqrt83.6%
fabs-sqr83.6%
add-sqr-sqrt87.1%
metadata-eval87.1%
Applied egg-rr87.1%
Taylor expanded in y around inf 66.9%
Final simplification34.5%
(FPCore (x y) :precision binary64 (/ (+ x y) 2.0))
double code(double x, double y) {
return (x + y) / 2.0;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (x + y) / 2.0d0
end function
public static double code(double x, double y) {
return (x + y) / 2.0;
}
def code(x, y): return (x + y) / 2.0
function code(x, y) return Float64(Float64(x + y) / 2.0) end
function tmp = code(x, y) tmp = (x + y) / 2.0; end
code[x_, y_] := N[(N[(x + y), $MachinePrecision] / 2.0), $MachinePrecision]
\begin{array}{l}
\\
\frac{x + y}{2}
\end{array}
Initial program 99.9%
+-commutative99.9%
div-inv99.9%
fma-def99.9%
add-sqr-sqrt50.0%
fabs-sqr50.0%
add-sqr-sqrt55.3%
metadata-eval55.3%
Applied egg-rr55.3%
fma-udef55.3%
flip-+27.5%
pow227.5%
pow227.5%
Applied egg-rr27.5%
unpow227.5%
unpow227.5%
difference-of-squares29.2%
fma-def29.2%
associate-/l*55.3%
fma-def55.3%
+-commutative55.3%
*-commutative55.3%
sub-neg55.3%
+-commutative55.3%
distribute-lft-in55.3%
distribute-rgt-neg-in55.3%
distribute-lft-neg-in55.3%
metadata-eval55.3%
associate-+r+55.3%
distribute-rgt1-in55.3%
metadata-eval55.3%
distribute-lft-out55.3%
*-inverses55.3%
Simplified55.3%
Final simplification55.3%
(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.2%
Final simplification11.2%
herbie shell --seed 2024024
(FPCore (x y)
:name "Graphics.Rendering.Chart.Plot.AreaSpots:renderSpotLegend from Chart-1.5.3"
:precision binary64
(+ x (/ (fabs (- y x)) 2.0)))