
(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 (+ x y) (* 0.5 (/ (fabs (- y x)) (+ x y))) x))
double code(double x, double y) {
return fma((x + y), (0.5 * (fabs((y - x)) / (x + y))), x);
}
function code(x, y) return fma(Float64(x + y), Float64(0.5 * Float64(abs(Float64(y - x)) / Float64(x + y))), x) end
code[x_, y_] := N[(N[(x + y), $MachinePrecision] * N[(0.5 * N[(N[Abs[N[(y - x), $MachinePrecision]], $MachinePrecision] / N[(x + y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x + y, 0.5 \cdot \frac{\left|y - x\right|}{x + y}, x\right)
\end{array}
Initial program 99.9%
lift--.f64N/A
flip--N/A
difference-of-squaresN/A
lift--.f64N/A
associate-/l*N/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-/.f64N/A
+-commutativeN/A
lower-+.f6499.9
Applied rewrites99.9%
lift-+.f64N/A
+-commutativeN/A
Applied rewrites99.9%
Final simplification99.9%
(FPCore (x y) :precision binary64 (let* ((t_0 (fabs (- y x)))) (if (<= (+ (/ t_0 2.0) x) 5e-260) (* 0.75 x) (* t_0 0.5))))
double code(double x, double y) {
double t_0 = fabs((y - x));
double tmp;
if (((t_0 / 2.0) + x) <= 5e-260) {
tmp = 0.75 * x;
} else {
tmp = t_0 * 0.5;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: t_0
real(8) :: tmp
t_0 = abs((y - x))
if (((t_0 / 2.0d0) + x) <= 5d-260) then
tmp = 0.75d0 * x
else
tmp = t_0 * 0.5d0
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = Math.abs((y - x));
double tmp;
if (((t_0 / 2.0) + x) <= 5e-260) {
tmp = 0.75 * x;
} else {
tmp = t_0 * 0.5;
}
return tmp;
}
def code(x, y): t_0 = math.fabs((y - x)) tmp = 0 if ((t_0 / 2.0) + x) <= 5e-260: tmp = 0.75 * x else: tmp = t_0 * 0.5 return tmp
function code(x, y) t_0 = abs(Float64(y - x)) tmp = 0.0 if (Float64(Float64(t_0 / 2.0) + x) <= 5e-260) tmp = Float64(0.75 * x); else tmp = Float64(t_0 * 0.5); end return tmp end
function tmp_2 = code(x, y) t_0 = abs((y - x)); tmp = 0.0; if (((t_0 / 2.0) + x) <= 5e-260) tmp = 0.75 * x; else tmp = t_0 * 0.5; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[Abs[N[(y - x), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[N[(N[(t$95$0 / 2.0), $MachinePrecision] + x), $MachinePrecision], 5e-260], N[(0.75 * x), $MachinePrecision], N[(t$95$0 * 0.5), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left|y - x\right|\\
\mathbf{if}\;\frac{t\_0}{2} + x \leq 5 \cdot 10^{-260}:\\
\;\;\;\;0.75 \cdot x\\
\mathbf{else}:\\
\;\;\;\;t\_0 \cdot 0.5\\
\end{array}
\end{array}
if (+.f64 x (/.f64 (fabs.f64 (-.f64 y x)) #s(literal 2 binary64))) < 5.0000000000000003e-260Initial program 100.0%
Applied rewrites42.1%
Taylor expanded in x around inf
lower-*.f6420.0
Applied rewrites20.0%
if 5.0000000000000003e-260 < (+.f64 x (/.f64 (fabs.f64 (-.f64 y x)) #s(literal 2 binary64))) Initial program 99.9%
Taylor expanded in x around 0
*-commutativeN/A
sub-negN/A
mul-1-negN/A
lower-*.f64N/A
mul-1-negN/A
remove-double-negN/A
mul-1-negN/A
distribute-neg-inN/A
+-commutativeN/A
lower-fabs.f64N/A
+-commutativeN/A
distribute-neg-inN/A
mul-1-negN/A
remove-double-negN/A
sub-negN/A
lower--.f6468.4
Applied rewrites68.4%
Final simplification55.3%
(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%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
div-invN/A
lower-fma.f64N/A
lift-fabs.f64N/A
neg-fabsN/A
lower-fabs.f64N/A
lift--.f64N/A
sub-negN/A
+-commutativeN/A
distribute-neg-inN/A
remove-double-negN/A
sub-negN/A
lower--.f64N/A
metadata-eval99.9
Applied rewrites99.9%
Final simplification99.9%
(FPCore (x y) :precision binary64 (fma (fabs (- y)) 0.5 x))
double code(double x, double y) {
return fma(fabs(-y), 0.5, x);
}
function code(x, y) return fma(abs(Float64(-y)), 0.5, x) end
code[x_, y_] := N[(N[Abs[(-y)], $MachinePrecision] * 0.5 + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\left|-y\right|, 0.5, x\right)
\end{array}
Initial program 99.9%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
div-invN/A
lower-fma.f64N/A
lift-fabs.f64N/A
neg-fabsN/A
lower-fabs.f64N/A
lift--.f64N/A
sub-negN/A
+-commutativeN/A
distribute-neg-inN/A
remove-double-negN/A
sub-negN/A
lower--.f64N/A
metadata-eval99.9
Applied rewrites99.9%
Taylor expanded in y around inf
mul-1-negN/A
lower-neg.f6455.6
Applied rewrites55.6%
(FPCore (x y) :precision binary64 (* 1.0 x))
double code(double x, double y) {
return 1.0 * x;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 1.0d0 * x
end function
public static double code(double x, double y) {
return 1.0 * x;
}
def code(x, y): return 1.0 * x
function code(x, y) return Float64(1.0 * x) end
function tmp = code(x, y) tmp = 1.0 * x; end
code[x_, y_] := N[(1.0 * x), $MachinePrecision]
\begin{array}{l}
\\
1 \cdot x
\end{array}
Initial program 99.9%
Taylor expanded in x around 0
*-commutativeN/A
sub-negN/A
mul-1-negN/A
lower-*.f64N/A
mul-1-negN/A
remove-double-negN/A
mul-1-negN/A
distribute-neg-inN/A
+-commutativeN/A
lower-fabs.f64N/A
+-commutativeN/A
distribute-neg-inN/A
mul-1-negN/A
remove-double-negN/A
sub-negN/A
lower--.f6450.2
Applied rewrites50.2%
Taylor expanded in x around inf
*-commutativeN/A
fabs-subN/A
lower-*.f64N/A
+-commutativeN/A
associate-*r/N/A
*-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
fabs-subN/A
sub-negN/A
mul-1-negN/A
lower-fabs.f64N/A
mul-1-negN/A
sub-negN/A
lower--.f64N/A
lower-/.f6486.1
Applied rewrites86.1%
Taylor expanded in x around inf
Applied rewrites12.0%
herbie shell --seed 2024235
(FPCore (x y)
:name "Graphics.Rendering.Chart.Plot.AreaSpots:renderSpotLegend from Chart-1.5.3"
:precision binary64
(+ x (/ (fabs (- y x)) 2.0)))