
(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 3 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%
Final simplification100.0%
(FPCore (x y)
:precision binary64
(let* ((t_0 (- 0.918938533204673 (* y 0.5))))
(if (or (<= y -3700000000000.0) (not (<= y 5.6e-6)))
(+ (* x y) t_0)
(- t_0 x))))
double code(double x, double y) {
double t_0 = 0.918938533204673 - (y * 0.5);
double tmp;
if ((y <= -3700000000000.0) || !(y <= 5.6e-6)) {
tmp = (x * y) + t_0;
} else {
tmp = t_0 - x;
}
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 = 0.918938533204673d0 - (y * 0.5d0)
if ((y <= (-3700000000000.0d0)) .or. (.not. (y <= 5.6d-6))) then
tmp = (x * y) + t_0
else
tmp = t_0 - x
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = 0.918938533204673 - (y * 0.5);
double tmp;
if ((y <= -3700000000000.0) || !(y <= 5.6e-6)) {
tmp = (x * y) + t_0;
} else {
tmp = t_0 - x;
}
return tmp;
}
def code(x, y): t_0 = 0.918938533204673 - (y * 0.5) tmp = 0 if (y <= -3700000000000.0) or not (y <= 5.6e-6): tmp = (x * y) + t_0 else: tmp = t_0 - x return tmp
function code(x, y) t_0 = Float64(0.918938533204673 - Float64(y * 0.5)) tmp = 0.0 if ((y <= -3700000000000.0) || !(y <= 5.6e-6)) tmp = Float64(Float64(x * y) + t_0); else tmp = Float64(t_0 - x); end return tmp end
function tmp_2 = code(x, y) t_0 = 0.918938533204673 - (y * 0.5); tmp = 0.0; if ((y <= -3700000000000.0) || ~((y <= 5.6e-6))) tmp = (x * y) + t_0; else tmp = t_0 - x; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(0.918938533204673 - N[(y * 0.5), $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[y, -3700000000000.0], N[Not[LessEqual[y, 5.6e-6]], $MachinePrecision]], N[(N[(x * y), $MachinePrecision] + t$95$0), $MachinePrecision], N[(t$95$0 - x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 0.918938533204673 - y \cdot 0.5\\
\mathbf{if}\;y \leq -3700000000000 \lor \neg \left(y \leq 5.6 \cdot 10^{-6}\right):\\
\;\;\;\;x \cdot y + t_0\\
\mathbf{else}:\\
\;\;\;\;t_0 - x\\
\end{array}
\end{array}
if y < -3.7e12 or 5.59999999999999975e-6 < y Initial program 100.0%
associate-+l-100.0%
sub-neg100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around inf 99.3%
if -3.7e12 < y < 5.59999999999999975e-6Initial program 100.0%
associate-+l-100.0%
sub-neg100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around 0 98.6%
mul-1-neg98.6%
Simplified98.6%
Final simplification99.0%
(FPCore (x y) :precision binary64 (- (- 0.918938533204673 (* y 0.5)) x))
double code(double x, double y) {
return (0.918938533204673 - (y * 0.5)) - x;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (0.918938533204673d0 - (y * 0.5d0)) - x
end function
public static double code(double x, double y) {
return (0.918938533204673 - (y * 0.5)) - x;
}
def code(x, y): return (0.918938533204673 - (y * 0.5)) - x
function code(x, y) return Float64(Float64(0.918938533204673 - Float64(y * 0.5)) - x) end
function tmp = code(x, y) tmp = (0.918938533204673 - (y * 0.5)) - x; end
code[x_, y_] := N[(N[(0.918938533204673 - N[(y * 0.5), $MachinePrecision]), $MachinePrecision] - x), $MachinePrecision]
\begin{array}{l}
\\
\left(0.918938533204673 - y \cdot 0.5\right) - x
\end{array}
Initial program 100.0%
associate-+l-100.0%
sub-neg100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around 0 72.0%
mul-1-neg72.0%
Simplified72.0%
Final simplification72.0%
herbie shell --seed 2023301
(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))