
(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 4 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 (fma (fabs (- y x)) 0.5 x))
double code(double x, double y) {
return fma(fabs((y - x)), 0.5, x);
}
function code(x, y) return fma(abs(Float64(y - x)), 0.5, x) end
code[x_, y_] := N[(N[Abs[N[(y - x), $MachinePrecision]], $MachinePrecision] * 0.5 + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\left|y - x\right|, 0.5, x\right)
\end{array}
Initial program 99.9%
+-commutativeN/A
div-invN/A
accelerator-lowering-fma.f64N/A
fabs-lowering-fabs.f64N/A
--lowering--.f64N/A
metadata-eval99.9
Applied egg-rr99.9%
(FPCore (x y) :precision binary64 (fma (fabs y) 0.5 x))
double code(double x, double y) {
return fma(fabs(y), 0.5, x);
}
function code(x, y) return fma(abs(y), 0.5, x) end
code[x_, y_] := N[(N[Abs[y], $MachinePrecision] * 0.5 + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\left|y\right|, 0.5, x\right)
\end{array}
Initial program 99.9%
+-commutativeN/A
div-invN/A
accelerator-lowering-fma.f64N/A
fabs-lowering-fabs.f64N/A
--lowering--.f64N/A
metadata-eval99.9
Applied egg-rr99.9%
Taylor expanded in y around inf
Simplified54.5%
(FPCore (x y) :precision binary64 (* x 1.0833333333333333))
double code(double x, double y) {
return x * 1.0833333333333333;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x * 1.0833333333333333d0
end function
public static double code(double x, double y) {
return x * 1.0833333333333333;
}
def code(x, y): return x * 1.0833333333333333
function code(x, y) return Float64(x * 1.0833333333333333) end
function tmp = code(x, y) tmp = x * 1.0833333333333333; end
code[x_, y_] := N[(x * 1.0833333333333333), $MachinePrecision]
\begin{array}{l}
\\
x \cdot 1.0833333333333333
\end{array}
Initial program 99.9%
Applied egg-rr51.1%
Taylor expanded in x around inf
*-commutativeN/A
*-lowering-*.f6412.4
Simplified12.4%
(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
Simplified12.3%
herbie shell --seed 2024195
(FPCore (x y)
:name "Graphics.Rendering.Chart.Plot.AreaSpots:renderSpotLegend from Chart-1.5.3"
:precision binary64
(+ x (/ (fabs (- y x)) 2.0)))