
(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
(if (<= y -4.2e+123)
(* x y)
(if (<= y -8.0)
(* y -0.5)
(if (<= y 1.0)
(- 0.918938533204673 x)
(if (or (<= y 7.5e+114)
(and (not (<= y 6.8e+225))
(or (<= y 1.2e+268) (not (<= y 5.8e+292)))))
(* x y)
(* y -0.5))))))
double code(double x, double y) {
double tmp;
if (y <= -4.2e+123) {
tmp = x * y;
} else if (y <= -8.0) {
tmp = y * -0.5;
} else if (y <= 1.0) {
tmp = 0.918938533204673 - x;
} else if ((y <= 7.5e+114) || (!(y <= 6.8e+225) && ((y <= 1.2e+268) || !(y <= 5.8e+292)))) {
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 (y <= (-4.2d+123)) then
tmp = x * y
else if (y <= (-8.0d0)) then
tmp = y * (-0.5d0)
else if (y <= 1.0d0) then
tmp = 0.918938533204673d0 - x
else if ((y <= 7.5d+114) .or. (.not. (y <= 6.8d+225)) .and. (y <= 1.2d+268) .or. (.not. (y <= 5.8d+292))) 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 (y <= -4.2e+123) {
tmp = x * y;
} else if (y <= -8.0) {
tmp = y * -0.5;
} else if (y <= 1.0) {
tmp = 0.918938533204673 - x;
} else if ((y <= 7.5e+114) || (!(y <= 6.8e+225) && ((y <= 1.2e+268) || !(y <= 5.8e+292)))) {
tmp = x * y;
} else {
tmp = y * -0.5;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -4.2e+123: tmp = x * y elif y <= -8.0: tmp = y * -0.5 elif y <= 1.0: tmp = 0.918938533204673 - x elif (y <= 7.5e+114) or (not (y <= 6.8e+225) and ((y <= 1.2e+268) or not (y <= 5.8e+292))): tmp = x * y else: tmp = y * -0.5 return tmp
function code(x, y) tmp = 0.0 if (y <= -4.2e+123) tmp = Float64(x * y); elseif (y <= -8.0) tmp = Float64(y * -0.5); elseif (y <= 1.0) tmp = Float64(0.918938533204673 - x); elseif ((y <= 7.5e+114) || (!(y <= 6.8e+225) && ((y <= 1.2e+268) || !(y <= 5.8e+292)))) tmp = Float64(x * y); else tmp = Float64(y * -0.5); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -4.2e+123) tmp = x * y; elseif (y <= -8.0) tmp = y * -0.5; elseif (y <= 1.0) tmp = 0.918938533204673 - x; elseif ((y <= 7.5e+114) || (~((y <= 6.8e+225)) && ((y <= 1.2e+268) || ~((y <= 5.8e+292))))) tmp = x * y; else tmp = y * -0.5; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -4.2e+123], N[(x * y), $MachinePrecision], If[LessEqual[y, -8.0], N[(y * -0.5), $MachinePrecision], If[LessEqual[y, 1.0], N[(0.918938533204673 - x), $MachinePrecision], If[Or[LessEqual[y, 7.5e+114], And[N[Not[LessEqual[y, 6.8e+225]], $MachinePrecision], Or[LessEqual[y, 1.2e+268], N[Not[LessEqual[y, 5.8e+292]], $MachinePrecision]]]], N[(x * y), $MachinePrecision], N[(y * -0.5), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.2 \cdot 10^{+123}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq -8:\\
\;\;\;\;y \cdot -0.5\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;0.918938533204673 - x\\
\mathbf{elif}\;y \leq 7.5 \cdot 10^{+114} \lor \neg \left(y \leq 6.8 \cdot 10^{+225}\right) \land \left(y \leq 1.2 \cdot 10^{+268} \lor \neg \left(y \leq 5.8 \cdot 10^{+292}\right)\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;y \cdot -0.5\\
\end{array}
\end{array}
if y < -4.19999999999999988e123 or 1 < y < 7.5000000000000001e114 or 6.80000000000000037e225 < y < 1.2e268 or 5.79999999999999981e292 < y Initial program 100.0%
associate-+l-100.0%
sub-neg100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around inf 97.9%
Taylor expanded in x around inf 63.0%
*-commutative63.0%
Simplified63.0%
if -4.19999999999999988e123 < y < -8 or 7.5000000000000001e114 < y < 6.80000000000000037e225 or 1.2e268 < y < 5.79999999999999981e292Initial program 100.0%
associate-+l-100.0%
sub-neg100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around inf 99.1%
Taylor expanded in x around 0 63.5%
if -8 < y < 1Initial program 100.0%
associate-+l-100.0%
sub-neg100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around 0 97.0%
neg-mul-197.0%
sub-neg97.0%
Simplified97.0%
Final simplification79.4%
(FPCore (x y)
:precision binary64
(let* ((t_0 (* x (+ y -1.0))))
(if (<= x -0.0034)
t_0
(if (<= x -2.3e-298)
(* y -0.5)
(if (<= x 5.3e-188)
(- 0.918938533204673 x)
(if (<= x 1.6e-142)
(* y -0.5)
(if (<= x 55.0) (- 0.918938533204673 x) t_0)))))))
double code(double x, double y) {
double t_0 = x * (y + -1.0);
double tmp;
if (x <= -0.0034) {
tmp = t_0;
} else if (x <= -2.3e-298) {
tmp = y * -0.5;
} else if (x <= 5.3e-188) {
tmp = 0.918938533204673 - x;
} else if (x <= 1.6e-142) {
tmp = y * -0.5;
} else if (x <= 55.0) {
tmp = 0.918938533204673 - x;
} else {
tmp = 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 = x * (y + (-1.0d0))
if (x <= (-0.0034d0)) then
tmp = t_0
else if (x <= (-2.3d-298)) then
tmp = y * (-0.5d0)
else if (x <= 5.3d-188) then
tmp = 0.918938533204673d0 - x
else if (x <= 1.6d-142) then
tmp = y * (-0.5d0)
else if (x <= 55.0d0) then
tmp = 0.918938533204673d0 - x
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = x * (y + -1.0);
double tmp;
if (x <= -0.0034) {
tmp = t_0;
} else if (x <= -2.3e-298) {
tmp = y * -0.5;
} else if (x <= 5.3e-188) {
tmp = 0.918938533204673 - x;
} else if (x <= 1.6e-142) {
tmp = y * -0.5;
} else if (x <= 55.0) {
tmp = 0.918938533204673 - x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y): t_0 = x * (y + -1.0) tmp = 0 if x <= -0.0034: tmp = t_0 elif x <= -2.3e-298: tmp = y * -0.5 elif x <= 5.3e-188: tmp = 0.918938533204673 - x elif x <= 1.6e-142: tmp = y * -0.5 elif x <= 55.0: tmp = 0.918938533204673 - x else: tmp = t_0 return tmp
function code(x, y) t_0 = Float64(x * Float64(y + -1.0)) tmp = 0.0 if (x <= -0.0034) tmp = t_0; elseif (x <= -2.3e-298) tmp = Float64(y * -0.5); elseif (x <= 5.3e-188) tmp = Float64(0.918938533204673 - x); elseif (x <= 1.6e-142) tmp = Float64(y * -0.5); elseif (x <= 55.0) tmp = Float64(0.918938533204673 - x); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y) t_0 = x * (y + -1.0); tmp = 0.0; if (x <= -0.0034) tmp = t_0; elseif (x <= -2.3e-298) tmp = y * -0.5; elseif (x <= 5.3e-188) tmp = 0.918938533204673 - x; elseif (x <= 1.6e-142) tmp = y * -0.5; elseif (x <= 55.0) tmp = 0.918938533204673 - x; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(x * N[(y + -1.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -0.0034], t$95$0, If[LessEqual[x, -2.3e-298], N[(y * -0.5), $MachinePrecision], If[LessEqual[x, 5.3e-188], N[(0.918938533204673 - x), $MachinePrecision], If[LessEqual[x, 1.6e-142], N[(y * -0.5), $MachinePrecision], If[LessEqual[x, 55.0], N[(0.918938533204673 - x), $MachinePrecision], t$95$0]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(y + -1\right)\\
\mathbf{if}\;x \leq -0.0034:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq -2.3 \cdot 10^{-298}:\\
\;\;\;\;y \cdot -0.5\\
\mathbf{elif}\;x \leq 5.3 \cdot 10^{-188}:\\
\;\;\;\;0.918938533204673 - x\\
\mathbf{elif}\;x \leq 1.6 \cdot 10^{-142}:\\
\;\;\;\;y \cdot -0.5\\
\mathbf{elif}\;x \leq 55:\\
\;\;\;\;0.918938533204673 - x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -0.00339999999999999981 or 55 < x Initial program 100.0%
associate-+l-100.0%
sub-neg100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in x around inf 98.7%
if -0.00339999999999999981 < x < -2.3000000000000001e-298 or 5.30000000000000014e-188 < x < 1.5999999999999999e-142Initial program 100.0%
associate-+l-100.0%
sub-neg100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around inf 68.5%
Taylor expanded in x around 0 67.1%
if -2.3000000000000001e-298 < x < 5.30000000000000014e-188 or 1.5999999999999999e-142 < x < 55Initial program 100.0%
associate-+l-100.0%
sub-neg100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around 0 64.5%
neg-mul-164.5%
sub-neg64.5%
Simplified64.5%
Final simplification82.1%
(FPCore (x y) :precision binary64 (if (or (<= y -1.35) (not (<= y 1.2))) (* y (- x 0.5)) (- 0.918938533204673 x)))
double code(double x, double y) {
double tmp;
if ((y <= -1.35) || !(y <= 1.2)) {
tmp = y * (x - 0.5);
} else {
tmp = 0.918938533204673 - x;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((y <= (-1.35d0)) .or. (.not. (y <= 1.2d0))) then
tmp = y * (x - 0.5d0)
else
tmp = 0.918938533204673d0 - x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -1.35) || !(y <= 1.2)) {
tmp = y * (x - 0.5);
} else {
tmp = 0.918938533204673 - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -1.35) or not (y <= 1.2): tmp = y * (x - 0.5) else: tmp = 0.918938533204673 - x return tmp
function code(x, y) tmp = 0.0 if ((y <= -1.35) || !(y <= 1.2)) tmp = Float64(y * Float64(x - 0.5)); else tmp = Float64(0.918938533204673 - x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -1.35) || ~((y <= 1.2))) tmp = y * (x - 0.5); else tmp = 0.918938533204673 - x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -1.35], N[Not[LessEqual[y, 1.2]], $MachinePrecision]], N[(y * N[(x - 0.5), $MachinePrecision]), $MachinePrecision], N[(0.918938533204673 - x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.35 \lor \neg \left(y \leq 1.2\right):\\
\;\;\;\;y \cdot \left(x - 0.5\right)\\
\mathbf{else}:\\
\;\;\;\;0.918938533204673 - x\\
\end{array}
\end{array}
if y < -1.3500000000000001 or 1.19999999999999996 < y Initial program 100.0%
associate-+l-100.0%
sub-neg100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around inf 98.4%
if -1.3500000000000001 < y < 1.19999999999999996Initial program 100.0%
associate-+l-100.0%
sub-neg100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around 0 97.0%
neg-mul-197.0%
sub-neg97.0%
Simplified97.0%
Final simplification97.7%
(FPCore (x y) :precision binary64 (if (or (<= x -0.68) (not (<= x 0.65))) (* x (+ y -1.0)) (- 0.918938533204673 (* y 0.5))))
double code(double x, double y) {
double tmp;
if ((x <= -0.68) || !(x <= 0.65)) {
tmp = x * (y + -1.0);
} 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 ((x <= (-0.68d0)) .or. (.not. (x <= 0.65d0))) then
tmp = x * (y + (-1.0d0))
else
tmp = 0.918938533204673d0 - (y * 0.5d0)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x <= -0.68) || !(x <= 0.65)) {
tmp = x * (y + -1.0);
} else {
tmp = 0.918938533204673 - (y * 0.5);
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -0.68) or not (x <= 0.65): tmp = x * (y + -1.0) else: tmp = 0.918938533204673 - (y * 0.5) return tmp
function code(x, y) tmp = 0.0 if ((x <= -0.68) || !(x <= 0.65)) tmp = Float64(x * Float64(y + -1.0)); else tmp = Float64(0.918938533204673 - Float64(y * 0.5)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -0.68) || ~((x <= 0.65))) tmp = x * (y + -1.0); else tmp = 0.918938533204673 - (y * 0.5); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -0.68], N[Not[LessEqual[x, 0.65]], $MachinePrecision]], N[(x * N[(y + -1.0), $MachinePrecision]), $MachinePrecision], N[(0.918938533204673 - N[(y * 0.5), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.68 \lor \neg \left(x \leq 0.65\right):\\
\;\;\;\;x \cdot \left(y + -1\right)\\
\mathbf{else}:\\
\;\;\;\;0.918938533204673 - y \cdot 0.5\\
\end{array}
\end{array}
if x < -0.680000000000000049 or 0.650000000000000022 < x Initial program 100.0%
associate-+l-100.0%
sub-neg100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in x around inf 99.4%
if -0.680000000000000049 < x < 0.650000000000000022Initial program 100.0%
associate-+l-100.0%
sub-neg100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in x around 0 98.4%
Final simplification98.9%
(FPCore (x y) :precision binary64 (if (or (<= x -0.5) (not (<= x 0.5))) (* x y) (* y -0.5)))
double code(double x, double y) {
double tmp;
if ((x <= -0.5) || !(x <= 0.5)) {
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 <= (-0.5d0)) .or. (.not. (x <= 0.5d0))) 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 <= -0.5) || !(x <= 0.5)) {
tmp = x * y;
} else {
tmp = y * -0.5;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -0.5) or not (x <= 0.5): tmp = x * y else: tmp = y * -0.5 return tmp
function code(x, y) tmp = 0.0 if ((x <= -0.5) || !(x <= 0.5)) 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 <= -0.5) || ~((x <= 0.5))) tmp = x * y; else tmp = y * -0.5; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -0.5], N[Not[LessEqual[x, 0.5]], $MachinePrecision]], N[(x * y), $MachinePrecision], N[(y * -0.5), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.5 \lor \neg \left(x \leq 0.5\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;y \cdot -0.5\\
\end{array}
\end{array}
if x < -0.5 or 0.5 < x Initial program 100.0%
associate-+l-100.0%
sub-neg100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around inf 54.2%
Taylor expanded in x around inf 53.6%
*-commutative53.6%
Simplified53.6%
if -0.5 < x < 0.5Initial program 100.0%
associate-+l-100.0%
sub-neg100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around inf 51.5%
Taylor expanded in x around 0 50.5%
Final simplification52.0%
(FPCore (x y) :precision binary64 (* y -0.5))
double code(double x, double y) {
return y * -0.5;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = y * (-0.5d0)
end function
public static double code(double x, double y) {
return y * -0.5;
}
def code(x, y): return y * -0.5
function code(x, y) return Float64(y * -0.5) end
function tmp = code(x, y) tmp = y * -0.5; end
code[x_, y_] := N[(y * -0.5), $MachinePrecision]
\begin{array}{l}
\\
y \cdot -0.5
\end{array}
Initial program 100.0%
associate-+l-100.0%
sub-neg100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around inf 52.8%
Taylor expanded in x around 0 27.1%
Final simplification27.1%
herbie shell --seed 2024055
(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))