
(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 -8.2e-99) (* (fabs (- y x)) 0.5) (* 0.5 (+ x y))))
double code(double x, double y) {
double tmp;
if (y <= -8.2e-99) {
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 <= (-8.2d-99)) 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 <= -8.2e-99) {
tmp = Math.abs((y - x)) * 0.5;
} else {
tmp = 0.5 * (x + y);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -8.2e-99: tmp = math.fabs((y - x)) * 0.5 else: tmp = 0.5 * (x + y) return tmp
function code(x, y) tmp = 0.0 if (y <= -8.2e-99) 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 <= -8.2e-99) tmp = abs((y - x)) * 0.5; else tmp = 0.5 * (x + y); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -8.2e-99], 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 -8.2 \cdot 10^{-99}:\\
\;\;\;\;\left|y - x\right| \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(x + y\right)\\
\end{array}
\end{array}
if y < -8.20000000000000057e-99Initial program 99.9%
Taylor expanded in x around 0 70.9%
if -8.20000000000000057e-99 < y Initial program 99.9%
+-commutative99.9%
add-sqr-sqrt99.4%
fma-def99.4%
div-inv99.4%
add-sqr-sqrt69.1%
fabs-sqr69.1%
add-sqr-sqrt69.2%
metadata-eval69.2%
div-inv69.2%
add-sqr-sqrt69.1%
fabs-sqr69.1%
add-sqr-sqrt69.2%
metadata-eval69.2%
Applied egg-rr69.2%
Taylor expanded in y around 0 0.0%
+-commutative0.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt0.0%
*-rgt-identity0.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt0.0%
*-commutative0.0%
associate-*l*0.0%
unpow20.0%
rem-square-sqrt75.0%
metadata-eval75.0%
distribute-lft-out75.0%
metadata-eval75.0%
distribute-rgt-out75.0%
+-commutative75.0%
Simplified75.0%
Final simplification73.7%
(FPCore (x y) :precision binary64 (if (<= y 1.3e-29) (* x 0.5) (* y 0.5)))
double code(double x, double y) {
double tmp;
if (y <= 1.3e-29) {
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.3d-29) 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.3e-29) {
tmp = x * 0.5;
} else {
tmp = y * 0.5;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 1.3e-29: tmp = x * 0.5 else: tmp = y * 0.5 return tmp
function code(x, y) tmp = 0.0 if (y <= 1.3e-29) 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.3e-29) tmp = x * 0.5; else tmp = y * 0.5; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 1.3e-29], N[(x * 0.5), $MachinePrecision], N[(y * 0.5), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.3 \cdot 10^{-29}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;y \cdot 0.5\\
\end{array}
\end{array}
if y < 1.3000000000000001e-29Initial program 99.9%
+-commutative99.9%
add-sqr-sqrt99.3%
fma-def99.3%
div-inv99.3%
add-sqr-sqrt32.7%
fabs-sqr32.7%
add-sqr-sqrt32.7%
metadata-eval32.7%
div-inv32.7%
add-sqr-sqrt32.7%
fabs-sqr32.7%
add-sqr-sqrt32.7%
metadata-eval32.7%
Applied egg-rr32.7%
Taylor expanded in y around 0 0.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt0.0%
*-commutative0.0%
associate-*l*0.0%
unpow20.0%
rem-square-sqrt35.4%
metadata-eval35.4%
*-commutative35.4%
distribute-lft1-in35.4%
metadata-eval35.4%
Simplified35.4%
if 1.3000000000000001e-29 < y Initial program 100.0%
+-commutative100.0%
add-sqr-sqrt99.3%
fma-def99.3%
div-inv99.3%
add-sqr-sqrt91.5%
fabs-sqr91.5%
add-sqr-sqrt91.6%
metadata-eval91.6%
div-inv91.6%
add-sqr-sqrt91.5%
fabs-sqr91.5%
add-sqr-sqrt91.6%
metadata-eval91.6%
Applied egg-rr91.6%
Taylor expanded in x around 0 78.0%
unpow278.0%
rem-square-sqrt79.6%
Simplified79.6%
Final simplification48.7%
(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-sqrt50.4%
fabs-sqr50.4%
add-sqr-sqrt50.4%
metadata-eval50.4%
div-inv50.4%
add-sqr-sqrt50.4%
fabs-sqr50.4%
add-sqr-sqrt50.4%
metadata-eval50.4%
Applied egg-rr50.4%
Taylor expanded in y around 0 0.0%
+-commutative0.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt0.0%
*-rgt-identity0.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt0.0%
*-commutative0.0%
associate-*l*0.0%
unpow20.0%
rem-square-sqrt55.8%
metadata-eval55.8%
distribute-lft-out55.8%
metadata-eval55.8%
distribute-rgt-out55.8%
+-commutative55.8%
Simplified55.8%
Final simplification55.8%
(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-sqrt50.4%
fabs-sqr50.4%
add-sqr-sqrt50.4%
metadata-eval50.4%
div-inv50.4%
add-sqr-sqrt50.4%
fabs-sqr50.4%
add-sqr-sqrt50.4%
metadata-eval50.4%
Applied egg-rr50.4%
Taylor expanded in y around 0 0.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt0.0%
*-commutative0.0%
associate-*l*0.0%
unpow20.0%
rem-square-sqrt29.4%
metadata-eval29.4%
*-commutative29.4%
distribute-lft1-in29.4%
metadata-eval29.4%
Simplified29.4%
Final simplification29.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 11.5%
Final simplification11.5%
herbie shell --seed 2023196
(FPCore (x y)
:name "Graphics.Rendering.Chart.Plot.AreaSpots:renderSpotLegend from Chart-1.5.3"
:precision binary64
(+ x (/ (fabs (- y x)) 2.0)))