
(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 -1.15e+29) (* (fabs (- y x)) 0.5) (/ (+ x y) 2.0)))
double code(double x, double y) {
double tmp;
if (y <= -1.15e+29) {
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 <= (-1.15d+29)) 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 <= -1.15e+29) {
tmp = Math.abs((y - x)) * 0.5;
} else {
tmp = (x + y) / 2.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.15e+29: tmp = math.fabs((y - x)) * 0.5 else: tmp = (x + y) / 2.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -1.15e+29) 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 <= -1.15e+29) tmp = abs((y - x)) * 0.5; else tmp = (x + y) / 2.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.15e+29], 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 -1.15 \cdot 10^{+29}:\\
\;\;\;\;\left|y - x\right| \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{x + y}{2}\\
\end{array}
\end{array}
if y < -1.1500000000000001e29Initial program 100.0%
Taylor expanded in x around 0 82.7%
if -1.1500000000000001e29 < y Initial program 99.9%
+-commutative99.9%
div-inv99.9%
fma-def99.9%
add-sqr-sqrt66.0%
fabs-sqr66.0%
add-sqr-sqrt71.5%
metadata-eval71.5%
Applied egg-rr71.5%
fma-udef71.5%
flip-+37.8%
pow237.8%
pow237.8%
Applied egg-rr37.8%
unpow237.8%
unpow237.8%
difference-of-squares40.0%
fma-def40.0%
associate-/l*71.5%
fma-def71.5%
*-commutative71.5%
sub-neg71.5%
+-commutative71.5%
distribute-lft-in71.5%
distribute-rgt-neg-in71.5%
distribute-lft-neg-in71.5%
metadata-eval71.5%
+-commutative71.5%
associate-+r+71.5%
distribute-rgt1-in71.5%
metadata-eval71.5%
distribute-lft-out71.5%
*-inverses71.5%
Simplified71.5%
Final simplification74.6%
(FPCore (x y) :precision binary64 (if (<= y 4.5e-239) x (* y 0.5)))
double code(double x, double y) {
double tmp;
if (y <= 4.5e-239) {
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 <= 4.5d-239) 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 <= 4.5e-239) {
tmp = x;
} else {
tmp = y * 0.5;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 4.5e-239: tmp = x else: tmp = y * 0.5 return tmp
function code(x, y) tmp = 0.0 if (y <= 4.5e-239) tmp = x; else tmp = Float64(y * 0.5); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 4.5e-239) tmp = x; else tmp = y * 0.5; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 4.5e-239], x, N[(y * 0.5), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 4.5 \cdot 10^{-239}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot 0.5\\
\end{array}
\end{array}
if y < 4.50000000000000013e-239Initial program 99.9%
Taylor expanded in x around inf 11.8%
if 4.50000000000000013e-239 < y Initial program 99.9%
+-commutative99.9%
div-inv99.9%
fma-def99.9%
add-sqr-sqrt79.8%
fabs-sqr79.8%
add-sqr-sqrt83.8%
metadata-eval83.8%
Applied egg-rr83.8%
Taylor expanded in y around inf 58.9%
Final simplification31.4%
(FPCore (x y) :precision binary64 (if (<= y 1.9e+36) (* x 0.5) (* y 0.5)))
double code(double x, double y) {
double tmp;
if (y <= 1.9e+36) {
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.9d+36) 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.9e+36) {
tmp = x * 0.5;
} else {
tmp = y * 0.5;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 1.9e+36: tmp = x * 0.5 else: tmp = y * 0.5 return tmp
function code(x, y) tmp = 0.0 if (y <= 1.9e+36) 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.9e+36) tmp = x * 0.5; else tmp = y * 0.5; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 1.9e+36], N[(x * 0.5), $MachinePrecision], N[(y * 0.5), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.9 \cdot 10^{+36}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;y \cdot 0.5\\
\end{array}
\end{array}
if y < 1.90000000000000012e36Initial program 99.9%
+-commutative99.9%
div-inv99.9%
fma-def99.9%
add-sqr-sqrt37.5%
fabs-sqr37.5%
add-sqr-sqrt42.8%
metadata-eval42.8%
Applied egg-rr42.8%
Taylor expanded in y around 0 35.9%
distribute-rgt1-in35.9%
metadata-eval35.9%
*-commutative35.9%
Simplified35.9%
if 1.90000000000000012e36 < y Initial program 100.0%
+-commutative100.0%
div-inv100.0%
fma-def100.0%
add-sqr-sqrt86.6%
fabs-sqr86.6%
add-sqr-sqrt89.5%
metadata-eval89.5%
Applied egg-rr89.5%
Taylor expanded in y around inf 76.6%
Final simplification45.9%
(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-sqrt49.6%
fabs-sqr49.6%
add-sqr-sqrt54.3%
metadata-eval54.3%
Applied egg-rr54.3%
fma-udef54.3%
flip-+27.4%
pow227.4%
pow227.4%
Applied egg-rr27.4%
unpow227.4%
unpow227.4%
difference-of-squares29.3%
fma-def29.3%
associate-/l*54.3%
fma-def54.3%
*-commutative54.3%
sub-neg54.3%
+-commutative54.3%
distribute-lft-in54.3%
distribute-rgt-neg-in54.3%
distribute-lft-neg-in54.3%
metadata-eval54.3%
+-commutative54.3%
associate-+r+54.3%
distribute-rgt1-in54.3%
metadata-eval54.3%
distribute-lft-out54.3%
*-inverses54.3%
Simplified54.3%
Final simplification54.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 10.9%
Final simplification10.9%
herbie shell --seed 2023310
(FPCore (x y)
:name "Graphics.Rendering.Chart.Plot.AreaSpots:renderSpotLegend from Chart-1.5.3"
:precision binary64
(+ x (/ (fabs (- y x)) 2.0)))