
(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 6 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 -1.5e-103) t_0 (if (<= y 6.2e-25) (+ (/ (fabs x) 2.0) x) t_0))))
double code(double x, double y) {
double t_0 = x + (fabs(y) / 2.0);
double tmp;
if (y <= -1.5e-103) {
tmp = t_0;
} else if (y <= 6.2e-25) {
tmp = (fabs(x) / 2.0) + x;
} 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 <= (-1.5d-103)) then
tmp = t_0
else if (y <= 6.2d-25) then
tmp = (abs(x) / 2.0d0) + x
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 <= -1.5e-103) {
tmp = t_0;
} else if (y <= 6.2e-25) {
tmp = (Math.abs(x) / 2.0) + x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y): t_0 = x + (math.fabs(y) / 2.0) tmp = 0 if y <= -1.5e-103: tmp = t_0 elif y <= 6.2e-25: tmp = (math.fabs(x) / 2.0) + x else: tmp = t_0 return tmp
function code(x, y) t_0 = Float64(x + Float64(abs(y) / 2.0)) tmp = 0.0 if (y <= -1.5e-103) tmp = t_0; elseif (y <= 6.2e-25) tmp = Float64(Float64(abs(x) / 2.0) + x); 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 <= -1.5e-103) tmp = t_0; elseif (y <= 6.2e-25) tmp = (abs(x) / 2.0) + x; 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, -1.5e-103], t$95$0, If[LessEqual[y, 6.2e-25], N[(N[(N[Abs[x], $MachinePrecision] / 2.0), $MachinePrecision] + x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x + \frac{\left|y\right|}{2}\\
\mathbf{if}\;y \leq -1.5 \cdot 10^{-103}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 6.2 \cdot 10^{-25}:\\
\;\;\;\;\frac{\left|x\right|}{2} + x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -1.5e-103 or 6.19999999999999989e-25 < y Initial program 100.0%
Taylor expanded in y around inf 0
Simplified0
if -1.5e-103 < y < 6.19999999999999989e-25Initial program 99.9%
Taylor expanded in y around 0 0
Simplified0
Applied egg-rr0
(FPCore (x y) :precision binary64 (if (<= x -1.2e-24) (/ x 2.0) (if (<= x 2.1e+20) (+ x (/ (fabs y) 2.0)) (+ (/ x 2.0) x))))
double code(double x, double y) {
double tmp;
if (x <= -1.2e-24) {
tmp = x / 2.0;
} else if (x <= 2.1e+20) {
tmp = x + (fabs(y) / 2.0);
} else {
tmp = (x / 2.0) + x;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= (-1.2d-24)) then
tmp = x / 2.0d0
else if (x <= 2.1d+20) then
tmp = x + (abs(y) / 2.0d0)
else
tmp = (x / 2.0d0) + x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -1.2e-24) {
tmp = x / 2.0;
} else if (x <= 2.1e+20) {
tmp = x + (Math.abs(y) / 2.0);
} else {
tmp = (x / 2.0) + x;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -1.2e-24: tmp = x / 2.0 elif x <= 2.1e+20: tmp = x + (math.fabs(y) / 2.0) else: tmp = (x / 2.0) + x return tmp
function code(x, y) tmp = 0.0 if (x <= -1.2e-24) tmp = Float64(x / 2.0); elseif (x <= 2.1e+20) tmp = Float64(x + Float64(abs(y) / 2.0)); else tmp = Float64(Float64(x / 2.0) + x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -1.2e-24) tmp = x / 2.0; elseif (x <= 2.1e+20) tmp = x + (abs(y) / 2.0); else tmp = (x / 2.0) + x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -1.2e-24], N[(x / 2.0), $MachinePrecision], If[LessEqual[x, 2.1e+20], N[(x + N[(N[Abs[y], $MachinePrecision] / 2.0), $MachinePrecision]), $MachinePrecision], N[(N[(x / 2.0), $MachinePrecision] + x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.2 \cdot 10^{-24}:\\
\;\;\;\;\frac{x}{2}\\
\mathbf{elif}\;x \leq 2.1 \cdot 10^{+20}:\\
\;\;\;\;x + \frac{\left|y\right|}{2}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{2} + x\\
\end{array}
\end{array}
if x < -1.1999999999999999e-24Initial program 100.0%
Taylor expanded in y around 0 0
Simplified0
Taylor expanded in x around 0 0
Simplified0
Applied egg-rr0
if -1.1999999999999999e-24 < x < 2.1e20Initial program 100.0%
Taylor expanded in y around inf 0
Simplified0
if 2.1e20 < x Initial program 99.8%
Taylor expanded in y around 0 0
Simplified0
Applied egg-rr0
Applied egg-rr0
(FPCore (x y) :precision binary64 (if (<= x -5e-310) (/ x 2.0) (+ (/ x 2.0) x)))
double code(double x, double y) {
double tmp;
if (x <= -5e-310) {
tmp = x / 2.0;
} else {
tmp = (x / 2.0) + x;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= (-5d-310)) then
tmp = x / 2.0d0
else
tmp = (x / 2.0d0) + x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -5e-310) {
tmp = x / 2.0;
} else {
tmp = (x / 2.0) + x;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -5e-310: tmp = x / 2.0 else: tmp = (x / 2.0) + x return tmp
function code(x, y) tmp = 0.0 if (x <= -5e-310) tmp = Float64(x / 2.0); else tmp = Float64(Float64(x / 2.0) + x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -5e-310) tmp = x / 2.0; else tmp = (x / 2.0) + x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -5e-310], N[(x / 2.0), $MachinePrecision], N[(N[(x / 2.0), $MachinePrecision] + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5 \cdot 10^{-310}:\\
\;\;\;\;\frac{x}{2}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{2} + x\\
\end{array}
\end{array}
if x < -4.999999999999985e-310Initial program 100.0%
Taylor expanded in y around 0 0
Simplified0
Taylor expanded in x around 0 0
Simplified0
Applied egg-rr0
if -4.999999999999985e-310 < x Initial program 99.9%
Taylor expanded in y around 0 0
Simplified0
Applied egg-rr0
Applied egg-rr0
(FPCore (x y) :precision binary64 (/ x 2.0))
double code(double x, double y) {
return x / 2.0;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x / 2.0d0
end function
public static double code(double x, double y) {
return x / 2.0;
}
def code(x, y): return x / 2.0
function code(x, y) return Float64(x / 2.0) end
function tmp = code(x, y) tmp = x / 2.0; end
code[x_, y_] := N[(x / 2.0), $MachinePrecision]
\begin{array}{l}
\\
\frac{x}{2}
\end{array}
Initial program 99.9%
Taylor expanded in y around 0 0
Simplified0
Taylor expanded in x around 0 0
Simplified0
Applied egg-rr0
(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 2024111
(FPCore (x y)
:name "Graphics.Rendering.Chart.Plot.AreaSpots:renderSpotLegend from Chart-1.5.3"
:precision binary64
(+ x (/ (fabs (- y x)) 2.0)))