
(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 9 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 (- 0.918938533204673 (fma (- 0.5 x) y x)))
double code(double x, double y) {
return 0.918938533204673 - fma((0.5 - x), y, x);
}
function code(x, y) return Float64(0.918938533204673 - fma(Float64(0.5 - x), y, x)) end
code[x_, y_] := N[(0.918938533204673 - N[(N[(0.5 - x), $MachinePrecision] * y + x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.918938533204673 - \mathsf{fma}\left(0.5 - x, y, x\right)
\end{array}
Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites100.0%
(FPCore (x y)
:precision binary64
(if (<= y -5.4e-8)
(fma -0.5 y 0.918938533204673)
(if (<= y 2.25e-9)
(- 0.918938533204673 x)
(if (<= y 2.65e+265) (fma -0.5 y 0.918938533204673) (* y x)))))
double code(double x, double y) {
double tmp;
if (y <= -5.4e-8) {
tmp = fma(-0.5, y, 0.918938533204673);
} else if (y <= 2.25e-9) {
tmp = 0.918938533204673 - x;
} else if (y <= 2.65e+265) {
tmp = fma(-0.5, y, 0.918938533204673);
} else {
tmp = y * x;
}
return tmp;
}
function code(x, y) tmp = 0.0 if (y <= -5.4e-8) tmp = fma(-0.5, y, 0.918938533204673); elseif (y <= 2.25e-9) tmp = Float64(0.918938533204673 - x); elseif (y <= 2.65e+265) tmp = fma(-0.5, y, 0.918938533204673); else tmp = Float64(y * x); end return tmp end
code[x_, y_] := If[LessEqual[y, -5.4e-8], N[(-0.5 * y + 0.918938533204673), $MachinePrecision], If[LessEqual[y, 2.25e-9], N[(0.918938533204673 - x), $MachinePrecision], If[LessEqual[y, 2.65e+265], N[(-0.5 * y + 0.918938533204673), $MachinePrecision], N[(y * x), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5.4 \cdot 10^{-8}:\\
\;\;\;\;\mathsf{fma}\left(-0.5, y, 0.918938533204673\right)\\
\mathbf{elif}\;y \leq 2.25 \cdot 10^{-9}:\\
\;\;\;\;0.918938533204673 - x\\
\mathbf{elif}\;y \leq 2.65 \cdot 10^{+265}:\\
\;\;\;\;\mathsf{fma}\left(-0.5, y, 0.918938533204673\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if y < -5.40000000000000005e-8 or 2.24999999999999988e-9 < y < 2.65000000000000017e265Initial program 100.0%
Taylor expanded in x around 0
sub-negN/A
+-commutativeN/A
distribute-lft-neg-inN/A
metadata-evalN/A
lower-fma.f6457.2
Applied rewrites57.2%
if -5.40000000000000005e-8 < y < 2.24999999999999988e-9Initial program 100.0%
Taylor expanded in y around 0
mul-1-negN/A
unsub-negN/A
lower--.f6499.8
Applied rewrites99.8%
if 2.65000000000000017e265 < y Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites100.0%
Taylor expanded in y around -inf
*-commutativeN/A
mul-1-negN/A
sub-negN/A
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
neg-sub0N/A
associate--r-N/A
metadata-evalN/A
+-commutativeN/A
metadata-evalN/A
sub-negN/A
lower--.f64100.0
Applied rewrites100.0%
Taylor expanded in x around inf
Applied rewrites86.8%
(FPCore (x y)
:precision binary64
(if (<= y -270.0)
(* -0.5 y)
(if (<= y 1.82)
(- 0.918938533204673 x)
(if (<= y 2.65e+265) (* -0.5 y) (* y x)))))
double code(double x, double y) {
double tmp;
if (y <= -270.0) {
tmp = -0.5 * y;
} else if (y <= 1.82) {
tmp = 0.918938533204673 - x;
} else if (y <= 2.65e+265) {
tmp = -0.5 * y;
} else {
tmp = y * x;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= (-270.0d0)) then
tmp = (-0.5d0) * y
else if (y <= 1.82d0) then
tmp = 0.918938533204673d0 - x
else if (y <= 2.65d+265) then
tmp = (-0.5d0) * y
else
tmp = y * x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -270.0) {
tmp = -0.5 * y;
} else if (y <= 1.82) {
tmp = 0.918938533204673 - x;
} else if (y <= 2.65e+265) {
tmp = -0.5 * y;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -270.0: tmp = -0.5 * y elif y <= 1.82: tmp = 0.918938533204673 - x elif y <= 2.65e+265: tmp = -0.5 * y else: tmp = y * x return tmp
function code(x, y) tmp = 0.0 if (y <= -270.0) tmp = Float64(-0.5 * y); elseif (y <= 1.82) tmp = Float64(0.918938533204673 - x); elseif (y <= 2.65e+265) tmp = Float64(-0.5 * y); else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -270.0) tmp = -0.5 * y; elseif (y <= 1.82) tmp = 0.918938533204673 - x; elseif (y <= 2.65e+265) tmp = -0.5 * y; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -270.0], N[(-0.5 * y), $MachinePrecision], If[LessEqual[y, 1.82], N[(0.918938533204673 - x), $MachinePrecision], If[LessEqual[y, 2.65e+265], N[(-0.5 * y), $MachinePrecision], N[(y * x), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -270:\\
\;\;\;\;-0.5 \cdot y\\
\mathbf{elif}\;y \leq 1.82:\\
\;\;\;\;0.918938533204673 - x\\
\mathbf{elif}\;y \leq 2.65 \cdot 10^{+265}:\\
\;\;\;\;-0.5 \cdot y\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if y < -270 or 1.82000000000000006 < y < 2.65000000000000017e265Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites100.0%
Taylor expanded in y around -inf
*-commutativeN/A
mul-1-negN/A
sub-negN/A
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
neg-sub0N/A
associate--r-N/A
metadata-evalN/A
+-commutativeN/A
metadata-evalN/A
sub-negN/A
lower--.f6499.1
Applied rewrites99.1%
Taylor expanded in x around 0
Applied rewrites55.2%
if -270 < y < 1.82000000000000006Initial program 100.0%
Taylor expanded in y around 0
mul-1-negN/A
unsub-negN/A
lower--.f6497.3
Applied rewrites97.3%
if 2.65000000000000017e265 < y Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites100.0%
Taylor expanded in y around -inf
*-commutativeN/A
mul-1-negN/A
sub-negN/A
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
neg-sub0N/A
associate--r-N/A
metadata-evalN/A
+-commutativeN/A
metadata-evalN/A
sub-negN/A
lower--.f64100.0
Applied rewrites100.0%
Taylor expanded in x around inf
Applied rewrites86.8%
(FPCore (x y)
:precision binary64
(let* ((t_0 (+ (* (- x 0.5) y) 0.918938533204673)))
(if (<= y -0.092)
t_0
(if (<= y 0.04) (- 0.918938533204673 (fma (- x) y x)) t_0))))
double code(double x, double y) {
double t_0 = ((x - 0.5) * y) + 0.918938533204673;
double tmp;
if (y <= -0.092) {
tmp = t_0;
} else if (y <= 0.04) {
tmp = 0.918938533204673 - fma(-x, y, x);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y) t_0 = Float64(Float64(Float64(x - 0.5) * y) + 0.918938533204673) tmp = 0.0 if (y <= -0.092) tmp = t_0; elseif (y <= 0.04) tmp = Float64(0.918938533204673 - fma(Float64(-x), y, x)); else tmp = t_0; end return tmp end
code[x_, y_] := Block[{t$95$0 = N[(N[(N[(x - 0.5), $MachinePrecision] * y), $MachinePrecision] + 0.918938533204673), $MachinePrecision]}, If[LessEqual[y, -0.092], t$95$0, If[LessEqual[y, 0.04], N[(0.918938533204673 - N[((-x) * y + x), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(x - 0.5\right) \cdot y + 0.918938533204673\\
\mathbf{if}\;y \leq -0.092:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 0.04:\\
\;\;\;\;0.918938533204673 - \mathsf{fma}\left(-x, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -0.091999999999999998 or 0.0400000000000000008 < y Initial program 100.0%
Taylor expanded in y around inf
sub-negN/A
remove-double-negN/A
mul-1-negN/A
distribute-neg-inN/A
+-commutativeN/A
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
distribute-neg-inN/A
mul-1-negN/A
remove-double-negN/A
sub-negN/A
lower--.f64100.0
Applied rewrites100.0%
if -0.091999999999999998 < y < 0.0400000000000000008Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites100.0%
Taylor expanded in x around inf
Applied rewrites99.7%
(FPCore (x y)
:precision binary64
(let* ((t_0 (- 0.918938533204673 (fma (- x) y x))))
(if (<= x -5.1e-11)
t_0
(if (<= x 1.25e-7) (fma -0.5 y 0.918938533204673) t_0))))
double code(double x, double y) {
double t_0 = 0.918938533204673 - fma(-x, y, x);
double tmp;
if (x <= -5.1e-11) {
tmp = t_0;
} else if (x <= 1.25e-7) {
tmp = fma(-0.5, y, 0.918938533204673);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y) t_0 = Float64(0.918938533204673 - fma(Float64(-x), y, x)) tmp = 0.0 if (x <= -5.1e-11) tmp = t_0; elseif (x <= 1.25e-7) tmp = fma(-0.5, y, 0.918938533204673); else tmp = t_0; end return tmp end
code[x_, y_] := Block[{t$95$0 = N[(0.918938533204673 - N[((-x) * y + x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -5.1e-11], t$95$0, If[LessEqual[x, 1.25e-7], N[(-0.5 * y + 0.918938533204673), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 0.918938533204673 - \mathsf{fma}\left(-x, y, x\right)\\
\mathbf{if}\;x \leq -5.1 \cdot 10^{-11}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 1.25 \cdot 10^{-7}:\\
\;\;\;\;\mathsf{fma}\left(-0.5, y, 0.918938533204673\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -5.09999999999999984e-11 or 1.24999999999999994e-7 < x Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites100.0%
Taylor expanded in x around inf
Applied rewrites97.9%
if -5.09999999999999984e-11 < x < 1.24999999999999994e-7Initial program 100.0%
Taylor expanded in x around 0
sub-negN/A
+-commutativeN/A
distribute-lft-neg-inN/A
metadata-evalN/A
lower-fma.f64100.0
Applied rewrites100.0%
(FPCore (x y) :precision binary64 (let* ((t_0 (* (- x 0.5) y))) (if (<= y -1.25) t_0 (if (<= y 1.2) (- 0.918938533204673 x) t_0))))
double code(double x, double y) {
double t_0 = (x - 0.5) * y;
double tmp;
if (y <= -1.25) {
tmp = t_0;
} else if (y <= 1.2) {
tmp = 0.918938533204673 - x;
} else {
tmp = t_0;
}
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 = (x - 0.5d0) * y
if (y <= (-1.25d0)) then
tmp = t_0
else if (y <= 1.2d0) then
tmp = 0.918938533204673d0 - x
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = (x - 0.5) * y;
double tmp;
if (y <= -1.25) {
tmp = t_0;
} else if (y <= 1.2) {
tmp = 0.918938533204673 - x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y): t_0 = (x - 0.5) * y tmp = 0 if y <= -1.25: tmp = t_0 elif y <= 1.2: tmp = 0.918938533204673 - x else: tmp = t_0 return tmp
function code(x, y) t_0 = Float64(Float64(x - 0.5) * y) tmp = 0.0 if (y <= -1.25) tmp = t_0; elseif (y <= 1.2) tmp = Float64(0.918938533204673 - x); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y) t_0 = (x - 0.5) * y; tmp = 0.0; if (y <= -1.25) tmp = t_0; elseif (y <= 1.2) tmp = 0.918938533204673 - x; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(N[(x - 0.5), $MachinePrecision] * y), $MachinePrecision]}, If[LessEqual[y, -1.25], t$95$0, If[LessEqual[y, 1.2], N[(0.918938533204673 - x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(x - 0.5\right) \cdot y\\
\mathbf{if}\;y \leq -1.25:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 1.2:\\
\;\;\;\;0.918938533204673 - x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -1.25 or 1.19999999999999996 < y Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites100.0%
Taylor expanded in y around -inf
*-commutativeN/A
mul-1-negN/A
sub-negN/A
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
neg-sub0N/A
associate--r-N/A
metadata-evalN/A
+-commutativeN/A
metadata-evalN/A
sub-negN/A
lower--.f6499.2
Applied rewrites99.2%
if -1.25 < y < 1.19999999999999996Initial program 100.0%
Taylor expanded in y around 0
mul-1-negN/A
unsub-negN/A
lower--.f6497.3
Applied rewrites97.3%
(FPCore (x y) :precision binary64 (if (<= y -2.6e+28) (* y x) (if (<= y 1.2) (- 0.918938533204673 x) (* y x))))
double code(double x, double y) {
double tmp;
if (y <= -2.6e+28) {
tmp = y * x;
} else if (y <= 1.2) {
tmp = 0.918938533204673 - x;
} else {
tmp = y * x;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= (-2.6d+28)) then
tmp = y * x
else if (y <= 1.2d0) then
tmp = 0.918938533204673d0 - x
else
tmp = y * x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -2.6e+28) {
tmp = y * x;
} else if (y <= 1.2) {
tmp = 0.918938533204673 - x;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -2.6e+28: tmp = y * x elif y <= 1.2: tmp = 0.918938533204673 - x else: tmp = y * x return tmp
function code(x, y) tmp = 0.0 if (y <= -2.6e+28) tmp = Float64(y * x); elseif (y <= 1.2) tmp = Float64(0.918938533204673 - x); else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -2.6e+28) tmp = y * x; elseif (y <= 1.2) tmp = 0.918938533204673 - x; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -2.6e+28], N[(y * x), $MachinePrecision], If[LessEqual[y, 1.2], N[(0.918938533204673 - x), $MachinePrecision], N[(y * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.6 \cdot 10^{+28}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq 1.2:\\
\;\;\;\;0.918938533204673 - x\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if y < -2.6000000000000002e28 or 1.19999999999999996 < y Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites100.0%
Taylor expanded in y around -inf
*-commutativeN/A
mul-1-negN/A
sub-negN/A
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
neg-sub0N/A
associate--r-N/A
metadata-evalN/A
+-commutativeN/A
metadata-evalN/A
sub-negN/A
lower--.f6499.8
Applied rewrites99.8%
Taylor expanded in x around inf
Applied rewrites51.1%
if -2.6000000000000002e28 < y < 1.19999999999999996Initial program 100.0%
Taylor expanded in y around 0
mul-1-negN/A
unsub-negN/A
lower--.f6495.4
Applied rewrites95.4%
(FPCore (x y) :precision binary64 (- 0.918938533204673 x))
double code(double x, double y) {
return 0.918938533204673 - x;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 0.918938533204673d0 - x
end function
public static double code(double x, double y) {
return 0.918938533204673 - x;
}
def code(x, y): return 0.918938533204673 - x
function code(x, y) return Float64(0.918938533204673 - x) end
function tmp = code(x, y) tmp = 0.918938533204673 - x; end
code[x_, y_] := N[(0.918938533204673 - x), $MachinePrecision]
\begin{array}{l}
\\
0.918938533204673 - x
\end{array}
Initial program 100.0%
Taylor expanded in y around 0
mul-1-negN/A
unsub-negN/A
lower--.f6451.6
Applied rewrites51.6%
(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}
Initial program 100.0%
Taylor expanded in y around 0
mul-1-negN/A
unsub-negN/A
lower--.f6451.6
Applied rewrites51.6%
Taylor expanded in x around 0
Applied rewrites24.4%
herbie shell --seed 2024294
(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))