
(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%
Final simplification99.9%
(FPCore (x y) :precision binary64 (if (<= y -2e-105) (* (fabs (- y x)) 0.5) (* 0.5 (+ x y))))
double code(double x, double y) {
double tmp;
if (y <= -2e-105) {
tmp = fabs((y - x)) * 0.5;
} else {
tmp = 0.5 * (x + y);
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= (-2d-105)) then
tmp = abs((y - x)) * 0.5d0
else
tmp = 0.5d0 * (x + y)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -2e-105) {
tmp = Math.abs((y - x)) * 0.5;
} else {
tmp = 0.5 * (x + y);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -2e-105: tmp = math.fabs((y - x)) * 0.5 else: tmp = 0.5 * (x + y) return tmp
function code(x, y) tmp = 0.0 if (y <= -2e-105) tmp = Float64(abs(Float64(y - x)) * 0.5); else tmp = Float64(0.5 * Float64(x + y)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -2e-105) tmp = abs((y - x)) * 0.5; else tmp = 0.5 * (x + y); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -2e-105], N[(N[Abs[N[(y - x), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision], N[(0.5 * N[(x + y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2 \cdot 10^{-105}:\\
\;\;\;\;\left|y - x\right| \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(x + y\right)\\
\end{array}
\end{array}
if y < -1.99999999999999993e-105Initial program 99.9%
Taylor expanded in x around 0 73.8%
if -1.99999999999999993e-105 < y Initial program 99.9%
+-commutative99.9%
add-sqr-sqrt99.3%
fma-def99.3%
div-inv99.3%
add-sqr-sqrt72.9%
fabs-sqr72.9%
add-sqr-sqrt72.9%
metadata-eval72.9%
div-inv72.9%
add-sqr-sqrt72.9%
fabs-sqr72.9%
add-sqr-sqrt72.9%
metadata-eval72.9%
Applied egg-rr72.9%
Taylor expanded in y around 0 0.0%
+-commutative0.0%
associate-*r*0.0%
distribute-lft1-in0.0%
unpow20.0%
rem-square-sqrt76.4%
*-commutative76.4%
+-commutative76.4%
mul-1-neg76.4%
unsub-neg76.4%
unpow276.4%
rem-square-sqrt77.0%
metadata-eval77.0%
unpow277.0%
rem-square-sqrt77.8%
distribute-lft-out77.8%
Simplified77.8%
Final simplification76.4%
(FPCore (x y) :precision binary64 (if (<= y 3.5e-175) (* x 0.5) (* y 0.5)))
double code(double x, double y) {
double tmp;
if (y <= 3.5e-175) {
tmp = x * 0.5;
} else {
tmp = 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 <= 3.5d-175) then
tmp = x * 0.5d0
else
tmp = y * 0.5d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 3.5e-175) {
tmp = x * 0.5;
} else {
tmp = y * 0.5;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 3.5e-175: tmp = x * 0.5 else: tmp = y * 0.5 return tmp
function code(x, y) tmp = 0.0 if (y <= 3.5e-175) tmp = Float64(x * 0.5); else tmp = Float64(y * 0.5); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 3.5e-175) tmp = x * 0.5; else tmp = y * 0.5; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 3.5e-175], N[(x * 0.5), $MachinePrecision], N[(y * 0.5), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 3.5 \cdot 10^{-175}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;y \cdot 0.5\\
\end{array}
\end{array}
if y < 3.49999999999999999e-175Initial program 99.9%
+-commutative99.9%
add-sqr-sqrt99.3%
fma-def99.3%
div-inv99.3%
add-sqr-sqrt31.5%
fabs-sqr31.5%
add-sqr-sqrt31.5%
metadata-eval31.5%
div-inv31.5%
add-sqr-sqrt31.5%
fabs-sqr31.5%
add-sqr-sqrt31.5%
metadata-eval31.5%
Applied egg-rr31.5%
Taylor expanded in y around 0 0.0%
associate-*r*0.0%
distribute-lft1-in0.0%
unpow20.0%
rem-square-sqrt35.2%
*-commutative35.2%
+-commutative35.2%
mul-1-neg35.2%
unsub-neg35.2%
unpow235.2%
rem-square-sqrt35.8%
metadata-eval35.8%
Simplified35.8%
if 3.49999999999999999e-175 < y Initial program 100.0%
+-commutative100.0%
add-sqr-sqrt99.3%
fma-def99.3%
div-inv99.3%
add-sqr-sqrt84.3%
fabs-sqr84.3%
add-sqr-sqrt84.2%
metadata-eval84.2%
div-inv84.2%
add-sqr-sqrt84.3%
fabs-sqr84.3%
add-sqr-sqrt84.2%
metadata-eval84.2%
Applied egg-rr84.2%
Taylor expanded in x around 0 67.1%
unpow267.1%
rem-square-sqrt68.3%
Simplified68.3%
Final simplification48.4%
(FPCore (x y) :precision binary64 (* 0.5 (+ x y)))
double code(double x, double y) {
return 0.5 * (x + y);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 0.5d0 * (x + y)
end function
public static double code(double x, double y) {
return 0.5 * (x + y);
}
def code(x, y): return 0.5 * (x + y)
function code(x, y) return Float64(0.5 * Float64(x + y)) end
function tmp = code(x, y) tmp = 0.5 * (x + y); end
code[x_, y_] := N[(0.5 * N[(x + y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.5 \cdot \left(x + y\right)
\end{array}
Initial program 99.9%
+-commutative99.9%
add-sqr-sqrt99.3%
fma-def99.3%
div-inv99.3%
add-sqr-sqrt51.9%
fabs-sqr51.9%
add-sqr-sqrt51.9%
metadata-eval51.9%
div-inv51.9%
add-sqr-sqrt51.9%
fabs-sqr51.9%
add-sqr-sqrt51.9%
metadata-eval51.9%
Applied egg-rr51.9%
Taylor expanded in y around 0 0.0%
+-commutative0.0%
associate-*r*0.0%
distribute-lft1-in0.0%
unpow20.0%
rem-square-sqrt55.2%
*-commutative55.2%
+-commutative55.2%
mul-1-neg55.2%
unsub-neg55.2%
unpow255.2%
rem-square-sqrt55.8%
metadata-eval55.8%
unpow255.8%
rem-square-sqrt56.3%
distribute-lft-out56.3%
Simplified56.3%
Final simplification56.3%
(FPCore (x y) :precision binary64 (* x 0.5))
double code(double x, double y) {
return x * 0.5;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x * 0.5d0
end function
public static double code(double x, double y) {
return x * 0.5;
}
def code(x, y): return x * 0.5
function code(x, y) return Float64(x * 0.5) end
function tmp = code(x, y) tmp = x * 0.5; end
code[x_, y_] := N[(x * 0.5), $MachinePrecision]
\begin{array}{l}
\\
x \cdot 0.5
\end{array}
Initial program 99.9%
+-commutative99.9%
add-sqr-sqrt99.3%
fma-def99.3%
div-inv99.3%
add-sqr-sqrt51.9%
fabs-sqr51.9%
add-sqr-sqrt51.9%
metadata-eval51.9%
div-inv51.9%
add-sqr-sqrt51.9%
fabs-sqr51.9%
add-sqr-sqrt51.9%
metadata-eval51.9%
Applied egg-rr51.9%
Taylor expanded in y around 0 0.0%
associate-*r*0.0%
distribute-lft1-in0.0%
unpow20.0%
rem-square-sqrt29.7%
*-commutative29.7%
+-commutative29.7%
mul-1-neg29.7%
unsub-neg29.7%
unpow229.7%
rem-square-sqrt30.2%
metadata-eval30.2%
Simplified30.2%
Final simplification30.2%
(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 10.7%
Final simplification10.7%
herbie shell --seed 2023200
(FPCore (x y)
:name "Graphics.Rendering.Chart.Plot.AreaSpots:renderSpotLegend from Chart-1.5.3"
:precision binary64
(+ x (/ (fabs (- y x)) 2.0)))