Factorial calculation : unsigned long long overflows, How to use uintmax_t?
Calculate the factorial of an arbitrarily large number, showing all the digits
Producing PDF/X compliant document with XeLaTeX A vessel is filled with liquid,3 parts of which are water and 5 parts syrup.How much of the mixture must be drawn off and replaced with water so that the mixture may be half water and half syrup?  What is the best possible way to solve this question? Intuition behind the definition of a measurable set Did this character lose a limb in “The Force Awakens?” Inspired by  which states limb loss as a recurring theme, I started thinking about the final lightsaber battle. After watching The Force Awakens the second time, I was not sure if      Kylo Ren   lost a limb or just lost his lightsaber. We definitely see      Rey slash at Ren’s right hand.   So knowing that context:      Did Kylo Ren actually lose his arm/hand? I want to implement the EM algorithm manually and then compare it to the results of the normalmixEM of mixtools package. Of course, I would be happy if they both lead to the same results. The main reference is Geoffrey McLachlan (2000), .  I have a mixture density of two Gaussians, in general form, the log-likelihood is given by (McLachlan page 48):      $$ \log L_c(\Psi) = \sum_{i=1}^g \sum_{j=1}^n z_{ij}\{\log \pi_i + \log f_i(y_i;\theta_i)\}. $$ The $z_{ij}$ are $1$, if the observation was from the $i$th component density, otherwise $0$. The $f_i$ is the density of the normal distribution. The $\pi$ is the mixture proportion, so $\pi_1$ is the probability, that an observation is from the first Gaussian distribution and $\pi_2$ is the probability, that an observation is from the second Gaussian distribution.   The E step is now, calculation of the conditional expectation:      $$ Q(\Psi;\Psi^{(0)}) = E_{\Psi(0)}\{\log L_c(|\Psi)|y\}. $$ which leads, after a few derivations to the result (page 49):      \begin{align} \tau_i(y_j;\Psi^{(k)}) &amp;= \frac{\pi_i^{(k)}f_i(y_j;\theta_i^{(k)}}{f(y_j;\Psi^{(k)}}  \\[8pt]                        &amp;= \frac{\pi_i^{(k)}f_i(y_j;\theta_i^{(k)}}{\sum_{h=1}^g \pi_h^{(k)}f_h(y_j;\theta_h^{(k)})} \end{align} in the case of two Gaussians (page 82):      $$ \tau_i(y_j;\Psi) = \frac{\pi_i \phi(y_j;\mu_i,\Sigma_i)}{\sum_{h=1}^g \pi_h\phi(y_j; \mu_h,\Sigma_h)} $$ The M step is now the maximization of Q (page 49):      $$ Q(\Psi;\Psi^{(k)}) = \sum_{i=1}^g\sum_{j=1}^n\tau_i(y_j;\Psi^{(k)})\{\log \pi_i + \log f_i(y_j;\theta_i)\}. $$ This leads to (in the case of two Gaussians) (page 82):      \begin{align} \mu_i^{(k+1)} &amp;= \frac{\sum_{j=1}^n \tau_{ij}^{(k)}y_j}{\sum_{j=1}^n \tau_{ij}^{(k)}}  \\[8pt] \Sigma_i^{(k+1)} &amp;= \frac{\sum_{j=1}^n \tau_{ij}^{(k)}(y_j - \mu_i^{(k+1)})(y_j - \mu_i^{(k+1)})^T}{\sum_{j=1}^n \tau_{ij}^{(k)}} \end{align} and we know that (p. 50)      $$ \pi_i^{(k+1)} = \frac{\sum_{j=1}^n \tau_i(y_j;\Psi^{(k)})}{n}\qquad (i = 1, \ldots, g). $$ We repeat the E, M steps until $L(\Psi^{(k+1)})-L(\Psi^{(k)})$ is small.        I tried to write a R code (data can be found ).    # EM algorithm manually # dat is the data  # initial values pi1       &lt;-  0.5 pi2       &lt;-  0.5 mu1       &lt;- -0.01 mu2       &lt;-  0.01 sigma1    &lt;-  0.01 sigma2    &lt;-  0.02 loglik[1] &lt;-  0 loglik[2] &lt;- sum(pi1*(log(pi1) + log(dnorm(dat,mu1,sigma1)))) +               sum(pi2*(log(pi2) + log(dnorm(dat,mu2,sigma2))))  tau1 &lt;- 0 tau2 &lt;- 0 k    &lt;- 1  # loop while(abs(loglik[k+1]-loglik[k]) &gt;= 0.00001) {    # E step   tau1 &lt;- pi1*dnorm(dat,mean=mu1,sd=sigma1)/(pi1*dnorm(x,mean=mu1,sd=sigma1) +            pi2*dnorm(dat,mean=mu2,sd=sigma2))   tau2 &lt;- pi2*dnorm(dat,mean=mu2,sd=sigma2)/(pi1*dnorm(x,mean=mu1,sd=sigma1) +            pi2*dnorm(dat,mean=mu2,sd=sigma2))    # M step   pi1 &lt;- sum(tau1)/length(dat)   pi2 &lt;- sum(tau2)/length(dat)    mu1 &lt;- sum(tau1*x)/sum(tau1)   mu2 &lt;- sum(tau2*x)/sum(tau2)    sigma1 &lt;- sum(tau1*(x-mu1)^2)/sum(tau1)   sigma2 &lt;- sum(tau2*(x-mu2)^2)/sum(tau2)    loglik[k] &lt;- sum(tau1*(log(pi1) + log(dnorm(x,mu1,sigma1)))) +                 sum(tau2*(log(pi2) + log(dnorm(x,mu2,sigma2))))   k         &lt;- k+1 }   # compare library(mixtools) gm &lt;- normalmixEM(x, k=2, lambda=c(0.5,0.5), mu=c(-0.01,0.01), sigma=c(0.01,0.02)) gm$lambda gm$mu gm$sigma  gm$loglik   The algorithm is not working, since some observations have the likelihood of zero and the log of this is -Inf. Where is my mistake? Is "double hashing" a password less secure than just hashing it once? Is hashing a password twice before storage any more or less secure than just hashing it once?  What I'm talking about is doing this:  $hashed_password = hash(hash($plaintext_password));   instead of just this:  $hashed_password = hash($plaintext_password);   If it is less secure, can you provide a good explanation (or a link to one)?  Also, does the hash function used make a difference?  Does it make any difference if you mix md5 and sha1 (for example) instead of repeating the same hash function?  Note 1:  When I say "double hashing" I'm talking about hashing a password twice in an attempt to make it more obscured.  I'm not talking about the .  Note 2:  I know I need to add a random salt to really make it secure.  The question is whether hashing twice with the same algorithm helps or hurts the hash. How to permanently set environmental variables My variables are   LD_LIBRARY_PATH=/usr/lib/oracle/11.2/client64/lib ORACLE_HOME=/usr/lib/oracle/11.2/client64   How to save these variables permanently ? counting number of specific string in each row Why does the Replace() string method not modify my string variable? Papers published from an academic project (MSc or PhD) usually have two authors; the first author is the student who mainly conducted the research, and the second author is the professor who supervised the projects.  The corresponding author is the one who take the responsibility of a paper, and thus, some believe that students are not yet prepared to take this responsibility.  Ideally, who should be corresponding author for papers published by MSc or PhD projects?  I understand that it mainly depends on personal agreements and preferences, but I want to know which case is more reasonable from academic logic? How to burn a Windows .iso to a USB device? I want to burn a Windows ISO to a USB device in Ubuntu. How do I do this?   I know how to burn a Ubuntu ISO into a USB device, but with a Windows ISO it's not the same. Does an increasing sequence of reals converge if the difference of consecutive terms approaches zero? What is the difference between the search() and match() functions in the ?  I've read the  (), but I never seem to remember it.  I keep having to look it up and re-learn it.  I'm hoping that someone will answer it clearly with examples so that (perhaps) it will stick in my head.  Or at least I'll have a better place to return with my question and it will take less time to re-learn it. Is there an idiom that means "revealing a secret unintentionally"? I am thinking there could be an idiom that states that you or someone revealed a secret unintentionally? Can you think of an idiom like that? I am looking for an idiom I can use to write a blog post about the recent incident where Secretary Pompeo unintentionally revealed the dirty secrets behind the CIA. Does anyone know of any interesting subsets of the Cantor set? When I first started thinking about this, I thought that since the Cantor set $C$ is the intersection of disjoint unions of closed sets, those particular closed sets would be subsets of $C$. Those sets, however, happen to be intervals! The Cantor set contains no isolated points nor (open) intervals, so then what subsets does it contain besides $\varnothing$ and itself? How did nobody at Hogwarts (especially Dumbledore) figure out what killed Myrtle? Every subspace of a vector space has a complement I want to see if my proof is true or I thought very trivially?    If $H$ is a subspace of a finite dimensional vector space $V$, show there is a subspace $K$ such that $H\cap K=0$ and $H+K=V$    So far I have tried :    $H\subseteq V$ is a subspace $\Rightarrow\,\exists\;K=(V-H)\subseteq V$ $K$ is a subspace because it's the sum of two subspace $V$ and $(-H)$ Now we should prove that $H\cap K=0$ We assume $H\cap K\neq0\Rightarrow\exists\,\vec u\neq0\,,\,\vec u\in H\cap K$ $\vec u\in H\cap K\Rightarrow \begin{cases}\vec u\in H\\\vec u\in K\,\Rightarrow\vec u\in V-H\Rightarrow\vec u\in V,\,\vec u\notin H\end{cases}$ That's a contradiction so our hypothesis was wrong and $\vec u=0$ Switching motherboard without new install? Negative solution to $x^2=2^x$ Just out of curiosity I was trying to solve the equation $x^2=2^x$, initially I thought there would be just the two solutions $x=2$ and $x=4$, but wolfram shows that the two equations intersect at not 2 but 3 locations, the third being a negative value of $x$. The third solution isn't obvious like the other two, so I just have a few questions about the negative solution. Is it rational? is it commonly represented with a greek letter? If it is irrational is there a way to approximate it? Will my checked luggage freeze in the airplane? I'm taking some freeze-sensitive items in a checked luggage for a short flight. It's cheese, chocolate, toothpaste and wine. I would like to know whether the luggage can get "frozen" in the aircraft. Sometimes it happened to me that my stuff actually was quite cold after the flight, so I'd like to be quite sure. Especially the cheese was really expensive and freezing it would very likely demage it.  Usually I pack everything well in clothes, but this time the things are just too many so it's tough to do more than just protect the wine from breaking.  Some details: It's an A320 flight taking 1.5 hours, with Czech Airlines, from Paris CDG to Prague PRG.