Style - if(null) { return } vs. if(!null)
Does inverting the "if" improve performance?
Often when I edit one of my answers, it's because I want to better address the original question. The only problem is that I can't see the original question while I'm editing my answer!  I'd love to see the original question text beneath the "answer edit" form. This way I could scroll down slightly to read it if I wanted to, or just ignore it if not.  Current workaround is to click the 'return to answer' link and hope that you remember to launch it in a new tab/window, then tab back and forth.    Imported from this uservoice item: Is the possessive of "one" spelled "ones" or "one's"? I've been confused about this as long as I can remember. Should it be:     One should do ones duty.   or     One should do one's duty.   I'm guessing it should be the latter. But that doesn't sit well with the possessive pronoun 'its'. For example:     It is its own purpose.   vs.     It is it's own purpose.   Here, the former seems clearly correct. How to compute the marginal likelihood given two multivariate Normal distribution? Given that $a$~$\mathcal{N}(\mu, \Sigma)$ and $\mu$~$\mathcal{N}(0, \sigma^2 I)$, Is $p(a|\Sigma, \sigma)=\int p(a|\mu, \Sigma)p(\mu|\sigma)d\mu$ again a Normal distribution? And how to estimate the mean and variance respectively? Thanks a lot! How do I print a double value with full precision using cout? In my  I was printing a double using cout that got rounded when I wasn't expecting it.  How can I make cout print a double using full precision? I'm looking for the fastest way to determine if a long value is a perfect square (i.e. its square root is another integer):    I've done it the easy way, by using the built-in  function, but I'm wondering if there is a way to do it faster by restricting yourself to integer-only domain. Maintaining a lookup table is impractical (since there are about 231.5 integers whose square is less than 263).   Here is the very simple and straightforward way I'm doing it now:  public final static boolean isPerfectSquare(long n) {   if (n &lt; 0)     return false;    long tst = (long)(Math.sqrt(n) + 0.5);   return tst*tst == n; }   Note: I'm using this function in many  problems.  So no one else will ever have to maintain this code.  And this kind of micro-optimization could actually make a difference, since part of the challenge is to do every algorithm in less than a minute, and this function will need to be called millions of times in some problems.    I've tried the different solutions to the problem:   After exhaustive testing, I found that adding 0.5 to the result of Math.sqrt() is not necessary, at least not on my machine. The  was faster, but it gave incorrect results for n >= 410881.  However, as suggested by , we can use the FISR hack for n &lt; 410881. Newton's method was a good bit slower than Math.sqrt().  This is probably because Math.sqrt() uses something similar to Newton's Method, but implemented in the hardware so it's much faster than in Java.  Also, Newton's Method still required use of doubles. A modified Newton's method, which used a few tricks so that only integer math was involved, required some hacks to avoid overflow (I want this function to work with all positive 64-bit signed integers), and it was still slower than Math.sqrt(). Binary chop was even slower.  This makes sense because the binary chop will on average require 16 passes to find the square root of a 64-bit number. According to John's tests, using or statements is faster in C++ than using a switch, but in Java and C# there appears to be no difference between or and switch. I also tried making a lookup table (as a private static array of 64 boolean values).  Then instead of either switch or or statement, I would just say if(lookup[(int)(n&amp;0x3F)]) { test } else return false;.  To my surprise, this was (just slightly) slower. This is because . Evaluate the integral $$\int_0^{\pi/2} \frac{1}{1+\tan^\alpha{x}}\,\mathrm{d}x$$ Add an image directly from the clipboard I've tried to find other questions covering this, but (surprisingly) I did not find any.  When I want to add a screenshot to a post, as far I know the only way to do it is to save it as a file and then upload the file, using Stack Overflow's image hosting. OK, much better than finding a hosting site yourself, but sometimes I wish I could just paste the image from the clipboard.  It's not as straightforward as it may seem, I know. , and it needs a Java applet to get it done. How can you sync Blender configs between multiple machines? Object rotate in a strange way today i run into another problem. i dont know how i have done it (probably i clicked sth what i should not click) - anyway - since that moment my objects are behaving totally different when i try to rotate them. the objects are now rotating around the pivot point but they keep their alignment - not sure if i am clear. eg. if u would rotate a plane which is lies flat on the ground it makes the rotation but the faces of the plane would still be up and dont which shouldn't be the case with the "normal" rotation that i know. so i want to understand what i have done (because this kind of rotation could be also usefull sometimes for me) and how can i return it in the case it happens again. My chain broke and in a moment of silliness (I was cold wet and slightly annoyed)  I threw the broken one away before thinking about measuring the new one.  Is there a guide to getting the chain length/tension correct ?  It's an 8 speed road bike (Shimano Sora back, double ring front) Error in pip: unsupported operand type(s) for -=: 'Retry' and 'int' I'm trying install the requests, but I can't do that. I'm using Ubuntu 16.04  I tried to install using  $ sudo pip install requests   and I get the following error   Collecting requests Exception: Traceback (most recent call last):   File "/usr/lib/python2.7/dist-packages/pip/basecommand.py", line 209, in main     status = self.run(options, args)   File "/usr/lib/python2.7/dist-packages/pip/commands/install.py", line 317, in run     requirement_set.prepare_files(finder)   File "/usr/lib/python2.7/dist-packages/pip/req/req_set.py", line 360, in prepare_files     ignore_dependencies=self.ignore_dependencies))   File "/usr/lib/python2.7/dist-packages/pip/req/req_set.py", line 512, in _prepare_file     finder, self.upgrade, require_hashes)   File "/usr/lib/python2.7/dist-packages/pip/req/req_install.py", line 273, in populate_link     self.link = finder.find_requirement(self, upgrade)   File "/usr/lib/python2.7/dist-packages/pip/index.py", line 442, in find_requirement     all_candidates = self.find_all_candidates(req.name)   File "/usr/lib/python2.7/dist-packages/pip/index.py", line 400, in find_all_candidates     for page in self._get_pages(url_locations, project_name):   File "/usr/lib/python2.7/dist-packages/pip/index.py", line 545, in _get_pages     page = self._get_page(location)   File "/usr/lib/python2.7/dist-packages/pip/index.py", line 648, in _get_page     return HTMLPage.get_page(link, session=self.session)   File "/usr/lib/python2.7/dist-packages/pip/index.py", line 757, in get_page     "Cache-Control": "max-age=600",   File "/usr/share/python-wheels/requests-2.9.1-py2.py3-none-any.whl/requests/sessions.py", line 480, in get     return self.request('GET', url, **kwargs)   File "/usr/lib/python2.7/dist-packages/pip/download.py", line 378, in request     return super(PipSession, self).request(method, url, *args, **kwargs)   File "/usr/share/python-wheels/requests-2.9.1-py2.py3-none-any.whl/requests/sessions.py", line 468, in request     resp = self.send(prep, **send_kwargs)   File "/usr/share/python-wheels/requests-2.9.1-py2.py3-none-any.whl/requests/sessions.py", line 597, in send     history = [resp for resp in gen] if allow_redirects else []   File "/usr/share/python-wheels/requests-2.9.1-py2.py3-none-any.whl/requests/sessions.py", line 195, in resolve_redirects     **adapter_kwargs   File "/usr/share/python-wheels/requests-2.9.1-py2.py3-none-any.whl/requests/sessions.py", line 576, in send     r = adapter.send(request, **kwargs)   File "/usr/share/python-wheels/CacheControl-0.11.5-py2.py3-none-any.whl/cachecontrol/adapter.py", line 46, in send     resp = super(CacheControlAdapter, self).send(request, **kw)   File "/usr/share/python-wheels/requests-2.9.1-py2.py3-none-any.whl/requests/adapters.py", line 376, in send     timeout=timeout   File "/usr/share/python-wheels/urllib3-1.13.1-py2.py3-none-any.whl/urllib3/connectionpool.py", line 610, in urlopen     _stacktrace=sys.exc_info()[2])   File "/usr/share/python-wheels/urllib3-1.13.1-py2.py3-none-any.whl/urllib3/util/retry.py", line 228, in increment     total -= 1 TypeError: unsupported operand type(s) for -=: 'Retry' and 'int'   My python version is the 2.7 and the pip is 8.1.1 Sum of independent Gamma distributions is a Gamma distribution If $X\sim \Gamma(a_1,b)$ and $Y \sim \Gamma(a_2,b)$, I need to prove $X+Y\sim\Gamma(a_1+a_2,b)$ if $X$ and $Y$ are independent. I am trying to apply formula for independence integral and just trying to multiply the gamma function but stuck ? Eigenvectors of real symmetric matrices are orthogonal Can someone point me to a paper, or show here, why symmetric matrices have orthogonal eigenvectors? In particular, I'd like to see proof that for a symmetric matrix $A$ there exists decomposition $A = Q\Lambda Q^{-1} = Q\Lambda Q^{T}$ where $\Lambda$ is diagonal. Is my Geoserver "Direct WMS Integration" working? A friend of mine accidentally left a carton of eggs on her counter, unrefrigerated, for three days. The eggs had been previously refrigerated both at the store and at home. Now she's planning to do some more cooking which requires eggs, and is wondering if it's still safe to use them for baking. I believe she is planning on baking cookies with them, so they would be baked at fairly high temperatures for probably at least 10 minutes. Would this be safe, or are eggs left unrefrigerated for that long not safe for consumption? BasicTeX - how to identify packages that need to be added after an upgrade I'm using the BasicTeX distribution on OS X and recently upgrade from the 2011 to the 2012 distribution. This forces me to add the packages that I had added over time to the BasixTeX 2011 installation by pulling them from the online repository with tlmgr. Is there a good way to list these packages that are not part of BasicTeX but are part of the complete TeXLive? Proving $\sum_{k=0}^n(-1)^k\binom nk=0$ Show that $$\sum_{k=0}^n(-1)^k\binom nk=0$$ So for odd $n$ we have an even number of terms. So $\binom nk=\binom n{n-k}$ which have opposite signs. Thus the sum is 0.  For even $n$ we have that $$\sum_{k=0}^n(-1)^k\binom nk= \binom n0+\sum_{k=1}^{n-1}(-1)^k\binom nk+\binom nn$$ Now $$\sum_{k=1}^{n-1}(-1)^k\binom nk= \sum_{k=1}^{n-1}(-1)^k\left[\binom{n-1}k+\binom{n-1}{k-1}\right]$$ What would that sum be in the square brackets? Redshift and conformal time What is the relationship between redshift and conformal time ?   For example in a paper i found:   taking $z_e = 3234 $ at the time of radiaton-matter equality yields the conformal time $\frac{\eta_e}{\eta_0} = 0.007$ and taking $z_E=0.39$ at matter-$\Lambda$ equality yields $\frac{\eta_E}{\eta_0}=0.894$ and setting redshift at decoupling $z_d=1089$ yields $\frac{\eta_d}{\eta_0} = 0.0195$  where $\eta_0$ is the present decoupling time.  Further some cosmological parameters are given as :  $\Omega_r = 8.36 \times 10^{-5}, \Omega_m = \Omega_b + \Omega_{dm} = 0.044 +0.226, \Omega_\Lambda = 0.73,  H_0=0.72$  Now how can i calculate all those $\eta_e, \eta_E, \eta_d, \eta_0$ from given redshift values and/or above parameters ? I searched whole of my text books trying to find an explicit relation for conformal time $\eta$ but all i got was $ \mathrm{d}t=a(t)\mathrm{d}\eta$. Any help would be very helpful. How can I install more recent versions of software than what Debian provides? Is there a measurable set $A$ such that $m(A \cap B) = \frac12 m(B)$ for every open set $B$? Is there a measurable set $A$ such that $m(A \cap B)= \frac12 m(B)$ for every open set $B$?  Edit: (t.b.) See also  for further answers.