
(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 -2.7e-94) (* 0.5 (+ x y)) (if (<= x 3.25e+15) (* (fabs (- y x)) 0.5) (* x 1.5))))
double code(double x, double y) {
double tmp;
if (x <= -2.7e-94) {
tmp = 0.5 * (x + y);
} else if (x <= 3.25e+15) {
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 <= (-2.7d-94)) then
tmp = 0.5d0 * (x + y)
else if (x <= 3.25d+15) 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 <= -2.7e-94) {
tmp = 0.5 * (x + y);
} else if (x <= 3.25e+15) {
tmp = Math.abs((y - x)) * 0.5;
} else {
tmp = x * 1.5;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -2.7e-94: tmp = 0.5 * (x + y) elif x <= 3.25e+15: tmp = math.fabs((y - x)) * 0.5 else: tmp = x * 1.5 return tmp
function code(x, y) tmp = 0.0 if (x <= -2.7e-94) tmp = Float64(0.5 * Float64(x + y)); elseif (x <= 3.25e+15) 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 <= -2.7e-94) tmp = 0.5 * (x + y); elseif (x <= 3.25e+15) tmp = abs((y - x)) * 0.5; else tmp = x * 1.5; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -2.7e-94], N[(0.5 * N[(x + y), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 3.25e+15], 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 -2.7 \cdot 10^{-94}:\\
\;\;\;\;0.5 \cdot \left(x + y\right)\\
\mathbf{elif}\;x \leq 3.25 \cdot 10^{+15}:\\
\;\;\;\;\left|y - x\right| \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;x \cdot 1.5\\
\end{array}
\end{array}
if x < -2.7000000000000001e-94Initial program 100.0%
flip-+45.4%
Applied egg-rr38.4%
Taylor expanded in x around 0 85.2%
distribute-lft-out85.2%
+-commutative85.2%
Simplified85.2%
if -2.7000000000000001e-94 < x < 3.25e15Initial program 100.0%
Taylor expanded in x around 0 82.3%
if 3.25e15 < x Initial program 99.8%
flip-+35.8%
Applied egg-rr7.9%
add-sqr-sqrt7.9%
sqrt-prod7.9%
add-cube-cbrt7.9%
sqrt-prod7.9%
fma-neg7.9%
cbrt-unprod5.3%
pow25.3%
pow25.3%
pow-prod-up5.3%
metadata-eval5.3%
cbrt-prod5.3%
pow25.3%
distribute-rgt-neg-in5.3%
metadata-eval5.3%
Applied egg-rr5.3%
unpow25.3%
rem-sqrt-square5.3%
*-commutative5.3%
Simplified5.3%
Taylor expanded in x around inf 78.6%
*-commutative78.6%
Simplified78.6%
Final simplification82.4%
(FPCore (x y) :precision binary64 (if (<= x -9e-95) (* x 0.5) (if (<= x 2.6e-73) (* y 0.5) (* x 1.5))))
double code(double x, double y) {
double tmp;
if (x <= -9e-95) {
tmp = x * 0.5;
} else if (x <= 2.6e-73) {
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 <= (-9d-95)) then
tmp = x * 0.5d0
else if (x <= 2.6d-73) 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 <= -9e-95) {
tmp = x * 0.5;
} else if (x <= 2.6e-73) {
tmp = y * 0.5;
} else {
tmp = x * 1.5;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -9e-95: tmp = x * 0.5 elif x <= 2.6e-73: tmp = y * 0.5 else: tmp = x * 1.5 return tmp
function code(x, y) tmp = 0.0 if (x <= -9e-95) tmp = Float64(x * 0.5); elseif (x <= 2.6e-73) 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 <= -9e-95) tmp = x * 0.5; elseif (x <= 2.6e-73) tmp = y * 0.5; else tmp = x * 1.5; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -9e-95], N[(x * 0.5), $MachinePrecision], If[LessEqual[x, 2.6e-73], N[(y * 0.5), $MachinePrecision], N[(x * 1.5), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -9 \cdot 10^{-95}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{elif}\;x \leq 2.6 \cdot 10^{-73}:\\
\;\;\;\;y \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;x \cdot 1.5\\
\end{array}
\end{array}
if x < -9e-95Initial program 100.0%
flip-+44.9%
Applied egg-rr37.9%
Taylor expanded in x around inf 71.0%
if -9e-95 < x < 2.6000000000000001e-73Initial program 100.0%
flip-+61.4%
Applied egg-rr35.7%
Taylor expanded in x around 0 42.4%
if 2.6000000000000001e-73 < x Initial program 99.9%
flip-+40.0%
Applied egg-rr10.1%
add-sqr-sqrt10.1%
sqrt-prod10.1%
add-cube-cbrt10.1%
sqrt-prod10.1%
fma-neg10.1%
cbrt-unprod8.3%
pow28.3%
pow28.3%
pow-prod-up8.3%
metadata-eval8.3%
cbrt-prod8.3%
pow28.3%
distribute-rgt-neg-in8.3%
metadata-eval8.3%
Applied egg-rr8.3%
unpow28.3%
rem-sqrt-square8.3%
*-commutative8.3%
Simplified8.3%
Taylor expanded in x around inf 65.4%
*-commutative65.4%
Simplified65.4%
Final simplification57.5%
(FPCore (x y) :precision binary64 (if (<= x 3.1e+14) (* 0.5 (+ x y)) (* x 1.5)))
double code(double x, double y) {
double tmp;
if (x <= 3.1e+14) {
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 <= 3.1d+14) 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 <= 3.1e+14) {
tmp = 0.5 * (x + y);
} else {
tmp = x * 1.5;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= 3.1e+14: tmp = 0.5 * (x + y) else: tmp = x * 1.5 return tmp
function code(x, y) tmp = 0.0 if (x <= 3.1e+14) 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 <= 3.1e+14) tmp = 0.5 * (x + y); else tmp = x * 1.5; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, 3.1e+14], N[(0.5 * N[(x + y), $MachinePrecision]), $MachinePrecision], N[(x * 1.5), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 3.1 \cdot 10^{+14}:\\
\;\;\;\;0.5 \cdot \left(x + y\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot 1.5\\
\end{array}
\end{array}
if x < 3.1e14Initial program 100.0%
flip-+54.1%
Applied egg-rr34.4%
Taylor expanded in x around 0 60.5%
distribute-lft-out60.5%
+-commutative60.5%
Simplified60.5%
if 3.1e14 < x Initial program 99.8%
flip-+35.8%
Applied egg-rr7.9%
add-sqr-sqrt7.9%
sqrt-prod7.9%
add-cube-cbrt7.9%
sqrt-prod7.9%
fma-neg7.9%
cbrt-unprod5.3%
pow25.3%
pow25.3%
pow-prod-up5.3%
metadata-eval5.3%
cbrt-prod5.3%
pow25.3%
distribute-rgt-neg-in5.3%
metadata-eval5.3%
Applied egg-rr5.3%
unpow25.3%
rem-sqrt-square5.3%
*-commutative5.3%
Simplified5.3%
Taylor expanded in x around inf 78.6%
*-commutative78.6%
Simplified78.6%
Final simplification64.3%
(FPCore (x y) :precision binary64 (if (<= y 8e-64) (* x 0.5) (* y 0.5)))
double code(double x, double y) {
double tmp;
if (y <= 8e-64) {
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 <= 8d-64) 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 <= 8e-64) {
tmp = x * 0.5;
} else {
tmp = y * 0.5;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 8e-64: tmp = x * 0.5 else: tmp = y * 0.5 return tmp
function code(x, y) tmp = 0.0 if (y <= 8e-64) 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 <= 8e-64) tmp = x * 0.5; else tmp = y * 0.5; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 8e-64], N[(x * 0.5), $MachinePrecision], N[(y * 0.5), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 8 \cdot 10^{-64}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;y \cdot 0.5\\
\end{array}
\end{array}
if y < 7.99999999999999972e-64Initial program 99.9%
flip-+50.4%
Applied egg-rr21.5%
Taylor expanded in x around inf 32.9%
if 7.99999999999999972e-64 < y Initial program 99.9%
flip-+50.0%
Applied egg-rr44.0%
Taylor expanded in x around 0 71.9%
Final simplification45.6%
(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%
flip-+50.3%
Applied egg-rr28.8%
Taylor expanded in x around inf 28.5%
Final simplification28.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 10.9%
Final simplification10.9%
herbie shell --seed 2023293
(FPCore (x y)
:name "Graphics.Rendering.Chart.Plot.AreaSpots:renderSpotLegend from Chart-1.5.3"
:precision binary64
(+ x (/ (fabs (- y x)) 2.0)))