
(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 (- 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 -4.2e-78) (* 0.5 (+ x y)) (if (<= x 2.2e+40) (+ x (/ (fabs y) 2.0)) (* x 1.5))))
double code(double x, double y) {
double tmp;
if (x <= -4.2e-78) {
tmp = 0.5 * (x + y);
} else if (x <= 2.2e+40) {
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 <= (-4.2d-78)) then
tmp = 0.5d0 * (x + y)
else if (x <= 2.2d+40) 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 <= -4.2e-78) {
tmp = 0.5 * (x + y);
} else if (x <= 2.2e+40) {
tmp = x + (Math.abs(y) / 2.0);
} else {
tmp = x * 1.5;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -4.2e-78: tmp = 0.5 * (x + y) elif x <= 2.2e+40: tmp = x + (math.fabs(y) / 2.0) else: tmp = x * 1.5 return tmp
function code(x, y) tmp = 0.0 if (x <= -4.2e-78) tmp = Float64(0.5 * Float64(x + y)); elseif (x <= 2.2e+40) 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 <= -4.2e-78) tmp = 0.5 * (x + y); elseif (x <= 2.2e+40) tmp = x + (abs(y) / 2.0); else tmp = x * 1.5; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -4.2e-78], N[(0.5 * N[(x + y), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 2.2e+40], 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 -4.2 \cdot 10^{-78}:\\
\;\;\;\;0.5 \cdot \left(x + y\right)\\
\mathbf{elif}\;x \leq 2.2 \cdot 10^{+40}:\\
\;\;\;\;x + \frac{\left|y\right|}{2}\\
\mathbf{else}:\\
\;\;\;\;x \cdot 1.5\\
\end{array}
\end{array}
if x < -4.2000000000000001e-78Initial 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-sqrt84.7%
fabs-sqr84.7%
rem-square-sqrt85.4%
Simplified85.4%
Taylor expanded in x around 0 85.5%
+-commutative85.5%
distribute-lft-in85.5%
Simplified85.5%
if -4.2000000000000001e-78 < x < 2.1999999999999999e40Initial program 100.0%
Taylor expanded in y around inf 85.3%
if 2.1999999999999999e40 < x Initial program 99.8%
Taylor expanded in y around 0 86.0%
neg-mul-186.0%
Simplified86.0%
Taylor expanded in x around 0 86.0%
+-commutative86.0%
fma-define86.0%
fabs-neg86.0%
rem-square-sqrt85.9%
fabs-sqr85.9%
rem-square-sqrt86.0%
fma-define86.0%
*-lft-identity86.0%
distribute-rgt-out86.0%
metadata-eval86.0%
Simplified86.0%
Final simplification85.5%
(FPCore (x y) :precision binary64 (if (<= x -3.6e-60) (* 0.5 (+ x y)) (if (<= x 7e+40) (fabs (* y 0.5)) (* x 1.5))))
double code(double x, double y) {
double tmp;
if (x <= -3.6e-60) {
tmp = 0.5 * (x + y);
} else if (x <= 7e+40) {
tmp = fabs((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 <= (-3.6d-60)) then
tmp = 0.5d0 * (x + y)
else if (x <= 7d+40) then
tmp = abs((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 <= -3.6e-60) {
tmp = 0.5 * (x + y);
} else if (x <= 7e+40) {
tmp = Math.abs((y * 0.5));
} else {
tmp = x * 1.5;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -3.6e-60: tmp = 0.5 * (x + y) elif x <= 7e+40: tmp = math.fabs((y * 0.5)) else: tmp = x * 1.5 return tmp
function code(x, y) tmp = 0.0 if (x <= -3.6e-60) tmp = Float64(0.5 * Float64(x + y)); elseif (x <= 7e+40) tmp = abs(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 <= -3.6e-60) tmp = 0.5 * (x + y); elseif (x <= 7e+40) tmp = abs((y * 0.5)); else tmp = x * 1.5; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -3.6e-60], N[(0.5 * N[(x + y), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 7e+40], N[Abs[N[(y * 0.5), $MachinePrecision]], $MachinePrecision], N[(x * 1.5), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.6 \cdot 10^{-60}:\\
\;\;\;\;0.5 \cdot \left(x + y\right)\\
\mathbf{elif}\;x \leq 7 \cdot 10^{+40}:\\
\;\;\;\;\left|y \cdot 0.5\right|\\
\mathbf{else}:\\
\;\;\;\;x \cdot 1.5\\
\end{array}
\end{array}
if x < -3.6e-60Initial 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-sqrt84.7%
fabs-sqr84.7%
rem-square-sqrt85.4%
Simplified85.4%
Taylor expanded in x around 0 85.5%
+-commutative85.5%
distribute-lft-in85.5%
Simplified85.5%
if -3.6e-60 < x < 6.9999999999999998e40Initial 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-sqrt37.1%
fabs-sqr37.1%
rem-square-sqrt40.0%
Simplified40.0%
Taylor expanded in x around 0 32.0%
add-sqr-sqrt30.7%
sqrt-unprod51.6%
*-commutative51.6%
*-commutative51.6%
swap-sqr51.6%
pow251.6%
metadata-eval51.6%
Applied egg-rr51.6%
unpow251.6%
metadata-eval51.6%
swap-sqr51.6%
rem-sqrt-square82.9%
*-commutative82.9%
Simplified82.9%
if 6.9999999999999998e40 < x Initial program 99.8%
Taylor expanded in y around 0 86.0%
neg-mul-186.0%
Simplified86.0%
Taylor expanded in x around 0 86.0%
+-commutative86.0%
fma-define86.0%
fabs-neg86.0%
rem-square-sqrt85.9%
fabs-sqr85.9%
rem-square-sqrt86.0%
fma-define86.0%
*-lft-identity86.0%
distribute-rgt-out86.0%
metadata-eval86.0%
Simplified86.0%
Final simplification84.4%
(FPCore (x y) :precision binary64 (if (<= x -1.1e-134) (* x 0.5) (if (<= x 2e-55) (* y 0.5) (* x 1.5))))
double code(double x, double y) {
double tmp;
if (x <= -1.1e-134) {
tmp = x * 0.5;
} else if (x <= 2e-55) {
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.1d-134)) then
tmp = x * 0.5d0
else if (x <= 2d-55) 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.1e-134) {
tmp = x * 0.5;
} else if (x <= 2e-55) {
tmp = y * 0.5;
} else {
tmp = x * 1.5;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -1.1e-134: tmp = x * 0.5 elif x <= 2e-55: tmp = y * 0.5 else: tmp = x * 1.5 return tmp
function code(x, y) tmp = 0.0 if (x <= -1.1e-134) tmp = Float64(x * 0.5); elseif (x <= 2e-55) 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.1e-134) tmp = x * 0.5; elseif (x <= 2e-55) tmp = y * 0.5; else tmp = x * 1.5; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -1.1e-134], N[(x * 0.5), $MachinePrecision], If[LessEqual[x, 2e-55], N[(y * 0.5), $MachinePrecision], N[(x * 1.5), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.1 \cdot 10^{-134}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{elif}\;x \leq 2 \cdot 10^{-55}:\\
\;\;\;\;y \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;x \cdot 1.5\\
\end{array}
\end{array}
if x < -1.1e-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-sqrt79.1%
fabs-sqr79.1%
rem-square-sqrt79.9%
Simplified79.9%
Taylor expanded in x around inf 60.1%
if -1.1e-134 < x < 1.99999999999999999e-55Initial 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-sqrt39.0%
fabs-sqr39.0%
rem-square-sqrt41.1%
Simplified41.1%
Taylor expanded in x around 0 37.0%
if 1.99999999999999999e-55 < x Initial program 99.8%
Taylor expanded in y around 0 76.9%
neg-mul-176.9%
Simplified76.9%
Taylor expanded in x around 0 76.9%
+-commutative76.9%
fma-define76.9%
fabs-neg76.9%
rem-square-sqrt76.8%
fabs-sqr76.8%
rem-square-sqrt76.9%
fma-define76.9%
*-lft-identity76.9%
distribute-rgt-out76.9%
metadata-eval76.9%
Simplified76.9%
Final simplification57.0%
(FPCore (x y) :precision binary64 (if (<= x 4e-56) (* 0.5 (+ x y)) (* x 1.5)))
double code(double x, double y) {
double tmp;
if (x <= 4e-56) {
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 <= 4d-56) 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 <= 4e-56) {
tmp = 0.5 * (x + y);
} else {
tmp = x * 1.5;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= 4e-56: tmp = 0.5 * (x + y) else: tmp = x * 1.5 return tmp
function code(x, y) tmp = 0.0 if (x <= 4e-56) 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 <= 4e-56) tmp = 0.5 * (x + y); else tmp = x * 1.5; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, 4e-56], N[(0.5 * N[(x + y), $MachinePrecision]), $MachinePrecision], N[(x * 1.5), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 4 \cdot 10^{-56}:\\
\;\;\;\;0.5 \cdot \left(x + y\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot 1.5\\
\end{array}
\end{array}
if x < 4.0000000000000002e-56Initial 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-sqrt61.2%
fabs-sqr61.2%
rem-square-sqrt62.6%
Simplified62.6%
Taylor expanded in x around 0 62.6%
+-commutative62.6%
distribute-lft-in62.6%
Simplified62.6%
if 4.0000000000000002e-56 < x Initial program 99.8%
Taylor expanded in y around 0 76.9%
neg-mul-176.9%
Simplified76.9%
Taylor expanded in x around 0 76.9%
+-commutative76.9%
fma-define76.9%
fabs-neg76.9%
rem-square-sqrt76.8%
fabs-sqr76.8%
rem-square-sqrt76.9%
fma-define76.9%
*-lft-identity76.9%
distribute-rgt-out76.9%
metadata-eval76.9%
Simplified76.9%
Final simplification66.4%
(FPCore (x y) :precision binary64 (if (<= y 2.05e-73) (* x 0.5) (* y 0.5)))
double code(double x, double y) {
double tmp;
if (y <= 2.05e-73) {
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.05d-73) 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.05e-73) {
tmp = x * 0.5;
} else {
tmp = y * 0.5;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 2.05e-73: tmp = x * 0.5 else: tmp = y * 0.5 return tmp
function code(x, y) tmp = 0.0 if (y <= 2.05e-73) 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.05e-73) tmp = x * 0.5; else tmp = y * 0.5; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 2.05e-73], N[(x * 0.5), $MachinePrecision], N[(y * 0.5), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 2.05 \cdot 10^{-73}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;y \cdot 0.5\\
\end{array}
\end{array}
if y < 2.05000000000000008e-73Initial 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-sqrt31.0%
fabs-sqr31.0%
rem-square-sqrt36.4%
Simplified36.4%
Taylor expanded in x around inf 36.0%
if 2.05000000000000008e-73 < 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-sqrt85.1%
fabs-sqr85.1%
rem-square-sqrt88.2%
Simplified88.2%
Taylor expanded in x around 0 67.7%
Final simplification45.6%
(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-sqrt47.3%
fabs-sqr47.3%
rem-square-sqrt52.0%
Simplified52.0%
Taylor expanded in x around inf 30.9%
Final simplification30.9%
(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.8%
herbie shell --seed 2024139
(FPCore (x y)
:name "Graphics.Rendering.Chart.Plot.AreaSpots:renderSpotLegend from Chart-1.5.3"
:precision binary64
(+ x (/ (fabs (- y x)) 2.0)))