
(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 4 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 (- (- (* y x) x) (- (* y 0.5) 0.918938533204673)))
double code(double x, double y) {
return ((y * x) - x) - ((y * 0.5) - 0.918938533204673);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = ((y * x) - x) - ((y * 0.5d0) - 0.918938533204673d0)
end function
public static double code(double x, double y) {
return ((y * x) - x) - ((y * 0.5) - 0.918938533204673);
}
def code(x, y): return ((y * x) - x) - ((y * 0.5) - 0.918938533204673)
function code(x, y) return Float64(Float64(Float64(y * x) - x) - Float64(Float64(y * 0.5) - 0.918938533204673)) end
function tmp = code(x, y) tmp = ((y * x) - x) - ((y * 0.5) - 0.918938533204673); end
code[x_, y_] := N[(N[(N[(y * x), $MachinePrecision] - x), $MachinePrecision] - N[(N[(y * 0.5), $MachinePrecision] - 0.918938533204673), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(y \cdot x - x\right) - \left(y \cdot 0.5 - 0.918938533204673\right)
\end{array}
Initial program 100.0%
associate-+l-100.0%
fma-neg100.0%
sub-neg100.0%
+-commutative100.0%
remove-double-neg100.0%
sub-neg100.0%
fma-neg100.0%
sub-neg100.0%
remove-double-neg100.0%
+-commutative100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in x around 0 100.0%
sub-neg100.0%
metadata-eval100.0%
*-commutative100.0%
distribute-rgt-in100.0%
fma-def100.0%
neg-mul-1100.0%
fma-neg100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y) :precision binary64 (let* ((t_0 (- 0.918938533204673 (* y 0.5)))) (if (or (<= y -3e+17) (not (<= y 1.0))) (+ (* y x) t_0) (- t_0 x))))
double code(double x, double y) {
double t_0 = 0.918938533204673 - (y * 0.5);
double tmp;
if ((y <= -3e+17) || !(y <= 1.0)) {
tmp = (y * x) + 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 <= (-3d+17)) .or. (.not. (y <= 1.0d0))) then
tmp = (y * x) + 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 <= -3e+17) || !(y <= 1.0)) {
tmp = (y * x) + t_0;
} else {
tmp = t_0 - x;
}
return tmp;
}
def code(x, y): t_0 = 0.918938533204673 - (y * 0.5) tmp = 0 if (y <= -3e+17) or not (y <= 1.0): tmp = (y * x) + 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 <= -3e+17) || !(y <= 1.0)) tmp = Float64(Float64(y * x) + 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 <= -3e+17) || ~((y <= 1.0))) tmp = (y * x) + 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, -3e+17], N[Not[LessEqual[y, 1.0]], $MachinePrecision]], N[(N[(y * x), $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 -3 \cdot 10^{+17} \lor \neg \left(y \leq 1\right):\\
\;\;\;\;y \cdot x + t_0\\
\mathbf{else}:\\
\;\;\;\;t_0 - x\\
\end{array}
\end{array}
if y < -3e17 or 1 < y Initial program 100.0%
associate-+l-100.0%
fma-neg100.0%
sub-neg100.0%
+-commutative100.0%
remove-double-neg100.0%
sub-neg100.0%
fma-neg100.0%
sub-neg100.0%
remove-double-neg100.0%
+-commutative100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around inf 99.1%
if -3e17 < y < 1Initial program 100.0%
associate-+l-100.0%
fma-neg100.0%
sub-neg100.0%
+-commutative100.0%
remove-double-neg100.0%
sub-neg100.0%
fma-neg100.0%
sub-neg100.0%
remove-double-neg100.0%
+-commutative100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around 0 99.0%
neg-mul-199.0%
Simplified99.0%
Final simplification99.0%
(FPCore (x y) :precision binary64 (+ 0.918938533204673 (- (* x (+ y -1.0)) (* y 0.5))))
double code(double x, double y) {
return 0.918938533204673 + ((x * (y + -1.0)) - (y * 0.5));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 0.918938533204673d0 + ((x * (y + (-1.0d0))) - (y * 0.5d0))
end function
public static double code(double x, double y) {
return 0.918938533204673 + ((x * (y + -1.0)) - (y * 0.5));
}
def code(x, y): return 0.918938533204673 + ((x * (y + -1.0)) - (y * 0.5))
function code(x, y) return Float64(0.918938533204673 + Float64(Float64(x * Float64(y + -1.0)) - Float64(y * 0.5))) end
function tmp = code(x, y) tmp = 0.918938533204673 + ((x * (y + -1.0)) - (y * 0.5)); end
code[x_, y_] := N[(0.918938533204673 + N[(N[(x * N[(y + -1.0), $MachinePrecision]), $MachinePrecision] - N[(y * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.918938533204673 + \left(x \cdot \left(y + -1\right) - y \cdot 0.5\right)
\end{array}
Initial program 100.0%
Final simplification100.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%
fma-neg100.0%
sub-neg100.0%
+-commutative100.0%
remove-double-neg100.0%
sub-neg100.0%
fma-neg100.0%
sub-neg100.0%
remove-double-neg100.0%
+-commutative100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around 0 73.1%
neg-mul-173.1%
Simplified73.1%
Final simplification73.1%
herbie shell --seed 2023229
(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))