
(FPCore (x y) :precision binary64 (* (+ x y) 0.5))
double code(double x, double y) {
return (x + y) * 0.5;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (x + y) * 0.5d0
end function
public static double code(double x, double y) {
return (x + y) * 0.5;
}
def code(x, y): return (x + y) * 0.5
function code(x, y) return Float64(Float64(x + y) * 0.5) end
function tmp = code(x, y) tmp = (x + y) * 0.5; end
code[x_, y_] := N[(N[(x + y), $MachinePrecision] * 0.5), $MachinePrecision]
\left(x + y\right) \cdot 0.5
Herbie found 3 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (* (+ x y) 0.5))
double code(double x, double y) {
return (x + y) * 0.5;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (x + y) * 0.5d0
end function
public static double code(double x, double y) {
return (x + y) * 0.5;
}
def code(x, y): return (x + y) * 0.5
function code(x, y) return Float64(Float64(x + y) * 0.5) end
function tmp = code(x, y) tmp = (x + y) * 0.5; end
code[x_, y_] := N[(N[(x + y), $MachinePrecision] * 0.5), $MachinePrecision]
\left(x + y\right) \cdot 0.5
(FPCore (x y) :precision binary64 (if (<= (* (+ (fmin x y) (fmax x y)) 0.5) -5e-294) (* 0.5 (fmin x y)) (* (fmax x y) 0.5)))
double code(double x, double y) {
double tmp;
if (((fmin(x, y) + fmax(x, y)) * 0.5) <= -5e-294) {
tmp = 0.5 * fmin(x, y);
} else {
tmp = fmax(x, 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 (((merge(y, merge(x, min(x, y), y /= y), x /= x) + merge(y, merge(x, max(x, y), y /= y), x /= x)) * 0.5d0) <= (-5d-294)) then
tmp = 0.5d0 * merge(y, merge(x, min(x, y), y /= y), x /= x)
else
tmp = merge(y, merge(x, max(x, y), y /= y), x /= x) * 0.5d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (((fmin(x, y) + fmax(x, y)) * 0.5) <= -5e-294) {
tmp = 0.5 * fmin(x, y);
} else {
tmp = fmax(x, y) * 0.5;
}
return tmp;
}
def code(x, y): tmp = 0 if ((fmin(x, y) + fmax(x, y)) * 0.5) <= -5e-294: tmp = 0.5 * fmin(x, y) else: tmp = fmax(x, y) * 0.5 return tmp
function code(x, y) tmp = 0.0 if (Float64(Float64(((x != x) ? y : ((y != y) ? x : min(x, y))) + ((x != x) ? y : ((y != y) ? x : max(x, y)))) * 0.5) <= -5e-294) tmp = Float64(0.5 * ((x != x) ? y : ((y != y) ? x : min(x, y)))); else tmp = Float64(((x != x) ? y : ((y != y) ? x : max(x, y))) * 0.5); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (((min(x, y) + max(x, y)) * 0.5) <= -5e-294) tmp = 0.5 * min(x, y); else tmp = max(x, y) * 0.5; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[N[(N[(N[Min[x, y], $MachinePrecision] + N[Max[x, y], $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision], -5e-294], N[(0.5 * N[Min[x, y], $MachinePrecision]), $MachinePrecision], N[(N[Max[x, y], $MachinePrecision] * 0.5), $MachinePrecision]]
\begin{array}{l}
\mathbf{if}\;\left(\mathsf{min}\left(x, y\right) + \mathsf{max}\left(x, y\right)\right) \cdot 0.5 \leq -5 \cdot 10^{-294}:\\
\;\;\;\;0.5 \cdot \mathsf{min}\left(x, y\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{max}\left(x, y\right) \cdot 0.5\\
\end{array}
if (*.f64 (+.f64 x y) #s(literal 1/2 binary64)) < -5.0000000000000003e-294Initial program 100.0%
Taylor expanded in x around inf
lower-*.f6451.7%
Applied rewrites51.7%
if -5.0000000000000003e-294 < (*.f64 (+.f64 x y) #s(literal 1/2 binary64)) Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites49.1%
(FPCore (x y) :precision binary64 (* 0.5 (fmin x y)))
double code(double x, double y) {
return 0.5 * fmin(x, y);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 0.5d0 * merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
public static double code(double x, double y) {
return 0.5 * fmin(x, y);
}
def code(x, y): return 0.5 * fmin(x, y)
function code(x, y) return Float64(0.5 * ((x != x) ? y : ((y != y) ? x : min(x, y)))) end
function tmp = code(x, y) tmp = 0.5 * min(x, y); end
code[x_, y_] := N[(0.5 * N[Min[x, y], $MachinePrecision]), $MachinePrecision]
0.5 \cdot \mathsf{min}\left(x, y\right)
Initial program 100.0%
Taylor expanded in x around inf
lower-*.f6451.7%
Applied rewrites51.7%
herbie shell --seed 1
(FPCore (x y)
:name "(x + y) * 0.5"
:precision binary64
:pre (and (and (<= -1000000000.0 x) (<= x 1000000000.0)) (and (<= -1000000000.0 y) (<= y 1000000000.0)))
(* (+ x y) 0.5))