
(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 -1000.0)
t_0
(if (<= t_1 0.0004)
(+ (+ (- 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 <= -1000.0) {
tmp = t_0;
} else if (t_1 <= 0.0004) {
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 <= (-1000.0d0)) then
tmp = t_0
else if (t_1 <= 0.0004d0) 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 <= -1000.0) {
tmp = t_0;
} else if (t_1 <= 0.0004) {
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 <= -1000.0: tmp = t_0 elif t_1 <= 0.0004: 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 <= -1000.0) tmp = t_0; elseif (t_1 <= 0.0004) 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 <= -1000.0) tmp = t_0; elseif (t_1 <= 0.0004) 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, -1000.0], t$95$0, If[LessEqual[t$95$1, 0.0004], 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 -1000:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;t\_1 \leq 0.0004:\\
\;\;\;\;\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))) < -1e3 or 4.00000000000000019e-4 < (-.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.9%
Taylor expanded in x around 0
Applied rewrites65.1%
if -1e3 < (-.f64 (*.f64 x (-.f64 y #s(literal 1 binary64))) (*.f64 y #s(literal 1/2 binary64))) < 4.00000000000000019e-4Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites98.8%
Taylor expanded in x around 0
Applied rewrites18.8%
Taylor expanded in x around 0
Applied rewrites22.9%
(FPCore (x y) :precision binary64 (let* ((t_0 (* x (- y 1.0))) (t_1 (- t_0 (* y 0.5)))) (if (<= y -1.82) t_1 (if (<= y 4.5e-6) (+ 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 <= -1.82) {
tmp = t_1;
} else if (y <= 4.5e-6) {
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 <= (-1.82d0)) then
tmp = t_1
else if (y <= 4.5d-6) 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 <= -1.82) {
tmp = t_1;
} else if (y <= 4.5e-6) {
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 <= -1.82: tmp = t_1 elif y <= 4.5e-6: 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 <= -1.82) tmp = t_1; elseif (y <= 4.5e-6) 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 <= -1.82) tmp = t_1; elseif (y <= 4.5e-6) 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, -1.82], t$95$1, If[LessEqual[y, 4.5e-6], 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 -1.82:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;y \leq 4.5 \cdot 10^{-6}:\\
\;\;\;\;t\_0 + 0.918938533204673\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if y < -1.82000000000000006 or 4.50000000000000011e-6 < y Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites98.8%
if -1.82000000000000006 < y < 4.50000000000000011e-6Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites99.4%
(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 rewrites73.6%
(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 rewrites75.9%
Taylor expanded in x around 0
Applied rewrites50.2%
(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 rewrites75.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 rewrites75.9%
Taylor expanded in x around 0
Applied rewrites2.1%
herbie shell --seed 2024321
(FPCore (x y)
:name "Numeric.SpecFunctions:logGamma from math-functions-0.1.5.2, A"
:precision binary64
:pre (TRUE)
(+ (- (* x (- y 1.0)) (* y 0.5)) 0.918938533204673))