
(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 8 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 (if (or (<= y -12.2) (not (<= y 1.0))) (+ 0.918938533204673 (* y (- x 0.5))) (- (- 0.918938533204673 (* y 0.5)) x)))
double code(double x, double y) {
double tmp;
if ((y <= -12.2) || !(y <= 1.0)) {
tmp = 0.918938533204673 + (y * (x - 0.5));
} else {
tmp = (0.918938533204673 - (y * 0.5)) - x;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((y <= (-12.2d0)) .or. (.not. (y <= 1.0d0))) then
tmp = 0.918938533204673d0 + (y * (x - 0.5d0))
else
tmp = (0.918938533204673d0 - (y * 0.5d0)) - x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -12.2) || !(y <= 1.0)) {
tmp = 0.918938533204673 + (y * (x - 0.5));
} else {
tmp = (0.918938533204673 - (y * 0.5)) - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -12.2) or not (y <= 1.0): tmp = 0.918938533204673 + (y * (x - 0.5)) else: tmp = (0.918938533204673 - (y * 0.5)) - x return tmp
function code(x, y) tmp = 0.0 if ((y <= -12.2) || !(y <= 1.0)) tmp = Float64(0.918938533204673 + Float64(y * Float64(x - 0.5))); else tmp = Float64(Float64(0.918938533204673 - Float64(y * 0.5)) - x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -12.2) || ~((y <= 1.0))) tmp = 0.918938533204673 + (y * (x - 0.5)); else tmp = (0.918938533204673 - (y * 0.5)) - x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -12.2], N[Not[LessEqual[y, 1.0]], $MachinePrecision]], N[(0.918938533204673 + N[(y * N[(x - 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(0.918938533204673 - N[(y * 0.5), $MachinePrecision]), $MachinePrecision] - x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -12.2 \lor \neg \left(y \leq 1\right):\\
\;\;\;\;0.918938533204673 + y \cdot \left(x - 0.5\right)\\
\mathbf{else}:\\
\;\;\;\;\left(0.918938533204673 - y \cdot 0.5\right) - x\\
\end{array}
\end{array}
if y < -12.199999999999999 or 1 < y Initial program 100.0%
associate-+l-100.0%
sub-neg100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around inf 99.0%
associate--r-99.0%
*-commutative99.0%
distribute-lft-out--99.0%
Applied egg-rr99.0%
if -12.199999999999999 < y < 1Initial program 100.0%
associate-+l-100.0%
sub-neg100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around 0 99.3%
neg-mul-199.3%
Simplified99.3%
Final simplification99.1%
(FPCore (x y) :precision binary64 (if (or (<= y -4.1e-17) (not (<= y 1.75))) (* y (- x 0.5)) 0.918938533204673))
double code(double x, double y) {
double tmp;
if ((y <= -4.1e-17) || !(y <= 1.75)) {
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 <= (-4.1d-17)) .or. (.not. (y <= 1.75d0))) 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 <= -4.1e-17) || !(y <= 1.75)) {
tmp = y * (x - 0.5);
} else {
tmp = 0.918938533204673;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -4.1e-17) or not (y <= 1.75): tmp = y * (x - 0.5) else: tmp = 0.918938533204673 return tmp
function code(x, y) tmp = 0.0 if ((y <= -4.1e-17) || !(y <= 1.75)) 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 <= -4.1e-17) || ~((y <= 1.75))) tmp = y * (x - 0.5); else tmp = 0.918938533204673; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -4.1e-17], N[Not[LessEqual[y, 1.75]], $MachinePrecision]], N[(y * N[(x - 0.5), $MachinePrecision]), $MachinePrecision], 0.918938533204673]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.1 \cdot 10^{-17} \lor \neg \left(y \leq 1.75\right):\\
\;\;\;\;y \cdot \left(x - 0.5\right)\\
\mathbf{else}:\\
\;\;\;\;0.918938533204673\\
\end{array}
\end{array}
if y < -4.1000000000000001e-17 or 1.75 < y Initial program 100.0%
associate-+l-100.0%
sub-neg100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around inf 97.8%
Taylor expanded in y around inf 96.2%
if -4.1000000000000001e-17 < y < 1.75Initial program 100.0%
associate-+l-100.0%
sub-neg100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around inf 49.9%
Taylor expanded in y around 0 50.1%
Final simplification75.7%
(FPCore (x y) :precision binary64 (if (<= x -0.0036) (+ 0.918938533204673 (* x y)) (if (<= x 0.175) (- 0.918938533204673 (* y 0.5)) (* y (- x 0.5)))))
double code(double x, double y) {
double tmp;
if (x <= -0.0036) {
tmp = 0.918938533204673 + (x * y);
} else if (x <= 0.175) {
tmp = 0.918938533204673 - (y * 0.5);
} else {
tmp = y * (x - 0.5);
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= (-0.0036d0)) then
tmp = 0.918938533204673d0 + (x * y)
else if (x <= 0.175d0) then
tmp = 0.918938533204673d0 - (y * 0.5d0)
else
tmp = y * (x - 0.5d0)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -0.0036) {
tmp = 0.918938533204673 + (x * y);
} else if (x <= 0.175) {
tmp = 0.918938533204673 - (y * 0.5);
} else {
tmp = y * (x - 0.5);
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -0.0036: tmp = 0.918938533204673 + (x * y) elif x <= 0.175: tmp = 0.918938533204673 - (y * 0.5) else: tmp = y * (x - 0.5) return tmp
function code(x, y) tmp = 0.0 if (x <= -0.0036) tmp = Float64(0.918938533204673 + Float64(x * y)); elseif (x <= 0.175) tmp = Float64(0.918938533204673 - Float64(y * 0.5)); else tmp = Float64(y * Float64(x - 0.5)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -0.0036) tmp = 0.918938533204673 + (x * y); elseif (x <= 0.175) tmp = 0.918938533204673 - (y * 0.5); else tmp = y * (x - 0.5); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -0.0036], N[(0.918938533204673 + N[(x * y), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 0.175], N[(0.918938533204673 - N[(y * 0.5), $MachinePrecision]), $MachinePrecision], N[(y * N[(x - 0.5), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.0036:\\
\;\;\;\;0.918938533204673 + x \cdot y\\
\mathbf{elif}\;x \leq 0.175:\\
\;\;\;\;0.918938533204673 - y \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(x - 0.5\right)\\
\end{array}
\end{array}
if x < -0.0035999999999999999Initial program 100.0%
associate-+l-100.0%
sub-neg100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around inf 51.0%
associate--r-51.0%
*-commutative51.0%
distribute-lft-out--51.0%
Applied egg-rr51.0%
Taylor expanded in x around inf 51.0%
*-commutative51.0%
Simplified51.0%
if -0.0035999999999999999 < x < 0.17499999999999999Initial program 100.0%
associate-+l-100.0%
sub-neg100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around inf 99.2%
Taylor expanded in x around 0 98.8%
if 0.17499999999999999 < x Initial program 100.0%
associate-+l-100.0%
sub-neg100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around inf 54.8%
Taylor expanded in y around inf 55.2%
Final simplification76.3%
(FPCore (x y) :precision binary64 (if (or (<= y -4.1e-17) (not (<= y 1.45e-11))) (* y -0.5) 0.918938533204673))
double code(double x, double y) {
double tmp;
if ((y <= -4.1e-17) || !(y <= 1.45e-11)) {
tmp = y * -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 <= (-4.1d-17)) .or. (.not. (y <= 1.45d-11))) then
tmp = y * (-0.5d0)
else
tmp = 0.918938533204673d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -4.1e-17) || !(y <= 1.45e-11)) {
tmp = y * -0.5;
} else {
tmp = 0.918938533204673;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -4.1e-17) or not (y <= 1.45e-11): tmp = y * -0.5 else: tmp = 0.918938533204673 return tmp
function code(x, y) tmp = 0.0 if ((y <= -4.1e-17) || !(y <= 1.45e-11)) tmp = Float64(y * -0.5); else tmp = 0.918938533204673; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -4.1e-17) || ~((y <= 1.45e-11))) tmp = y * -0.5; else tmp = 0.918938533204673; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -4.1e-17], N[Not[LessEqual[y, 1.45e-11]], $MachinePrecision]], N[(y * -0.5), $MachinePrecision], 0.918938533204673]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.1 \cdot 10^{-17} \lor \neg \left(y \leq 1.45 \cdot 10^{-11}\right):\\
\;\;\;\;y \cdot -0.5\\
\mathbf{else}:\\
\;\;\;\;0.918938533204673\\
\end{array}
\end{array}
if y < -4.1000000000000001e-17 or 1.45e-11 < y Initial program 100.0%
associate-+l-100.0%
sub-neg100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around inf 97.1%
Taylor expanded in y around inf 95.5%
Taylor expanded in x around 0 51.3%
if -4.1000000000000001e-17 < y < 1.45e-11Initial program 100.0%
associate-+l-100.0%
sub-neg100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around inf 50.3%
Taylor expanded in y around 0 50.5%
Final simplification50.9%
(FPCore (x y) :precision binary64 (if (or (<= x -54000000000000.0) (not (<= x 3.7))) (* x y) (* y -0.5)))
double code(double x, double y) {
double tmp;
if ((x <= -54000000000000.0) || !(x <= 3.7)) {
tmp = x * y;
} else {
tmp = 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 ((x <= (-54000000000000.0d0)) .or. (.not. (x <= 3.7d0))) then
tmp = x * y
else
tmp = y * (-0.5d0)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x <= -54000000000000.0) || !(x <= 3.7)) {
tmp = x * y;
} else {
tmp = y * -0.5;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -54000000000000.0) or not (x <= 3.7): tmp = x * y else: tmp = y * -0.5 return tmp
function code(x, y) tmp = 0.0 if ((x <= -54000000000000.0) || !(x <= 3.7)) tmp = Float64(x * y); else tmp = Float64(y * -0.5); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -54000000000000.0) || ~((x <= 3.7))) tmp = x * y; else tmp = y * -0.5; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -54000000000000.0], N[Not[LessEqual[x, 3.7]], $MachinePrecision]], N[(x * y), $MachinePrecision], N[(y * -0.5), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -54000000000000 \lor \neg \left(x \leq 3.7\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;y \cdot -0.5\\
\end{array}
\end{array}
if x < -5.4e13 or 3.7000000000000002 < x Initial program 100.0%
associate-+l-100.0%
sub-neg100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around inf 53.9%
Taylor expanded in x around inf 53.5%
*-commutative53.5%
Simplified53.5%
if -5.4e13 < x < 3.7000000000000002Initial program 100.0%
associate-+l-100.0%
sub-neg100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around inf 97.3%
Taylor expanded in y around inf 55.5%
Taylor expanded in x around 0 55.1%
Final simplification54.3%
(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%
sub-neg100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around inf 76.4%
associate--r-76.4%
*-commutative76.4%
distribute-lft-out--76.4%
Applied egg-rr76.4%
Final simplification76.4%
(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%
sub-neg100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around inf 76.4%
Taylor expanded in y around 0 23.8%
Final simplification23.8%
herbie shell --seed 2024043
(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))