
(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 (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%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
div-invN/A
lower-fma.f64N/A
lift-fabs.f64N/A
neg-fabsN/A
lower-fabs.f64N/A
lift--.f64N/A
sub-negN/A
+-commutativeN/A
distribute-neg-inN/A
remove-double-negN/A
sub-negN/A
lower--.f64N/A
metadata-eval99.9
Applied rewrites99.9%
Final simplification99.9%
(FPCore (x y) :precision binary64 (if (<= x 4.1e-69) (fma (fabs (- y)) 0.5 x) (fma (- x y) 0.5 x)))
double code(double x, double y) {
double tmp;
if (x <= 4.1e-69) {
tmp = fma(fabs(-y), 0.5, x);
} else {
tmp = fma((x - y), 0.5, x);
}
return tmp;
}
function code(x, y) tmp = 0.0 if (x <= 4.1e-69) tmp = fma(abs(Float64(-y)), 0.5, x); else tmp = fma(Float64(x - y), 0.5, x); end return tmp end
code[x_, y_] := If[LessEqual[x, 4.1e-69], N[(N[Abs[(-y)], $MachinePrecision] * 0.5 + x), $MachinePrecision], N[(N[(x - y), $MachinePrecision] * 0.5 + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 4.1 \cdot 10^{-69}:\\
\;\;\;\;\mathsf{fma}\left(\left|-y\right|, 0.5, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x - y, 0.5, x\right)\\
\end{array}
\end{array}
if x < 4.0999999999999999e-69Initial program 100.0%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
div-invN/A
lower-fma.f64N/A
lift-fabs.f64N/A
neg-fabsN/A
lower-fabs.f64N/A
lift--.f64N/A
sub-negN/A
+-commutativeN/A
distribute-neg-inN/A
remove-double-negN/A
sub-negN/A
lower--.f64N/A
metadata-eval100.0
Applied rewrites100.0%
Taylor expanded in y around inf
mul-1-negN/A
lower-neg.f6467.4
Applied rewrites67.4%
if 4.0999999999999999e-69 < x Initial program 99.7%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
div-invN/A
lower-fma.f64N/A
lift-fabs.f64N/A
neg-fabsN/A
lower-fabs.f64N/A
lift--.f64N/A
sub-negN/A
+-commutativeN/A
distribute-neg-inN/A
remove-double-negN/A
sub-negN/A
lower--.f64N/A
metadata-eval99.7
Applied rewrites99.7%
unpow1N/A
metadata-evalN/A
pow-prod-upN/A
lower-*.f64N/A
unpow1/2N/A
lower-sqrt.f64N/A
lift-fabs.f64N/A
lift--.f64N/A
fabs-subN/A
lift--.f64N/A
lift-fabs.f64N/A
unpow1/2N/A
lower-sqrt.f6499.5
lift-fabs.f64N/A
lift--.f64N/A
fabs-subN/A
lift--.f64N/A
lift-fabs.f6499.5
Applied rewrites99.5%
Applied rewrites99.5%
Applied rewrites92.0%
(FPCore (x y) :precision binary64 (if (<= y 2.8e-41) (fma (- x y) 0.5 x) (* (fabs (- y x)) 0.5)))
double code(double x, double y) {
double tmp;
if (y <= 2.8e-41) {
tmp = fma((x - y), 0.5, x);
} else {
tmp = fabs((y - x)) * 0.5;
}
return tmp;
}
function code(x, y) tmp = 0.0 if (y <= 2.8e-41) tmp = fma(Float64(x - y), 0.5, x); else tmp = Float64(abs(Float64(y - x)) * 0.5); end return tmp end
code[x_, y_] := If[LessEqual[y, 2.8e-41], N[(N[(x - y), $MachinePrecision] * 0.5 + x), $MachinePrecision], N[(N[Abs[N[(y - x), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 2.8 \cdot 10^{-41}:\\
\;\;\;\;\mathsf{fma}\left(x - y, 0.5, x\right)\\
\mathbf{else}:\\
\;\;\;\;\left|y - x\right| \cdot 0.5\\
\end{array}
\end{array}
if y < 2.8000000000000002e-41Initial program 99.9%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
div-invN/A
lower-fma.f64N/A
lift-fabs.f64N/A
neg-fabsN/A
lower-fabs.f64N/A
lift--.f64N/A
sub-negN/A
+-commutativeN/A
distribute-neg-inN/A
remove-double-negN/A
sub-negN/A
lower--.f64N/A
metadata-eval99.9
Applied rewrites99.9%
unpow1N/A
metadata-evalN/A
pow-prod-upN/A
lower-*.f64N/A
unpow1/2N/A
lower-sqrt.f64N/A
lift-fabs.f64N/A
lift--.f64N/A
fabs-subN/A
lift--.f64N/A
lift-fabs.f64N/A
unpow1/2N/A
lower-sqrt.f6499.3
lift-fabs.f64N/A
lift--.f64N/A
fabs-subN/A
lift--.f64N/A
lift-fabs.f6499.3
Applied rewrites99.3%
Applied rewrites99.5%
Applied rewrites73.5%
if 2.8000000000000002e-41 < y Initial program 99.9%
Taylor expanded in x around 0
*-commutativeN/A
sub-negN/A
mul-1-negN/A
lower-*.f64N/A
mul-1-negN/A
remove-double-negN/A
mul-1-negN/A
distribute-neg-inN/A
+-commutativeN/A
lower-fabs.f64N/A
+-commutativeN/A
distribute-neg-inN/A
mul-1-negN/A
remove-double-negN/A
sub-negN/A
lower--.f6469.4
Applied rewrites69.4%
(FPCore (x y) :precision binary64 (fma (- x y) 0.5 x))
double code(double x, double y) {
return fma((x - y), 0.5, x);
}
function code(x, y) return fma(Float64(x - y), 0.5, x) end
code[x_, y_] := N[(N[(x - y), $MachinePrecision] * 0.5 + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x - y, 0.5, x\right)
\end{array}
Initial program 99.9%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
div-invN/A
lower-fma.f64N/A
lift-fabs.f64N/A
neg-fabsN/A
lower-fabs.f64N/A
lift--.f64N/A
sub-negN/A
+-commutativeN/A
distribute-neg-inN/A
remove-double-negN/A
sub-negN/A
lower--.f64N/A
metadata-eval99.9
Applied rewrites99.9%
unpow1N/A
metadata-evalN/A
pow-prod-upN/A
lower-*.f64N/A
unpow1/2N/A
lower-sqrt.f64N/A
lift-fabs.f64N/A
lift--.f64N/A
fabs-subN/A
lift--.f64N/A
lift-fabs.f64N/A
unpow1/2N/A
lower-sqrt.f6499.3
lift-fabs.f64N/A
lift--.f64N/A
fabs-subN/A
lift--.f64N/A
lift-fabs.f6499.3
Applied rewrites99.3%
Applied rewrites99.4%
Applied rewrites56.8%
(FPCore (x y) :precision binary64 (* (fabs (- x)) 0.5))
double code(double x, double y) {
return fabs(-x) * 0.5;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = abs(-x) * 0.5d0
end function
public static double code(double x, double y) {
return Math.abs(-x) * 0.5;
}
def code(x, y): return math.fabs(-x) * 0.5
function code(x, y) return Float64(abs(Float64(-x)) * 0.5) end
function tmp = code(x, y) tmp = abs(-x) * 0.5; end
code[x_, y_] := N[(N[Abs[(-x)], $MachinePrecision] * 0.5), $MachinePrecision]
\begin{array}{l}
\\
\left|-x\right| \cdot 0.5
\end{array}
Initial program 99.9%
Taylor expanded in x around 0
*-commutativeN/A
sub-negN/A
mul-1-negN/A
lower-*.f64N/A
mul-1-negN/A
remove-double-negN/A
mul-1-negN/A
distribute-neg-inN/A
+-commutativeN/A
lower-fabs.f64N/A
+-commutativeN/A
distribute-neg-inN/A
mul-1-negN/A
remove-double-negN/A
sub-negN/A
lower--.f6452.9
Applied rewrites52.9%
Taylor expanded in y around 0
Applied rewrites7.4%
herbie shell --seed 2024268
(FPCore (x y)
:name "Graphics.Rendering.Chart.Plot.AreaSpots:renderSpotLegend from Chart-1.5.3"
:precision binary64
(+ x (/ (fabs (- y x)) 2.0)))