
(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 5 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%
(FPCore (x y)
:precision binary64
(let* ((t_0 (+ x (/ (fabs y) 2.0))))
(if (<= y -7.2e-31)
t_0
(if (<= y 5.2e-93) (+ x (/ (fabs (- x)) 2.0)) t_0))))
double code(double x, double y) {
double t_0 = x + (fabs(y) / 2.0);
double tmp;
if (y <= -7.2e-31) {
tmp = t_0;
} else if (y <= 5.2e-93) {
tmp = x + (fabs(-x) / 2.0);
} else {
tmp = t_0;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: t_0
real(8) :: tmp
t_0 = x + (abs(y) / 2.0d0)
if (y <= (-7.2d-31)) then
tmp = t_0
else if (y <= 5.2d-93) then
tmp = x + (abs(-x) / 2.0d0)
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = x + (Math.abs(y) / 2.0);
double tmp;
if (y <= -7.2e-31) {
tmp = t_0;
} else if (y <= 5.2e-93) {
tmp = x + (Math.abs(-x) / 2.0);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y): t_0 = x + (math.fabs(y) / 2.0) tmp = 0 if y <= -7.2e-31: tmp = t_0 elif y <= 5.2e-93: tmp = x + (math.fabs(-x) / 2.0) else: tmp = t_0 return tmp
function code(x, y) t_0 = Float64(x + Float64(abs(y) / 2.0)) tmp = 0.0 if (y <= -7.2e-31) tmp = t_0; elseif (y <= 5.2e-93) tmp = Float64(x + Float64(abs(Float64(-x)) / 2.0)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y) t_0 = x + (abs(y) / 2.0); tmp = 0.0; if (y <= -7.2e-31) tmp = t_0; elseif (y <= 5.2e-93) tmp = x + (abs(-x) / 2.0); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(x + N[(N[Abs[y], $MachinePrecision] / 2.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -7.2e-31], t$95$0, If[LessEqual[y, 5.2e-93], N[(x + N[(N[Abs[(-x)], $MachinePrecision] / 2.0), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x + \frac{\left|y\right|}{2}\\
\mathbf{if}\;y \leq -7.2 \cdot 10^{-31}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 5.2 \cdot 10^{-93}:\\
\;\;\;\;x + \frac{\left|-x\right|}{2}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -7.20000000000000007e-31 or 5.1999999999999997e-93 < y Initial program 100.0%
Taylor expanded in y around inf 0
Simplified0
if -7.20000000000000007e-31 < y < 5.1999999999999997e-93Initial program 99.9%
Applied egg-rr0
Taylor expanded in y around 0 0
Simplified0
(FPCore (x y) :precision binary64 (+ x (/ (fabs y) 2.0)))
double code(double x, double y) {
return x + (fabs(y) / 2.0);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x + (abs(y) / 2.0d0)
end function
public static double code(double x, double y) {
return x + (Math.abs(y) / 2.0);
}
def code(x, y): return x + (math.fabs(y) / 2.0)
function code(x, y) return Float64(x + Float64(abs(y) / 2.0)) end
function tmp = code(x, y) tmp = x + (abs(y) / 2.0); end
code[x_, y_] := N[(x + N[(N[Abs[y], $MachinePrecision] / 2.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \frac{\left|y\right|}{2}
\end{array}
Initial program 99.9%
Taylor expanded in y around inf 0
Simplified0
(FPCore (x y) :precision binary64 (* 0.5 (fabs y)))
double code(double x, double y) {
return 0.5 * fabs(y);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 0.5d0 * abs(y)
end function
public static double code(double x, double y) {
return 0.5 * Math.abs(y);
}
def code(x, y): return 0.5 * math.fabs(y)
function code(x, y) return Float64(0.5 * abs(y)) end
function tmp = code(x, y) tmp = 0.5 * abs(y); end
code[x_, y_] := N[(0.5 * N[Abs[y], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.5 \cdot \left|y\right|
\end{array}
Initial program 99.9%
Taylor expanded in y around inf 0
Simplified0
Taylor expanded in x around 0 0
Simplified0
(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 0
Simplified0
herbie shell --seed 2024110
(FPCore (x y)
:name "Graphics.Rendering.Chart.Plot.AreaSpots:renderSpotLegend from Chart-1.5.3"
:precision binary64
(+ x (/ (fabs (- y x)) 2.0)))