
(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 (+ x (/ (fabs (- x y)) 2.0)))
double code(double x, double y) {
return x + (fabs((x - y)) / 2.0);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x + (abs((x - y)) / 2.0d0)
end function
public static double code(double x, double y) {
return x + (Math.abs((x - y)) / 2.0);
}
def code(x, y): return x + (math.fabs((x - y)) / 2.0)
function code(x, y) return Float64(x + Float64(abs(Float64(x - y)) / 2.0)) end
function tmp = code(x, y) tmp = x + (abs((x - y)) / 2.0); end
code[x_, y_] := N[(x + N[(N[Abs[N[(x - y), $MachinePrecision]], $MachinePrecision] / 2.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \frac{\left|x - y\right|}{2}
\end{array}
Initial program 99.9%
Final simplification99.9%
(FPCore (x y) :precision binary64 (if (<= y -2.7e-14) (+ x (/ (fabs y) 2.0)) (if (<= y 3e-109) (+ x (/ (fabs x) 2.0)) (* 0.5 (+ x y)))))
double code(double x, double y) {
double tmp;
if (y <= -2.7e-14) {
tmp = x + (fabs(y) / 2.0);
} else if (y <= 3e-109) {
tmp = x + (fabs(x) / 2.0);
} 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 <= (-2.7d-14)) then
tmp = x + (abs(y) / 2.0d0)
else if (y <= 3d-109) then
tmp = x + (abs(x) / 2.0d0)
else
tmp = 0.5d0 * (x + y)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -2.7e-14) {
tmp = x + (Math.abs(y) / 2.0);
} else if (y <= 3e-109) {
tmp = x + (Math.abs(x) / 2.0);
} else {
tmp = 0.5 * (x + y);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -2.7e-14: tmp = x + (math.fabs(y) / 2.0) elif y <= 3e-109: tmp = x + (math.fabs(x) / 2.0) else: tmp = 0.5 * (x + y) return tmp
function code(x, y) tmp = 0.0 if (y <= -2.7e-14) tmp = Float64(x + Float64(abs(y) / 2.0)); elseif (y <= 3e-109) tmp = Float64(x + Float64(abs(x) / 2.0)); else tmp = Float64(0.5 * Float64(x + y)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -2.7e-14) tmp = x + (abs(y) / 2.0); elseif (y <= 3e-109) tmp = x + (abs(x) / 2.0); else tmp = 0.5 * (x + y); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -2.7e-14], N[(x + N[(N[Abs[y], $MachinePrecision] / 2.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 3e-109], N[(x + N[(N[Abs[x], $MachinePrecision] / 2.0), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(x + y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.7 \cdot 10^{-14}:\\
\;\;\;\;x + \frac{\left|y\right|}{2}\\
\mathbf{elif}\;y \leq 3 \cdot 10^{-109}:\\
\;\;\;\;x + \frac{\left|x\right|}{2}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(x + y\right)\\
\end{array}
\end{array}
if y < -2.6999999999999999e-14Initial program 100.0%
Taylor expanded in y around inf 88.0%
if -2.6999999999999999e-14 < y < 3.00000000000000021e-109Initial program 99.9%
Taylor expanded in y around 0 85.4%
neg-mul-185.4%
Simplified85.4%
if 3.00000000000000021e-109 < y Initial program 99.9%
Taylor expanded in x around inf 83.7%
add-sqr-sqrt72.4%
fabs-sqr72.4%
add-sqr-sqrt74.8%
*-commutative74.8%
sub-neg74.8%
metadata-eval74.8%
Applied egg-rr74.8%
Taylor expanded in x around 0 91.2%
distribute-lft-out91.2%
+-commutative91.2%
Simplified91.2%
Final simplification88.1%
(FPCore (x y) :precision binary64 (if (<= y -7.8e-111) (+ x (/ (fabs y) 2.0)) (* 0.5 (+ x y))))
double code(double x, double y) {
double tmp;
if (y <= -7.8e-111) {
tmp = x + (fabs(y) / 2.0);
} 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 <= (-7.8d-111)) then
tmp = x + (abs(y) / 2.0d0)
else
tmp = 0.5d0 * (x + y)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -7.8e-111) {
tmp = x + (Math.abs(y) / 2.0);
} else {
tmp = 0.5 * (x + y);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -7.8e-111: tmp = x + (math.fabs(y) / 2.0) else: tmp = 0.5 * (x + y) return tmp
function code(x, y) tmp = 0.0 if (y <= -7.8e-111) tmp = Float64(x + Float64(abs(y) / 2.0)); else tmp = Float64(0.5 * Float64(x + y)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -7.8e-111) tmp = x + (abs(y) / 2.0); else tmp = 0.5 * (x + y); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -7.8e-111], N[(x + N[(N[Abs[y], $MachinePrecision] / 2.0), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(x + y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -7.8 \cdot 10^{-111}:\\
\;\;\;\;x + \frac{\left|y\right|}{2}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(x + y\right)\\
\end{array}
\end{array}
if y < -7.8000000000000006e-111Initial program 99.9%
Taylor expanded in y around inf 80.2%
if -7.8000000000000006e-111 < y Initial program 99.9%
Taylor expanded in x around inf 91.7%
add-sqr-sqrt58.5%
fabs-sqr58.5%
add-sqr-sqrt64.2%
*-commutative64.2%
sub-neg64.2%
metadata-eval64.2%
Applied egg-rr64.2%
Taylor expanded in x around 0 72.5%
distribute-lft-out72.5%
+-commutative72.5%
Simplified72.5%
Final simplification74.7%
(FPCore (x y) :precision binary64 (if (<= y -7e-70) (* (fabs y) 0.5) (* 0.5 (+ x y))))
double code(double x, double y) {
double tmp;
if (y <= -7e-70) {
tmp = fabs(y) * 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 <= (-7d-70)) then
tmp = abs(y) * 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 <= -7e-70) {
tmp = Math.abs(y) * 0.5;
} else {
tmp = 0.5 * (x + y);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -7e-70: tmp = math.fabs(y) * 0.5 else: tmp = 0.5 * (x + y) return tmp
function code(x, y) tmp = 0.0 if (y <= -7e-70) tmp = Float64(abs(y) * 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 <= -7e-70) tmp = abs(y) * 0.5; else tmp = 0.5 * (x + y); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -7e-70], N[(N[Abs[y], $MachinePrecision] * 0.5), $MachinePrecision], N[(0.5 * N[(x + y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -7 \cdot 10^{-70}:\\
\;\;\;\;\left|y\right| \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(x + y\right)\\
\end{array}
\end{array}
if y < -6.99999999999999949e-70Initial program 99.9%
Taylor expanded in y around inf 84.2%
Taylor expanded in x around 0 81.4%
if -6.99999999999999949e-70 < y Initial program 99.9%
Taylor expanded in x around inf 92.0%
add-sqr-sqrt57.4%
fabs-sqr57.4%
add-sqr-sqrt63.2%
*-commutative63.2%
sub-neg63.2%
metadata-eval63.2%
Applied egg-rr63.2%
Taylor expanded in x around 0 71.2%
distribute-lft-out71.2%
+-commutative71.2%
Simplified71.2%
Final simplification73.8%
(FPCore (x y) :precision binary64 (if (<= y 2.6e-37) (* x 0.5) (* y 0.5)))
double code(double x, double y) {
double tmp;
if (y <= 2.6e-37) {
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 <= 2.6d-37) 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 <= 2.6e-37) {
tmp = x * 0.5;
} else {
tmp = y * 0.5;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 2.6e-37: tmp = x * 0.5 else: tmp = y * 0.5 return tmp
function code(x, y) tmp = 0.0 if (y <= 2.6e-37) 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 <= 2.6e-37) tmp = x * 0.5; else tmp = y * 0.5; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 2.6e-37], N[(x * 0.5), $MachinePrecision], N[(y * 0.5), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 2.6 \cdot 10^{-37}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;y \cdot 0.5\\
\end{array}
\end{array}
if y < 2.5999999999999998e-37Initial program 99.9%
Taylor expanded in x around inf 92.5%
add-sqr-sqrt32.1%
fabs-sqr32.1%
add-sqr-sqrt38.4%
*-commutative38.4%
sub-neg38.4%
metadata-eval38.4%
Applied egg-rr38.4%
Taylor expanded in x around inf 34.2%
if 2.5999999999999998e-37 < y Initial program 99.9%
Taylor expanded in y around inf 79.7%
Taylor expanded in x around 0 76.3%
rem-square-sqrt75.8%
fabs-sqr75.8%
rem-square-sqrt76.3%
Simplified76.3%
Final simplification47.3%
(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%
Taylor expanded in x around inf 88.9%
add-sqr-sqrt44.1%
fabs-sqr44.1%
add-sqr-sqrt49.2%
*-commutative49.2%
sub-neg49.2%
metadata-eval49.2%
Applied egg-rr49.2%
Taylor expanded in x around 0 55.1%
distribute-lft-out55.1%
+-commutative55.1%
Simplified55.1%
Final simplification55.1%
(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%
Taylor expanded in x around inf 88.9%
add-sqr-sqrt44.1%
fabs-sqr44.1%
add-sqr-sqrt49.2%
*-commutative49.2%
sub-neg49.2%
metadata-eval49.2%
Applied egg-rr49.2%
Taylor expanded in x around inf 28.1%
Final simplification28.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 99.9%
Taylor expanded in x around inf 10.9%
herbie shell --seed 2024132
(FPCore (x y)
:name "Graphics.Rendering.Chart.Plot.AreaSpots:renderSpotLegend from Chart-1.5.3"
:precision binary64
(+ x (/ (fabs (- y x)) 2.0)))