
(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 5 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 (fma (fabs (- y x)) 0.5 x))
double code(double x, double y) {
return fma(fabs((y - x)), 0.5, x);
}
function code(x, y) return fma(abs(Float64(y - x)), 0.5, x) end
code[x_, y_] := N[(N[Abs[N[(y - x), $MachinePrecision]], $MachinePrecision] * 0.5 + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\left|y - x\right|, 0.5, x\right)
\end{array}
Initial program 99.9%
+-commutativeN/A
div-invN/A
accelerator-lowering-fma.f64N/A
fabs-lowering-fabs.f64N/A
--lowering--.f64N/A
metadata-eval99.9
Applied egg-rr99.9%
(FPCore (x y) :precision binary64 (if (<= (+ x (/ (fabs (- y x)) 2.0)) -5e-198) (* x 0.75) (* 0.5 (fabs y))))
double code(double x, double y) {
double tmp;
if ((x + (fabs((y - x)) / 2.0)) <= -5e-198) {
tmp = x * 0.75;
} else {
tmp = 0.5 * fabs(y);
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((x + (abs((y - x)) / 2.0d0)) <= (-5d-198)) then
tmp = x * 0.75d0
else
tmp = 0.5d0 * abs(y)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x + (Math.abs((y - x)) / 2.0)) <= -5e-198) {
tmp = x * 0.75;
} else {
tmp = 0.5 * Math.abs(y);
}
return tmp;
}
def code(x, y): tmp = 0 if (x + (math.fabs((y - x)) / 2.0)) <= -5e-198: tmp = x * 0.75 else: tmp = 0.5 * math.fabs(y) return tmp
function code(x, y) tmp = 0.0 if (Float64(x + Float64(abs(Float64(y - x)) / 2.0)) <= -5e-198) tmp = Float64(x * 0.75); else tmp = Float64(0.5 * abs(y)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x + (abs((y - x)) / 2.0)) <= -5e-198) tmp = x * 0.75; else tmp = 0.5 * abs(y); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[N[(x + N[(N[Abs[N[(y - x), $MachinePrecision]], $MachinePrecision] / 2.0), $MachinePrecision]), $MachinePrecision], -5e-198], N[(x * 0.75), $MachinePrecision], N[(0.5 * N[Abs[y], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x + \frac{\left|y - x\right|}{2} \leq -5 \cdot 10^{-198}:\\
\;\;\;\;x \cdot 0.75\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left|y\right|\\
\end{array}
\end{array}
if (+.f64 x (/.f64 (fabs.f64 (-.f64 y x)) #s(literal 2 binary64))) < -4.9999999999999999e-198Initial program 100.0%
flip-+N/A
/-lowering-/.f64N/A
Applied egg-rr52.4%
Taylor expanded in x around inf
*-commutativeN/A
*-lowering-*.f6420.0
Simplified20.0%
if -4.9999999999999999e-198 < (+.f64 x (/.f64 (fabs.f64 (-.f64 y x)) #s(literal 2 binary64))) Initial program 99.9%
Taylor expanded in x around 0
sub-negN/A
mul-1-negN/A
*-lowering-*.f64N/A
mul-1-negN/A
remove-double-negN/A
mul-1-negN/A
distribute-neg-inN/A
+-commutativeN/A
fabs-lowering-fabs.f64N/A
+-commutativeN/A
distribute-neg-inN/A
mul-1-negN/A
remove-double-negN/A
sub-negN/A
--lowering--.f6469.7
Simplified69.7%
Taylor expanded in y around inf
Simplified65.2%
(FPCore (x y) :precision binary64 (let* ((t_0 (fma 0.5 (fabs x) x))) (if (<= x -5.5e+15) t_0 (if (<= x 1.12e-39) (fma (fabs y) 0.5 x) t_0))))
double code(double x, double y) {
double t_0 = fma(0.5, fabs(x), x);
double tmp;
if (x <= -5.5e+15) {
tmp = t_0;
} else if (x <= 1.12e-39) {
tmp = fma(fabs(y), 0.5, x);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y) t_0 = fma(0.5, abs(x), x) tmp = 0.0 if (x <= -5.5e+15) tmp = t_0; elseif (x <= 1.12e-39) tmp = fma(abs(y), 0.5, x); else tmp = t_0; end return tmp end
code[x_, y_] := Block[{t$95$0 = N[(0.5 * N[Abs[x], $MachinePrecision] + x), $MachinePrecision]}, If[LessEqual[x, -5.5e+15], t$95$0, If[LessEqual[x, 1.12e-39], N[(N[Abs[y], $MachinePrecision] * 0.5 + x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(0.5, \left|x\right|, x\right)\\
\mathbf{if}\;x \leq -5.5 \cdot 10^{+15}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 1.12 \cdot 10^{-39}:\\
\;\;\;\;\mathsf{fma}\left(\left|y\right|, 0.5, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -5.5e15 or 1.12e-39 < x Initial program 99.9%
+-commutativeN/A
div-invN/A
accelerator-lowering-fma.f64N/A
fabs-lowering-fabs.f64N/A
--lowering--.f64N/A
metadata-eval99.9
Applied egg-rr99.9%
Taylor expanded in x around inf
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
accelerator-lowering-fma.f64N/A
*-commutativeN/A
associate-*l/N/A
associate-/l*N/A
*-lowering-*.f64N/A
fabs-lowering-fabs.f64N/A
--lowering--.f64N/A
/-lowering-/.f6499.7
Simplified99.7%
Taylor expanded in y around 0
mul-1-negN/A
neg-lowering-neg.f6480.7
Simplified80.7%
Taylor expanded in x around 0
+-commutativeN/A
accelerator-lowering-fma.f64N/A
fabs-negN/A
fabs-lowering-fabs.f6480.8
Simplified80.8%
if -5.5e15 < x < 1.12e-39Initial program 100.0%
+-commutativeN/A
div-invN/A
accelerator-lowering-fma.f64N/A
fabs-lowering-fabs.f64N/A
--lowering--.f64N/A
metadata-eval100.0
Applied egg-rr100.0%
Taylor expanded in y around inf
Simplified83.9%
(FPCore (x y) :precision binary64 (let* ((t_0 (fma 0.5 (fabs x) x))) (if (<= x -1.9e+16) t_0 (if (<= x 1.22e-58) (* 0.5 (fabs y)) t_0))))
double code(double x, double y) {
double t_0 = fma(0.5, fabs(x), x);
double tmp;
if (x <= -1.9e+16) {
tmp = t_0;
} else if (x <= 1.22e-58) {
tmp = 0.5 * fabs(y);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y) t_0 = fma(0.5, abs(x), x) tmp = 0.0 if (x <= -1.9e+16) tmp = t_0; elseif (x <= 1.22e-58) tmp = Float64(0.5 * abs(y)); else tmp = t_0; end return tmp end
code[x_, y_] := Block[{t$95$0 = N[(0.5 * N[Abs[x], $MachinePrecision] + x), $MachinePrecision]}, If[LessEqual[x, -1.9e+16], t$95$0, If[LessEqual[x, 1.22e-58], N[(0.5 * N[Abs[y], $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(0.5, \left|x\right|, x\right)\\
\mathbf{if}\;x \leq -1.9 \cdot 10^{+16}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 1.22 \cdot 10^{-58}:\\
\;\;\;\;0.5 \cdot \left|y\right|\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -1.9e16 or 1.2199999999999999e-58 < x Initial program 99.9%
+-commutativeN/A
div-invN/A
accelerator-lowering-fma.f64N/A
fabs-lowering-fabs.f64N/A
--lowering--.f64N/A
metadata-eval99.9
Applied egg-rr99.9%
Taylor expanded in x around inf
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
accelerator-lowering-fma.f64N/A
*-commutativeN/A
associate-*l/N/A
associate-/l*N/A
*-lowering-*.f64N/A
fabs-lowering-fabs.f64N/A
--lowering--.f64N/A
/-lowering-/.f6499.7
Simplified99.7%
Taylor expanded in y around 0
mul-1-negN/A
neg-lowering-neg.f6479.9
Simplified79.9%
Taylor expanded in x around 0
+-commutativeN/A
accelerator-lowering-fma.f64N/A
fabs-negN/A
fabs-lowering-fabs.f6480.0
Simplified80.0%
if -1.9e16 < x < 1.2199999999999999e-58Initial program 100.0%
Taylor expanded in x around 0
sub-negN/A
mul-1-negN/A
*-lowering-*.f64N/A
mul-1-negN/A
remove-double-negN/A
mul-1-negN/A
distribute-neg-inN/A
+-commutativeN/A
fabs-lowering-fabs.f64N/A
+-commutativeN/A
distribute-neg-inN/A
mul-1-negN/A
remove-double-negN/A
sub-negN/A
--lowering--.f6482.8
Simplified82.8%
Taylor expanded in y around inf
Simplified82.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
Simplified11.3%
herbie shell --seed 2024205
(FPCore (x y)
:name "Graphics.Rendering.Chart.Plot.AreaSpots:renderSpotLegend from Chart-1.5.3"
:precision binary64
(+ x (/ (fabs (- y x)) 2.0)))