
(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 7 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 (+ (- (* 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}
Initial program 100.0%
(FPCore (x y)
:precision binary64
(let* ((t_0 (* x (- y 1.0))) (t_1 (- t_0 (* y 0.5))))
(if (<= t_1 -200000.0)
t_0
(if (<= t_1 0.04)
(+ (+ (- y 1.0) 0.918938533204673) 0.918938533204673)
t_0))))
double code(double x, double y) {
double t_0 = x * (y - 1.0);
double t_1 = t_0 - (y * 0.5);
double tmp;
if (t_1 <= -200000.0) {
tmp = t_0;
} else if (t_1 <= 0.04) {
tmp = ((y - 1.0) + 0.918938533204673) + 0.918938533204673;
} 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) :: t_1
real(8) :: tmp
t_0 = x * (y - 1.0d0)
t_1 = t_0 - (y * 0.5d0)
if (t_1 <= (-200000.0d0)) then
tmp = t_0
else if (t_1 <= 0.04d0) then
tmp = ((y - 1.0d0) + 0.918938533204673d0) + 0.918938533204673d0
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = x * (y - 1.0);
double t_1 = t_0 - (y * 0.5);
double tmp;
if (t_1 <= -200000.0) {
tmp = t_0;
} else if (t_1 <= 0.04) {
tmp = ((y - 1.0) + 0.918938533204673) + 0.918938533204673;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y): t_0 = x * (y - 1.0) t_1 = t_0 - (y * 0.5) tmp = 0 if t_1 <= -200000.0: tmp = t_0 elif t_1 <= 0.04: tmp = ((y - 1.0) + 0.918938533204673) + 0.918938533204673 else: tmp = t_0 return tmp
function code(x, y) t_0 = Float64(x * Float64(y - 1.0)) t_1 = Float64(t_0 - Float64(y * 0.5)) tmp = 0.0 if (t_1 <= -200000.0) tmp = t_0; elseif (t_1 <= 0.04) tmp = Float64(Float64(Float64(y - 1.0) + 0.918938533204673) + 0.918938533204673); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y) t_0 = x * (y - 1.0); t_1 = t_0 - (y * 0.5); tmp = 0.0; if (t_1 <= -200000.0) tmp = t_0; elseif (t_1 <= 0.04) tmp = ((y - 1.0) + 0.918938533204673) + 0.918938533204673; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(x * N[(y - 1.0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(t$95$0 - N[(y * 0.5), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, -200000.0], t$95$0, If[LessEqual[t$95$1, 0.04], N[(N[(N[(y - 1.0), $MachinePrecision] + 0.918938533204673), $MachinePrecision] + 0.918938533204673), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(y - 1\right)\\
t_1 := t\_0 - y \cdot 0.5\\
\mathbf{if}\;t\_1 \leq -200000:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;t\_1 \leq 0.04:\\
\;\;\;\;\left(\left(y - 1\right) + 0.918938533204673\right) + 0.918938533204673\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if (-.f64 (*.f64 x (-.f64 y #s(literal 1 binary64))) (*.f64 y #s(literal 1/2 binary64))) < -2e5 or 0.0400000000000000008 < (-.f64 (*.f64 x (-.f64 y #s(literal 1 binary64))) (*.f64 y #s(literal 1/2 binary64))) Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites98.7%
Taylor expanded in x around 0
Applied rewrites67.6%
if -2e5 < (-.f64 (*.f64 x (-.f64 y #s(literal 1 binary64))) (*.f64 y #s(literal 1/2 binary64))) < 0.0400000000000000008Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites96.5%
Taylor expanded in x around 0
Applied rewrites18.8%
Taylor expanded in x around 0
Applied rewrites22.8%
(FPCore (x y)
:precision binary64
(let* ((t_0 (* x (- y 1.0))) (t_1 (- t_0 (* y 0.5))))
(if (<= y -235000000.0)
t_1
(if (<= y 1.85) (+ t_0 0.918938533204673) t_1))))
double code(double x, double y) {
double t_0 = x * (y - 1.0);
double t_1 = t_0 - (y * 0.5);
double tmp;
if (y <= -235000000.0) {
tmp = t_1;
} else if (y <= 1.85) {
tmp = t_0 + 0.918938533204673;
} else {
tmp = t_1;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = x * (y - 1.0d0)
t_1 = t_0 - (y * 0.5d0)
if (y <= (-235000000.0d0)) then
tmp = t_1
else if (y <= 1.85d0) then
tmp = t_0 + 0.918938533204673d0
else
tmp = t_1
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = x * (y - 1.0);
double t_1 = t_0 - (y * 0.5);
double tmp;
if (y <= -235000000.0) {
tmp = t_1;
} else if (y <= 1.85) {
tmp = t_0 + 0.918938533204673;
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y): t_0 = x * (y - 1.0) t_1 = t_0 - (y * 0.5) tmp = 0 if y <= -235000000.0: tmp = t_1 elif y <= 1.85: tmp = t_0 + 0.918938533204673 else: tmp = t_1 return tmp
function code(x, y) t_0 = Float64(x * Float64(y - 1.0)) t_1 = Float64(t_0 - Float64(y * 0.5)) tmp = 0.0 if (y <= -235000000.0) tmp = t_1; elseif (y <= 1.85) tmp = Float64(t_0 + 0.918938533204673); else tmp = t_1; end return tmp end
function tmp_2 = code(x, y) t_0 = x * (y - 1.0); t_1 = t_0 - (y * 0.5); tmp = 0.0; if (y <= -235000000.0) tmp = t_1; elseif (y <= 1.85) tmp = t_0 + 0.918938533204673; else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(x * N[(y - 1.0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(t$95$0 - N[(y * 0.5), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -235000000.0], t$95$1, If[LessEqual[y, 1.85], N[(t$95$0 + 0.918938533204673), $MachinePrecision], t$95$1]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(y - 1\right)\\
t_1 := t\_0 - y \cdot 0.5\\
\mathbf{if}\;y \leq -235000000:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;y \leq 1.85:\\
\;\;\;\;t\_0 + 0.918938533204673\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if y < -2.35e8 or 1.8500000000000001 < y Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites99.4%
if -2.35e8 < y < 1.8500000000000001Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites98.2%
(FPCore (x y) :precision binary64 (+ (* x (- y 1.0)) 0.918938533204673))
double code(double x, double y) {
return (x * (y - 1.0)) + 0.918938533204673;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (x * (y - 1.0d0)) + 0.918938533204673d0
end function
public static double code(double x, double y) {
return (x * (y - 1.0)) + 0.918938533204673;
}
def code(x, y): return (x * (y - 1.0)) + 0.918938533204673
function code(x, y) return Float64(Float64(x * Float64(y - 1.0)) + 0.918938533204673) end
function tmp = code(x, y) tmp = (x * (y - 1.0)) + 0.918938533204673; end
code[x_, y_] := N[(N[(x * N[(y - 1.0), $MachinePrecision]), $MachinePrecision] + 0.918938533204673), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(y - 1\right) + 0.918938533204673
\end{array}
Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites76.3%
(FPCore (x y) :precision binary64 (* x (- y 1.0)))
double code(double x, double y) {
return x * (y - 1.0);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x * (y - 1.0d0)
end function
public static double code(double x, double y) {
return x * (y - 1.0);
}
def code(x, y): return x * (y - 1.0)
function code(x, y) return Float64(x * Float64(y - 1.0)) end
function tmp = code(x, y) tmp = x * (y - 1.0); end
code[x_, y_] := N[(x * N[(y - 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(y - 1\right)
\end{array}
Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites72.9%
Taylor expanded in x around 0
Applied rewrites50.1%
(FPCore (x y) :precision binary64 (* y 0.5))
double code(double x, double y) {
return y * 0.5;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = y * 0.5d0
end function
public static double code(double x, double y) {
return y * 0.5;
}
def code(x, y): return y * 0.5
function code(x, y) return Float64(y * 0.5) end
function tmp = code(x, y) tmp = y * 0.5; end
code[x_, y_] := N[(y * 0.5), $MachinePrecision]
\begin{array}{l}
\\
y \cdot 0.5
\end{array}
Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites72.9%
Taylor expanded in x around -inf
Applied rewrites2.5%
(FPCore (x y) :precision binary64 (- y 1.0))
double code(double x, double y) {
return y - 1.0;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = y - 1.0d0
end function
public static double code(double x, double y) {
return y - 1.0;
}
def code(x, y): return y - 1.0
function code(x, y) return Float64(y - 1.0) end
function tmp = code(x, y) tmp = y - 1.0; end
code[x_, y_] := N[(y - 1.0), $MachinePrecision]
\begin{array}{l}
\\
y - 1
\end{array}
Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites72.9%
Taylor expanded in x around 0
Applied rewrites2.1%
herbie shell --seed 2024313
(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))