
(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 -3e-52) (+ x (/ (fabs y) 2.0)) (if (<= y 1.16e-131) (+ x (/ (fabs x) 2.0)) (* 0.5 (+ x y)))))
double code(double x, double y) {
double tmp;
if (y <= -3e-52) {
tmp = x + (fabs(y) / 2.0);
} else if (y <= 1.16e-131) {
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 <= (-3d-52)) then
tmp = x + (abs(y) / 2.0d0)
else if (y <= 1.16d-131) 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 <= -3e-52) {
tmp = x + (Math.abs(y) / 2.0);
} else if (y <= 1.16e-131) {
tmp = x + (Math.abs(x) / 2.0);
} else {
tmp = 0.5 * (x + y);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -3e-52: tmp = x + (math.fabs(y) / 2.0) elif y <= 1.16e-131: tmp = x + (math.fabs(x) / 2.0) else: tmp = 0.5 * (x + y) return tmp
function code(x, y) tmp = 0.0 if (y <= -3e-52) tmp = Float64(x + Float64(abs(y) / 2.0)); elseif (y <= 1.16e-131) 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 <= -3e-52) tmp = x + (abs(y) / 2.0); elseif (y <= 1.16e-131) tmp = x + (abs(x) / 2.0); else tmp = 0.5 * (x + y); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -3e-52], N[(x + N[(N[Abs[y], $MachinePrecision] / 2.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 1.16e-131], 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 -3 \cdot 10^{-52}:\\
\;\;\;\;x + \frac{\left|y\right|}{2}\\
\mathbf{elif}\;y \leq 1.16 \cdot 10^{-131}:\\
\;\;\;\;x + \frac{\left|x\right|}{2}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(x + y\right)\\
\end{array}
\end{array}
if y < -3e-52Initial program 100.0%
Taylor expanded in y around inf 83.8%
if -3e-52 < y < 1.15999999999999993e-131Initial program 99.9%
Taylor expanded in y around 0 86.5%
neg-mul-186.5%
Simplified86.5%
if 1.15999999999999993e-131 < y Initial program 100.0%
Taylor expanded in y around -inf 100.0%
fabs-neg100.0%
mul-1-neg100.0%
sub-neg100.0%
fabs-sub100.0%
rem-square-sqrt80.6%
fabs-sqr80.6%
rem-square-sqrt84.5%
Simplified84.5%
Taylor expanded in x around 0 84.6%
+-commutative84.6%
distribute-lft-in84.6%
Simplified84.6%
Final simplification85.0%
(FPCore (x y) :precision binary64 (if (<= x -6.6e-189) (* 0.5 (+ x y)) (if (<= x 4e+112) (+ x (/ (fabs y) 2.0)) (* x 1.5))))
double code(double x, double y) {
double tmp;
if (x <= -6.6e-189) {
tmp = 0.5 * (x + y);
} else if (x <= 4e+112) {
tmp = x + (fabs(y) / 2.0);
} else {
tmp = x * 1.5;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= (-6.6d-189)) then
tmp = 0.5d0 * (x + y)
else if (x <= 4d+112) then
tmp = x + (abs(y) / 2.0d0)
else
tmp = x * 1.5d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -6.6e-189) {
tmp = 0.5 * (x + y);
} else if (x <= 4e+112) {
tmp = x + (Math.abs(y) / 2.0);
} else {
tmp = x * 1.5;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -6.6e-189: tmp = 0.5 * (x + y) elif x <= 4e+112: tmp = x + (math.fabs(y) / 2.0) else: tmp = x * 1.5 return tmp
function code(x, y) tmp = 0.0 if (x <= -6.6e-189) tmp = Float64(0.5 * Float64(x + y)); elseif (x <= 4e+112) tmp = Float64(x + Float64(abs(y) / 2.0)); else tmp = Float64(x * 1.5); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -6.6e-189) tmp = 0.5 * (x + y); elseif (x <= 4e+112) tmp = x + (abs(y) / 2.0); else tmp = x * 1.5; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -6.6e-189], N[(0.5 * N[(x + y), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 4e+112], N[(x + N[(N[Abs[y], $MachinePrecision] / 2.0), $MachinePrecision]), $MachinePrecision], N[(x * 1.5), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -6.6 \cdot 10^{-189}:\\
\;\;\;\;0.5 \cdot \left(x + y\right)\\
\mathbf{elif}\;x \leq 4 \cdot 10^{+112}:\\
\;\;\;\;x + \frac{\left|y\right|}{2}\\
\mathbf{else}:\\
\;\;\;\;x \cdot 1.5\\
\end{array}
\end{array}
if x < -6.6000000000000002e-189Initial program 100.0%
Taylor expanded in y around -inf 100.0%
fabs-neg100.0%
mul-1-neg100.0%
sub-neg100.0%
fabs-sub100.0%
rem-square-sqrt78.1%
fabs-sqr78.1%
rem-square-sqrt78.9%
Simplified78.9%
Taylor expanded in x around 0 78.9%
+-commutative78.9%
distribute-lft-in78.9%
Simplified78.9%
if -6.6000000000000002e-189 < x < 3.9999999999999997e112Initial program 99.9%
Taylor expanded in y around inf 80.8%
if 3.9999999999999997e112 < x Initial program 99.8%
Taylor expanded in y around 0 80.6%
neg-mul-180.6%
Simplified80.6%
Taylor expanded in x around 0 80.6%
+-commutative80.6%
fma-define80.6%
fabs-neg80.6%
rem-square-sqrt80.5%
fabs-sqr80.5%
rem-square-sqrt80.6%
fma-define80.6%
*-lft-identity80.6%
distribute-rgt-out80.6%
metadata-eval80.6%
Simplified80.6%
Final simplification80.0%
(FPCore (x y) :precision binary64 (if (<= x -2.5e-121) (* x 0.5) (if (<= x 7.6e-134) (* y 0.5) (* x 1.5))))
double code(double x, double y) {
double tmp;
if (x <= -2.5e-121) {
tmp = x * 0.5;
} else if (x <= 7.6e-134) {
tmp = y * 0.5;
} else {
tmp = x * 1.5;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= (-2.5d-121)) then
tmp = x * 0.5d0
else if (x <= 7.6d-134) then
tmp = y * 0.5d0
else
tmp = x * 1.5d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -2.5e-121) {
tmp = x * 0.5;
} else if (x <= 7.6e-134) {
tmp = y * 0.5;
} else {
tmp = x * 1.5;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -2.5e-121: tmp = x * 0.5 elif x <= 7.6e-134: tmp = y * 0.5 else: tmp = x * 1.5 return tmp
function code(x, y) tmp = 0.0 if (x <= -2.5e-121) tmp = Float64(x * 0.5); elseif (x <= 7.6e-134) tmp = Float64(y * 0.5); else tmp = Float64(x * 1.5); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -2.5e-121) tmp = x * 0.5; elseif (x <= 7.6e-134) tmp = y * 0.5; else tmp = x * 1.5; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -2.5e-121], N[(x * 0.5), $MachinePrecision], If[LessEqual[x, 7.6e-134], N[(y * 0.5), $MachinePrecision], N[(x * 1.5), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.5 \cdot 10^{-121}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{elif}\;x \leq 7.6 \cdot 10^{-134}:\\
\;\;\;\;y \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;x \cdot 1.5\\
\end{array}
\end{array}
if x < -2.49999999999999995e-121Initial program 100.0%
Taylor expanded in y around -inf 100.0%
fabs-neg100.0%
mul-1-neg100.0%
sub-neg100.0%
fabs-sub100.0%
rem-square-sqrt77.3%
fabs-sqr77.3%
rem-square-sqrt78.1%
Simplified78.1%
Taylor expanded in x around inf 63.4%
if -2.49999999999999995e-121 < x < 7.60000000000000006e-134Initial program 100.0%
Taylor expanded in y around -inf 100.0%
fabs-neg100.0%
mul-1-neg100.0%
sub-neg100.0%
fabs-sub100.0%
rem-square-sqrt60.9%
fabs-sqr60.9%
rem-square-sqrt62.6%
Simplified62.6%
Taylor expanded in x around 0 52.0%
if 7.60000000000000006e-134 < x Initial program 99.8%
Taylor expanded in y around 0 59.4%
neg-mul-159.4%
Simplified59.4%
Taylor expanded in x around 0 59.4%
+-commutative59.4%
fma-define59.4%
fabs-neg59.4%
rem-square-sqrt59.3%
fabs-sqr59.3%
rem-square-sqrt59.4%
fma-define59.4%
*-lft-identity59.4%
distribute-rgt-out59.4%
metadata-eval59.4%
Simplified59.4%
Final simplification58.8%
(FPCore (x y) :precision binary64 (if (<= x 8.5e-134) (* 0.5 (+ x y)) (* x 1.5)))
double code(double x, double y) {
double tmp;
if (x <= 8.5e-134) {
tmp = 0.5 * (x + y);
} else {
tmp = x * 1.5;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= 8.5d-134) then
tmp = 0.5d0 * (x + y)
else
tmp = x * 1.5d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= 8.5e-134) {
tmp = 0.5 * (x + y);
} else {
tmp = x * 1.5;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= 8.5e-134: tmp = 0.5 * (x + y) else: tmp = x * 1.5 return tmp
function code(x, y) tmp = 0.0 if (x <= 8.5e-134) tmp = Float64(0.5 * Float64(x + y)); else tmp = Float64(x * 1.5); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= 8.5e-134) tmp = 0.5 * (x + y); else tmp = x * 1.5; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, 8.5e-134], N[(0.5 * N[(x + y), $MachinePrecision]), $MachinePrecision], N[(x * 1.5), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 8.5 \cdot 10^{-134}:\\
\;\;\;\;0.5 \cdot \left(x + y\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot 1.5\\
\end{array}
\end{array}
if x < 8.50000000000000015e-134Initial program 100.0%
Taylor expanded in y around -inf 100.0%
fabs-neg100.0%
mul-1-neg100.0%
sub-neg100.0%
fabs-sub100.0%
rem-square-sqrt70.3%
fabs-sqr70.3%
rem-square-sqrt71.5%
Simplified71.5%
Taylor expanded in x around 0 71.5%
+-commutative71.5%
distribute-lft-in71.5%
Simplified71.5%
if 8.50000000000000015e-134 < x Initial program 99.8%
Taylor expanded in y around 0 59.4%
neg-mul-159.4%
Simplified59.4%
Taylor expanded in x around 0 59.4%
+-commutative59.4%
fma-define59.4%
fabs-neg59.4%
rem-square-sqrt59.3%
fabs-sqr59.3%
rem-square-sqrt59.4%
fma-define59.4%
*-lft-identity59.4%
distribute-rgt-out59.4%
metadata-eval59.4%
Simplified59.4%
Final simplification67.2%
(FPCore (x y) :precision binary64 (if (<= y 1.95e-94) (* x 0.5) (* y 0.5)))
double code(double x, double y) {
double tmp;
if (y <= 1.95e-94) {
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.95d-94) 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.95e-94) {
tmp = x * 0.5;
} else {
tmp = y * 0.5;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 1.95e-94: tmp = x * 0.5 else: tmp = y * 0.5 return tmp
function code(x, y) tmp = 0.0 if (y <= 1.95e-94) 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.95e-94) tmp = x * 0.5; else tmp = y * 0.5; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 1.95e-94], N[(x * 0.5), $MachinePrecision], N[(y * 0.5), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.95 \cdot 10^{-94}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;y \cdot 0.5\\
\end{array}
\end{array}
if y < 1.9500000000000001e-94Initial program 99.9%
Taylor expanded in y around -inf 99.9%
fabs-neg99.9%
mul-1-neg99.9%
sub-neg99.9%
fabs-sub99.9%
rem-square-sqrt36.4%
fabs-sqr36.4%
rem-square-sqrt41.1%
Simplified41.1%
Taylor expanded in x around inf 38.7%
if 1.9500000000000001e-94 < y Initial program 99.9%
Taylor expanded in y around -inf 99.9%
fabs-neg99.9%
mul-1-neg99.9%
sub-neg99.9%
fabs-sub99.9%
rem-square-sqrt79.8%
fabs-sqr79.8%
rem-square-sqrt83.9%
Simplified83.9%
Taylor expanded in x around 0 69.2%
Final simplification49.0%
(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 y around -inf 99.9%
fabs-neg99.9%
mul-1-neg99.9%
sub-neg99.9%
fabs-sub99.9%
rem-square-sqrt51.1%
fabs-sqr51.1%
rem-square-sqrt55.6%
Simplified55.6%
Taylor expanded in x around inf 31.4%
Final simplification31.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.0%
herbie shell --seed 2024144
(FPCore (x y)
:name "Graphics.Rendering.Chart.Plot.AreaSpots:renderSpotLegend from Chart-1.5.3"
:precision binary64
(+ x (/ (fabs (- y x)) 2.0)))