
(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 99.9%
Final simplification99.9%
(FPCore (x y) :precision binary64 (if (<= x -3.05e-140) (* 0.5 (+ x y)) (if (<= x 2.05e-26) (* (fabs (- y x)) 0.5) (* x 1.5))))
double code(double x, double y) {
double tmp;
if (x <= -3.05e-140) {
tmp = 0.5 * (x + y);
} else if (x <= 2.05e-26) {
tmp = fabs((y - x)) * 0.5;
} else {
tmp = x * 1.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.05d-140)) then
tmp = 0.5d0 * (x + y)
else if (x <= 2.05d-26) then
tmp = abs((y - x)) * 0.5d0
else
tmp = x * 1.5d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -3.05e-140) {
tmp = 0.5 * (x + y);
} else if (x <= 2.05e-26) {
tmp = Math.abs((y - x)) * 0.5;
} else {
tmp = x * 1.5;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -3.05e-140: tmp = 0.5 * (x + y) elif x <= 2.05e-26: tmp = math.fabs((y - x)) * 0.5 else: tmp = x * 1.5 return tmp
function code(x, y) tmp = 0.0 if (x <= -3.05e-140) tmp = Float64(0.5 * Float64(x + y)); elseif (x <= 2.05e-26) tmp = Float64(abs(Float64(y - x)) * 0.5); else tmp = Float64(x * 1.5); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -3.05e-140) tmp = 0.5 * (x + y); elseif (x <= 2.05e-26) tmp = abs((y - x)) * 0.5; else tmp = x * 1.5; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -3.05e-140], N[(0.5 * N[(x + y), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 2.05e-26], N[(N[Abs[N[(y - x), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision], N[(x * 1.5), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.05 \cdot 10^{-140}:\\
\;\;\;\;0.5 \cdot \left(x + y\right)\\
\mathbf{elif}\;x \leq 2.05 \cdot 10^{-26}:\\
\;\;\;\;\left|y - x\right| \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;x \cdot 1.5\\
\end{array}
\end{array}
if x < -3.04999999999999982e-140Initial program 99.9%
+-commutative99.9%
div-inv99.9%
fma-def99.9%
add-sqr-sqrt86.1%
fabs-sqr86.1%
add-sqr-sqrt86.8%
metadata-eval86.8%
Applied egg-rr86.8%
Taylor expanded in y around 0 86.8%
+-commutative86.8%
associate-+r+86.8%
distribute-lft1-in86.8%
metadata-eval86.8%
distribute-lft-out86.8%
Simplified86.8%
if -3.04999999999999982e-140 < x < 2.0499999999999999e-26Initial program 99.9%
Taylor expanded in x around 0 87.3%
if 2.0499999999999999e-26 < x Initial program 99.6%
flip-+37.3%
Applied egg-rr8.2%
sub-neg8.2%
add-sqr-sqrt8.2%
sqrt-prod8.2%
add-cube-cbrt8.2%
sqrt-prod8.2%
fma-def8.2%
cbrt-unprod3.9%
pow23.9%
pow23.9%
pow-prod-up3.9%
metadata-eval3.9%
cbrt-prod3.9%
pow23.9%
distribute-rgt-neg-in3.9%
metadata-eval3.9%
Applied egg-rr3.9%
unpow23.9%
rem-sqrt-square3.9%
*-commutative3.9%
Simplified3.9%
Taylor expanded in x around inf 74.8%
*-commutative74.8%
Simplified74.8%
Final simplification83.6%
(FPCore (x y)
:precision binary64
(if (<= x -4.1e-22)
(* x 0.5)
(if (<= x -3.1e-59)
(* y 0.5)
(if (<= x -5.8e-124) (* x 0.5) (if (<= x 6.5e-97) (* y 0.5) (* x 1.5))))))
double code(double x, double y) {
double tmp;
if (x <= -4.1e-22) {
tmp = x * 0.5;
} else if (x <= -3.1e-59) {
tmp = y * 0.5;
} else if (x <= -5.8e-124) {
tmp = x * 0.5;
} else if (x <= 6.5e-97) {
tmp = y * 0.5;
} else {
tmp = x * 1.5;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= (-4.1d-22)) then
tmp = x * 0.5d0
else if (x <= (-3.1d-59)) then
tmp = y * 0.5d0
else if (x <= (-5.8d-124)) then
tmp = x * 0.5d0
else if (x <= 6.5d-97) then
tmp = y * 0.5d0
else
tmp = x * 1.5d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -4.1e-22) {
tmp = x * 0.5;
} else if (x <= -3.1e-59) {
tmp = y * 0.5;
} else if (x <= -5.8e-124) {
tmp = x * 0.5;
} else if (x <= 6.5e-97) {
tmp = y * 0.5;
} else {
tmp = x * 1.5;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -4.1e-22: tmp = x * 0.5 elif x <= -3.1e-59: tmp = y * 0.5 elif x <= -5.8e-124: tmp = x * 0.5 elif x <= 6.5e-97: tmp = y * 0.5 else: tmp = x * 1.5 return tmp
function code(x, y) tmp = 0.0 if (x <= -4.1e-22) tmp = Float64(x * 0.5); elseif (x <= -3.1e-59) tmp = Float64(y * 0.5); elseif (x <= -5.8e-124) tmp = Float64(x * 0.5); elseif (x <= 6.5e-97) tmp = Float64(y * 0.5); else tmp = Float64(x * 1.5); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -4.1e-22) tmp = x * 0.5; elseif (x <= -3.1e-59) tmp = y * 0.5; elseif (x <= -5.8e-124) tmp = x * 0.5; elseif (x <= 6.5e-97) tmp = y * 0.5; else tmp = x * 1.5; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -4.1e-22], N[(x * 0.5), $MachinePrecision], If[LessEqual[x, -3.1e-59], N[(y * 0.5), $MachinePrecision], If[LessEqual[x, -5.8e-124], N[(x * 0.5), $MachinePrecision], If[LessEqual[x, 6.5e-97], N[(y * 0.5), $MachinePrecision], N[(x * 1.5), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.1 \cdot 10^{-22}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{elif}\;x \leq -3.1 \cdot 10^{-59}:\\
\;\;\;\;y \cdot 0.5\\
\mathbf{elif}\;x \leq -5.8 \cdot 10^{-124}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{elif}\;x \leq 6.5 \cdot 10^{-97}:\\
\;\;\;\;y \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;x \cdot 1.5\\
\end{array}
\end{array}
if x < -4.0999999999999999e-22 or -3.09999999999999999e-59 < x < -5.8000000000000004e-124Initial program 99.9%
+-commutative99.9%
div-inv99.9%
fma-def99.9%
add-sqr-sqrt84.8%
fabs-sqr84.8%
add-sqr-sqrt85.4%
metadata-eval85.4%
Applied egg-rr85.4%
Taylor expanded in y around 0 71.1%
distribute-lft1-in71.1%
metadata-eval71.1%
*-commutative71.1%
Simplified71.1%
if -4.0999999999999999e-22 < x < -3.09999999999999999e-59 or -5.8000000000000004e-124 < x < 6.5000000000000004e-97Initial program 100.0%
+-commutative100.0%
div-inv100.0%
fma-def100.0%
add-sqr-sqrt50.2%
fabs-sqr50.2%
add-sqr-sqrt52.6%
metadata-eval52.6%
Applied egg-rr52.6%
Taylor expanded in y around inf 46.8%
if 6.5000000000000004e-97 < x Initial program 99.7%
flip-+42.5%
Applied egg-rr11.2%
sub-neg11.2%
add-sqr-sqrt11.2%
sqrt-prod11.2%
add-cube-cbrt11.2%
sqrt-prod11.2%
fma-def11.2%
cbrt-unprod10.4%
pow210.4%
pow210.4%
pow-prod-up10.4%
metadata-eval10.4%
cbrt-prod10.4%
pow210.4%
distribute-rgt-neg-in10.4%
metadata-eval10.4%
Applied egg-rr10.4%
unpow210.4%
rem-sqrt-square10.4%
*-commutative10.4%
Simplified10.4%
Taylor expanded in x around inf 67.4%
*-commutative67.4%
Simplified67.4%
Final simplification62.0%
(FPCore (x y) :precision binary64 (if (<= x 4.4e-33) (* 0.5 (+ x y)) (* x 1.5)))
double code(double x, double y) {
double tmp;
if (x <= 4.4e-33) {
tmp = 0.5 * (x + y);
} else {
tmp = x * 1.5;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= 4.4d-33) then
tmp = 0.5d0 * (x + y)
else
tmp = x * 1.5d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= 4.4e-33) {
tmp = 0.5 * (x + y);
} else {
tmp = x * 1.5;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= 4.4e-33: tmp = 0.5 * (x + y) else: tmp = x * 1.5 return tmp
function code(x, y) tmp = 0.0 if (x <= 4.4e-33) tmp = Float64(0.5 * Float64(x + y)); else tmp = Float64(x * 1.5); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= 4.4e-33) tmp = 0.5 * (x + y); else tmp = x * 1.5; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, 4.4e-33], N[(0.5 * N[(x + y), $MachinePrecision]), $MachinePrecision], N[(x * 1.5), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 4.4 \cdot 10^{-33}:\\
\;\;\;\;0.5 \cdot \left(x + y\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot 1.5\\
\end{array}
\end{array}
if x < 4.40000000000000011e-33Initial program 99.9%
+-commutative99.9%
div-inv99.9%
fma-def99.9%
add-sqr-sqrt65.3%
fabs-sqr65.3%
add-sqr-sqrt67.0%
metadata-eval67.0%
Applied egg-rr67.0%
Taylor expanded in y around 0 67.0%
+-commutative67.0%
associate-+r+67.0%
distribute-lft1-in67.0%
metadata-eval67.0%
distribute-lft-out67.0%
Simplified67.0%
if 4.40000000000000011e-33 < x Initial program 99.7%
flip-+38.1%
Applied egg-rr8.1%
sub-neg8.1%
add-sqr-sqrt8.1%
sqrt-prod8.1%
add-cube-cbrt8.1%
sqrt-prod8.1%
fma-def8.1%
cbrt-unprod3.8%
pow23.8%
pow23.8%
pow-prod-up3.8%
metadata-eval3.8%
cbrt-prod3.8%
pow23.8%
distribute-rgt-neg-in3.8%
metadata-eval3.8%
Applied egg-rr3.8%
unpow23.8%
rem-sqrt-square3.8%
*-commutative3.8%
Simplified3.8%
Taylor expanded in x around inf 73.9%
*-commutative73.9%
Simplified73.9%
Final simplification69.0%
(FPCore (x y) :precision binary64 (if (<= y 3.95e-118) x (* y 0.5)))
double code(double x, double y) {
double tmp;
if (y <= 3.95e-118) {
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.95d-118) 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.95e-118) {
tmp = x;
} else {
tmp = y * 0.5;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 3.95e-118: tmp = x else: tmp = y * 0.5 return tmp
function code(x, y) tmp = 0.0 if (y <= 3.95e-118) tmp = x; else tmp = Float64(y * 0.5); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 3.95e-118) tmp = x; else tmp = y * 0.5; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 3.95e-118], x, N[(y * 0.5), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 3.95 \cdot 10^{-118}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot 0.5\\
\end{array}
\end{array}
if y < 3.9500000000000002e-118Initial program 99.9%
Taylor expanded in x around inf 12.8%
if 3.9500000000000002e-118 < y Initial program 99.9%
+-commutative99.9%
div-inv99.9%
fma-def99.9%
add-sqr-sqrt82.2%
fabs-sqr82.2%
add-sqr-sqrt85.8%
metadata-eval85.8%
Applied egg-rr85.8%
Taylor expanded in y around inf 59.5%
Final simplification30.8%
(FPCore (x y) :precision binary64 (if (<= y 8.2e-56) (* x 0.5) (* y 0.5)))
double code(double x, double y) {
double tmp;
if (y <= 8.2e-56) {
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 <= 8.2d-56) 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 <= 8.2e-56) {
tmp = x * 0.5;
} else {
tmp = y * 0.5;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 8.2e-56: tmp = x * 0.5 else: tmp = y * 0.5 return tmp
function code(x, y) tmp = 0.0 if (y <= 8.2e-56) 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 <= 8.2e-56) tmp = x * 0.5; else tmp = y * 0.5; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 8.2e-56], N[(x * 0.5), $MachinePrecision], N[(y * 0.5), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 8.2 \cdot 10^{-56}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;y \cdot 0.5\\
\end{array}
\end{array}
if y < 8.2000000000000003e-56Initial program 99.9%
+-commutative99.9%
div-inv99.9%
fma-def99.9%
add-sqr-sqrt37.3%
fabs-sqr37.3%
add-sqr-sqrt42.8%
metadata-eval42.8%
Applied egg-rr42.8%
Taylor expanded in y around 0 37.6%
distribute-lft1-in37.6%
metadata-eval37.6%
*-commutative37.6%
Simplified37.6%
if 8.2000000000000003e-56 < y Initial program 99.8%
+-commutative99.8%
div-inv99.8%
fma-def99.8%
add-sqr-sqrt81.8%
fabs-sqr81.8%
add-sqr-sqrt85.5%
metadata-eval85.5%
Applied egg-rr85.5%
Taylor expanded in y around inf 67.1%
Final simplification46.8%
(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.7%
Final simplification11.7%
herbie shell --seed 2023274
(FPCore (x y)
:name "Graphics.Rendering.Chart.Plot.AreaSpots:renderSpotLegend from Chart-1.5.3"
:precision binary64
(+ x (/ (fabs (- y x)) 2.0)))