
(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 100.0%
Final simplification100.0%
(FPCore (x y) :precision binary64 (if (<= x -7.2e-128) (* 0.5 (+ x y)) (* (fabs (- y x)) 0.5)))
double code(double x, double y) {
double tmp;
if (x <= -7.2e-128) {
tmp = 0.5 * (x + y);
} else {
tmp = fabs((y - x)) * 0.5;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= (-7.2d-128)) then
tmp = 0.5d0 * (x + y)
else
tmp = abs((y - x)) * 0.5d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -7.2e-128) {
tmp = 0.5 * (x + y);
} else {
tmp = Math.abs((y - x)) * 0.5;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -7.2e-128: tmp = 0.5 * (x + y) else: tmp = math.fabs((y - x)) * 0.5 return tmp
function code(x, y) tmp = 0.0 if (x <= -7.2e-128) tmp = Float64(0.5 * Float64(x + y)); else tmp = Float64(abs(Float64(y - x)) * 0.5); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -7.2e-128) tmp = 0.5 * (x + y); else tmp = abs((y - x)) * 0.5; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -7.2e-128], N[(0.5 * N[(x + y), $MachinePrecision]), $MachinePrecision], N[(N[Abs[N[(y - x), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -7.2 \cdot 10^{-128}:\\
\;\;\;\;0.5 \cdot \left(x + y\right)\\
\mathbf{else}:\\
\;\;\;\;\left|y - x\right| \cdot 0.5\\
\end{array}
\end{array}
if x < -7.20000000000000049e-128Initial program 100.0%
+-commutative100.0%
div-inv100.0%
fma-define100.0%
add-sqr-sqrt86.6%
fabs-sqr86.6%
add-sqr-sqrt87.3%
fma-define87.3%
div-inv87.3%
add-sqr-sqrt86.6%
fabs-sqr86.6%
add-sqr-sqrt100.0%
add-cube-cbrt97.7%
associate-/l*97.7%
fma-define97.7%
Applied egg-rr85.4%
fma-undefine85.4%
+-commutative85.4%
associate-*r/85.4%
unpow285.4%
rem-3cbrt-lft87.3%
Simplified87.3%
Taylor expanded in x around 0 87.3%
distribute-lft-out87.3%
+-commutative87.3%
Simplified87.3%
if -7.20000000000000049e-128 < x Initial program 99.9%
Taylor expanded in x around 0 60.9%
Final simplification71.5%
(FPCore (x y) :precision binary64 (if (<= y 1.05e-93) (* x 0.5) (* y 0.5)))
double code(double x, double y) {
double tmp;
if (y <= 1.05e-93) {
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 <= 1.05d-93) 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 <= 1.05e-93) {
tmp = x * 0.5;
} else {
tmp = y * 0.5;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 1.05e-93: tmp = x * 0.5 else: tmp = y * 0.5 return tmp
function code(x, y) tmp = 0.0 if (y <= 1.05e-93) 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 <= 1.05e-93) tmp = x * 0.5; else tmp = y * 0.5; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 1.05e-93], N[(x * 0.5), $MachinePrecision], N[(y * 0.5), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.05 \cdot 10^{-93}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;y \cdot 0.5\\
\end{array}
\end{array}
if y < 1.05e-93Initial program 99.9%
+-commutative99.9%
div-inv99.9%
fma-define99.9%
add-sqr-sqrt40.9%
fabs-sqr40.9%
add-sqr-sqrt46.3%
fma-define46.3%
div-inv46.3%
add-sqr-sqrt40.9%
fabs-sqr40.9%
add-sqr-sqrt99.9%
add-cube-cbrt98.2%
associate-/l*98.2%
fma-define98.2%
Applied egg-rr45.4%
fma-undefine45.4%
+-commutative45.4%
associate-*r/45.4%
unpow245.4%
rem-3cbrt-lft46.3%
Simplified46.3%
Taylor expanded in x around inf 42.3%
if 1.05e-93 < y Initial program 100.0%
+-commutative100.0%
div-inv100.0%
fma-define100.0%
add-sqr-sqrt79.0%
fabs-sqr79.0%
add-sqr-sqrt83.3%
fma-define83.3%
div-inv83.3%
add-sqr-sqrt79.0%
fabs-sqr79.0%
add-sqr-sqrt100.0%
add-cube-cbrt98.1%
associate-/l*98.1%
fma-define98.1%
Applied egg-rr81.5%
fma-undefine81.5%
+-commutative81.5%
associate-*r/81.5%
unpow281.5%
rem-3cbrt-lft83.3%
Simplified83.3%
Taylor expanded in x around 0 69.6%
Final simplification49.6%
(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 100.0%
+-commutative100.0%
div-inv100.0%
fma-define100.0%
add-sqr-sqrt51.1%
fabs-sqr51.1%
add-sqr-sqrt56.3%
fma-define56.3%
div-inv56.3%
add-sqr-sqrt51.1%
fabs-sqr51.1%
add-sqr-sqrt100.0%
add-cube-cbrt98.2%
associate-/l*98.2%
fma-define98.2%
Applied egg-rr55.2%
fma-undefine55.2%
+-commutative55.2%
associate-*r/55.2%
unpow255.2%
rem-3cbrt-lft56.3%
Simplified56.3%
Taylor expanded in x around 0 56.3%
distribute-lft-out56.3%
+-commutative56.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 100.0%
+-commutative100.0%
div-inv100.0%
fma-define100.0%
add-sqr-sqrt51.1%
fabs-sqr51.1%
add-sqr-sqrt56.3%
fma-define56.3%
div-inv56.3%
add-sqr-sqrt51.1%
fabs-sqr51.1%
add-sqr-sqrt100.0%
add-cube-cbrt98.2%
associate-/l*98.2%
fma-define98.2%
Applied egg-rr55.2%
fma-undefine55.2%
+-commutative55.2%
associate-*r/55.2%
unpow255.2%
rem-3cbrt-lft56.3%
Simplified56.3%
Taylor expanded in x around inf 35.1%
Final simplification35.1%
(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 100.0%
Taylor expanded in x around inf 12.3%
Final simplification12.3%
herbie shell --seed 2024066
(FPCore (x y)
:name "Graphics.Rendering.Chart.Plot.AreaSpots:renderSpotLegend from Chart-1.5.3"
:precision binary64
(+ x (/ (fabs (- y x)) 2.0)))