
(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 -400000.0) (not (<= y 3.6e-13))) (+ (* 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 <= -400000.0) || !(y <= 3.6e-13)) {
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 <= (-400000.0d0)) .or. (.not. (y <= 3.6d-13))) 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 <= -400000.0) || !(y <= 3.6e-13)) {
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 <= -400000.0) or not (y <= 3.6e-13): 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 <= -400000.0) || !(y <= 3.6e-13)) 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 <= -400000.0) || ~((y <= 3.6e-13))) 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, -400000.0], N[Not[LessEqual[y, 3.6e-13]], $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 -400000 \lor \neg \left(y \leq 3.6 \cdot 10^{-13}\right):\\
\;\;\;\;x \cdot y + t\_0\\
\mathbf{else}:\\
\;\;\;\;t\_0 - x\\
\end{array}
\end{array}
if y < -4e5 or 3.5999999999999998e-13 < y Initial program 100.0%
associate-+l-100.0%
sub-neg100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around inf 98.7%
if -4e5 < y < 3.5999999999999998e-13Initial program 100.0%
associate-+l-100.0%
sub-neg100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around 0 99.4%
neg-mul-199.4%
Simplified99.4%
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 77.0%
neg-mul-177.0%
Simplified77.0%
Final simplification77.0%
herbie shell --seed 2024130
(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))