
(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%
(FPCore (x y) :precision binary64 (if (<= y -6.4e-127) (* 0.5 (fabs (- y x))) (+ (* x 0.75) (* y 0.5))))
double code(double x, double y) {
double tmp;
if (y <= -6.4e-127) {
tmp = 0.5 * fabs((y - x));
} else {
tmp = (x * 0.75) + (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 <= (-6.4d-127)) then
tmp = 0.5d0 * abs((y - x))
else
tmp = (x * 0.75d0) + (y * 0.5d0)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -6.4e-127) {
tmp = 0.5 * Math.abs((y - x));
} else {
tmp = (x * 0.75) + (y * 0.5);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -6.4e-127: tmp = 0.5 * math.fabs((y - x)) else: tmp = (x * 0.75) + (y * 0.5) return tmp
function code(x, y) tmp = 0.0 if (y <= -6.4e-127) tmp = Float64(0.5 * abs(Float64(y - x))); else tmp = Float64(Float64(x * 0.75) + Float64(y * 0.5)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -6.4e-127) tmp = 0.5 * abs((y - x)); else tmp = (x * 0.75) + (y * 0.5); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -6.4e-127], N[(0.5 * N[Abs[N[(y - x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[(x * 0.75), $MachinePrecision] + N[(y * 0.5), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6.4 \cdot 10^{-127}:\\
\;\;\;\;0.5 \cdot \left|y - x\right|\\
\mathbf{else}:\\
\;\;\;\;x \cdot 0.75 + y \cdot 0.5\\
\end{array}
\end{array}
if y < -6.40000000000000035e-127Initial program 99.9%
Taylor expanded in x around 0
sub-negN/A
mul-1-negN/A
*-lowering-*.f64N/A
mul-1-negN/A
sub-negN/A
fabs-subN/A
sub-negN/A
mul-1-negN/A
fabs-lowering-fabs.f64N/A
mul-1-negN/A
sub-negN/A
--lowering--.f6470.3%
Simplified70.3%
if -6.40000000000000035e-127 < y Initial program 99.9%
+-commutativeN/A
flip-+N/A
/-lowering-/.f64N/A
--lowering--.f64N/A
frac-timesN/A
/-lowering-/.f64N/A
sqr-absN/A
*-lowering-*.f64N/A
--lowering--.f64N/A
--lowering--.f64N/A
metadata-evalN/A
*-lowering-*.f64N/A
--lowering--.f64N/A
/-lowering-/.f64N/A
fabs-lowering-fabs.f64N/A
--lowering--.f6450.6%
Applied egg-rr50.6%
Taylor expanded in x around inf
mul-1-negN/A
neg-sub0N/A
--lowering--.f647.3%
Simplified7.3%
Taylor expanded in y around 0
*-commutativeN/A
Simplified47.7%
Final simplification55.8%
(FPCore (x y) :precision binary64 (if (<= y -6.4e-127) (* (fabs y) 0.5) (+ (* x 0.75) (* y 0.5))))
double code(double x, double y) {
double tmp;
if (y <= -6.4e-127) {
tmp = fabs(y) * 0.5;
} else {
tmp = (x * 0.75) + (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 <= (-6.4d-127)) then
tmp = abs(y) * 0.5d0
else
tmp = (x * 0.75d0) + (y * 0.5d0)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -6.4e-127) {
tmp = Math.abs(y) * 0.5;
} else {
tmp = (x * 0.75) + (y * 0.5);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -6.4e-127: tmp = math.fabs(y) * 0.5 else: tmp = (x * 0.75) + (y * 0.5) return tmp
function code(x, y) tmp = 0.0 if (y <= -6.4e-127) tmp = Float64(abs(y) * 0.5); else tmp = Float64(Float64(x * 0.75) + Float64(y * 0.5)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -6.4e-127) tmp = abs(y) * 0.5; else tmp = (x * 0.75) + (y * 0.5); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -6.4e-127], N[(N[Abs[y], $MachinePrecision] * 0.5), $MachinePrecision], N[(N[(x * 0.75), $MachinePrecision] + N[(y * 0.5), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6.4 \cdot 10^{-127}:\\
\;\;\;\;\left|y\right| \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;x \cdot 0.75 + y \cdot 0.5\\
\end{array}
\end{array}
if y < -6.40000000000000035e-127Initial program 99.9%
Taylor expanded in y around inf
Simplified73.6%
Taylor expanded in x around 0
*-lowering-*.f64N/A
fabs-lowering-fabs.f6468.3%
Simplified68.3%
if -6.40000000000000035e-127 < y Initial program 99.9%
+-commutativeN/A
flip-+N/A
/-lowering-/.f64N/A
--lowering--.f64N/A
frac-timesN/A
/-lowering-/.f64N/A
sqr-absN/A
*-lowering-*.f64N/A
--lowering--.f64N/A
--lowering--.f64N/A
metadata-evalN/A
*-lowering-*.f64N/A
--lowering--.f64N/A
/-lowering-/.f64N/A
fabs-lowering-fabs.f64N/A
--lowering--.f6450.6%
Applied egg-rr50.6%
Taylor expanded in x around inf
mul-1-negN/A
neg-sub0N/A
--lowering--.f647.3%
Simplified7.3%
Taylor expanded in y around 0
*-commutativeN/A
Simplified47.7%
Final simplification55.1%
(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
Simplified57.4%
(FPCore (x y) :precision binary64 (+ (* x 0.75) (* y 0.5)))
double code(double x, double y) {
return (x * 0.75) + (y * 0.5);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (x * 0.75d0) + (y * 0.5d0)
end function
public static double code(double x, double y) {
return (x * 0.75) + (y * 0.5);
}
def code(x, y): return (x * 0.75) + (y * 0.5)
function code(x, y) return Float64(Float64(x * 0.75) + Float64(y * 0.5)) end
function tmp = code(x, y) tmp = (x * 0.75) + (y * 0.5); end
code[x_, y_] := N[(N[(x * 0.75), $MachinePrecision] + N[(y * 0.5), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot 0.75 + y \cdot 0.5
\end{array}
Initial program 99.9%
+-commutativeN/A
flip-+N/A
/-lowering-/.f64N/A
--lowering--.f64N/A
frac-timesN/A
/-lowering-/.f64N/A
sqr-absN/A
*-lowering-*.f64N/A
--lowering--.f64N/A
--lowering--.f64N/A
metadata-evalN/A
*-lowering-*.f64N/A
--lowering--.f64N/A
/-lowering-/.f64N/A
fabs-lowering-fabs.f64N/A
--lowering--.f6448.4%
Applied egg-rr48.4%
Taylor expanded in x around inf
mul-1-negN/A
neg-sub0N/A
--lowering--.f646.4%
Simplified6.4%
Taylor expanded in y around 0
*-commutativeN/A
Simplified33.0%
(FPCore (x y) :precision binary64 (* x 0.75))
double code(double x, double y) {
return x * 0.75;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x * 0.75d0
end function
public static double code(double x, double y) {
return x * 0.75;
}
def code(x, y): return x * 0.75
function code(x, y) return Float64(x * 0.75) end
function tmp = code(x, y) tmp = x * 0.75; end
code[x_, y_] := N[(x * 0.75), $MachinePrecision]
\begin{array}{l}
\\
x \cdot 0.75
\end{array}
Initial program 99.9%
+-commutativeN/A
flip-+N/A
/-lowering-/.f64N/A
--lowering--.f64N/A
frac-timesN/A
/-lowering-/.f64N/A
sqr-absN/A
*-lowering-*.f64N/A
--lowering--.f64N/A
--lowering--.f64N/A
metadata-evalN/A
*-lowering-*.f64N/A
--lowering--.f64N/A
/-lowering-/.f64N/A
fabs-lowering-fabs.f64N/A
--lowering--.f6448.4%
Applied egg-rr48.4%
Taylor expanded in x around inf
*-commutativeN/A
*-lowering-*.f6411.5%
Simplified11.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
Simplified11.4%
herbie shell --seed 2024152
(FPCore (x y)
:name "Graphics.Rendering.Chart.Plot.AreaSpots:renderSpotLegend from Chart-1.5.3"
:precision binary64
(+ x (/ (fabs (- y x)) 2.0)))