
(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 7 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 100.0%
Final simplification100.0%
(FPCore (x y) :precision binary64 (if (<= x -3.4e-69) (* 0.5 (+ x y)) (* (fabs (- y x)) 0.5)))
double code(double x, double y) {
double tmp;
if (x <= -3.4e-69) {
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 <= (-3.4d-69)) 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 <= -3.4e-69) {
tmp = 0.5 * (x + y);
} else {
tmp = Math.abs((y - x)) * 0.5;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -3.4e-69: tmp = 0.5 * (x + y) else: tmp = math.fabs((y - x)) * 0.5 return tmp
function code(x, y) tmp = 0.0 if (x <= -3.4e-69) 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 <= -3.4e-69) tmp = 0.5 * (x + y); else tmp = abs((y - x)) * 0.5; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -3.4e-69], 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.4 \cdot 10^{-69}:\\
\;\;\;\;0.5 \cdot \left(x + y\right)\\
\mathbf{else}:\\
\;\;\;\;\left|y - x\right| \cdot 0.5\\
\end{array}
\end{array}
if x < -3.40000000000000008e-69Initial program 100.0%
+-commutative100.0%
div-inv100.0%
fma-def100.0%
add-sqr-sqrt83.4%
fabs-sqr83.4%
add-sqr-sqrt84.3%
metadata-eval84.3%
Applied egg-rr84.3%
Taylor expanded in y around 0 84.3%
associate-+r+84.3%
distribute-rgt1-in84.3%
metadata-eval84.3%
distribute-lft-out84.3%
Simplified84.3%
if -3.40000000000000008e-69 < x Initial program 99.9%
Taylor expanded in x around 0 66.0%
Final simplification70.5%
(FPCore (x y) :precision binary64 (if (<= x -3.7e-54) (* x 0.5) (if (<= x 1.42e-9) (* y 0.5) x)))
double code(double x, double y) {
double tmp;
if (x <= -3.7e-54) {
tmp = x * 0.5;
} else if (x <= 1.42e-9) {
tmp = y * 0.5;
} else {
tmp = x;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= (-3.7d-54)) then
tmp = x * 0.5d0
else if (x <= 1.42d-9) then
tmp = y * 0.5d0
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -3.7e-54) {
tmp = x * 0.5;
} else if (x <= 1.42e-9) {
tmp = y * 0.5;
} else {
tmp = x;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -3.7e-54: tmp = x * 0.5 elif x <= 1.42e-9: tmp = y * 0.5 else: tmp = x return tmp
function code(x, y) tmp = 0.0 if (x <= -3.7e-54) tmp = Float64(x * 0.5); elseif (x <= 1.42e-9) tmp = Float64(y * 0.5); else tmp = x; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -3.7e-54) tmp = x * 0.5; elseif (x <= 1.42e-9) tmp = y * 0.5; else tmp = x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -3.7e-54], N[(x * 0.5), $MachinePrecision], If[LessEqual[x, 1.42e-9], N[(y * 0.5), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.7 \cdot 10^{-54}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{elif}\;x \leq 1.42 \cdot 10^{-9}:\\
\;\;\;\;y \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if x < -3.7000000000000003e-54Initial program 100.0%
+-commutative100.0%
div-inv100.0%
fma-def100.0%
add-sqr-sqrt82.6%
fabs-sqr82.6%
add-sqr-sqrt83.5%
metadata-eval83.5%
Applied egg-rr83.5%
Taylor expanded in y around 0 69.7%
distribute-rgt1-in69.7%
metadata-eval69.7%
*-commutative69.7%
Simplified69.7%
if -3.7000000000000003e-54 < x < 1.4200000000000001e-9Initial program 100.0%
+-commutative100.0%
div-inv100.0%
fma-def100.0%
add-sqr-sqrt42.5%
fabs-sqr42.5%
add-sqr-sqrt45.7%
metadata-eval45.7%
Applied egg-rr45.7%
Taylor expanded in y around inf 41.0%
if 1.4200000000000001e-9 < x Initial program 99.9%
Taylor expanded in x around inf 17.9%
Final simplification41.4%
(FPCore (x y) :precision binary64 (if (<= y -1.45e-243) (* (/ y 0.5) -0.25) (* 0.5 (+ x y))))
double code(double x, double y) {
double tmp;
if (y <= -1.45e-243) {
tmp = (y / 0.5) * -0.25;
} 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.45d-243)) then
tmp = (y / 0.5d0) * (-0.25d0)
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.45e-243) {
tmp = (y / 0.5) * -0.25;
} else {
tmp = 0.5 * (x + y);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.45e-243: tmp = (y / 0.5) * -0.25 else: tmp = 0.5 * (x + y) return tmp
function code(x, y) tmp = 0.0 if (y <= -1.45e-243) tmp = Float64(Float64(y / 0.5) * -0.25); else tmp = Float64(0.5 * Float64(x + y)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -1.45e-243) tmp = (y / 0.5) * -0.25; else tmp = 0.5 * (x + y); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.45e-243], N[(N[(y / 0.5), $MachinePrecision] * -0.25), $MachinePrecision], N[(0.5 * N[(x + y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.45 \cdot 10^{-243}:\\
\;\;\;\;\frac{y}{0.5} \cdot -0.25\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(x + y\right)\\
\end{array}
\end{array}
if y < -1.44999999999999988e-243Initial program 100.0%
+-commutative100.0%
div-inv100.0%
fma-def100.0%
add-sqr-sqrt12.4%
fabs-sqr12.4%
add-sqr-sqrt18.0%
metadata-eval18.0%
Applied egg-rr18.0%
fma-udef18.0%
flip-+8.5%
Applied egg-rr8.5%
add-sqr-sqrt5.0%
sqrt-prod55.1%
associate-*r*55.1%
sqrt-prod54.8%
fma-neg54.8%
*-commutative54.8%
associate-*l*54.8%
pow254.8%
Applied egg-rr54.8%
Taylor expanded in y around -inf 61.0%
*-commutative61.0%
unpow261.0%
rem-square-sqrt62.2%
Simplified62.2%
if -1.44999999999999988e-243 < y Initial program 99.9%
+-commutative99.9%
div-inv99.9%
fma-def99.9%
add-sqr-sqrt67.0%
fabs-sqr67.0%
add-sqr-sqrt73.4%
metadata-eval73.4%
Applied egg-rr73.4%
Taylor expanded in y around 0 73.4%
associate-+r+73.4%
distribute-rgt1-in73.4%
metadata-eval73.4%
distribute-lft-out73.4%
Simplified73.4%
Final simplification68.2%
(FPCore (x y) :precision binary64 (if (<= y 3.8e-247) x (* y 0.5)))
double code(double x, double y) {
double tmp;
if (y <= 3.8e-247) {
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 <= 3.8d-247) 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 <= 3.8e-247) {
tmp = x;
} else {
tmp = y * 0.5;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 3.8e-247: tmp = x else: tmp = y * 0.5 return tmp
function code(x, y) tmp = 0.0 if (y <= 3.8e-247) tmp = x; else tmp = Float64(y * 0.5); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 3.8e-247) tmp = x; else tmp = y * 0.5; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 3.8e-247], x, N[(y * 0.5), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 3.8 \cdot 10^{-247}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot 0.5\\
\end{array}
\end{array}
if y < 3.79999999999999988e-247Initial program 100.0%
Taylor expanded in x around inf 11.1%
if 3.79999999999999988e-247 < y Initial program 99.9%
+-commutative99.9%
div-inv99.9%
fma-def99.9%
add-sqr-sqrt73.2%
fabs-sqr73.2%
add-sqr-sqrt78.5%
metadata-eval78.5%
Applied egg-rr78.5%
Taylor expanded in y around inf 53.7%
Final simplification30.2%
(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 100.0%
+-commutative100.0%
div-inv100.0%
fma-def100.0%
add-sqr-sqrt41.4%
fabs-sqr41.4%
add-sqr-sqrt47.4%
metadata-eval47.4%
Applied egg-rr47.4%
Taylor expanded in y around 0 47.4%
associate-+r+47.4%
distribute-rgt1-in47.4%
metadata-eval47.4%
distribute-lft-out47.4%
Simplified47.4%
Final simplification47.4%
(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 100.0%
Taylor expanded in x around inf 11.0%
Final simplification11.0%
herbie shell --seed 2023275
(FPCore (x y)
:name "Graphics.Rendering.Chart.Plot.AreaSpots:renderSpotLegend from Chart-1.5.3"
:precision binary64
(+ x (/ (fabs (- y x)) 2.0)))