
(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.3e+75)
(* 0.5 (+ x y))
(if (<= x 20.0)
(* (fabs (- y x)) 0.5)
(* (/ x (+ x (* (- y x) 0.5))) (* x 0.75)))))
double code(double x, double y) {
double tmp;
if (x <= -3.3e+75) {
tmp = 0.5 * (x + y);
} else if (x <= 20.0) {
tmp = fabs((y - x)) * 0.5;
} else {
tmp = (x / (x + ((y - x) * 0.5))) * (x * 0.75);
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= (-3.3d+75)) then
tmp = 0.5d0 * (x + y)
else if (x <= 20.0d0) then
tmp = abs((y - x)) * 0.5d0
else
tmp = (x / (x + ((y - x) * 0.5d0))) * (x * 0.75d0)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -3.3e+75) {
tmp = 0.5 * (x + y);
} else if (x <= 20.0) {
tmp = Math.abs((y - x)) * 0.5;
} else {
tmp = (x / (x + ((y - x) * 0.5))) * (x * 0.75);
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -3.3e+75: tmp = 0.5 * (x + y) elif x <= 20.0: tmp = math.fabs((y - x)) * 0.5 else: tmp = (x / (x + ((y - x) * 0.5))) * (x * 0.75) return tmp
function code(x, y) tmp = 0.0 if (x <= -3.3e+75) tmp = Float64(0.5 * Float64(x + y)); elseif (x <= 20.0) tmp = Float64(abs(Float64(y - x)) * 0.5); else tmp = Float64(Float64(x / Float64(x + Float64(Float64(y - x) * 0.5))) * Float64(x * 0.75)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -3.3e+75) tmp = 0.5 * (x + y); elseif (x <= 20.0) tmp = abs((y - x)) * 0.5; else tmp = (x / (x + ((y - x) * 0.5))) * (x * 0.75); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -3.3e+75], N[(0.5 * N[(x + y), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 20.0], N[(N[Abs[N[(y - x), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision], N[(N[(x / N[(x + N[(N[(y - x), $MachinePrecision] * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(x * 0.75), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.3 \cdot 10^{+75}:\\
\;\;\;\;0.5 \cdot \left(x + y\right)\\
\mathbf{elif}\;x \leq 20:\\
\;\;\;\;\left|y - x\right| \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{x + \left(y - x\right) \cdot 0.5} \cdot \left(x \cdot 0.75\right)\\
\end{array}
\end{array}
if x < -3.29999999999999998e75Initial program 100.0%
flip-+30.3%
Applied egg-rr28.1%
Taylor expanded in x around 0 94.0%
+-commutative94.0%
distribute-lft-out94.0%
Simplified94.0%
if -3.29999999999999998e75 < x < 20Initial program 100.0%
Taylor expanded in x around 0 77.7%
if 20 < x Initial program 99.9%
flip-+30.7%
Applied egg-rr6.0%
Taylor expanded in x around inf 9.8%
unpow29.8%
*-commutative9.8%
associate-*l*9.8%
Simplified9.8%
associate-/l*14.8%
associate-/r/14.8%
sub-neg14.8%
distribute-rgt-neg-in14.8%
metadata-eval14.8%
Applied egg-rr14.8%
+-commutative14.8%
add-cube-cbrt14.8%
fma-def14.8%
Applied egg-rr77.5%
fma-udef77.5%
unpow277.5%
rem-3cbrt-lft79.2%
*-commutative79.2%
Simplified79.2%
Final simplification81.2%
(FPCore (x y) :precision binary64 (if (<= x 6.5e-12) (* 0.5 (+ x y)) (* (/ x (+ x (* (- y x) 0.5))) (* x 0.75))))
double code(double x, double y) {
double tmp;
if (x <= 6.5e-12) {
tmp = 0.5 * (x + y);
} else {
tmp = (x / (x + ((y - x) * 0.5))) * (x * 0.75);
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= 6.5d-12) then
tmp = 0.5d0 * (x + y)
else
tmp = (x / (x + ((y - x) * 0.5d0))) * (x * 0.75d0)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= 6.5e-12) {
tmp = 0.5 * (x + y);
} else {
tmp = (x / (x + ((y - x) * 0.5))) * (x * 0.75);
}
return tmp;
}
def code(x, y): tmp = 0 if x <= 6.5e-12: tmp = 0.5 * (x + y) else: tmp = (x / (x + ((y - x) * 0.5))) * (x * 0.75) return tmp
function code(x, y) tmp = 0.0 if (x <= 6.5e-12) tmp = Float64(0.5 * Float64(x + y)); else tmp = Float64(Float64(x / Float64(x + Float64(Float64(y - x) * 0.5))) * Float64(x * 0.75)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= 6.5e-12) tmp = 0.5 * (x + y); else tmp = (x / (x + ((y - x) * 0.5))) * (x * 0.75); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, 6.5e-12], N[(0.5 * N[(x + y), $MachinePrecision]), $MachinePrecision], N[(N[(x / N[(x + N[(N[(y - x), $MachinePrecision] * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(x * 0.75), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 6.5 \cdot 10^{-12}:\\
\;\;\;\;0.5 \cdot \left(x + y\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{x + \left(y - x\right) \cdot 0.5} \cdot \left(x \cdot 0.75\right)\\
\end{array}
\end{array}
if x < 6.5000000000000002e-12Initial program 100.0%
flip-+53.6%
Applied egg-rr32.8%
Taylor expanded in x around 0 63.8%
+-commutative63.8%
distribute-lft-out63.8%
Simplified63.8%
if 6.5000000000000002e-12 < x Initial program 99.9%
flip-+30.3%
Applied egg-rr5.9%
Taylor expanded in x around inf 9.6%
unpow29.6%
*-commutative9.6%
associate-*l*9.6%
Simplified9.6%
associate-/l*14.6%
associate-/r/14.6%
sub-neg14.6%
distribute-rgt-neg-in14.6%
metadata-eval14.6%
Applied egg-rr14.6%
+-commutative14.6%
add-cube-cbrt14.6%
fma-def14.6%
Applied egg-rr76.2%
fma-udef76.2%
unpow276.2%
rem-3cbrt-lft77.8%
*-commutative77.8%
Simplified77.8%
Final simplification67.0%
(FPCore (x y) :precision binary64 (if (<= y 3.2e-56) (* x 0.5) (* y 0.5)))
double code(double x, double y) {
double tmp;
if (y <= 3.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 <= 3.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 <= 3.2e-56) {
tmp = x * 0.5;
} else {
tmp = y * 0.5;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 3.2e-56: tmp = x * 0.5 else: tmp = y * 0.5 return tmp
function code(x, y) tmp = 0.0 if (y <= 3.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 <= 3.2e-56) tmp = x * 0.5; else tmp = y * 0.5; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 3.2e-56], N[(x * 0.5), $MachinePrecision], N[(y * 0.5), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 3.2 \cdot 10^{-56}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;y \cdot 0.5\\
\end{array}
\end{array}
if y < 3.19999999999999986e-56Initial program 99.9%
flip-+49.0%
Applied egg-rr20.0%
Taylor expanded in x around inf 36.8%
if 3.19999999999999986e-56 < y Initial program 100.0%
flip-+47.1%
Applied egg-rr40.2%
Taylor expanded in x around 0 72.1%
Final simplification48.5%
(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%
flip-+48.4%
Applied egg-rr26.7%
Taylor expanded in x around 0 54.4%
+-commutative54.4%
distribute-lft-out54.4%
Simplified54.4%
Final simplification54.4%
(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 100.0%
flip-+48.4%
Applied egg-rr26.7%
Taylor expanded in x around inf 29.2%
Final simplification29.2%
(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 10.8%
Final simplification10.8%
herbie shell --seed 2023290
(FPCore (x y)
:name "Graphics.Rendering.Chart.Plot.AreaSpots:renderSpotLegend from Chart-1.5.3"
:precision binary64
(+ x (/ (fabs (- y x)) 2.0)))