
(FPCore (x y) :precision binary64 (+ (- (* x (- y 1.0)) (* y 0.5)) 0.918938533204673))
double code(double x, double y) {
return ((x * (y - 1.0)) - (y * 0.5)) + 0.918938533204673;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = ((x * (y - 1.0d0)) - (y * 0.5d0)) + 0.918938533204673d0
end function
public static double code(double x, double y) {
return ((x * (y - 1.0)) - (y * 0.5)) + 0.918938533204673;
}
def code(x, y): return ((x * (y - 1.0)) - (y * 0.5)) + 0.918938533204673
function code(x, y) return Float64(Float64(Float64(x * Float64(y - 1.0)) - Float64(y * 0.5)) + 0.918938533204673) end
function tmp = code(x, y) tmp = ((x * (y - 1.0)) - (y * 0.5)) + 0.918938533204673; end
code[x_, y_] := N[(N[(N[(x * N[(y - 1.0), $MachinePrecision]), $MachinePrecision] - N[(y * 0.5), $MachinePrecision]), $MachinePrecision] + 0.918938533204673), $MachinePrecision]
\begin{array}{l}
\\
\left(x \cdot \left(y - 1\right) - y \cdot 0.5\right) + 0.918938533204673
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 11 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (+ (- (* x (- y 1.0)) (* y 0.5)) 0.918938533204673))
double code(double x, double y) {
return ((x * (y - 1.0)) - (y * 0.5)) + 0.918938533204673;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = ((x * (y - 1.0d0)) - (y * 0.5d0)) + 0.918938533204673d0
end function
public static double code(double x, double y) {
return ((x * (y - 1.0)) - (y * 0.5)) + 0.918938533204673;
}
def code(x, y): return ((x * (y - 1.0)) - (y * 0.5)) + 0.918938533204673
function code(x, y) return Float64(Float64(Float64(x * Float64(y - 1.0)) - Float64(y * 0.5)) + 0.918938533204673) end
function tmp = code(x, y) tmp = ((x * (y - 1.0)) - (y * 0.5)) + 0.918938533204673; end
code[x_, y_] := N[(N[(N[(x * N[(y - 1.0), $MachinePrecision]), $MachinePrecision] - N[(y * 0.5), $MachinePrecision]), $MachinePrecision] + 0.918938533204673), $MachinePrecision]
\begin{array}{l}
\\
\left(x \cdot \left(y - 1\right) - y \cdot 0.5\right) + 0.918938533204673
\end{array}
(FPCore (x y) :precision binary64 (fma x (+ y -1.0) (fma y -0.5 0.918938533204673)))
double code(double x, double y) {
return fma(x, (y + -1.0), fma(y, -0.5, 0.918938533204673));
}
function code(x, y) return fma(x, Float64(y + -1.0), fma(y, -0.5, 0.918938533204673)) end
code[x_, y_] := N[(x * N[(y + -1.0), $MachinePrecision] + N[(y * -0.5 + 0.918938533204673), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, y + -1, \mathsf{fma}\left(y, -0.5, 0.918938533204673\right)\right)
\end{array}
(FPCore (x y)
:precision binary64
(if (<= x -0.92)
(- x)
(if (<= x 0.92)
0.918938533204673
(if (or (<= x 2.7e+73) (not (<= x 2.35e+226))) (- x) (* x y)))))
double code(double x, double y) {
double tmp;
if (x <= -0.92) {
tmp = -x;
} else if (x <= 0.92) {
tmp = 0.918938533204673;
} else if ((x <= 2.7e+73) || !(x <= 2.35e+226)) {
tmp = -x;
} else {
tmp = x * y;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= (-0.92d0)) then
tmp = -x
else if (x <= 0.92d0) then
tmp = 0.918938533204673d0
else if ((x <= 2.7d+73) .or. (.not. (x <= 2.35d+226))) then
tmp = -x
else
tmp = x * y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -0.92) {
tmp = -x;
} else if (x <= 0.92) {
tmp = 0.918938533204673;
} else if ((x <= 2.7e+73) || !(x <= 2.35e+226)) {
tmp = -x;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -0.92: tmp = -x elif x <= 0.92: tmp = 0.918938533204673 elif (x <= 2.7e+73) or not (x <= 2.35e+226): tmp = -x else: tmp = x * y return tmp
function code(x, y) tmp = 0.0 if (x <= -0.92) tmp = Float64(-x); elseif (x <= 0.92) tmp = 0.918938533204673; elseif ((x <= 2.7e+73) || !(x <= 2.35e+226)) tmp = Float64(-x); else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -0.92) tmp = -x; elseif (x <= 0.92) tmp = 0.918938533204673; elseif ((x <= 2.7e+73) || ~((x <= 2.35e+226))) tmp = -x; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -0.92], (-x), If[LessEqual[x, 0.92], 0.918938533204673, If[Or[LessEqual[x, 2.7e+73], N[Not[LessEqual[x, 2.35e+226]], $MachinePrecision]], (-x), N[(x * y), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.92:\\
\;\;\;\;-x\\
\mathbf{elif}\;x \leq 0.92:\\
\;\;\;\;0.918938533204673\\
\mathbf{elif}\;x \leq 2.7 \cdot 10^{+73} \lor \neg \left(x \leq 2.35 \cdot 10^{+226}\right):\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
(FPCore (x y) :precision binary64 (if (or (<= x -7e-13) (not (<= x 1.2e-14))) (+ (- 0.918938533204673 x) (* x y)) (- 0.918938533204673 (* y 0.5))))
double code(double x, double y) {
double tmp;
if ((x <= -7e-13) || !(x <= 1.2e-14)) {
tmp = (0.918938533204673 - x) + (x * y);
} else {
tmp = 0.918938533204673 - (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 ((x <= (-7d-13)) .or. (.not. (x <= 1.2d-14))) then
tmp = (0.918938533204673d0 - x) + (x * y)
else
tmp = 0.918938533204673d0 - (y * 0.5d0)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x <= -7e-13) || !(x <= 1.2e-14)) {
tmp = (0.918938533204673 - x) + (x * y);
} else {
tmp = 0.918938533204673 - (y * 0.5);
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -7e-13) or not (x <= 1.2e-14): tmp = (0.918938533204673 - x) + (x * y) else: tmp = 0.918938533204673 - (y * 0.5) return tmp
function code(x, y) tmp = 0.0 if ((x <= -7e-13) || !(x <= 1.2e-14)) tmp = Float64(Float64(0.918938533204673 - x) + Float64(x * y)); else tmp = Float64(0.918938533204673 - Float64(y * 0.5)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -7e-13) || ~((x <= 1.2e-14))) tmp = (0.918938533204673 - x) + (x * y); else tmp = 0.918938533204673 - (y * 0.5); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -7e-13], N[Not[LessEqual[x, 1.2e-14]], $MachinePrecision]], N[(N[(0.918938533204673 - x), $MachinePrecision] + N[(x * y), $MachinePrecision]), $MachinePrecision], N[(0.918938533204673 - N[(y * 0.5), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -7 \cdot 10^{-13} \lor \neg \left(x \leq 1.2 \cdot 10^{-14}\right):\\
\;\;\;\;\left(0.918938533204673 - x\right) + x \cdot y\\
\mathbf{else}:\\
\;\;\;\;0.918938533204673 - y \cdot 0.5\\
\end{array}
\end{array}
(FPCore (x y) :precision binary64 (if (or (<= y -7.8e-7) (not (<= y 4.8e-6))) (* x (+ y -1.0)) (- 0.918938533204673 x)))
double code(double x, double y) {
double tmp;
if ((y <= -7.8e-7) || !(y <= 4.8e-6)) {
tmp = x * (y + -1.0);
} else {
tmp = 0.918938533204673 - x;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((y <= (-7.8d-7)) .or. (.not. (y <= 4.8d-6))) then
tmp = x * (y + (-1.0d0))
else
tmp = 0.918938533204673d0 - x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -7.8e-7) || !(y <= 4.8e-6)) {
tmp = x * (y + -1.0);
} else {
tmp = 0.918938533204673 - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -7.8e-7) or not (y <= 4.8e-6): tmp = x * (y + -1.0) else: tmp = 0.918938533204673 - x return tmp
function code(x, y) tmp = 0.0 if ((y <= -7.8e-7) || !(y <= 4.8e-6)) tmp = Float64(x * Float64(y + -1.0)); else tmp = Float64(0.918938533204673 - x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -7.8e-7) || ~((y <= 4.8e-6))) tmp = x * (y + -1.0); else tmp = 0.918938533204673 - x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -7.8e-7], N[Not[LessEqual[y, 4.8e-6]], $MachinePrecision]], N[(x * N[(y + -1.0), $MachinePrecision]), $MachinePrecision], N[(0.918938533204673 - x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -7.8 \cdot 10^{-7} \lor \neg \left(y \leq 4.8 \cdot 10^{-6}\right):\\
\;\;\;\;x \cdot \left(y + -1\right)\\
\mathbf{else}:\\
\;\;\;\;0.918938533204673 - x\\
\end{array}
\end{array}
(FPCore (x y) :precision binary64 (if (or (<= y -1.4) (not (<= y 1.75))) (* y (- x 0.5)) (- 0.918938533204673 x)))
double code(double x, double y) {
double tmp;
if ((y <= -1.4) || !(y <= 1.75)) {
tmp = y * (x - 0.5);
} else {
tmp = 0.918938533204673 - x;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((y <= (-1.4d0)) .or. (.not. (y <= 1.75d0))) then
tmp = y * (x - 0.5d0)
else
tmp = 0.918938533204673d0 - x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -1.4) || !(y <= 1.75)) {
tmp = y * (x - 0.5);
} else {
tmp = 0.918938533204673 - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -1.4) or not (y <= 1.75): tmp = y * (x - 0.5) else: tmp = 0.918938533204673 - x return tmp
function code(x, y) tmp = 0.0 if ((y <= -1.4) || !(y <= 1.75)) tmp = Float64(y * Float64(x - 0.5)); else tmp = Float64(0.918938533204673 - x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -1.4) || ~((y <= 1.75))) tmp = y * (x - 0.5); else tmp = 0.918938533204673 - x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -1.4], N[Not[LessEqual[y, 1.75]], $MachinePrecision]], N[(y * N[(x - 0.5), $MachinePrecision]), $MachinePrecision], N[(0.918938533204673 - x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.4 \lor \neg \left(y \leq 1.75\right):\\
\;\;\;\;y \cdot \left(x - 0.5\right)\\
\mathbf{else}:\\
\;\;\;\;0.918938533204673 - x\\
\end{array}
\end{array}
(FPCore (x y) :precision binary64 (if (or (<= x -0.65) (not (<= x 0.83))) (* x (+ y -1.0)) (- 0.918938533204673 (* y 0.5))))
double code(double x, double y) {
double tmp;
if ((x <= -0.65) || !(x <= 0.83)) {
tmp = x * (y + -1.0);
} else {
tmp = 0.918938533204673 - (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 ((x <= (-0.65d0)) .or. (.not. (x <= 0.83d0))) then
tmp = x * (y + (-1.0d0))
else
tmp = 0.918938533204673d0 - (y * 0.5d0)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x <= -0.65) || !(x <= 0.83)) {
tmp = x * (y + -1.0);
} else {
tmp = 0.918938533204673 - (y * 0.5);
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -0.65) or not (x <= 0.83): tmp = x * (y + -1.0) else: tmp = 0.918938533204673 - (y * 0.5) return tmp
function code(x, y) tmp = 0.0 if ((x <= -0.65) || !(x <= 0.83)) tmp = Float64(x * Float64(y + -1.0)); else tmp = Float64(0.918938533204673 - Float64(y * 0.5)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -0.65) || ~((x <= 0.83))) tmp = x * (y + -1.0); else tmp = 0.918938533204673 - (y * 0.5); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -0.65], N[Not[LessEqual[x, 0.83]], $MachinePrecision]], N[(x * N[(y + -1.0), $MachinePrecision]), $MachinePrecision], N[(0.918938533204673 - N[(y * 0.5), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.65 \lor \neg \left(x \leq 0.83\right):\\
\;\;\;\;x \cdot \left(y + -1\right)\\
\mathbf{else}:\\
\;\;\;\;0.918938533204673 - y \cdot 0.5\\
\end{array}
\end{array}
(FPCore (x y) :precision binary64 (if (<= x -0.74) (- (* x y) x) (if (<= x 0.9) (- 0.918938533204673 (* y 0.5)) (* x (+ y -1.0)))))
double code(double x, double y) {
double tmp;
if (x <= -0.74) {
tmp = (x * y) - x;
} else if (x <= 0.9) {
tmp = 0.918938533204673 - (y * 0.5);
} else {
tmp = x * (y + -1.0);
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= (-0.74d0)) then
tmp = (x * y) - x
else if (x <= 0.9d0) then
tmp = 0.918938533204673d0 - (y * 0.5d0)
else
tmp = x * (y + (-1.0d0))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -0.74) {
tmp = (x * y) - x;
} else if (x <= 0.9) {
tmp = 0.918938533204673 - (y * 0.5);
} else {
tmp = x * (y + -1.0);
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -0.74: tmp = (x * y) - x elif x <= 0.9: tmp = 0.918938533204673 - (y * 0.5) else: tmp = x * (y + -1.0) return tmp
function code(x, y) tmp = 0.0 if (x <= -0.74) tmp = Float64(Float64(x * y) - x); elseif (x <= 0.9) tmp = Float64(0.918938533204673 - Float64(y * 0.5)); else tmp = Float64(x * Float64(y + -1.0)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -0.74) tmp = (x * y) - x; elseif (x <= 0.9) tmp = 0.918938533204673 - (y * 0.5); else tmp = x * (y + -1.0); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -0.74], N[(N[(x * y), $MachinePrecision] - x), $MachinePrecision], If[LessEqual[x, 0.9], N[(0.918938533204673 - N[(y * 0.5), $MachinePrecision]), $MachinePrecision], N[(x * N[(y + -1.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.74:\\
\;\;\;\;x \cdot y - x\\
\mathbf{elif}\;x \leq 0.9:\\
\;\;\;\;0.918938533204673 - y \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(y + -1\right)\\
\end{array}
\end{array}
(FPCore (x y) :precision binary64 (+ (* y (+ x -0.5)) (- 0.918938533204673 x)))
double code(double x, double y) {
return (y * (x + -0.5)) + (0.918938533204673 - x);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (y * (x + (-0.5d0))) + (0.918938533204673d0 - x)
end function
public static double code(double x, double y) {
return (y * (x + -0.5)) + (0.918938533204673 - x);
}
def code(x, y): return (y * (x + -0.5)) + (0.918938533204673 - x)
function code(x, y) return Float64(Float64(y * Float64(x + -0.5)) + Float64(0.918938533204673 - x)) end
function tmp = code(x, y) tmp = (y * (x + -0.5)) + (0.918938533204673 - x); end
code[x_, y_] := N[(N[(y * N[(x + -0.5), $MachinePrecision]), $MachinePrecision] + N[(0.918938533204673 - x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
y \cdot \left(x + -0.5\right) + \left(0.918938533204673 - x\right)
\end{array}
(FPCore (x y) :precision binary64 (if (or (<= y -18.0) (not (<= y 1.0))) (* x y) (- 0.918938533204673 x)))
double code(double x, double y) {
double tmp;
if ((y <= -18.0) || !(y <= 1.0)) {
tmp = x * y;
} else {
tmp = 0.918938533204673 - x;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((y <= (-18.0d0)) .or. (.not. (y <= 1.0d0))) then
tmp = x * y
else
tmp = 0.918938533204673d0 - x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -18.0) || !(y <= 1.0)) {
tmp = x * y;
} else {
tmp = 0.918938533204673 - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -18.0) or not (y <= 1.0): tmp = x * y else: tmp = 0.918938533204673 - x return tmp
function code(x, y) tmp = 0.0 if ((y <= -18.0) || !(y <= 1.0)) tmp = Float64(x * y); else tmp = Float64(0.918938533204673 - x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -18.0) || ~((y <= 1.0))) tmp = x * y; else tmp = 0.918938533204673 - x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -18.0], N[Not[LessEqual[y, 1.0]], $MachinePrecision]], N[(x * y), $MachinePrecision], N[(0.918938533204673 - x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -18 \lor \neg \left(y \leq 1\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;0.918938533204673 - x\\
\end{array}
\end{array}
(FPCore (x y) :precision binary64 (if (or (<= x -0.92) (not (<= x 0.92))) (- x) 0.918938533204673))
double code(double x, double y) {
double tmp;
if ((x <= -0.92) || !(x <= 0.92)) {
tmp = -x;
} else {
tmp = 0.918938533204673;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((x <= (-0.92d0)) .or. (.not. (x <= 0.92d0))) then
tmp = -x
else
tmp = 0.918938533204673d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x <= -0.92) || !(x <= 0.92)) {
tmp = -x;
} else {
tmp = 0.918938533204673;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -0.92) or not (x <= 0.92): tmp = -x else: tmp = 0.918938533204673 return tmp
function code(x, y) tmp = 0.0 if ((x <= -0.92) || !(x <= 0.92)) tmp = Float64(-x); else tmp = 0.918938533204673; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -0.92) || ~((x <= 0.92))) tmp = -x; else tmp = 0.918938533204673; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -0.92], N[Not[LessEqual[x, 0.92]], $MachinePrecision]], (-x), 0.918938533204673]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.92 \lor \neg \left(x \leq 0.92\right):\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;0.918938533204673\\
\end{array}
\end{array}
(FPCore (x y) :precision binary64 0.918938533204673)
double code(double x, double y) {
return 0.918938533204673;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 0.918938533204673d0
end function
public static double code(double x, double y) {
return 0.918938533204673;
}
def code(x, y): return 0.918938533204673
function code(x, y) return 0.918938533204673 end
function tmp = code(x, y) tmp = 0.918938533204673; end
code[x_, y_] := 0.918938533204673
\begin{array}{l}
\\
0.918938533204673
\end{array}
herbie shell --seed 2023347
(FPCore (x y)
:name "Numeric.SpecFunctions:logGamma from math-functions-0.1.5.2, A"
:precision binary64
(+ (- (* x (- y 1.0)) (* y 0.5)) 0.918938533204673))