
(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 8 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%
Taylor expanded in x around 0
Applied rewrites99.9%
Final simplification99.9%
(FPCore (x y) :precision binary64 (if (<= y -1.35e-145) (+ x (* -0.5 y)) (if (<= y 2.3e-70) (* 1.5 x) (* (fabs (- y)) 0.5))))
double code(double x, double y) {
double tmp;
if (y <= -1.35e-145) {
tmp = x + (-0.5 * y);
} else if (y <= 2.3e-70) {
tmp = 1.5 * x;
} else {
tmp = fabs(-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 <= (-1.35d-145)) then
tmp = x + ((-0.5d0) * y)
else if (y <= 2.3d-70) then
tmp = 1.5d0 * x
else
tmp = abs(-y) * 0.5d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -1.35e-145) {
tmp = x + (-0.5 * y);
} else if (y <= 2.3e-70) {
tmp = 1.5 * x;
} else {
tmp = Math.abs(-y) * 0.5;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.35e-145: tmp = x + (-0.5 * y) elif y <= 2.3e-70: tmp = 1.5 * x else: tmp = math.fabs(-y) * 0.5 return tmp
function code(x, y) tmp = 0.0 if (y <= -1.35e-145) tmp = Float64(x + Float64(-0.5 * y)); elseif (y <= 2.3e-70) tmp = Float64(1.5 * x); else tmp = Float64(abs(Float64(-y)) * 0.5); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -1.35e-145) tmp = x + (-0.5 * y); elseif (y <= 2.3e-70) tmp = 1.5 * x; else tmp = abs(-y) * 0.5; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.35e-145], N[(x + N[(-0.5 * y), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 2.3e-70], N[(1.5 * x), $MachinePrecision], N[(N[Abs[(-y)], $MachinePrecision] * 0.5), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.35 \cdot 10^{-145}:\\
\;\;\;\;x + -0.5 \cdot y\\
\mathbf{elif}\;y \leq 2.3 \cdot 10^{-70}:\\
\;\;\;\;1.5 \cdot x\\
\mathbf{else}:\\
\;\;\;\;\left|-y\right| \cdot 0.5\\
\end{array}
\end{array}
if y < -1.35e-145Initial program 100.0%
Applied rewrites50.5%
Taylor expanded in x around 0
lower-*.f6471.6
Applied rewrites71.6%
if -1.35e-145 < y < 2.30000000000000001e-70Initial program 99.8%
Applied rewrites43.6%
Taylor expanded in x around inf
*-commutativeN/A
+-commutativeN/A
unpow2N/A
rem-square-sqrtN/A
metadata-evalN/A
metadata-evalN/A
lower-*.f6445.5
Applied rewrites45.5%
if 2.30000000000000001e-70 < y Initial program 99.9%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites69.4%
Taylor expanded in x around 0
Applied rewrites68.2%
(FPCore (x y) :precision binary64 (if (<= y 1.6e-220) (fma (- y x) -0.5 x) (fma (fabs (- y)) 0.5 x)))
double code(double x, double y) {
double tmp;
if (y <= 1.6e-220) {
tmp = fma((y - x), -0.5, x);
} else {
tmp = fma(fabs(-y), 0.5, x);
}
return tmp;
}
function code(x, y) tmp = 0.0 if (y <= 1.6e-220) tmp = fma(Float64(y - x), -0.5, x); else tmp = fma(abs(Float64(-y)), 0.5, x); end return tmp end
code[x_, y_] := If[LessEqual[y, 1.6e-220], N[(N[(y - x), $MachinePrecision] * -0.5 + x), $MachinePrecision], N[(N[Abs[(-y)], $MachinePrecision] * 0.5 + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.6 \cdot 10^{-220}:\\
\;\;\;\;\mathsf{fma}\left(y - x, -0.5, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\left|-y\right|, 0.5, x\right)\\
\end{array}
\end{array}
if y < 1.60000000000000003e-220Initial program 99.9%
Applied rewrites68.5%
Taylor expanded in x around 0
*-commutativeN/A
unpow2N/A
rem-square-sqrtN/A
lower-*.f6448.3
Applied rewrites48.3%
Taylor expanded in x around 0
Applied rewrites74.2%
if 1.60000000000000003e-220 < y Initial program 99.9%
Taylor expanded in x around 0
Applied rewrites99.9%
Taylor expanded in x around 0
Applied rewrites63.1%
(FPCore (x y) :precision binary64 (if (<= y 2e-70) (fma (- y x) -0.5 x) (* (fabs (- y x)) 0.5)))
double code(double x, double y) {
double tmp;
if (y <= 2e-70) {
tmp = fma((y - x), -0.5, x);
} else {
tmp = fabs((y - x)) * 0.5;
}
return tmp;
}
function code(x, y) tmp = 0.0 if (y <= 2e-70) tmp = fma(Float64(y - x), -0.5, x); else tmp = Float64(abs(Float64(y - x)) * 0.5); end return tmp end
code[x_, y_] := If[LessEqual[y, 2e-70], N[(N[(y - x), $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 \cdot 10^{-70}:\\
\;\;\;\;\mathsf{fma}\left(y - x, -0.5, x\right)\\
\mathbf{else}:\\
\;\;\;\;\left|y - x\right| \cdot 0.5\\
\end{array}
\end{array}
if y < 1.99999999999999999e-70Initial program 99.9%
Applied rewrites61.9%
Taylor expanded in x around 0
*-commutativeN/A
unpow2N/A
rem-square-sqrtN/A
lower-*.f6441.4
Applied rewrites41.4%
Taylor expanded in x around 0
Applied rewrites68.2%
if 1.99999999999999999e-70 < y Initial program 99.9%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites69.4%
Final simplification68.6%
(FPCore (x y) :precision binary64 (if (<= y 2.3e-70) (fma (- y x) -0.5 x) (* (fabs (- y)) 0.5)))
double code(double x, double y) {
double tmp;
if (y <= 2.3e-70) {
tmp = fma((y - x), -0.5, x);
} else {
tmp = fabs(-y) * 0.5;
}
return tmp;
}
function code(x, y) tmp = 0.0 if (y <= 2.3e-70) tmp = fma(Float64(y - x), -0.5, x); else tmp = Float64(abs(Float64(-y)) * 0.5); end return tmp end
code[x_, y_] := If[LessEqual[y, 2.3e-70], N[(N[(y - x), $MachinePrecision] * -0.5 + x), $MachinePrecision], N[(N[Abs[(-y)], $MachinePrecision] * 0.5), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 2.3 \cdot 10^{-70}:\\
\;\;\;\;\mathsf{fma}\left(y - x, -0.5, x\right)\\
\mathbf{else}:\\
\;\;\;\;\left|-y\right| \cdot 0.5\\
\end{array}
\end{array}
if y < 2.30000000000000001e-70Initial program 99.9%
Applied rewrites61.9%
Taylor expanded in x around 0
*-commutativeN/A
unpow2N/A
rem-square-sqrtN/A
lower-*.f6441.4
Applied rewrites41.4%
Taylor expanded in x around 0
Applied rewrites68.2%
if 2.30000000000000001e-70 < y Initial program 99.9%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites69.4%
Taylor expanded in x around 0
Applied rewrites68.2%
(FPCore (x y) :precision binary64 (if (<= y -1.35e-145) (+ x (* -0.5 y)) (* 1.5 x)))
double code(double x, double y) {
double tmp;
if (y <= -1.35e-145) {
tmp = x + (-0.5 * y);
} else {
tmp = 1.5 * x;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= (-1.35d-145)) then
tmp = x + ((-0.5d0) * y)
else
tmp = 1.5d0 * x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -1.35e-145) {
tmp = x + (-0.5 * y);
} else {
tmp = 1.5 * x;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.35e-145: tmp = x + (-0.5 * y) else: tmp = 1.5 * x return tmp
function code(x, y) tmp = 0.0 if (y <= -1.35e-145) tmp = Float64(x + Float64(-0.5 * y)); else tmp = Float64(1.5 * x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -1.35e-145) tmp = x + (-0.5 * y); else tmp = 1.5 * x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.35e-145], N[(x + N[(-0.5 * y), $MachinePrecision]), $MachinePrecision], N[(1.5 * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.35 \cdot 10^{-145}:\\
\;\;\;\;x + -0.5 \cdot y\\
\mathbf{else}:\\
\;\;\;\;1.5 \cdot x\\
\end{array}
\end{array}
if y < -1.35e-145Initial program 100.0%
Applied rewrites50.5%
Taylor expanded in x around 0
lower-*.f6471.6
Applied rewrites71.6%
if -1.35e-145 < y Initial program 99.9%
Applied rewrites28.2%
Taylor expanded in x around inf
*-commutativeN/A
+-commutativeN/A
unpow2N/A
rem-square-sqrtN/A
metadata-evalN/A
metadata-evalN/A
lower-*.f6432.0
Applied rewrites32.0%
(FPCore (x y) :precision binary64 (if (<= y -7.2e-139) (* -0.5 y) (* 1.5 x)))
double code(double x, double y) {
double tmp;
if (y <= -7.2e-139) {
tmp = -0.5 * y;
} else {
tmp = 1.5 * x;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= (-7.2d-139)) then
tmp = (-0.5d0) * y
else
tmp = 1.5d0 * x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -7.2e-139) {
tmp = -0.5 * y;
} else {
tmp = 1.5 * x;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -7.2e-139: tmp = -0.5 * y else: tmp = 1.5 * x return tmp
function code(x, y) tmp = 0.0 if (y <= -7.2e-139) tmp = Float64(-0.5 * y); else tmp = Float64(1.5 * x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -7.2e-139) tmp = -0.5 * y; else tmp = 1.5 * x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -7.2e-139], N[(-0.5 * y), $MachinePrecision], N[(1.5 * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -7.2 \cdot 10^{-139}:\\
\;\;\;\;-0.5 \cdot y\\
\mathbf{else}:\\
\;\;\;\;1.5 \cdot x\\
\end{array}
\end{array}
if y < -7.20000000000000007e-139Initial program 100.0%
Applied rewrites78.2%
Taylor expanded in x around 0
*-commutativeN/A
unpow2N/A
rem-square-sqrtN/A
lower-*.f6467.4
Applied rewrites67.4%
if -7.20000000000000007e-139 < y Initial program 99.9%
Applied rewrites27.8%
Taylor expanded in x around inf
*-commutativeN/A
+-commutativeN/A
unpow2N/A
rem-square-sqrtN/A
metadata-evalN/A
metadata-evalN/A
lower-*.f6431.8
Applied rewrites31.8%
(FPCore (x y) :precision binary64 (* -0.5 y))
double code(double x, double y) {
return -0.5 * y;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (-0.5d0) * y
end function
public static double code(double x, double y) {
return -0.5 * y;
}
def code(x, y): return -0.5 * y
function code(x, y) return Float64(-0.5 * y) end
function tmp = code(x, y) tmp = -0.5 * y; end
code[x_, y_] := N[(-0.5 * y), $MachinePrecision]
\begin{array}{l}
\\
-0.5 \cdot y
\end{array}
Initial program 99.9%
Applied rewrites47.3%
Taylor expanded in x around 0
*-commutativeN/A
unpow2N/A
rem-square-sqrtN/A
lower-*.f6430.1
Applied rewrites30.1%
herbie shell --seed 2024343
(FPCore (x y)
:name "Graphics.Rendering.Chart.Plot.AreaSpots:renderSpotLegend from Chart-1.5.3"
:precision binary64
(+ x (/ (fabs (- y x)) 2.0)))