
(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 7 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%
(FPCore (x y) :precision binary64 (if (<= x -9.5e-164) (* 0.5 (+ x y)) (if (<= x 2.55e+113) (+ x (/ (fabs y) 2.0)) (* x 1.5))))
double code(double x, double y) {
double tmp;
if (x <= -9.5e-164) {
tmp = 0.5 * (x + y);
} else if (x <= 2.55e+113) {
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 <= (-9.5d-164)) then
tmp = 0.5d0 * (x + y)
else if (x <= 2.55d+113) 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 <= -9.5e-164) {
tmp = 0.5 * (x + y);
} else if (x <= 2.55e+113) {
tmp = x + (Math.abs(y) / 2.0);
} else {
tmp = x * 1.5;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -9.5e-164: tmp = 0.5 * (x + y) elif x <= 2.55e+113: tmp = x + (math.fabs(y) / 2.0) else: tmp = x * 1.5 return tmp
function code(x, y) tmp = 0.0 if (x <= -9.5e-164) tmp = Float64(0.5 * Float64(x + y)); elseif (x <= 2.55e+113) 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 <= -9.5e-164) tmp = 0.5 * (x + y); elseif (x <= 2.55e+113) tmp = x + (abs(y) / 2.0); else tmp = x * 1.5; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -9.5e-164], N[(0.5 * N[(x + y), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 2.55e+113], 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 -9.5 \cdot 10^{-164}:\\
\;\;\;\;0.5 \cdot \left(x + y\right)\\
\mathbf{elif}\;x \leq 2.55 \cdot 10^{+113}:\\
\;\;\;\;x + \frac{\left|y\right|}{2}\\
\mathbf{else}:\\
\;\;\;\;x \cdot 1.5\\
\end{array}
\end{array}
if x < -9.5000000000000001e-164Initial program 100.0%
Taylor expanded in x around inf 97.9%
+-commutative97.9%
sub-neg97.9%
neg-mul-197.9%
fma-define97.9%
neg-mul-197.9%
sub-neg97.9%
rem-square-sqrt85.4%
fabs-sqr85.4%
rem-square-sqrt86.0%
Simplified86.0%
Taylor expanded in x around 0 87.1%
distribute-lft-out87.1%
+-commutative87.1%
Simplified87.1%
if -9.5000000000000001e-164 < x < 2.54999999999999997e113Initial program 99.9%
Taylor expanded in y around inf 79.5%
if 2.54999999999999997e113 < x Initial program 99.7%
Taylor expanded in y around 0 88.7%
neg-mul-188.7%
Simplified88.7%
Taylor expanded in x around 0 88.7%
*-commutative88.7%
fabs-neg88.7%
rem-square-sqrt88.7%
fabs-sqr88.7%
rem-square-sqrt88.7%
*-rgt-identity88.7%
distribute-lft-out88.7%
metadata-eval88.7%
Simplified88.7%
Final simplification83.6%
(FPCore (x y) :precision binary64 (if (<= x -1.12e-163) (* x 0.5) (if (<= x 7e-83) (* y 0.5) (* x 1.5))))
double code(double x, double y) {
double tmp;
if (x <= -1.12e-163) {
tmp = x * 0.5;
} else if (x <= 7e-83) {
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 <= (-1.12d-163)) then
tmp = x * 0.5d0
else if (x <= 7d-83) 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 <= -1.12e-163) {
tmp = x * 0.5;
} else if (x <= 7e-83) {
tmp = y * 0.5;
} else {
tmp = x * 1.5;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -1.12e-163: tmp = x * 0.5 elif x <= 7e-83: tmp = y * 0.5 else: tmp = x * 1.5 return tmp
function code(x, y) tmp = 0.0 if (x <= -1.12e-163) tmp = Float64(x * 0.5); elseif (x <= 7e-83) 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 <= -1.12e-163) tmp = x * 0.5; elseif (x <= 7e-83) tmp = y * 0.5; else tmp = x * 1.5; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -1.12e-163], N[(x * 0.5), $MachinePrecision], If[LessEqual[x, 7e-83], N[(y * 0.5), $MachinePrecision], N[(x * 1.5), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.12 \cdot 10^{-163}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{elif}\;x \leq 7 \cdot 10^{-83}:\\
\;\;\;\;y \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;x \cdot 1.5\\
\end{array}
\end{array}
if x < -1.12e-163Initial program 100.0%
Taylor expanded in x around inf 97.9%
+-commutative97.9%
sub-neg97.9%
neg-mul-197.9%
fma-define97.9%
neg-mul-197.9%
sub-neg97.9%
rem-square-sqrt85.4%
fabs-sqr85.4%
rem-square-sqrt86.0%
Simplified86.0%
Taylor expanded in y around 0 70.6%
if -1.12e-163 < x < 7.00000000000000061e-83Initial program 99.9%
Taylor expanded in y around inf 89.4%
add-sqr-sqrt88.7%
associate-/l*88.7%
add-sqr-sqrt40.0%
fabs-sqr40.0%
add-sqr-sqrt40.0%
add-sqr-sqrt40.0%
fabs-sqr40.0%
add-sqr-sqrt40.0%
Applied egg-rr40.0%
associate-*r/40.0%
rem-square-sqrt42.5%
Simplified42.5%
Taylor expanded in y around inf 42.5%
Taylor expanded in x around 0 41.1%
if 7.00000000000000061e-83 < x Initial program 99.8%
Taylor expanded in y around 0 69.3%
neg-mul-169.3%
Simplified69.3%
Taylor expanded in x around 0 69.3%
*-commutative69.3%
fabs-neg69.3%
rem-square-sqrt69.3%
fabs-sqr69.3%
rem-square-sqrt69.3%
*-rgt-identity69.3%
distribute-lft-out69.3%
metadata-eval69.3%
Simplified69.3%
(FPCore (x y) :precision binary64 (if (<= x 3.3e-83) (* 0.5 (+ x y)) (* x 1.5)))
double code(double x, double y) {
double tmp;
if (x <= 3.3e-83) {
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 <= 3.3d-83) 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 <= 3.3e-83) {
tmp = 0.5 * (x + y);
} else {
tmp = x * 1.5;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= 3.3e-83: tmp = 0.5 * (x + y) else: tmp = x * 1.5 return tmp
function code(x, y) tmp = 0.0 if (x <= 3.3e-83) 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 <= 3.3e-83) tmp = 0.5 * (x + y); else tmp = x * 1.5; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, 3.3e-83], N[(0.5 * N[(x + y), $MachinePrecision]), $MachinePrecision], N[(x * 1.5), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 3.3 \cdot 10^{-83}:\\
\;\;\;\;0.5 \cdot \left(x + y\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot 1.5\\
\end{array}
\end{array}
if x < 3.2999999999999999e-83Initial program 100.0%
Taylor expanded in x around inf 85.0%
+-commutative85.0%
sub-neg85.0%
neg-mul-185.0%
fma-define85.0%
neg-mul-185.0%
sub-neg85.0%
rem-square-sqrt61.0%
fabs-sqr61.0%
rem-square-sqrt62.3%
Simplified62.3%
Taylor expanded in x around 0 67.7%
distribute-lft-out67.7%
+-commutative67.7%
Simplified67.7%
if 3.2999999999999999e-83 < x Initial program 99.8%
Taylor expanded in y around 0 69.3%
neg-mul-169.3%
Simplified69.3%
Taylor expanded in x around 0 69.3%
*-commutative69.3%
fabs-neg69.3%
rem-square-sqrt69.3%
fabs-sqr69.3%
rem-square-sqrt69.3%
*-rgt-identity69.3%
distribute-lft-out69.3%
metadata-eval69.3%
Simplified69.3%
Final simplification68.2%
(FPCore (x y) :precision binary64 (if (<= x -5e-310) (* x 0.5) (* x 1.5)))
double code(double x, double y) {
double tmp;
if (x <= -5e-310) {
tmp = x * 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 <= (-5d-310)) then
tmp = x * 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 <= -5e-310) {
tmp = x * 0.5;
} else {
tmp = x * 1.5;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -5e-310: tmp = x * 0.5 else: tmp = x * 1.5 return tmp
function code(x, y) tmp = 0.0 if (x <= -5e-310) tmp = Float64(x * 0.5); else tmp = Float64(x * 1.5); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -5e-310) tmp = x * 0.5; else tmp = x * 1.5; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -5e-310], N[(x * 0.5), $MachinePrecision], N[(x * 1.5), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5 \cdot 10^{-310}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;x \cdot 1.5\\
\end{array}
\end{array}
if x < -4.999999999999985e-310Initial program 100.0%
Taylor expanded in x around inf 88.1%
+-commutative88.1%
sub-neg88.1%
neg-mul-188.1%
fma-define88.1%
neg-mul-188.1%
sub-neg88.1%
rem-square-sqrt72.3%
fabs-sqr72.3%
rem-square-sqrt73.0%
Simplified73.0%
Taylor expanded in y around 0 53.8%
if -4.999999999999985e-310 < x Initial program 99.8%
Taylor expanded in y around 0 48.3%
neg-mul-148.3%
Simplified48.3%
Taylor expanded in x around 0 48.3%
*-commutative48.3%
fabs-neg48.3%
rem-square-sqrt48.3%
fabs-sqr48.3%
rem-square-sqrt48.3%
*-rgt-identity48.3%
distribute-lft-out48.3%
metadata-eval48.3%
Simplified48.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%
Taylor expanded in x around inf 89.6%
+-commutative89.6%
sub-neg89.6%
neg-mul-189.6%
fma-define89.6%
neg-mul-189.6%
sub-neg89.6%
rem-square-sqrt45.6%
fabs-sqr45.6%
rem-square-sqrt50.4%
Simplified50.4%
Taylor expanded in y around 0 32.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 11.6%
herbie shell --seed 2024186
(FPCore (x y)
:name "Graphics.Rendering.Chart.Plot.AreaSpots:renderSpotLegend from Chart-1.5.3"
:precision binary64
(+ x (/ (fabs (- y x)) 2.0)))