
(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 (+ 0.918938533204673 (- (* (- y 1.0) x) (* 0.5 y))))
double code(double x, double y) {
return 0.918938533204673 + (((y - 1.0) * x) - (0.5 * y));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 0.918938533204673d0 + (((y - 1.0d0) * x) - (0.5d0 * y))
end function
public static double code(double x, double y) {
return 0.918938533204673 + (((y - 1.0) * x) - (0.5 * y));
}
def code(x, y): return 0.918938533204673 + (((y - 1.0) * x) - (0.5 * y))
function code(x, y) return Float64(0.918938533204673 + Float64(Float64(Float64(y - 1.0) * x) - Float64(0.5 * y))) end
function tmp = code(x, y) tmp = 0.918938533204673 + (((y - 1.0) * x) - (0.5 * y)); end
code[x_, y_] := N[(0.918938533204673 + N[(N[(N[(y - 1.0), $MachinePrecision] * x), $MachinePrecision] - N[(0.5 * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.918938533204673 + \left(\left(y - 1\right) \cdot x - 0.5 \cdot y\right)
\end{array}
Initial program 100.0%
Final simplification100.0%
(FPCore (x y) :precision binary64 (let* ((t_0 (* (- y 1.0) x))) (if (<= x -0.68) t_0 (if (<= x 0.55) (fma y -0.5 0.918938533204673) t_0))))
double code(double x, double y) {
double t_0 = (y - 1.0) * x;
double tmp;
if (x <= -0.68) {
tmp = t_0;
} else if (x <= 0.55) {
tmp = fma(y, -0.5, 0.918938533204673);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y) t_0 = Float64(Float64(y - 1.0) * x) tmp = 0.0 if (x <= -0.68) tmp = t_0; elseif (x <= 0.55) tmp = fma(y, -0.5, 0.918938533204673); else tmp = t_0; end return tmp end
code[x_, y_] := Block[{t$95$0 = N[(N[(y - 1.0), $MachinePrecision] * x), $MachinePrecision]}, If[LessEqual[x, -0.68], t$95$0, If[LessEqual[x, 0.55], N[(y * -0.5 + 0.918938533204673), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(y - 1\right) \cdot x\\
\mathbf{if}\;x \leq -0.68:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 0.55:\\
\;\;\;\;\mathsf{fma}\left(y, -0.5, 0.918938533204673\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -0.680000000000000049 or 0.55000000000000004 < x Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6498.0
Applied rewrites98.0%
if -0.680000000000000049 < x < 0.55000000000000004Initial program 100.0%
Taylor expanded in x around 0
sub-negN/A
+-commutativeN/A
distribute-lft-neg-inN/A
metadata-evalN/A
*-commutativeN/A
lower-fma.f6498.0
Applied rewrites98.0%
herbie shell --seed 2024230
(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))