
(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%
Final simplification100.0%
(FPCore (x y)
:precision binary64
(let* ((t_0 (* y (- x 0.5))))
(if (<= y -880000000.0)
t_0
(if (<= y 1.45e-29)
(- (- 0.918938533204673 (* y 0.5)) x)
(+ 0.918938533204673 t_0)))))
double code(double x, double y) {
double t_0 = y * (x - 0.5);
double tmp;
if (y <= -880000000.0) {
tmp = t_0;
} else if (y <= 1.45e-29) {
tmp = (0.918938533204673 - (y * 0.5)) - x;
} else {
tmp = 0.918938533204673 + 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) :: tmp
t_0 = y * (x - 0.5d0)
if (y <= (-880000000.0d0)) then
tmp = t_0
else if (y <= 1.45d-29) then
tmp = (0.918938533204673d0 - (y * 0.5d0)) - x
else
tmp = 0.918938533204673d0 + t_0
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = y * (x - 0.5);
double tmp;
if (y <= -880000000.0) {
tmp = t_0;
} else if (y <= 1.45e-29) {
tmp = (0.918938533204673 - (y * 0.5)) - x;
} else {
tmp = 0.918938533204673 + t_0;
}
return tmp;
}
def code(x, y): t_0 = y * (x - 0.5) tmp = 0 if y <= -880000000.0: tmp = t_0 elif y <= 1.45e-29: tmp = (0.918938533204673 - (y * 0.5)) - x else: tmp = 0.918938533204673 + t_0 return tmp
function code(x, y) t_0 = Float64(y * Float64(x - 0.5)) tmp = 0.0 if (y <= -880000000.0) tmp = t_0; elseif (y <= 1.45e-29) tmp = Float64(Float64(0.918938533204673 - Float64(y * 0.5)) - x); else tmp = Float64(0.918938533204673 + t_0); end return tmp end
function tmp_2 = code(x, y) t_0 = y * (x - 0.5); tmp = 0.0; if (y <= -880000000.0) tmp = t_0; elseif (y <= 1.45e-29) tmp = (0.918938533204673 - (y * 0.5)) - x; else tmp = 0.918938533204673 + t_0; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(y * N[(x - 0.5), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -880000000.0], t$95$0, If[LessEqual[y, 1.45e-29], N[(N[(0.918938533204673 - N[(y * 0.5), $MachinePrecision]), $MachinePrecision] - x), $MachinePrecision], N[(0.918938533204673 + t$95$0), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(x - 0.5\right)\\
\mathbf{if}\;y \leq -880000000:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq 1.45 \cdot 10^{-29}:\\
\;\;\;\;\left(0.918938533204673 - y \cdot 0.5\right) - x\\
\mathbf{else}:\\
\;\;\;\;0.918938533204673 + t_0\\
\end{array}
\end{array}
if y < -8.8e8Initial 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 100.0%
Taylor expanded in y around inf 100.0%
if -8.8e8 < y < 1.45000000000000012e-29Initial 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.4%
neg-mul-199.4%
Simplified99.4%
if 1.45000000000000012e-29 < 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.7%
associate--r-99.7%
distribute-lft-out--99.7%
Applied egg-rr99.7%
Final simplification99.7%
(FPCore (x y) :precision binary64 (if (or (<= y -1.1e-29) (not (<= y 1.85))) (* y (- x 0.5)) 0.918938533204673))
double code(double x, double y) {
double tmp;
if ((y <= -1.1e-29) || !(y <= 1.85)) {
tmp = y * (x - 0.5);
} else {
tmp = 0.918938533204673;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((y <= (-1.1d-29)) .or. (.not. (y <= 1.85d0))) then
tmp = y * (x - 0.5d0)
else
tmp = 0.918938533204673d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -1.1e-29) || !(y <= 1.85)) {
tmp = y * (x - 0.5);
} else {
tmp = 0.918938533204673;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -1.1e-29) or not (y <= 1.85): tmp = y * (x - 0.5) else: tmp = 0.918938533204673 return tmp
function code(x, y) tmp = 0.0 if ((y <= -1.1e-29) || !(y <= 1.85)) tmp = Float64(y * Float64(x - 0.5)); else tmp = 0.918938533204673; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -1.1e-29) || ~((y <= 1.85))) tmp = y * (x - 0.5); else tmp = 0.918938533204673; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -1.1e-29], N[Not[LessEqual[y, 1.85]], $MachinePrecision]], N[(y * N[(x - 0.5), $MachinePrecision]), $MachinePrecision], 0.918938533204673]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.1 \cdot 10^{-29} \lor \neg \left(y \leq 1.85\right):\\
\;\;\;\;y \cdot \left(x - 0.5\right)\\
\mathbf{else}:\\
\;\;\;\;0.918938533204673\\
\end{array}
\end{array}
if y < -1.09999999999999995e-29 or 1.8500000000000001 < 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 98.6%
Taylor expanded in y around inf 98.3%
if -1.09999999999999995e-29 < y < 1.8500000000000001Initial 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 49.3%
Taylor expanded in y around 0 49.1%
Final simplification76.8%
(FPCore (x y) :precision binary64 (if (or (<= y -490000000.0) (not (<= y 60000000.0))) (* y (- x 0.5)) (- 0.918938533204673 (* y 0.5))))
double code(double x, double y) {
double tmp;
if ((y <= -490000000.0) || !(y <= 60000000.0)) {
tmp = y * (x - 0.5);
} else {
tmp = 0.918938533204673 - (y * 0.5);
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((y <= (-490000000.0d0)) .or. (.not. (y <= 60000000.0d0))) then
tmp = y * (x - 0.5d0)
else
tmp = 0.918938533204673d0 - (y * 0.5d0)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -490000000.0) || !(y <= 60000000.0)) {
tmp = y * (x - 0.5);
} else {
tmp = 0.918938533204673 - (y * 0.5);
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -490000000.0) or not (y <= 60000000.0): tmp = y * (x - 0.5) else: tmp = 0.918938533204673 - (y * 0.5) return tmp
function code(x, y) tmp = 0.0 if ((y <= -490000000.0) || !(y <= 60000000.0)) tmp = Float64(y * Float64(x - 0.5)); else tmp = Float64(0.918938533204673 - Float64(y * 0.5)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -490000000.0) || ~((y <= 60000000.0))) tmp = y * (x - 0.5); else tmp = 0.918938533204673 - (y * 0.5); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -490000000.0], N[Not[LessEqual[y, 60000000.0]], $MachinePrecision]], N[(y * N[(x - 0.5), $MachinePrecision]), $MachinePrecision], N[(0.918938533204673 - N[(y * 0.5), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -490000000 \lor \neg \left(y \leq 60000000\right):\\
\;\;\;\;y \cdot \left(x - 0.5\right)\\
\mathbf{else}:\\
\;\;\;\;0.918938533204673 - y \cdot 0.5\\
\end{array}
\end{array}
if y < -4.9e8 or 6e7 < 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.8%
Taylor expanded in y around inf 99.8%
if -4.9e8 < y < 6e7Initial 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 49.1%
Taylor expanded in x around 0 48.7%
Final simplification76.9%
(FPCore (x y) :precision binary64 (if (<= y -1.1e-29) (* x y) (if (<= y 1.55) 0.918938533204673 (* x y))))
double code(double x, double y) {
double tmp;
if (y <= -1.1e-29) {
tmp = x * y;
} else if (y <= 1.55) {
tmp = 0.918938533204673;
} else {
tmp = x * y;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= (-1.1d-29)) then
tmp = x * y
else if (y <= 1.55d0) then
tmp = 0.918938533204673d0
else
tmp = x * y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -1.1e-29) {
tmp = x * y;
} else if (y <= 1.55) {
tmp = 0.918938533204673;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.1e-29: tmp = x * y elif y <= 1.55: tmp = 0.918938533204673 else: tmp = x * y return tmp
function code(x, y) tmp = 0.0 if (y <= -1.1e-29) tmp = Float64(x * y); elseif (y <= 1.55) tmp = 0.918938533204673; else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -1.1e-29) tmp = x * y; elseif (y <= 1.55) tmp = 0.918938533204673; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.1e-29], N[(x * y), $MachinePrecision], If[LessEqual[y, 1.55], 0.918938533204673, N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.1 \cdot 10^{-29}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq 1.55:\\
\;\;\;\;0.918938533204673\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if y < -1.09999999999999995e-29 or 1.55000000000000004 < 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 98.6%
Taylor expanded in x around inf 50.7%
if -1.09999999999999995e-29 < y < 1.55000000000000004Initial 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 49.3%
Taylor expanded in y around 0 49.1%
Final simplification50.0%
(FPCore (x y) :precision binary64 (+ 0.918938533204673 (* y (- x 0.5))))
double code(double x, double y) {
return 0.918938533204673 + (y * (x - 0.5));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 0.918938533204673d0 + (y * (x - 0.5d0))
end function
public static double code(double x, double y) {
return 0.918938533204673 + (y * (x - 0.5));
}
def code(x, y): return 0.918938533204673 + (y * (x - 0.5))
function code(x, y) return Float64(0.918938533204673 + Float64(y * Float64(x - 0.5))) end
function tmp = code(x, y) tmp = 0.918938533204673 + (y * (x - 0.5)); end
code[x_, y_] := N[(0.918938533204673 + N[(y * N[(x - 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.918938533204673 + y \cdot \left(x - 0.5\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 y around inf 77.0%
associate--r-77.0%
distribute-lft-out--77.0%
Applied egg-rr77.0%
Final simplification77.0%
(FPCore (x y) :precision binary64 0.918938533204673)
double code(double x, double y) {
return 0.918938533204673;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 0.918938533204673d0
end function
public static double code(double x, double y) {
return 0.918938533204673;
}
def code(x, y): return 0.918938533204673
function code(x, y) return 0.918938533204673 end
function tmp = code(x, y) tmp = 0.918938533204673; end
code[x_, y_] := 0.918938533204673
\begin{array}{l}
\\
0.918938533204673
\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 inf 77.0%
Taylor expanded in y around 0 22.8%
Final simplification22.8%
herbie shell --seed 2023196
(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))